compression_context_cache.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  6. // Use of this source code is governed by a BSD-style license that can be
  7. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  8. //
  9. // Compression context cache allows to cache compression/uncompression contexts
  10. // This helps with Random Read latencies and reduces CPU utilization
  11. // Caching is implemented using CoreLocal facility. Compression/Uncompression
  12. // instances are cached on a per core basis using CoreLocalArray. A borrowed
  13. // instance is atomically replaced with a sentinel value for the time of being
  14. // used. If it turns out that another thread is already makes use of the
  15. // instance we still create one on the heap which is later is destroyed.
  16. #pragma once
  17. #include <stdint.h>
  18. #include "rocksdb/rocksdb_namespace.h"
  19. namespace ROCKSDB_NAMESPACE {
  20. class ZSTDUncompressCachedData;
  21. class CompressionContextCache {
  22. public:
  23. // Singleton
  24. static CompressionContextCache* Instance();
  25. static void InitSingleton();
  26. CompressionContextCache(const CompressionContextCache&) = delete;
  27. CompressionContextCache& operator=(const CompressionContextCache&) = delete;
  28. ZSTDUncompressCachedData GetCachedZSTDUncompressData();
  29. void ReturnCachedZSTDUncompressData(int64_t idx);
  30. private:
  31. // Singleton
  32. CompressionContextCache();
  33. ~CompressionContextCache();
  34. class Rep;
  35. Rep* rep_;
  36. };
  37. } // namespace ROCKSDB_NAMESPACE