-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue=1258, t-cache support block-level cache evict #1266
base: master
Are you sure you want to change the base?
Changes from all commits
177cb1e
3256bd2
c5e3f83
9b00baa
170318f
a1e51d3
b749896
716270e
e516c24
a94781f
1c4682e
749296e
ae0298a
415d026
9794ff4
13813f3
d95181f
6394ef7
9dc1665
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) 2017, Baidu.com, Inc. All Rights Reserved | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// | ||
// Author: [email protected] | ||
|
||
#ifndef STOREAGE_LEVELDB_UTIL_BLOCK_CACHE_H_ | ||
#define STOREAGE_LEVELDB_UTIL_BLOCK_CACHE_H_ | ||
|
||
#include "leveldb/env.h" | ||
#include "leveldb/options.h" | ||
#include "leveldb/status.h" | ||
|
||
namespace leveldb { | ||
///////////////////////////////////////////// | ||
// Tcache | ||
///////////////////////////////////////////// | ||
extern uint64_t kBlockSize; | ||
extern uint64_t kDataSetSize; | ||
extern uint64_t kFidBatchNum; | ||
extern uint64_t kCacheSize; | ||
extern uint64_t kMetaBlockSize; | ||
extern uint64_t kMetaTableSize; | ||
extern uint64_t kWriteBufferSize; | ||
|
||
struct BlockCacheOptions { | ||
Options opts; | ||
std::string cache_dir; | ||
uint64_t block_size; | ||
uint64_t dataset_size; | ||
uint64_t fid_batch_num; | ||
uint64_t cache_size; | ||
uint64_t dataset_num; | ||
uint64_t meta_block_cache_size; | ||
uint64_t meta_table_cache_size; | ||
uint64_t write_buffer_size; | ||
Env* env; | ||
Env* cache_env; | ||
|
||
BlockCacheOptions() | ||
: block_size(kBlockSize), | ||
dataset_size(kDataSetSize), | ||
fid_batch_num(kFidBatchNum), | ||
cache_size(kCacheSize), | ||
meta_block_cache_size(kMetaBlockSize), | ||
meta_table_cache_size(kMetaTableSize), | ||
write_buffer_size(kWriteBufferSize), | ||
env(NULL) { | ||
dataset_num = cache_size / dataset_size + 1; | ||
} | ||
}; | ||
|
||
class BlockCacheImpl; | ||
|
||
class BlockCacheEnv : public EnvWrapper { | ||
public: | ||
BlockCacheEnv(Env* base); | ||
|
||
~BlockCacheEnv(); | ||
|
||
virtual Status FileExists(const std::string& fname); | ||
|
||
virtual Status GetChildren(const std::string& path, | ||
std::vector<std::string>* result); | ||
|
||
virtual Status DeleteFile(const std::string& fname); | ||
|
||
virtual Status CreateDir(const std::string& name); | ||
|
||
virtual Status DeleteDir(const std::string& name); | ||
|
||
virtual Status CopyFile(const std::string& from, | ||
const std::string& to); | ||
|
||
virtual Status GetFileSize(const std::string& fname, uint64_t* size); | ||
|
||
virtual Status RenameFile(const std::string& src, const std::string& target); | ||
|
||
virtual Status LockFile(const std::string& fname, FileLock** lock); | ||
|
||
virtual Status UnlockFile(FileLock* lock); | ||
|
||
virtual Status NewSequentialFile(const std::string& fname, | ||
SequentialFile** result); // never cache log | ||
|
||
// cache relatively | ||
virtual Status NewRandomAccessFile(const std::string& fname, | ||
RandomAccessFile** result); // cache Pread | ||
virtual Status NewRandomAccessFile(const std::string& fname, | ||
uint64_t fsize, | ||
RandomAccessFile** result); // cache Pread | ||
|
||
virtual Status NewWritableFile(const std::string& fname, | ||
WritableFile** result); // cache Append | ||
virtual Status LoadCache(const BlockCacheOptions& opts, const std::string& cache_dir); | ||
|
||
private: | ||
std::vector<BlockCacheImpl*> cache_vec_; | ||
Env* dfs_env_; | ||
}; | ||
|
||
Env* NewBlockCacheEnv(Env* base); | ||
|
||
} // leveldb | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. STOREAGE_LEVELDB_UTIL_BLOCK_CACHE_H_ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已改 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,9 +29,36 @@ namespace leveldb { | |
|
||
class Cache; | ||
|
||
// An entry is a variable length heap-allocated structure. Entries | ||
// are kept in a circular doubly linked list ordered by access time. | ||
struct LRUHandle { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 挪出来的目的是? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 能填充cache_id |
||
void* value; | ||
void (*deleter)(const Slice&, void* value); | ||
LRUHandle* next_hash; | ||
LRUHandle* next; | ||
LRUHandle* prev; | ||
size_t charge; // TODO(opt): Only allow uint32_t? | ||
size_t key_length; | ||
uint32_t refs; | ||
uint32_t hash; // Hash of key(); used for fast sharding and comparisons | ||
uint64_t cache_id; // cache id, user spec | ||
char key_data[1]; // Beginning of key | ||
|
||
Slice key() const { | ||
// For cheaper lookups, we allow a temporary Handle object | ||
// to store a pointer to a key in "value". | ||
if (next == this) { | ||
return *(reinterpret_cast<Slice*>(value)); | ||
} else { | ||
return Slice(key_data, key_length); | ||
} | ||
} | ||
}; | ||
|
||
// Create a new cache with a fixed size capacity. This implementation | ||
// of Cache uses a least-recently-used eviction policy. | ||
extern Cache* NewLRUCache(size_t capacity); | ||
extern Cache* New2QCache(size_t capacity); | ||
|
||
class Cache { | ||
public: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为啥不像mem及flash一样,弄成函数内的静态变量
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是静态的