Merge pull request #44706 from kssenii/fix-filelog-tests

Fix flaky filelog tests with database ordinary
This commit is contained in:
Alexey Milovidov 2022-12-29 20:31:08 +03:00 committed by GitHub
commit 4c80f597c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,6 +72,21 @@ StorageFileLog::StorageFileLog(
storage_metadata.setComment(comment);
setInMemoryMetadata(storage_metadata);
if (!fileOrSymlinkPathStartsWith(path, getContext()->getUserFilesPath()))
{
if (attach)
{
LOG_ERROR(log, "The absolute data path should be inside `user_files_path`({})", getContext()->getUserFilesPath());
return;
}
else
throw Exception(
ErrorCodes::BAD_ARGUMENTS,
"The absolute data path should be inside `user_files_path`({})",
getContext()->getUserFilesPath());
}
bool created_metadata_directory = false;
try
{
if (!attach)
@ -84,6 +99,7 @@ StorageFileLog::StorageFileLog(
metadata_base_path);
}
disk->createDirectories(metadata_base_path);
created_metadata_directory = true;
}
loadMetaFiles(attach);
@ -101,7 +117,12 @@ StorageFileLog::StorageFileLog(
catch (...)
{
if (!attach)
{
if (created_metadata_directory)
disk->removeRecursive(metadata_base_path);
throw;
}
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
@ -124,12 +145,6 @@ void StorageFileLog::loadMetaFiles(bool attach)
void StorageFileLog::loadFiles()
{
if (!fileOrSymlinkPathStartsWith(path, getContext()->getUserFilesPath()))
{
throw Exception(
ErrorCodes::BAD_ARGUMENTS, "The absolute data path should be inside `user_files_path`({})", getContext()->getUserFilesPath());
}
auto absolute_path = std::filesystem::absolute(path);
absolute_path = absolute_path.lexically_normal(); /// Normalize path.
@ -372,43 +387,26 @@ void StorageFileLog::drop()
void StorageFileLog::startup()
{
try
{
if (task)
{
task->holder->activateAndSchedule();
}
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
if (task)
task->holder->activateAndSchedule();
}
void StorageFileLog::shutdown()
{
try
if (task)
{
if (task)
{
task->stream_cancelled = true;
task->stream_cancelled = true;
/// Reader thread may wait for wake up
wakeUp();
/// Reader thread may wait for wake up
wakeUp();
LOG_TRACE(log, "Waiting for cleanup");
task->holder->deactivate();
}
LOG_TRACE(log, "Waiting for cleanup");
task->holder->deactivate();
/// If no reading call and threadFunc, the log files will never
/// be opened, also just leave the work of close files and
/// store meta to streams. because if we close files in here,
/// may result in data race with unfinishing reading pipeline
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
task->holder->deactivate();
}
}
void StorageFileLog::assertStreamGood(const std::ifstream & reader)