Skip to content

Commit

Permalink
More fixes for interacting with LMDB v1, #267, #273
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Mar 10, 2024
1 parent b13d39c commit 5d9f3e5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
7 changes: 4 additions & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"target_name": "lmdb",
"sources": [
"src/lmdb-js.cpp",
"dependencies/lmdb/libraries/liblmdb/midl.c",
"dependencies/lmdb/libraries/liblmdb/chacha8.c",
"dependencies/lz4/lib/lz4.h",
"dependencies/lz4/lib/lz4.c",
Expand Down Expand Up @@ -79,14 +78,16 @@
}],
["use_data_v1=='true'", {
"sources": [
"dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c"
"dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c",
"dependencies/lmdb-data-v1/libraries/liblmdb/midl.c"
],
"include_dirs": [
"dependencies/lmdb-data-v1/libraries/liblmdb",
],
}, {
"sources": [
"dependencies/lmdb/libraries/liblmdb/mdb.c"
"dependencies/lmdb/libraries/liblmdb/mdb.c",
"dependencies/lmdb/libraries/liblmdb/midl.c"
],
"include_dirs": [
"dependencies/lmdb/libraries/liblmdb",
Expand Down
6 changes: 3 additions & 3 deletions dependencies/lmdb/libraries/liblmdb/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3483,13 +3483,13 @@ mdb_txn_renew(MDB_txn *txn)
if (!txn)
last_error = "No transaction to renew";
else if (F_ISSET(txn->mt_flags, MDB_TXN_RDONLY)) {
// Txn is already renewed, we can just keep using it
return MDB_SUCCESS;
// Txn is already renewed, consider this as invalid for compatibility with v1
return EINVAL;
} else {
last_error = malloc(100);
sprintf(last_error, "Transaction flag was invalid for renew: %u", txn->mt_flags);
}
return EINVAL;
return MDB_BAD_TXN; // if the transaction is not read-only, communicate this with a separate error code
}

rc = mdb_txn_renew0(txn);
Expand Down
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,5 @@
"useTabs": true,
"singleQuote": true
},
"optionalDependencies": {
"@lmdb/lmdb-darwin-arm64": "2.9.1",
"@lmdb/lmdb-darwin-x64": "2.9.1",
"@lmdb/lmdb-linux-arm": "2.9.1",
"@lmdb/lmdb-linux-arm64": "2.9.1",
"@lmdb/lmdb-linux-x64": "2.9.1",
"@lmdb/lmdb-win32-x64": "2.9.1"
}
"optionalDependencies": {}
}
5 changes: 3 additions & 2 deletions src/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ MDB_txn* EnvWrap::getReadTxn(int64_t tw_address) {
if (rc) {
if (!txn)
fprintf(stderr, "No current read transaction available");
if (rc != EINVAL)
if (rc != EINVAL) // EINVAL indicates that the transaction is already renewed, which we can just allow
return nullptr; // if there was a real error, signal with nullptr and let error propagate with last_error
}
return txn;
Expand Down Expand Up @@ -657,6 +657,7 @@ void notifyCallbacks(std::vector<napi_threadsafe_function> callbacks);
void EnvWrap::closeEnv(bool hasLock) {
if (!env)
return;
#ifdef MDB_OVERLAPPINGSYNC
// unlock any record locks held by this thread/EnvWrap
ExtendedEnv* extended_env = (ExtendedEnv*) mdb_env_get_userctx(env);
pthread_mutex_lock(&extended_env->locksModificationLock);
Expand All @@ -669,7 +670,7 @@ void EnvWrap::closeEnv(bool hasLock) {
} else ++it;
}
pthread_mutex_unlock(&extended_env->locksModificationLock);

#endif
if (openEnvWraps) {
for (auto ewRef = openEnvWraps->begin(); ewRef != openEnvWraps->end(); ) {
if (*ewRef == this) {
Expand Down
2 changes: 2 additions & 0 deletions src/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ next_inst: start = instruction++;
}
goto next_inst;
case PUT:
#ifdef MDB_OVERLAPPINGSYNC
if (flags & ASSIGN_TIMESTAMP) {
if ((*(uint64_t*)key.mv_data & 0xfffffffful) == REPLACE_WITH_TIMESTAMP) {
ExtendedEnv* extended_env = (ExtendedEnv*) mdb_env_get_userctx(envForTxn->env);
Expand Down Expand Up @@ -357,6 +358,7 @@ next_inst: start = instruction++;
}
}
}
#endif
if (flags & SET_VERSION)
rc = putWithVersion(txn, dbi, &key, &value, flags & (MDB_NOOVERWRITE | MDB_NODUPDATA | MDB_APPEND | MDB_APPENDDUP), setVersion);
else
Expand Down

0 comments on commit 5d9f3e5

Please sign in to comment.