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 }
  • 相关阅读:
    Mysql蠕虫复制
    Mysql中如何开启慢查询功能?
    线程的状态以及状态切换
    Java的Unsafe类
    Spring 获取jar内外文件的方式
    RocketMQ学习
    volatile的理解
    快速排序
    JVM的发展史
    nginx安装配置
  • 原文地址:https://www.cnblogs.com/liuhao/p/2807826.html
Copyright © 2011-2022 走看看