int _ol_set_bucket_no_incr(ol_database *db, ol_bucket *bucket, uint32_t hash) { /* TODO: error codes? */ unsigned int index = _ol_calc_idx(db->cur_ht_size, hash); if (db->hashes[index] != NULL) { db->meta->key_collisions++; ol_bucket *tmp_bucket = db->hashes[index]; tmp_bucket = _ol_get_last_bucket_in_slot(tmp_bucket); tmp_bucket->next = bucket; } else { db->hashes[index] = bucket; } if (db->is_enabled(OL_F_SPLAYTREE, &db->feature_set)) { /* Put the bucket into the tree */ ol_splay_tree_node *node = NULL; node = ols_insert(db->tree, bucket->key, bucket->klen, bucket); /* Make sure the bucket can reference the node. */ bucket->node = node; } return 0; }
ol_transaction *olt_begin(ol_database *db) { char *name = NULL; ol_transaction *new_transaction = NULL; check(db != NULL, "No database specified in transaction begin."); check(db->cur_transactions != NULL, "No transaction tree."); /* We initialize on the stack because tx_id is a const parameter. */ ol_transaction stack_tx = { .tx_id = global_transaction_id, .dirty = 0, .parent_db = db, .transaction_db = NULL }; /* Setup a ".../tx/" directory for our transaction databases. */ char new_path[PATH_LENGTH] = {0}; _tx_directory(new_path, db); /* Convert our integer tx_id into a string */ name = tx_to_str(stack_tx.tx_id); check(name != NULL, "Could not convert tx_id to str."); /* Make sure implicit transactions is turned OFF, because otherwise we'll * get endless recursion. Wooo! */ ol_feature_flags flags = OL_F_APPENDONLY | OL_F_SPLAYTREE | OL_F_LZ4 | OL_F_DISABLE_TX; stack_tx.transaction_db = ol_open(new_path, name, flags); stack_tx.transaction_db->rcrd_cnt = stack_tx.parent_db->rcrd_cnt; check(stack_tx.transaction_db != NULL, "Could not open transaction database."); /* Copy the stack thing into the heap thing. */ new_transaction = malloc(sizeof(ol_transaction)); check_mem(new_transaction); memcpy(new_transaction, &stack_tx, sizeof(ol_transaction)); free(name); ols_insert(db->cur_transactions, stack_tx.transaction_db->name, strnlen(stack_tx.transaction_db->name, DB_NAME_SIZE), new_transaction ); global_transaction_id++; return new_transaction; error: free(new_transaction); free(name); return NULL; } static void _olt_cleanup_common(ol_transaction *tx, char *values_filename, char *tx_aol_filename) { /* Yeah, come at me. */ debug("Unlinking values file for transaction, %s", values_filename); unlink(values_filename); debug("Unlinking aol file for transaction, %s", tx_aol_filename); unlink(tx_aol_filename); free(tx); }