zoukankan      html  css  js  c++  java
  • LevelDB PUT/GET操作调用关系

    • LevelDB的Put操作,是一个顺序写log,然后插入memtable(数据结构是skiplist)的过程,调用关系如下图所示:

    • LevelDB的Get操作,会优先查找memtable,如果memtable查找不到,逐层在sstable中查找。下图是在memtable不存在,但在sstable中可以找到key的调用关系图:

    • 程序代码如下:
      1 #include "third_party/leveldb/db.h"
      2 
      3 int main(void) {
      4   leveldb::DB* db;
      5   leveldb::Options options;
      6 
      7   options.create_if_missing = true;
      8   leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);
      9   if (!status.ok()) {
     10     printf("%s\n", status.ToString().c_str());
     11   }
     12   std::string key = "hello";
     13   std::string value = "world";
     14   std::string exist_key = "nwlrbbmqbhcdarzowkkyhiddqscdxrjmowfr";
     15   std::string empty_value;
     16   status = db->Put(leveldb::WriteOptions(), key, value);
     17   if (!status.ok()) {
     18     printf("%s\n", status.ToString().c_str());
     19   }
     20   status = db->Get(leveldb::ReadOptions(), exist_key, &empty_value);
     21   if (!status.ok()) {
     22     printf("%s\n", status.ToString().c_str());
     23   }
     24 }
  • 相关阅读:
    P4297 [NOI2006]网络收费
    P4207 [NOI2005]月下柠檬树
    bzoj2517 矩形覆盖
    bzoj2506 calc
    ......
    SP1811 LCS
    CF585E Present for Vitalik the Philatelist
    好康的
    CF605E Intergalaxy Trips
    字符串
  • 原文地址:https://www.cnblogs.com/liuhao/p/2807826.html
Copyright © 2011-2022 走看看