persistent_cache_helper.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 <string>
  7. #include "monitoring/statistics_impl.h"
  8. #include "table/format.h"
  9. #include "table/persistent_cache_options.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. struct BlockContents;
  12. // PersistentCacheHelper
  13. //
  14. // Encapsulates some of the helper logic for read and writing from the cache
  15. class PersistentCacheHelper {
  16. public:
  17. // Insert block into cache of serialized blocks. Size includes block trailer
  18. // (if applicable).
  19. static void InsertSerialized(const PersistentCacheOptions& cache_options,
  20. const BlockHandle& handle, const char* data,
  21. const size_t size);
  22. // Insert block into cache of uncompressed blocks. No block trailer.
  23. static void InsertUncompressed(const PersistentCacheOptions& cache_options,
  24. const BlockHandle& handle,
  25. const BlockContents& contents);
  26. // Lookup block from cache of serialized blocks. Size includes block trailer
  27. // (if applicable).
  28. static Status LookupSerialized(const PersistentCacheOptions& cache_options,
  29. const BlockHandle& handle,
  30. std::unique_ptr<char[]>* out_data,
  31. const size_t expected_data_size);
  32. // Lookup block from uncompressed cache. No block trailer.
  33. static Status LookupUncompressed(const PersistentCacheOptions& cache_options,
  34. const BlockHandle& handle,
  35. BlockContents* contents);
  36. };
  37. } // namespace ROCKSDB_NAMESPACE