diff --git a/include/abstract_data_store.h b/include/abstract_data_store.h index 2e0266814..976174378 100644 --- a/include/abstract_data_store.h +++ b/include/abstract_data_store.h @@ -18,6 +18,8 @@ template class AbstractDataStore public: AbstractDataStore(const location_t capacity, const size_t dim); + // virtual ~AbstractDataStore() = default; + // Return number of points returned virtual location_t load(const std::string &filename) = 0; diff --git a/include/logger.h b/include/logger.h index 1a1b79e71..0b17807db 100644 --- a/include/logger.h +++ b/include/logger.h @@ -14,8 +14,13 @@ namespace diskann { +#ifdef ENABLE_CUSTOM_LOGGER DISKANN_DLLEXPORT extern std::basic_ostream cout; DISKANN_DLLEXPORT extern std::basic_ostream cerr; +#else +using std::cerr; +using std::cout; +#endif enum class DISKANN_DLLEXPORT LogLevel { diff --git a/include/logger_impl.h b/include/logger_impl.h index 510c5aa08..03c65e0ce 100644 --- a/include/logger_impl.h +++ b/include/logger_impl.h @@ -11,6 +11,7 @@ namespace diskann { +#ifdef ENABLE_CUSTOM_LOGGER class ANNStreamBuf : public std::basic_streambuf { public: @@ -36,30 +37,25 @@ class ANNStreamBuf : public std::basic_streambuf int flush(); void logImpl(char *str, int numchars); -// Why the two buffer-sizes? If we are running normally, we are basically -// interacting with a character output system, so we short-circuit the -// output process by keeping an empty buffer and writing each character -// to stdout/stderr. But if we are running in OLS, we have to take all -// the text that is written to diskann::cout/diskann:cerr, consolidate it -// and push it out in one-shot, because the OLS infra does not give us -// character based output. Therefore, we use a larger buffer that is large -// enough to store the longest message, and continuously add characters -// to it. When the calling code outputs a std::endl or std::flush, sync() -// will be called and will output a log level, component name, and the text -// that has been collected. (sync() is also called if the buffer is full, so -// overflows/missing text are not a concern). -// This implies calling code _must_ either print std::endl or std::flush -// to ensure that the message is written immediately. -#ifdef ENABLE_CUSTOM_LOGGER + // Why the two buffer-sizes? If we are running normally, we are basically + // interacting with a character output system, so we short-circuit the + // output process by keeping an empty buffer and writing each character + // to stdout/stderr. But if we are running in OLS, we have to take all + // the text that is written to diskann::cout/diskann:cerr, consolidate it + // and push it out in one-shot, because the OLS infra does not give us + // character based output. Therefore, we use a larger buffer that is large + // enough to store the longest message, and continuously add characters + // to it. When the calling code outputs a std::endl or std::flush, sync() + // will be called and will output a log level, component name, and the text + // that has been collected. (sync() is also called if the buffer is full, so + // overflows/missing text are not a concern). + // This implies calling code _must_ either print std::endl or std::flush + // to ensure that the message is written immediately. + static const int BUFFER_SIZE = 1024; -#else - // Allocating an arbitrarily small buffer here because the overflow() and - // other function implementations push the BUFFER_SIZE chars into the - // buffer before flushing to fwrite. - static const int BUFFER_SIZE = 4; -#endif ANNStreamBuf(const ANNStreamBuf &); ANNStreamBuf &operator=(const ANNStreamBuf &); }; +#endif } // namespace diskann diff --git a/src/logger.cpp b/src/logger.cpp index dc27f718d..052f54877 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -10,13 +10,12 @@ namespace diskann { +#ifdef ENABLE_CUSTOM_LOGGER DISKANN_DLLEXPORT ANNStreamBuf coutBuff(stdout); DISKANN_DLLEXPORT ANNStreamBuf cerrBuff(stderr); DISKANN_DLLEXPORT std::basic_ostream cout(&coutBuff); DISKANN_DLLEXPORT std::basic_ostream cerr(&cerrBuff); - -#ifdef ENABLE_CUSTOM_LOGGER std::function g_logger; void SetCustomLogger(std::function logger) @@ -24,7 +23,6 @@ void SetCustomLogger(std::function logger) g_logger = logger; diskann::cout << "Set Custom Logger" << std::endl; } -#endif ANNStreamBuf::ANNStreamBuf(FILE *fp) { @@ -38,11 +36,7 @@ ANNStreamBuf::ANNStreamBuf(FILE *fp) } _fp = fp; _logLevel = (_fp == stdout) ? LogLevel::LL_Info : LogLevel::LL_Error; -#ifdef ENABLE_CUSTOM_LOGGER _buf = new char[BUFFER_SIZE + 1]; // See comment in the header -#else - _buf = new char[BUFFER_SIZE]; // See comment in the header -#endif std::memset(_buf, 0, (BUFFER_SIZE) * sizeof(char)); setp(_buf, _buf + BUFFER_SIZE - 1); @@ -88,17 +82,16 @@ int ANNStreamBuf::flush() } void ANNStreamBuf::logImpl(char *str, int num) { -#ifdef ENABLE_CUSTOM_LOGGER str[num] = '\0'; // Safe. See the c'tor. // Invoke the OLS custom logging function. if (g_logger) { g_logger(_logLevel, str); } +} #else - fwrite(str, sizeof(char), num, _fp); - fflush(_fp); +using std::cerr; +using std::cout; #endif -} } // namespace diskann