LMDB:轻量级内存映射数据库-----介绍(翻译)

LMDB是轻量级、快速、强大的内存映射数据库,实现简化版BerkeleyDB API。它包括环境打开、事务处理、数据库操作等流程。支持游标、多线程/多进程操作,提供数据操作事务功能,允许重复关键词(一对多模型),并具备优化选项。LMDB使用POSIX文件锁,确保并发安全,但一个进程只能打开一个环境一次。
摘要由CSDN通过智能技术生成

1.     概述

LMDB is compact(紧凑的), fast,powerful, and robust and implements a simplified variant of the BerkeleyDB(BDB) API. (BDB is also very powerful, and verbosely documented in its ownright.) After reading this page, the main \ref mdb documentation should make sense.Thanks to Bert Hubert for creating the <ahref="https://github.com/ahupowerdns/ahutils/blob/master/lmdb-semantics.md">initial version</a> of this writeup.

补充介绍:

LMDB的全称是LightningMemory-Mapped Database,闪电般的内存映射数据库。它文件结构简单,一个文件夹,里面一个数据文件,一个锁文件。数据随意复制,随意传输。它的访问简单,不需要运行单独的数据库管理进程,只要在访问数据的代码里引用LMDB库,访问时给文件路径即可。

2.     使用流程?

1)    先打开环境:

Everything starts with anenvironment, created by #mdb_env_create().Once created, this environment mustalso be opened with #mdb_env_open().

#mdb_env_open() gets passed a name which isinterpretedas a directory path. Note that thisdirectory must exist already(目录路径必须已经存在), it is not created foryou. Within that directory,a lock file and a storagefile will be generated(产生一个锁文件和存储文件). If you don't want to use adirectory, you can pass the#MDB_NOSUBDIRoption, in which case the path you provided is used directly as the data file,and another file with a "-lock" suffix added will be used for thelock file.

2)    开始事务

Once the environment is open, a transactioncan be created within it using#mdb_txn_begin().Transactions may be read-write or read-only, and read-write transactions may benested(嵌套的).A transaction must only be used by onethread at a time(一个事务必须同时只有一个线程执行). Transactions are alwaysrequired, even for read-only access. The transaction provides a consistent viewof the data.

3)    打开数据库

Once a transaction has been created, adatabase can be opened within it using#mdb_dbi_open().If only one database will ever be used in the environment, a NULLcan be passed as the database name. For named databases, the#MDB_CREATE flag must be used to create the database ifit doesn't already exist. Also,#mdb_env_set_maxdbs()must be called after #mdb_env_create() and before#mdb_env_open() (

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值