This commit is contained in:
Alexey Milovidov 2020-07-16 11:33:51 +03:00
parent 68f9fd3767
commit 6df282e813
3 changed files with 3 additions and 8 deletions

View File

@ -82,8 +82,8 @@ void FileChecker::repair()
const String & name = name_size.first;
size_t expected_size = name_size.second;
String path = parentPath(files_info_path) + name;
auto real_size = disk->exists(path) ? disk->getFileSize(path) : 0; /// Race condition is Ok.
bool exists = disk->exists(path);
auto real_size = exists ? disk->getFileSize(path) : 0; /// No race condition assuming no one else is working with these files.
if (real_size < expected_size)
throw Exception(ErrorCodes::UNEXPECTED_END_OF_FILE, "Size of {} is less than expected. Size is {} but should be {}.",

View File

@ -264,7 +264,7 @@ void DiskLocal::createHardLink(const String & src_path, const String & dst_path)
void DiskLocal::truncateFile(const String & path, size_t size)
{
int res = truncate(path.c_str(), size);
int res = truncate((disk_path + path).c_str(), size);
if (-1 == res)
throwFromErrnoWithPath("Cannot truncate file " + path, path, ErrorCodes::CANNOT_TRUNCATE_FILE);
}

View File

@ -118,15 +118,10 @@ public:
{
try
{
LOG_TRACE(storage.log, "Done: {}\n", done);
if (!done)
{
/// Rollback partial writes.
streams.clear();
LOG_TRACE(storage.log, "Repairing");
storage.file_checker.repair();
}
}