Implementation of timestamp in both datastore and journalstore
This commit is contained in:
parent
bf87d93136
commit
bf7ba9049c
9 changed files with 393 additions and 108 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "lmdb.h"
|
||||
#include "libp2p/db/datastore.h"
|
||||
#include "ipfs/repo/fsrepo/lmdb_cursor.h"
|
||||
|
||||
struct JournalRecord {
|
||||
unsigned long long timestamp; // the timestamp of the file
|
||||
|
@ -23,19 +24,40 @@ int lmdb_journal_record_free(struct JournalRecord* rec);
|
|||
|
||||
/**
|
||||
* Open a cursor to the journalstore table
|
||||
* @param db_handle a handle to the database (an MDB_env pointer)
|
||||
* @param cursor where to place the results
|
||||
* @returns true(1) on success, false(0) otherwise
|
||||
*/
|
||||
int repo_journalstore_cursor_open(struct Datastore* datastore, void** cursor);
|
||||
int lmdb_journalstore_cursor_open(void* db_handle, struct lmdb_trans_cursor **cursor);
|
||||
|
||||
/**
|
||||
* Read a record from the cursor
|
||||
*/
|
||||
int repo_journalstore_cursor_get(struct Datastore* datastore, void* cursor, enum DatastoreCursorOp op, struct JournalRecord** record);
|
||||
int lmdb_journalstore_cursor_get(struct lmdb_trans_cursor *cursor, enum DatastoreCursorOp op, struct JournalRecord** record);
|
||||
|
||||
/***
|
||||
* Write the record at the cursor
|
||||
* @param crsr the cursor
|
||||
* @param journal_record the record to write
|
||||
* @returns true(1) on success, false(0) otherwise
|
||||
*/
|
||||
int lmdb_journalstore_cursor_put(struct lmdb_trans_cursor *crsr, struct JournalRecord* journal_record);
|
||||
|
||||
/**
|
||||
* Close the cursor
|
||||
*/
|
||||
int repo_journalstore_cursor_close(struct Datastore* datastore, void* cursor);
|
||||
int lmdb_journalstore_cursor_close(struct lmdb_trans_cursor *cursor);
|
||||
|
||||
int journal_record_free(struct JournalRecord* rec);
|
||||
|
||||
int lmdb_journalstore_journal_add(MDB_txn* mdb_txn, struct JournalRecord* record);
|
||||
|
||||
/***
|
||||
* Attempt to get a specific record identified by its timestamp and bytes
|
||||
* @param handle a handle to the database engine
|
||||
* @param journalstore_cursor the cursor (will be returned as a cursor that points to the record found
|
||||
* @param journalstore_record where to put the results (can pass null). If data is within the struct, will use it as search criteria
|
||||
* @returns true(1) on success, false(0) otherwise
|
||||
*/
|
||||
int lmdb_journalstore_get_record(void* handle, struct lmdb_trans_cursor *journalstore_cursor, struct JournalRecord **journalstore_record);
|
||||
|
||||
|
|
22
include/ipfs/repo/fsrepo/lmdb_cursor.h
Normal file
22
include/ipfs/repo/fsrepo/lmdb_cursor.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "lmdb.h"
|
||||
|
||||
struct lmdb_trans_cursor {
|
||||
MDB_txn* transaction;
|
||||
MDB_dbi* database;
|
||||
MDB_cursor* cursor;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new lmdb_trans_cursor struct
|
||||
* @returns a newly allocated trans_cursor struct
|
||||
*/
|
||||
struct lmdb_trans_cursor* lmdb_trans_cursor_new();
|
||||
|
||||
/***
|
||||
* Clean up resources from a lmdb_trans_cursor struct
|
||||
* @param in the cursor
|
||||
* @returns true(1)
|
||||
*/
|
||||
int lmdb_trans_cursor_free(struct lmdb_trans_cursor* in);
|
|
@ -3,11 +3,6 @@
|
|||
#include "lmdb.h"
|
||||
#include "libp2p/db/datastore.h"
|
||||
|
||||
struct lmdb_trans_cursor {
|
||||
MDB_txn* transaction;
|
||||
MDB_cursor* cursor;
|
||||
};
|
||||
|
||||
/***
|
||||
* Places the LMDB methods into the datastore's function pointers
|
||||
* @param datastore the datastore to fill
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue