gavinchou commented on code in PR #58903:
URL: https://github.com/apache/doris/pull/58903#discussion_r2605694178
##########
be/src/io/cache/block_file_cache.h:
##########
@@ -73,6 +78,46 @@ class LockScopedTimer {
class FSFileCacheStorage;
+// NeedUpdateLRUBlocks keeps FileBlockSPtr entries that require LRU updates in
a
+// deduplicated, sharded container. Entries are keyed by the raw FileBlock
+// pointer so that multiple shared_ptr copies of the same block are treated as
a
+// single pending update. The structure is thread-safe and optimized for high
+// contention insert/drain workloads in the background update thread.
+// Note that Blocks are updated in batch, internal order is not important.
+class NeedUpdateLRUBlocks {
+public:
+ NeedUpdateLRUBlocks() = default;
+
+ // Insert a block into the pending set. Returns true only when the block
+ // was not already queued. Null inputs are ignored.
+ bool insert(FileBlockSPtr block);
+
+ // Drain up to `limit` unique blocks into `output`. The method returns how
+ // many blocks were actually drained and shrinks the internal size
+ // accordingly.
+ size_t drain(size_t limit, std::vector<FileBlockSPtr>* output);
+
+ // Remove every pending block from the structure and reset the size.
+ void clear();
+
+ // Thread-safe approximate size of queued unique blocks.
+ size_t size() const { return _size.load(std::memory_order_relaxed); }
+
+private:
+ static constexpr size_t kShardCount = 64;
+ static constexpr size_t kShardMask = kShardCount - 1;
+
+ struct Shard {
+ std::mutex mutex;
+ std::unordered_map<FileBlock*, FileBlockSPtr> entries;
Review Comment:
do we need sharedptr to keep reference of file block?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]