2017-08-21 19:49:21 +00:00
|
|
|
#pragma once
|
|
|
|
/**
|
|
|
|
* Piggyback on the datastore to access the journal entries
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-08-24 15:08:27 +00:00
|
|
|
#include "lmdb.h"
|
2017-08-21 19:49:21 +00:00
|
|
|
#include "libp2p/db/datastore.h"
|
2017-09-04 22:10:57 +00:00
|
|
|
#include "ipfs/repo/fsrepo/lmdb_cursor.h"
|
2017-08-21 19:49:21 +00:00
|
|
|
|
|
|
|
struct JournalRecord {
|
2017-09-04 18:33:56 +00:00
|
|
|
unsigned long long timestamp; // the timestamp of the file
|
|
|
|
int pin; // true if it is to be stored, false if it is to be deleted
|
|
|
|
int pending; // true if we do not have this file yet
|
|
|
|
uint8_t *hash; // the hash of the block (file)
|
|
|
|
size_t hash_size; // the size of the hash
|
2017-08-21 19:49:21 +00:00
|
|
|
};
|
|
|
|
|
2017-09-04 18:33:56 +00:00
|
|
|
struct JournalRecord* lmdb_journal_record_new();
|
|
|
|
|
|
|
|
int lmdb_journal_record_free(struct JournalRecord* rec);
|
|
|
|
|
2017-08-21 19:49:21 +00:00
|
|
|
/**
|
|
|
|
* Open a cursor to the journalstore table
|
2017-09-04 22:10:57 +00:00
|
|
|
* @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
|
2017-08-21 19:49:21 +00:00
|
|
|
*/
|
2017-09-07 23:45:09 +00:00
|
|
|
int lmdb_journalstore_cursor_open(void* db_handle, struct lmdb_trans_cursor **cursor, struct MDB_txn *trans_to_use);
|
2017-08-21 19:49:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a record from the cursor
|
|
|
|
*/
|
2017-09-04 22:10:57 +00:00
|
|
|
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);
|
2017-08-21 19:49:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the cursor
|
|
|
|
*/
|
2017-09-07 23:45:09 +00:00
|
|
|
int lmdb_journalstore_cursor_close(struct lmdb_trans_cursor *cursor, int commitTransaction);
|
2017-08-21 19:49:21 +00:00
|
|
|
|
|
|
|
int journal_record_free(struct JournalRecord* rec);
|
2017-08-24 15:08:27 +00:00
|
|
|
|
2017-09-07 16:05:56 +00:00
|
|
|
int lmdb_journalstore_journal_add(struct lmdb_trans_cursor *journalstore_cursor, struct JournalRecord *journalstore_record);
|
2017-09-04 22:10:57 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* 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);
|
|
|
|
|
2017-09-07 16:05:56 +00:00
|
|
|
/***
|
|
|
|
* Convert the JournalRec struct into a lmdb key and lmdb value
|
|
|
|
* @param journal_record the record to convert
|
|
|
|
* @param db_key where to store the key information
|
|
|
|
* @param db_value where to store the value information
|
|
|
|
*/
|
|
|
|
int lmdb_journalstore_build_key_value_pair(const struct JournalRecord* journal_record, struct MDB_val* db_key, struct MDB_val *db_value);
|
|
|
|
|