mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-16 03:12:43 +00:00
Fix stress tests
This commit is contained in:
parent
ad34ff24dc
commit
6320a1c4e1
@ -469,7 +469,7 @@ CachedOnDiskReadBufferFromFile::getImplementationBuffer(FileSegment & file_segme
|
||||
bool CachedOnDiskReadBufferFromFile::completeFileSegmentAndGetNext()
|
||||
{
|
||||
auto * current_file_segment = &file_segments->front();
|
||||
const auto & completed_range = current_file_segment->range();
|
||||
auto completed_range = current_file_segment->range();
|
||||
|
||||
if (enable_logging)
|
||||
appendFilesystemCacheLog(completed_range, read_type);
|
||||
|
@ -371,25 +371,36 @@ KeyTransactionPtr FileCache::createKeyTransaction(const Key & key, KeyNotFoundPo
|
||||
{
|
||||
auto lock = metadata_guard.lock();
|
||||
|
||||
cleanup_keys_metadata_queue->clear([this](const Key & cleanup_key)
|
||||
{
|
||||
[[maybe_unused]] const bool erased = metadata.erase(cleanup_key);
|
||||
chassert(erased);
|
||||
// cleanup_keys_metadata_queue->clear([this](const Key & cleanup_key)
|
||||
// {
|
||||
// auto it = metadata.find(cleanup_key);
|
||||
// if (it == metadata.end())
|
||||
// throw Exception(ErrorCodes::LOGICAL_ERROR, "No such key {} in metadata", cleanup_key);
|
||||
|
||||
try
|
||||
{
|
||||
const fs::path prefix_path = fs::path(getPathInLocalCache(cleanup_key)).parent_path();
|
||||
if (fs::exists(prefix_path) && fs::is_empty(prefix_path))
|
||||
fs::remove_all(prefix_path);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
tryLogCurrentException(__PRETTY_FUNCTION__);
|
||||
}
|
||||
});
|
||||
// auto guard = it->second->guard;
|
||||
// auto key_lock = guard->lock();
|
||||
|
||||
// [[maybe_unused]] const bool erased = metadata.erase(it);
|
||||
// chassert(erased);
|
||||
|
||||
// try
|
||||
// {
|
||||
// const fs::path prefix_path = fs::path(getPathInLocalCache(cleanup_key)).parent_path();
|
||||
// if (fs::exists(prefix_path) && fs::is_empty(prefix_path))
|
||||
// fs::remove_all(prefix_path);
|
||||
// }
|
||||
// catch (...)
|
||||
// {
|
||||
// tryLogCurrentException(__PRETTY_FUNCTION__);
|
||||
// }
|
||||
// });
|
||||
|
||||
auto it = metadata.find(key);
|
||||
if (it == metadata.end())
|
||||
bool erased = false;
|
||||
if (it != metadata.end() && it->second->removed)
|
||||
erased = metadata.erase(it);
|
||||
|
||||
if (erased || it == metadata.end())
|
||||
{
|
||||
switch (key_not_found_policy)
|
||||
{
|
||||
@ -918,9 +929,11 @@ void KeyTransaction::cleanupKeyDirectory() const
|
||||
return;
|
||||
|
||||
/// Someone might still need this directory.
|
||||
if (!offsets.empty())
|
||||
if (!key_metadata.empty())
|
||||
return;
|
||||
|
||||
key_metadata.removed = true;
|
||||
|
||||
/// Now `offsets` empty and the key lock is still locked.
|
||||
/// So it is guaranteed that no one will add something.
|
||||
|
||||
|
@ -167,6 +167,8 @@ public:
|
||||
|
||||
KeyGuardPtr guard = std::make_shared<KeyGuard>();
|
||||
bool created_base_directory = false;
|
||||
|
||||
bool removed = false;
|
||||
};
|
||||
using KeyMetadataPtr = std::shared_ptr<KeyMetadata>;
|
||||
|
||||
@ -384,15 +386,18 @@ struct KeyTransactionCreator
|
||||
{
|
||||
KeyTransactionCreator(
|
||||
const FileCacheKey & key_,
|
||||
FileCache::KeyMetadata & offsets_,
|
||||
FileCache::KeyMetadata & key_metadata_,
|
||||
KeysQueuePtr cleanup_keys_metadata_queue_,
|
||||
const FileCache * cache_)
|
||||
: key(key_), offsets(offsets_), cleanup_keys_metadata_queue(cleanup_keys_metadata_queue_), cache(cache_) {}
|
||||
: key(key_)
|
||||
, key_metadata(key_metadata_)
|
||||
, cleanup_keys_metadata_queue(cleanup_keys_metadata_queue_)
|
||||
, cache(cache_) {}
|
||||
|
||||
KeyTransactionPtr create();
|
||||
|
||||
FileCacheKey key;
|
||||
FileCache::KeyMetadata & offsets;
|
||||
FileCache::KeyMetadata & key_metadata;
|
||||
KeysQueuePtr cleanup_keys_metadata_queue;
|
||||
const FileCache * cache;
|
||||
};
|
||||
@ -420,8 +425,8 @@ struct KeyTransaction : private boost::noncopyable
|
||||
|
||||
bool isLastHolder(size_t offset);
|
||||
|
||||
FileCache::KeyMetadata & getOffsets() { return offsets; }
|
||||
const FileCache::KeyMetadata & getOffsets() const { return offsets; }
|
||||
FileCache::KeyMetadata & getKeyMetadata() { return key_metadata; }
|
||||
const FileCache::KeyMetadata & getKeyMetadata() const { return key_metadata; }
|
||||
|
||||
std::vector<size_t> delete_offsets;
|
||||
|
||||
@ -433,7 +438,7 @@ private:
|
||||
const FileCache * cache;
|
||||
|
||||
KeyGuard::Lock lock;
|
||||
FileCache::KeyMetadata & offsets;
|
||||
FileCache::KeyMetadata & key_metadata;
|
||||
KeysQueuePtr cleanup_keys_metadata_queue;
|
||||
|
||||
Poco::Logger * log;
|
||||
|
Loading…
Reference in New Issue
Block a user