Skip to content

Commit

Permalink
Basic lmdb level support for direct writes
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Aug 29, 2023
1 parent 515eece commit 672ba8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions dependencies/lmdb/libraries/liblmdb/lmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,7 @@ int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx);
* </ul>
*/
int mdb_get_with_txn(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, mdb_size_t *txn_id);
int mdb_direct_write(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);

int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);

Expand Down
19 changes: 19 additions & 0 deletions dependencies/lmdb/libraries/liblmdb/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -7922,6 +7922,25 @@ mdb_get_with_txn(MDB_txn *txn, MDB_dbi dbi,
MDB_CURSOR_UNREF(&mc, 1);
return rc;
}
int
mdb_direct_write(MDB_txn *txn, MDB_dbi dbi,
MDB_val *key, MDB_val *data)
{
MDB_val existing_data;
int rc = mdb_get_with_txn(txn, dbi, key, &existing_data, NULL);
if (rc == 0) {
if (data->mv_size > existing_data.mv_size) {
last_error = malloc(100);
sprintf(last_error, "Attempt to direct write beyond the size of the value");
return EINVAL;
}
MDB_env* env = txn->mt_env;
mdb_size_t file_offset = (char*)existing_data.mv_data - env->me_map;
int written = pwrite(env->me_fd, data->mv_data, data->mv_size, file_offset);
if (written < 0) rc = written;
}
return rc;
}

/** Find a sibling for a page.
* Replaces the page at the top of the cursor's stack with the
Expand Down

0 comments on commit 672ba8d

Please sign in to comment.