Skip to content

Commit 79d831f

Browse files
committedJul 23, 2022
Pass MDB_RDONLY to the LMDB environment for readonly DBs
1 parent 0887a1d commit 79d831f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed
 

‎ext/dba/dba_lmdb.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ DBA_OPEN_FUNC(lmdb)
4646

4747
ZEND_ASSERT(map_size >= 0);
4848

49+
/* Add readonly flag if DB is opened in read only mode */
50+
if (info->mode == DBA_READER) {
51+
flags |= MDB_RDONLY;
52+
}
53+
4954
rc = mdb_env_create(&env);
5055
if (rc) {
5156
*error = mdb_strerror(rc);
@@ -69,7 +74,7 @@ DBA_OPEN_FUNC(lmdb)
6974
return FAILURE;
7075
}
7176

72-
rc = mdb_txn_begin(env, NULL, 0, &txn);
77+
rc = mdb_txn_begin(env, NULL, /* flags */ MDB_RDONLY, &txn);
7378
if (rc) {
7479
mdb_env_close(env);
7580
*error = mdb_strerror(rc);

0 commit comments

Comments
 (0)