fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.8 KiB
87 lines
2.8 KiB
![]()
3 years ago
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||
|
// This source code is licensed under both the GPLv2 (found in the
|
||
|
// COPYING file in the root directory) and Apache 2.0 License
|
||
|
// (found in the LICENSE.Apache file in the root directory).
|
||
|
|
||
|
#pragma once
|
||
|
|
||
|
#include <memory>
|
||
|
|
||
|
#include "cache/lru_cache.h"
|
||
|
#include "memory/memory_allocator.h"
|
||
|
#include "rocksdb/secondary_cache.h"
|
||
|
#include "rocksdb/slice.h"
|
||
|
#include "rocksdb/status.h"
|
||
|
#include "util/compression.h"
|
||
|
|
||
|
namespace ROCKSDB_NAMESPACE {
|
||
|
|
||
![]()
2 years ago
|
class CompressedSecondaryCacheResultHandle : public SecondaryCacheResultHandle {
|
||
![]()
3 years ago
|
public:
|
||
![]()
2 years ago
|
CompressedSecondaryCacheResultHandle(void* value, size_t size)
|
||
![]()
3 years ago
|
: value_(value), size_(size) {}
|
||
![]()
2 years ago
|
virtual ~CompressedSecondaryCacheResultHandle() override = default;
|
||
![]()
3 years ago
|
|
||
![]()
2 years ago
|
CompressedSecondaryCacheResultHandle(
|
||
|
const CompressedSecondaryCacheResultHandle&) = delete;
|
||
|
CompressedSecondaryCacheResultHandle& operator=(
|
||
|
const CompressedSecondaryCacheResultHandle&) = delete;
|
||
![]()
3 years ago
|
|
||
|
bool IsReady() override { return true; }
|
||
|
|
||
|
void Wait() override {}
|
||
|
|
||
|
void* Value() override { return value_; }
|
||
|
|
||
|
size_t Size() override { return size_; }
|
||
|
|
||
|
private:
|
||
|
void* value_;
|
||
|
size_t size_;
|
||
|
};
|
||
|
|
||
![]()
2 years ago
|
// The CompressedSecondaryCache is a concrete implementation of
|
||
![]()
3 years ago
|
// rocksdb::SecondaryCache.
|
||
|
//
|
||
|
// Users can also cast a pointer to it and call methods on
|
||
|
// it directly, especially custom methods that may be added
|
||
|
// in the future. For example -
|
||
|
// std::unique_ptr<rocksdb::SecondaryCache> cache =
|
||
![]()
2 years ago
|
// NewCompressedSecondaryCache(opts);
|
||
|
// static_cast<CompressedSecondaryCache*>(cache.get())->Erase(key);
|
||
![]()
3 years ago
|
|
||
![]()
2 years ago
|
class CompressedSecondaryCache : public SecondaryCache {
|
||
![]()
3 years ago
|
public:
|
||
![]()
2 years ago
|
CompressedSecondaryCache(
|
||
![]()
3 years ago
|
size_t capacity, int num_shard_bits, bool strict_capacity_limit,
|
||
|
double high_pri_pool_ratio,
|
||
|
std::shared_ptr<MemoryAllocator> memory_allocator = nullptr,
|
||
|
bool use_adaptive_mutex = kDefaultToAdaptiveMutex,
|
||
|
CacheMetadataChargePolicy metadata_charge_policy =
|
||
|
kDontChargeCacheMetadata,
|
||
|
CompressionType compression_type = CompressionType::kLZ4Compression,
|
||
|
uint32_t compress_format_version = 2);
|
||
![]()
2 years ago
|
virtual ~CompressedSecondaryCache() override;
|
||
![]()
3 years ago
|
|
||
![]()
2 years ago
|
const char* Name() const override { return "CompressedSecondaryCache"; }
|
||
![]()
3 years ago
|
|
||
|
Status Insert(const Slice& key, void* value,
|
||
|
const Cache::CacheItemHelper* helper) override;
|
||
|
|
||
|
std::unique_ptr<SecondaryCacheResultHandle> Lookup(
|
||
![]()
2 years ago
|
const Slice& key, const Cache::CreateCallback& create_cb, bool /*wait*/,
|
||
|
bool& is_in_sec_cache) override;
|
||
![]()
3 years ago
|
|
||
|
void Erase(const Slice& key) override;
|
||
|
|
||
|
void WaitAll(std::vector<SecondaryCacheResultHandle*> /*handles*/) override {}
|
||
|
|
||
|
std::string GetPrintableOptions() const override;
|
||
|
|
||
|
private:
|
||
|
std::shared_ptr<Cache> cache_;
|
||
![]()
2 years ago
|
CompressedSecondaryCacheOptions cache_options_;
|
||
![]()
3 years ago
|
};
|
||
|
|
||
|
} // namespace ROCKSDB_NAMESPACE
|