Apply comments

This commit is contained in:
Antonio Andelic 2023-01-31 14:18:54 +00:00
parent 1786237be6
commit 8457d3bf3d

View File

@ -7,6 +7,7 @@
#include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/trim.hpp>
#include <Common/filesystemHelpers.h>
#include <Common/Exception.h> #include <Common/Exception.h>
#include <Common/SipHash.h> #include <Common/SipHash.h>
#include <Common/logger_useful.h> #include <Common/logger_useful.h>
@ -162,7 +163,9 @@ public:
rotate(record.header.index); rotate(record.header.index);
// writing at least 1 log is requirement - we don't want empty log files // writing at least 1 log is requirement - we don't want empty log files
const bool log_too_big = record.header.index != getStartIndex() && log_file_settings.max_size != 0 && initial_file_size + file_buffer->count() > log_file_settings.max_size; // we use count() that can be unreliable for more complex WriteBuffers, so we should be careful if we change the type of it in the future
const bool log_too_big = record.header.index != getStartIndex() && log_file_settings.max_size != 0
&& initial_file_size + file_buffer->count() > log_file_settings.max_size;
if (log_too_big) if (log_too_big)
{ {
@ -325,25 +328,25 @@ private:
const auto & file_buffer = getFileBuffer(); const auto & file_buffer = getFileBuffer();
#ifdef OS_LINUX #ifdef OS_LINUX
{ {
int res = fallocate(file_buffer.getFD(), FALLOC_FL_KEEP_SIZE, 0, log_file_settings.max_size + log_file_settings.overallocate_size); int res = 0;
if (res == ENOSPC) do
{ {
LOG_FATAL(log, "Failed to allocate enough space on disk for logs"); res = fallocate(file_buffer.getFD(), FALLOC_FL_KEEP_SIZE, 0, log_file_settings.max_size + log_file_settings.overallocate_size);
return; } while (errno == EINTR);
}
if (res != 0) if (res != 0)
{
if (errno == ENOSPC)
{
LOG_FATAL(log, "Failed to allocate enough space on disk for logs");
return;
}
LOG_WARNING(log, "Could not preallocate space on disk using fallocate. Error: {}, errno: {}", errnoToString(), errno); LOG_WARNING(log, "Could not preallocate space on disk using fallocate. Error: {}, errno: {}", errnoToString(), errno);
}
} }
#endif #endif
initial_file_size = getSizeFromFileDescriptor(file_buffer.getFD());
struct stat buf;
{
[[maybe_unused]] int res = fstat(file_buffer.getFD(), &buf);
assert(res == 0);
}
initial_file_size = buf.st_size;
prealloc_done = true; prealloc_done = true;
} }
@ -1066,6 +1069,8 @@ bool Changelog::flush()
return !*failed_ptr; return !*failed_ptr;
} }
// if we are shutting down let's return true to avoid abort inside NuRaft
// this can only happen when the config change is appended so no data loss should happen
return true; return true;
} }