int olt_commit(ol_transaction *tx) { /* So at this point we should have a series of operations stored up and * successful in our tx->transaction_db. At this point we need to replay * them all back onto the parent_db. */ check(tx->parent_db != NULL, "No parent database."); check(tx->parent_db->cur_transactions != NULL, "No transaction tree."); if (!tx->dirty) return olt_abort(tx); char tx_aol_filename[AOL_FILENAME_ALLOC] = {0}; tx->transaction_db->get_db_file_name(tx->transaction_db, AOL_FILENAME, tx_aol_filename); char values_filename[DB_NAME_SIZE] = {0}; tx->transaction_db->get_db_file_name(tx->transaction_db, VALUES_FILENAME, values_filename); /* Don't squish or compact or anything here because it'll remove stuff * that we don't want removed from the log file, like SCOOP commands. */ /* Make sure everything is written: */ ol_sync(tx->transaction_db); /* Throw fflush in here because f**k Linux */ fflush(tx->transaction_db->aolfd); tx->parent_db->state = OL_S_COMMITTING; ol_aol_restore_from_file(tx->parent_db, tx_aol_filename, tx->transaction_db->values); tx->parent_db->state = OL_S_AOKAY; return _olt_cleanup(tx, values_filename, tx_aol_filename); error: return 1; }
int ol_scoop(ol_database *db, const char *key, size_t klen) { if (db->is_enabled(OL_F_DISABLE_TX, &db->feature_set) || db->state == OL_S_COMMITTING || db->state == OL_S_STARTUP) { /* Fake a transaction: */ ol_transaction stack_tx = { .tx_id = 0, .parent_db = NULL, .transaction_db = db }; return olt_scoop(&stack_tx, key, klen); } ol_transaction *tx = olt_begin(db); int scoop_ret = OL_SUCCESS; check(tx != NULL, "Could not begin implicit transaction."); scoop_ret = olt_scoop(tx, key, klen); check(scoop_ret == OL_SUCCESS, "Could not scoop value. Aborting."); check(olt_commit(tx) == OL_SUCCESS, "Could not commit transaction."); return OL_SUCCESS; error: if (tx != NULL && scoop_ret != 10) olt_abort(tx); return OL_FAILURE; }
int ol_jar(ol_database *db, const char *key, size_t klen, const unsigned char *value, size_t vsize) { /* Is disabled_tx enabled? lksjdlkfpfpfllfplflpf */ if (db->is_enabled(OL_F_DISABLE_TX, &db->feature_set) || db->state == OL_S_COMMITTING || db->state == OL_S_STARTUP) { /* Fake a transaction: */ ol_transaction stack_tx = { .tx_id = 0, .parent_db = NULL, .transaction_db = db }; return olt_jar(&stack_tx, key, klen, value, vsize); } ol_transaction *tx = olt_begin(db); int jar_ret = OL_SUCCESS; check(tx != NULL, "Could not begin implicit transaction."); jar_ret = olt_jar(tx, key, klen, value, vsize); check(jar_ret == OL_SUCCESS, "Could not jar value. Aborting."); check(olt_commit(tx) == OL_SUCCESS, "Could not commit transaction."); return OL_SUCCESS; error: if (tx != NULL && jar_ret != OL_SUCCESS) olt_abort(tx); return OL_FAILURE; }
int ol_spoil(ol_database *db, const char *key, size_t klen, struct tm *expiration_date) { if (db->is_enabled(OL_F_DISABLE_TX, &db->feature_set) || db->state == OL_S_COMMITTING || db->state == OL_S_STARTUP) { /* Fake a transaction: */ ol_transaction stack_tx = { .tx_id = 0, .parent_db = NULL, .transaction_db = db }; return olt_spoil(&stack_tx, key, klen, expiration_date); } debug("Beginning ol_spoil."); ol_transaction *tx = olt_begin(db); int spoil_ret = OL_SUCCESS; check(tx != NULL, "Could not begin implicit transaction."); spoil_ret = olt_spoil(tx, key, klen, expiration_date); check(spoil_ret == OL_SUCCESS, "Could not spoil value. Aborting."); check(olt_commit(tx) == OL_SUCCESS, "Could not commit transaction."); debug("End of ol_spoil."); return OL_SUCCESS; error: debug("Error in ol_spoil."); if (tx != NULL && spoil_ret != OL_SUCCESS) olt_abort(tx); return OL_FAILURE; }
int ol_unjar(ol_database *db, const char *key, size_t klen, unsigned char **data, size_t *dsize) { if (db->is_enabled(OL_F_DISABLE_TX, &db->feature_set) || db->state == OL_S_COMMITTING || db->state == OL_S_STARTUP) { /* Fake a transaction: */ ol_transaction stack_tx = { .tx_id = 0, .parent_db = NULL, .transaction_db = db }; return olt_unjar(&stack_tx, key, klen, data, dsize); } ol_transaction *tx = olt_begin(db); int unjar_ret = OL_SUCCESS; check(tx != NULL, "Could not begin transaction."); unjar_ret = olt_unjar(tx, key, klen, data, dsize); check(unjar_ret == OL_SUCCESS, "Could not unjar."); check(olt_commit(tx) == OL_SUCCESS, "Could not commit transaction."); return OL_SUCCESS; error: if (tx != NULL && unjar_ret != OL_SUCCESS) olt_abort(tx); return OL_FAILURE; }