mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-03 04:40:50 +03:00
u3m_lmdb -> u3_lmdb
This commit is contained in:
parent
16788f92c1
commit
175fd18585
@ -1270,26 +1270,26 @@
|
||||
|
||||
/* Database
|
||||
*/
|
||||
/* u3m_lmdb_init(): Initializes lmdb inside log_path
|
||||
/* u3_lmdb_init(): Initializes lmdb inside log_path
|
||||
*/
|
||||
MDB_env* u3m_lmdb_init(const char* log_path);
|
||||
MDB_env* u3_lmdb_init(const char* log_path);
|
||||
|
||||
/* u3m_lmdb_shutdown(): Shuts down the entire logging system
|
||||
/* u3_lmdb_shutdown(): Shuts down the entire logging system
|
||||
*/
|
||||
void u3m_lmdb_shutdown(MDB_env* env);
|
||||
void u3_lmdb_shutdown(MDB_env* env);
|
||||
|
||||
/* u3m_lmdb_get_latest_event_number(): Gets last event id persisted
|
||||
/* u3_lmdb_get_latest_event_number(): Gets last event id persisted
|
||||
*/
|
||||
c3_o u3m_lmdb_get_latest_event_number(MDB_env* environment,
|
||||
c3_d* event_number);
|
||||
c3_o u3_lmdb_get_latest_event_number(MDB_env* environment,
|
||||
c3_d* event_number);
|
||||
|
||||
/* u3m_lmdb_write_event(): Persists an event to the database
|
||||
/* u3_lmdb_write_event(): Persists an event to the database
|
||||
*/
|
||||
void u3m_lmdb_write_event(MDB_env* environment,
|
||||
u3_writ* event_u,
|
||||
void (*on_complete)(u3_writ*));
|
||||
void u3_lmdb_write_event(MDB_env* environment,
|
||||
u3_writ* event_u,
|
||||
void (*on_complete)(u3_writ*));
|
||||
|
||||
/* u3m_lmdb_read_events(): Reads events back from the database
|
||||
/* u3_lmdb_read_events(): Reads events back from the database
|
||||
**
|
||||
** Reads back up to |len_d| events starting with |first_event_d|. For
|
||||
** each event, the event will be passed to |on_event_read| and further
|
||||
@ -1297,24 +1297,24 @@
|
||||
**
|
||||
** Returns c3y on complete success; c3n on any error.
|
||||
*/
|
||||
c3_o u3m_lmdb_read_events(u3_pier* pir_u,
|
||||
c3_d first_event_d,
|
||||
c3_d len_d,
|
||||
c3_o(*on_event_read)(u3_pier* pir_u,
|
||||
c3_d id,
|
||||
u3_noun mat,
|
||||
u3_noun ovo));
|
||||
c3_o u3_lmdb_read_events(u3_pier* pir_u,
|
||||
c3_d first_event_d,
|
||||
c3_d len_d,
|
||||
c3_o(*on_event_read)(u3_pier* pir_u,
|
||||
c3_d id,
|
||||
u3_noun mat,
|
||||
u3_noun ovo));
|
||||
|
||||
/* u3m_lmdb_write_identity(): Writes log identity
|
||||
/* u3_lmdb_write_identity(): Writes log identity
|
||||
*/
|
||||
void u3m_lmdb_write_identity(MDB_env* environment,
|
||||
u3_noun who,
|
||||
u3_noun is_fake,
|
||||
u3_noun life);
|
||||
void u3_lmdb_write_identity(MDB_env* environment,
|
||||
u3_noun who,
|
||||
u3_noun is_fake,
|
||||
u3_noun life);
|
||||
|
||||
/* u3m_lmdb_read_identity(): Reads log identity
|
||||
/* u3_lmdb_read_identity(): Reads log identity
|
||||
*/
|
||||
void u3m_lmdb_read_identity(MDB_env* environment,
|
||||
u3_noun* who,
|
||||
u3_noun* is_fake,
|
||||
u3_noun* life);
|
||||
void u3_lmdb_read_identity(MDB_env* environment,
|
||||
u3_noun* who,
|
||||
u3_noun* is_fake,
|
||||
u3_noun* life);
|
||||
|
@ -21,11 +21,11 @@
|
||||
// We perform the very first metadata writes on the main thread because we
|
||||
// can't do anything until they persist.
|
||||
|
||||
/* u3m_lmdb_init(): Opens up a log environment
|
||||
/* u3_lmdb_init(): Opens up a log environment
|
||||
**
|
||||
** Precondition: log_path points to an already created directory
|
||||
*/
|
||||
MDB_env* u3m_lmdb_init(const char* log_path)
|
||||
MDB_env* u3_lmdb_init(const char* log_path)
|
||||
{
|
||||
MDB_env* env = 0;
|
||||
c3_w ret_w = mdb_env_create(&env);
|
||||
@ -58,9 +58,9 @@ MDB_env* u3m_lmdb_init(const char* log_path)
|
||||
return env;
|
||||
}
|
||||
|
||||
/* u3m_lmdb_shutdown(): Shuts down lmdb
|
||||
/* u3_lmdb_shutdown(): Shuts down lmdb
|
||||
*/
|
||||
void u3m_lmdb_shutdown(MDB_env* env)
|
||||
void u3_lmdb_shutdown(MDB_env* env)
|
||||
{
|
||||
mdb_env_close(env);
|
||||
}
|
||||
@ -164,7 +164,7 @@ void _perform_get_on_databse_noun(MDB_txn* transaction_u,
|
||||
}
|
||||
|
||||
|
||||
/* _write_request_data: callback struct for u3m_lmdb_write_event()
|
||||
/* _write_request_data: callback struct for u3_lmdb_write_event()
|
||||
*/
|
||||
struct _write_request_data {
|
||||
// The database environment to write to. This object is thread-safe, though
|
||||
@ -191,12 +191,12 @@ struct _write_request_data {
|
||||
void (*on_complete)(u3_writ*);
|
||||
};
|
||||
|
||||
/* _u3m_lmdb_write_event_cb(): Implementation of u3m_lmdb_write_event()
|
||||
/* _u3_lmdb_write_event_cb(): Implementation of u3_lmdb_write_event()
|
||||
**
|
||||
** This is always run on a libuv background worker thread; actual nouns cannot
|
||||
** be touched here.
|
||||
*/
|
||||
static void _u3m_lmdb_write_event_cb(uv_work_t* req) {
|
||||
static void _u3_lmdb_write_event_cb(uv_work_t* req) {
|
||||
struct _write_request_data* data = req->data;
|
||||
|
||||
// Creates the write transaction.
|
||||
@ -242,12 +242,12 @@ static void _u3m_lmdb_write_event_cb(uv_work_t* req) {
|
||||
}
|
||||
}
|
||||
|
||||
/* _u3m_lmdb_write_event_after_cb(): Implementation of u3m_lmdb_write_event()
|
||||
/* _u3_lmdb_write_event_after_cb(): Implementation of u3_lmdb_write_event()
|
||||
**
|
||||
** This is always run on the main loop thread after the worker thread event
|
||||
** completes.
|
||||
*/
|
||||
static void _u3m_lmdb_write_event_after_cb(uv_work_t* req, int status) {
|
||||
static void _u3_lmdb_write_event_after_cb(uv_work_t* req, int status) {
|
||||
struct _write_request_data* data = req->data;
|
||||
|
||||
data->on_complete(data->event);
|
||||
@ -257,7 +257,7 @@ static void _u3m_lmdb_write_event_after_cb(uv_work_t* req, int status) {
|
||||
free(req);
|
||||
}
|
||||
|
||||
/* u3m_lmdb_write_event(): Asynchronously writes events to the database.
|
||||
/* u3_lmdb_write_event(): Asynchronously writes events to the database.
|
||||
**
|
||||
** This writes all the passed in events along with log metadata updates to the
|
||||
** database as a single transaction on a worker thread. Once the transaction
|
||||
@ -266,9 +266,9 @@ static void _u3m_lmdb_write_event_after_cb(uv_work_t* req, int status) {
|
||||
** TODO: Make this take multiple events in one commit once we have this
|
||||
** working one at a time.
|
||||
*/
|
||||
void u3m_lmdb_write_event(MDB_env* environment,
|
||||
u3_writ* event_u,
|
||||
void (*on_complete)(u3_writ*))
|
||||
void u3_lmdb_write_event(MDB_env* environment,
|
||||
u3_writ* event_u,
|
||||
void (*on_complete)(u3_writ*))
|
||||
{
|
||||
// Serialize the jammed $work into a malloced buffer we can send to the other
|
||||
// thread.
|
||||
@ -291,11 +291,11 @@ void u3m_lmdb_write_event(MDB_env* environment,
|
||||
|
||||
uv_queue_work(uv_default_loop(),
|
||||
req,
|
||||
_u3m_lmdb_write_event_cb,
|
||||
_u3m_lmdb_write_event_after_cb);
|
||||
_u3_lmdb_write_event_cb,
|
||||
_u3_lmdb_write_event_after_cb);
|
||||
}
|
||||
|
||||
/* u3m_lmdb_read_events(): Synchronously reads events from the database.
|
||||
/* u3_lmdb_read_events(): Synchronously reads events from the database.
|
||||
**
|
||||
** Reads back up to |len_d| events starting with |first_event_d|. For
|
||||
** each event, the event will be passed to |on_event_read| and further
|
||||
@ -303,11 +303,11 @@ void u3m_lmdb_write_event(MDB_env* environment,
|
||||
**
|
||||
** Returns c3y on complete success; c3n on any error.
|
||||
*/
|
||||
c3_o u3m_lmdb_read_events(u3_pier* pir_u,
|
||||
c3_d first_event_d,
|
||||
c3_d len_d,
|
||||
c3_o(*on_event_read)(u3_pier* pir_u, c3_d id,
|
||||
u3_noun mat, u3_noun ovo))
|
||||
c3_o u3_lmdb_read_events(u3_pier* pir_u,
|
||||
c3_d first_event_d,
|
||||
c3_d len_d,
|
||||
c3_o(*on_event_read)(u3_pier* pir_u, c3_d id,
|
||||
u3_noun mat, u3_noun ovo))
|
||||
{
|
||||
// Creates the read transaction.
|
||||
MDB_txn* transaction_u;
|
||||
@ -397,12 +397,12 @@ c3_o u3m_lmdb_read_events(u3_pier* pir_u,
|
||||
return c3y;
|
||||
}
|
||||
|
||||
/* u3m_lmdb_get_latest_event_number(): Gets last event id persisted
|
||||
/* u3_lmdb_get_latest_event_number(): Gets last event id persisted
|
||||
**
|
||||
** Reads the last key in order from the EVENTS table as the latest event
|
||||
** number. On table empty, returns c3y but doesn't modify event_number.
|
||||
*/
|
||||
c3_o u3m_lmdb_get_latest_event_number(MDB_env* environment, c3_d* event_number)
|
||||
c3_o u3_lmdb_get_latest_event_number(MDB_env* environment, c3_d* event_number)
|
||||
{
|
||||
// Creates the read transaction.
|
||||
MDB_txn* transaction_u;
|
||||
@ -464,15 +464,15 @@ c3_o u3m_lmdb_get_latest_event_number(MDB_env* environment, c3_d* event_number)
|
||||
return c3y;
|
||||
}
|
||||
|
||||
/* u3m_lmdb_write_identity(): Writes the event log identity information
|
||||
/* u3_lmdb_write_identity(): Writes the event log identity information
|
||||
**
|
||||
** We have a secondary database (table) in this environment named META where we
|
||||
** read/write identity information from/to.
|
||||
*/
|
||||
void u3m_lmdb_write_identity(MDB_env* environment,
|
||||
u3_noun who,
|
||||
u3_noun is_fake,
|
||||
u3_noun life)
|
||||
void u3_lmdb_write_identity(MDB_env* environment,
|
||||
u3_noun who,
|
||||
u3_noun is_fake,
|
||||
u3_noun life)
|
||||
{
|
||||
// Creates the write transaction.
|
||||
MDB_txn* transaction_u;
|
||||
@ -509,12 +509,12 @@ void u3m_lmdb_write_identity(MDB_env* environment,
|
||||
}
|
||||
|
||||
|
||||
/* u3m_lmdb_read_identity(): Reads the event log identity information.
|
||||
/* u3_lmdb_read_identity(): Reads the event log identity information.
|
||||
*/
|
||||
void u3m_lmdb_read_identity(MDB_env* environment,
|
||||
u3_noun* who,
|
||||
u3_noun* is_fake,
|
||||
u3_noun* life) {
|
||||
void u3_lmdb_read_identity(MDB_env* environment,
|
||||
u3_noun* who,
|
||||
u3_noun* is_fake,
|
||||
u3_noun* life) {
|
||||
// Creates the write transaction.
|
||||
MDB_txn* transaction_u;
|
||||
c3_w ret_w = mdb_txn_begin(environment,
|
||||
|
@ -83,7 +83,7 @@ _pier_db_bail(void* vod_p, const c3_c* err_c)
|
||||
static void
|
||||
_pier_db_shutdown(u3_pier* pir_u)
|
||||
{
|
||||
u3m_lmdb_shutdown(pir_u->log_u->db_u);
|
||||
u3_lmdb_shutdown(pir_u->log_u->db_u);
|
||||
}
|
||||
|
||||
/* _pier_db_commit_complete(): commit complete.
|
||||
@ -124,9 +124,9 @@ _pier_db_commit_request(u3_writ* wit_u)
|
||||
/* put it in the database
|
||||
*/
|
||||
{
|
||||
u3m_lmdb_write_event(log_u->db_u,
|
||||
wit_u,
|
||||
_pier_db_commit_complete);
|
||||
u3_lmdb_write_event(log_u->db_u,
|
||||
wit_u,
|
||||
_pier_db_commit_complete);
|
||||
}
|
||||
|
||||
/* advance commit-request counter
|
||||
@ -144,8 +144,8 @@ _pier_db_write_header(u3_pier* pir_u,
|
||||
u3_noun is_fake,
|
||||
u3_noun life)
|
||||
{
|
||||
u3m_lmdb_write_identity(pir_u->log_u->db_u,
|
||||
who, is_fake, life);
|
||||
u3_lmdb_write_identity(pir_u->log_u->db_u,
|
||||
who, is_fake, life);
|
||||
}
|
||||
|
||||
/* _pier_db_read_header(): reads the ships metadata from lmdb
|
||||
@ -154,8 +154,8 @@ static void
|
||||
_pier_db_read_header(u3_pier* pir_u)
|
||||
{
|
||||
u3_noun who, is_fake, life;
|
||||
u3m_lmdb_read_identity(pir_u->log_u->db_u,
|
||||
&who, &is_fake, &life);
|
||||
u3_lmdb_read_identity(pir_u->log_u->db_u,
|
||||
&who, &is_fake, &life);
|
||||
|
||||
_pier_boot_set_ship(pir_u, u3k(who), u3k(is_fake));
|
||||
pir_u->lif_d = u3r_chub(0, life);
|
||||
@ -221,10 +221,10 @@ _pier_db_load_commits(u3_pier* pir_u,
|
||||
// We are restarting from event 1. That means we need to set the ship from
|
||||
// the log identity information.
|
||||
u3_noun who, fak, len;
|
||||
u3m_lmdb_read_identity(pir_u->log_u->db_u,
|
||||
&who,
|
||||
&fak,
|
||||
&len);
|
||||
u3_lmdb_read_identity(pir_u->log_u->db_u,
|
||||
&who,
|
||||
&fak,
|
||||
&len);
|
||||
|
||||
_pier_boot_set_ship(pir_u, u3k(who), u3k(fak));
|
||||
pir_u->lif_d = u3r_chub(0, len);
|
||||
@ -234,10 +234,10 @@ _pier_db_load_commits(u3_pier* pir_u,
|
||||
u3z(len);
|
||||
}
|
||||
|
||||
u3m_lmdb_read_events(pir_u,
|
||||
lav_d,
|
||||
len_d,
|
||||
_pier_db_on_commit_loaded);
|
||||
u3_lmdb_read_events(pir_u,
|
||||
lav_d,
|
||||
len_d,
|
||||
_pier_db_on_commit_loaded);
|
||||
}
|
||||
|
||||
/* _pier_db_init():
|
||||
@ -251,7 +251,7 @@ _pier_db_init(u3_disk* log_u)
|
||||
c3_assert( c3n == log_u->liv_o );
|
||||
|
||||
// Request from the database the last event
|
||||
if ( c3n == u3m_lmdb_get_latest_event_number(log_u->db_u, &evt_d) ) {
|
||||
if ( c3n == u3_lmdb_get_latest_event_number(log_u->db_u, &evt_d) ) {
|
||||
u3l_log("disk init from lmdb failed.");
|
||||
return c3n;
|
||||
}
|
||||
@ -316,7 +316,7 @@ _pier_disk_create(u3_pier* pir_u)
|
||||
}
|
||||
|
||||
// Inits the database
|
||||
if ( 0 == (log_u->db_u = u3m_lmdb_init(log_c)) ) {
|
||||
if ( 0 == (log_u->db_u = u3_lmdb_init(log_c)) ) {
|
||||
c3_free(log_c);
|
||||
return c3n;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user