1 测试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| int main() { rocksdb::Options options; options.create_if_missing = true;
std::string dbName = "/tmp/rocksdb_ctest_put"; std::string walDir = dbName + "/wal"; std::string sstDir = dbName + "/sst"; options.wal_dir = walDir; std::vector<rocksdb::DbPath> sstPaths = {{sstDir + "/flash_path", 512}, {sstDir + "/hard_drive", 1024}}; options.db_paths = sstPaths;
auto* env = rocksdb::Env::Default(); env->CreateDirIfMissing(dbName); env->CreateDirIfMissing(walDir); env->CreateDirIfMissing(sstDir); env->CreateDirIfMissing(sstDir + "/flash_path"); env->CreateDirIfMissing(sstDir + "/hard_drive");
std::unique_ptr<rocksdb::DB> db; auto s = rocksdb::DB::Open(options, dbName, &db); assert(s.ok());
db->Put(rocksdb::WriteOptions(), "hello", "world"); return 0; }
|
2 WriteBatch协议编码
首先把键值对编码,见RocksDB源码-0x10-WriteBatch协议
3