9c24a5cb4d
Summary: Persistent cache feature caused rocks db crash on windows. I posted a issue for it, https://github.com/facebook/rocksdb/issues/6919. I found this is because no "persistent_cache_key_prefix" is generated for persistent cache. Looking repo history, "GetUniqueIdFromFile" is not implemented on Windows. So my fix is adding "NewId()" function in "persistent_cache" and using it to generate prefix for persistent cache. In this PR, i also re-enable related test cases defined in "db_test2" and "persistent_cache_test" for windows. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6932 Test Plan: 1. run related test cases in "db_test2" and "persistent_cache_test" on windows and see it passed. 2. manually run db_bench.exe with "read_cache_path" and verified. Reviewed By: riversand963 Differential Revision: D21911608 Pulled By: cheng-chang fbshipit-source-id: cdfd938d54a385edbb2836b13aaa1d39b0a6f1c2
74 lines
2.5 KiB
C++
74 lines
2.5 KiB
C++
// Copyright (c) 2013, 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).
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "rocksdb/env.h"
|
|
#include "rocksdb/slice.h"
|
|
#include "rocksdb/statistics.h"
|
|
#include "rocksdb/status.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
// PersistentCache
|
|
//
|
|
// Persistent cache interface for caching IO pages on a persistent medium. The
|
|
// cache interface is specifically designed for persistent read cache.
|
|
class PersistentCache {
|
|
public:
|
|
typedef std::vector<std::map<std::string, double>> StatsType;
|
|
|
|
virtual ~PersistentCache() {}
|
|
|
|
// Insert to page cache
|
|
//
|
|
// page_key Identifier to identify a page uniquely across restarts
|
|
// data Page data
|
|
// size Size of the page
|
|
virtual Status Insert(const Slice& key, const char* data,
|
|
const size_t size) = 0;
|
|
|
|
// Lookup page cache by page identifier
|
|
//
|
|
// page_key Page identifier
|
|
// buf Buffer where the data should be copied
|
|
// size Size of the page
|
|
virtual Status Lookup(const Slice& key, std::unique_ptr<char[]>* data,
|
|
size_t* size) = 0;
|
|
|
|
// Is cache storing uncompressed data ?
|
|
//
|
|
// True if the cache is configured to store uncompressed data else false
|
|
virtual bool IsCompressed() = 0;
|
|
|
|
// Return stats as map of {string, double} per-tier
|
|
//
|
|
// Persistent cache can be initialized as a tier of caches. The stats are per
|
|
// tire top-down
|
|
virtual StatsType Stats() = 0;
|
|
|
|
virtual std::string GetPrintableOptions() const = 0;
|
|
|
|
// Return a new numeric id. May be used by multiple clients who are
|
|
// sharding the same persistent cache to partition the key space. Typically
|
|
// the client will allocate a new id at startup and prepend the id to its
|
|
// cache keys.
|
|
virtual uint64_t NewId() = 0;
|
|
};
|
|
|
|
// Factor method to create a new persistent cache
|
|
Status NewPersistentCache(Env* const env, const std::string& path,
|
|
const uint64_t size,
|
|
const std::shared_ptr<Logger>& log,
|
|
const bool optimized_for_nvm,
|
|
std::shared_ptr<PersistentCache>* cache);
|
|
} // namespace ROCKSDB_NAMESPACE
|