Merge 'cnch_dev_s3_unique_index_handler' into 'cnch-dev'

fix(clickhousech@m-5283670005): fix s3 handler for unique index read

See merge request: !25432
This commit is contained in:
勾王敏浩 2024-09-27 07:36:08 +00:00 committed by Fred Wang
parent 9519515809
commit fda10ec5ac
6 changed files with 30 additions and 2 deletions

View File

@ -116,6 +116,10 @@ public:
//
// Safe for concurrent use by multiple threads.
virtual Status Read(uint64_t offset, size_t n, Slice * result, char * scratch, bool * from_local) const = 0;
// After the iter call ends, we need to explicitly release the buffer, otherwise there may be too many open files due to remote handles.
// Safe for concurrent use by multiple threads.
virtual void releaseRemoteFD() const { }
};
// A file abstraction for sequential writing. The implementation

View File

@ -47,7 +47,11 @@ Status IndexFileReader::Open(const RemoteFileInfo & remote_file)
std::unique_ptr<RandomAccessFile> file;
Status s = rep->options.env->NewRandomAccessRemoteFileWithCache(remote_file, rep->options.remote_file_cache, &file);
if (s.ok())
{
s = Table::Open(rep->options, std::move(file), remote_file.size, &rep->table_reader);
/// directly release remote FD, as SSTable read from footer, meta, etc, then data block
rep->table_reader->releaseRemoteFD();
}
return s;
}

View File

@ -141,6 +141,13 @@ namespace
return s;
}
virtual void releaseRemoteFD() const override
{
std::lock_guard lock(remote_fd_mutex);
if (buffer)
buffer = nullptr;
}
private:
RemoteFileInfo file;
RemoteFileCachePtr cache;

View File

@ -275,6 +275,11 @@ Iterator * Table::NewIterator(const ReadOptions & options) const
rep_->options.comparator, rep_->index_block->NewIterator(rep_->options.comparator), rep_->filter, &Table::BlockReader, const_cast<Table *>(this), options);
}
void Table::releaseRemoteFD() const
{
rep_->file->releaseRemoteFD();
}
Status Table::Get(const ReadOptions & options, const Slice & k, std::string * value)
{
Status notfound = Status::NotFound(Slice());

View File

@ -68,6 +68,10 @@ public:
// be close to the file length.
// uint64_t ApproximateOffsetOf(const Slice & key) const;
// After the iter call ends, we need to explicitly release the buffer, otherwise there may be too many open files due to remote handles.
// Safe for concurrent use by multiple threads.
void releaseRemoteFD() const;
private:
struct Rep;

View File

@ -93,7 +93,11 @@ namespace
{
}
TwoLevelIterator::~TwoLevelIterator() = default;
TwoLevelIterator::~TwoLevelIterator()
{
Table * table = reinterpret_cast<Table *>(arg_);
table->releaseRemoteFD();
}
void TwoLevelIterator::Seek(const Slice & target)
{
@ -157,7 +161,7 @@ namespace
// move to the next block
index_iter_.Next();
// Filter data using min max index.
// Filter data using min max index.
// If target is greater than index.key(max), then find target in next data block
if (index_iter_.Valid() && Compare(index_iter_.key(), target) < 0)
continue; // skip the next block