阅读量: searchstar 2022-03-02 22:07:42
Categories: Tags:


  // A list of paths where SST files can be put into, with its target size.
  // Newer data is placed into paths specified earlier in the vector while
  // older data gradually moves to paths specified later in the vector.
  // For example, you have a flash device with 10GB allocated for the DB,
  // as well as a hard drive of 2TB, you should config it to be:
  //   [{"/flash_path", 10GB}, {"/hard_drive", 2TB}]
  // The system will try to guarantee data under each path is close to but
  // not larger than the target size. But current and future file sizes used
  // by determining where to place a file are based on best-effort estimation,
  // which means there is a chance that the actual size under the directory
  // is slightly more than target size under some workloads. User should give
  // some buffer room for those cases.
  // If none of the paths has sufficient room to place a file, the file will
  // be placed to the last path anyway, despite to the target size.
  // Placing newer data to earlier paths is also best-efforts. User should
  // expect user files to be placed in higher levels in some extreme cases.
  // If left empty, only one path will be used, which is db_name passed when
  // opening the DB.
  // Default: empty
  std::vector<DbPath> db_paths;


#include <iostream>
#include <filesystem>
#include <fstream>
#include <cstdint>

#include "rocksdb/db.h"

using namespace std;

int main(int argc, char **argv) {
    rocksdb::Options options;
    options.db_paths = <!--swig0-->; // 100MB, 1GB
    rocksdb::DB *db;
    options.create_if_missing = true;
    auto s = rocksdb::DB::Open(options, "/tmp/rocksdb", &db);
    for (uint64_t i = 0; i < 10000000; ++i) {
        rocksdb::Slice key_slice((const char *)&i, 8);
        rocksdb::Slice value_slice((const char *)&i, 8);
        auto s = db->Put(rocksdb::WriteOptions(), key_slice, value_slice);
        if (!s.ok()) {
            std::cout << "Put failed with error: " << s.ToString() << std::endl;
            delete db;
            return -1;
    delete db;
    return 0;


rm -rf /tmp/rocksdb/ && rm -rf /tmp/sd/* && rm -rf /tmp/cd/*
g++ test.cpp -o test -lrocksdb -I/home/searchstar/git/master/rocksdb/include/ -L/home/searchstar/git/master/rocksdb/build/
LD_LIBRARY_PATH=~/git/master/rocksdb/build/ ./test


du -sh /tmp/rocksdb/ /tmp/sd /tmp/cd


17M     /tmp/rocksdb/
100M    /tmp/sd
133M    /tmp/cd