prefetch_buffer_collection.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #pragma once
  6. #include <cassert>
  7. #include <cstdint>
  8. #include <memory>
  9. #include <unordered_map>
  10. #include "file/file_prefetch_buffer.h"
  11. #include "rocksdb/rocksdb_namespace.h"
  12. namespace ROCKSDB_NAMESPACE {
  13. // A class that owns a collection of FilePrefetchBuffers using the file number
  14. // as key. Used for implementing compaction readahead for blob files. Designed
  15. // to be accessed by a single thread only: every (sub)compaction needs its own
  16. // buffers since they are guaranteed to read different blobs from different
  17. // positions even when reading the same file.
  18. class PrefetchBufferCollection {
  19. public:
  20. explicit PrefetchBufferCollection(uint64_t readahead_size)
  21. : readahead_size_(readahead_size) {
  22. assert(readahead_size_ > 0);
  23. }
  24. FilePrefetchBuffer* GetOrCreatePrefetchBuffer(uint64_t file_number);
  25. private:
  26. uint64_t readahead_size_;
  27. std::unordered_map<uint64_t, std::unique_ptr<FilePrefetchBuffer>>
  28. prefetch_buffers_; // maps file number to prefetch buffer
  29. };
  30. } // namespace ROCKSDB_NAMESPACE