leveldb

[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.)
  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。