LevelDB

  LevelDB is a fast key-value storage library that provides an ordered mapping from string keys to string values.

  • Keys and values are arbitrary byte arrays.
  • Data is stored sorted by key.
  • Callers can provide a custom comparison function to override the sort order. 自定义Comparator。
  • The basic operations are Put(key,value)Get(key)Delete(key).
  • Multiple changes can be made in one atomic batch. 批处理,原子化,高效。
  • Users can create a transient snapshot to get a consistent view of data.
  • Forward and backward iteration is supported over the data.
  • Data is automatically compressed using the Snappy compression library.
  • External activity (file system operations etc.) is relayed through a virtual interface so users can customize the operating system interactions.

性能

  LevelDB性能非常突出,官方网站报道其随机写性能达到40万条记录每秒,而随机读性能达到6万条记录每秒。总体来说,LevelDb的写操作要大大快于读操作,而顺序读写操作则大大快于随机读写操作。

Limitations

  • This is not a SQL database. It does not have a relational data model, it does not support SQL queries, and it has no support for indexes. 不支持结SQL查询。
  • Only a single process (possibly multi-threaded) can access a particular database at a time. 一个数据库只能被单进程访问。
  • There is no client-server support builtin to the library. An application that needs such support will have to wrap their own server around the library.  无网络模型。

[Synchronous Writes]

  By default, each write to leveldb is asynchronous: it returns after pushing the write from the process into the operating system.

默认所有到leveldb的写操作都是异步, 在把数据从进程交给操作系统后该写操作就返回.

  The transfer from operating system memory to the underlying persistent storage happens asynchronously.

  从操作系统到下层的持久存储是一个异步的过程.

  The sync flag can be turned on for a particular write to make the write operation not return until the data being written has been pushed all the way to persistent storage.

  sync标致可打开, 以使得写操作到直至把数据写入到持久存储才返回.

  

  The downside of asynchronous writes is that a crash of the machine may cause the last few updates to be lost.

  异步写操作不利的一面是, 机器的崩溃会导致最后几个操作丢失.

  Note that a crash of just the writing process will not cause any loss since even when sync is false, an update is pushed from the process memory into the operating system before it is considered done.

  当sync为false时,写进程的崩溃不会导致异步写操作丢失, 国为数据已经被写到了操作系统.

  Asynchronous writes can often be used safely. For example, when loading a large amount of data into the database you can handle lost updates by restarting the bulk load after a crash. A hybrid scheme is also possible where every Nth write is synchronous, and in the event of a crash, the bulk load is restarted just after the last synchronous write finished by the previous run.

[Concurrency]

  A database may only be opened by one process at a time. The leveldb implementation acquires a lock from the operating system to prevent misuse. Within a single process, the same leveldb::DB object may be safely shared by multiple concurrent threads. I.e., different threads may write into or fetch iterators or call Get on the same database without any external synchronization (the leveldb implementation will automatically do the required synchronization). However other objects (like Iterator and WriteBatch) may require external synchronization. If two threads share such an object, they must protect access to it using their own locking protocol.

[Iteration]

  The following example demonstrates how to print all key,value pairs in a database.

  

   The following variation shows how to process just the keys in the range [start,limit):

   

   You can also process entries in reverse order. (Caveat: reverse iteration may be somewhat slower than forward iteration.)
  
[Snapshots]
  Snapshots provide consistent read-only views over the entire state of the key-value store. ReadOptions::snapshot may be non-NULL to indicate that a read should operate on a particular version of the DB state. IReadOptions::snapshot is NULL, the read will operate on an implicit snapshot of the current state.
  如果ReadOptions的snapshot属性非空, 意味着操作会在该版本上发生, 如果为NULL, 操作会在一个隐含的版本上发生. 所以无论怎样, 使用iterator都会得到一个一致的版本, 不用担心在iteration过程中会插入或是删除数据.

  Snapshots are created by the DB::GetSnapshot() method:

  

  Note that when a snapshot is no longer needed, it should be released using the DB::ReleaseSnapshot interface. This allows the implementation to get rid of state that was being maintained just to support reading as of that snapshot.

leveldb的更多相关文章

  1. leveldb 性能、使用场景评估

    最近有个业务写远远大于读,读也集中在最近写入,这不很适合采用leveldb存储么,leveldb业界貌似ssdb用得挺广,花了两天时间就ssdb简单做下测试,以下总结. ssdb 是leveldb的r ...

  2. leveldb源码分析--SSTable之Compaction

    对于compaction是leveldb中体量最大的一部分,也应该是最为复杂的部分,为了便于理解我们首先从一些基本的概念开始.下面是一些从doc/impl.html中翻译和整理的内容: Level 0 ...

  3. leveldb 学习。

    1)大概浏览了leveldb文档的介绍.本想逐步看代码,想想还是自己先实现一个看看如何改进. 2)完成了一个非常丑陋的初版,但是还是比初初版有进步. 3)key value的数据库,不允许有key重复 ...

  4. 解决: org.iq80.leveldb.DBException: IO error: C:\data\trie\000945.sst: Could not create random access file.

    以太坊MPT树的持久化层是采用了leveldb数据库,然而在抽取MPT树代码运行过程中,进行get和write操作时却发生了错误: Caused by: org.fusesource.leveldbj ...

  5. 用Qt Creator 对 leveldb 进行简单的读写

    #include <iostream> #include <string> #include <leveldb/db.h> #include <boost/l ...

  6. leveldb 学习笔记之VarInt

    在leveldb在查找比较时的key里面保存key长度用的是VarInt,何为VarInt呢,就是变长的整数,每7bit代表一个数,第8bit代表是否还有下一个字节, 1. 比如小于128(一个字节以 ...

  7. leveldb源码学习系列

    楼主从2014年7月份开始学习<>,由于书籍比较抽象,为了加深思考,同时开始了Google leveldb的源码学习,主要是想学习leveldb的设计思想和Google的C++编程规范.目 ...

  8. LevelDB库简介

    LevelDB库简介 一.LevelDB入门 LevelDB是Google开源的持久化KV单机数据库,具有很高的随机写,顺序读/写性能,但是随机读的性能很一般,也就是说,LevelDB很适合应用在查询 ...

  9. zookeeper + LevelDB + ActiveMQ实现消息队列高可用

    通过集群实现消息队列高可用. 消息队列在项目中存储订单.邮件通知.数据分发等重要信息,故对消息队列稳定可用性有高要求. 现在通过zookeeper选取activemq leader的形式实现当某个ac ...

  10. leveldb.net对象读写封装

    leveldb是一个非常高效的可嵌入式K-V数据库,在.NET下有着基于win实现的包装leveldb.net;不过leveldb.net只提供了基于byte[]和string的处理,这显然会对使用的 ...

随机推荐

  1. HTML的列表标签

    一.上下层列表标签:<dl>..</dl>: 上层dt 下层dd:封装的内容会被自动缩进的效果 <dl> <dt>运动户外</dt> < ...

  2. grub rescue修复引导项

    1.需要先找到linux系统盘所在到目录 grub rescue > ls 然后依次 ls (hd0,msdosX)/ 假如我们到系统在msdos2 2.输入 set root=(hd0,msd ...

  3. [转载] mysql5.6 删除之前的ibdata1文件后再重新生成,遇到[Warning] Info table is not ready to be used. Table 'mysql.slave_master_info' cannot be opened.问题

    [转载] mysql5.6 删除之前的ibdata1文件后再重新生成,遇到[Warning] Info table is not ready to be used. Table 'mysql.slav ...

  4. 在页面中使用js

    JavaScript:用来在页面编写特效的,和HTML\CSS一样当都是由浏览器解析 JavaScript语言 一.JS如何运行(JavaScript,jscript,VbScript,applet ...

  5. 学习macos常用的一些快捷键笔记

    学习mac 操作系统使用笔记 Dock功能学习 类似快捷图标一样 Command+q quit a program Dock上添加与删除都用拖动 command+delete 删除文件 shift+c ...

  6. Heritrix源码分析(七) Heritrix总体介绍(转)

    本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/642794         本博客已迁移到本人独立博客: http://www.yun ...

  7. 【转】session setup failed: NT_STATUS_LOGON_FAILURE -- 不错

    原文网址:http://blog.sina.com.cn/s/blog_5cdb72780100l26f.html samba服务器出现“session setup failed: NT_STATUS ...

  8. Android 图文教学让你彻底理解activity启动模式

    我们首先从最简单的开始, standard 这个模式就是默认的模式,我们都知道 当你用这个模式时,每次发送一个intent,都会生成一个新的实例! 我写一个简单的例子: <?xml versio ...

  9. OpenGL学习之路(四)

    1 引子 上次读书笔记主要是学习了应用三维坐标变换矩阵对二维的图形进行变换,并附带介绍了GLSL语言的编译.链接相关的知识,之后介绍了GLSL中变量的修饰符,着重介绍了uniform修饰符,来向着色器 ...

  10. MySQL与Oracle 差异比较之三函数

    函数 编号 类别 ORACLE MYSQL 注释 1 数字函数 round(1.23456,4) round(1.23456,4) 一样:ORACLE:select round(1.23456,4) ...