};
typedef struct write_rec {
- const char *key;
+ void *key;
update_rec_t *rec;
} write_rec_t;
// Validate the updates for <key>. Validation fails for a key we have written to if there is a
// write committed newer than our read version.
-static txn_state_e tm_validate_key (txn_t *txn, const char *key, uint32_t key_len) {
+static txn_state_e tm_validate_key (txn_t *txn, void *key) {
- update_rec_t *update = (update_rec_t *) map_get(txn->map, key, key_len);
+ update_rec_t *update = (update_rec_t *) map_get(txn->map, key);
for (; update != NULL; update = update->prev) {
uint64_t writer_version = update->version;
if (writer_version <= txn->rv)
}
for (i = 0; i < txn->writes_count; ++i) {
- txn_state_e s = tm_validate_key(txn, txn->writes[i].key, strlen(txn->writes[i].key));
+ txn_state_e s = tm_validate_key(txn, txn->writes[i].key);
if (s == TXN_ABORTED) {
txn->state = TXN_ABORTED;
break;
return u;
}
-txn_t *txn_begin (txn_access_e access, txn_isolation_e isolation, map_type_t map_type) {
+txn_t *txn_begin (txn_access_e access, txn_isolation_e isolation, map_t *map) {
txn_t *txn = (txn_t *)nbd_malloc(sizeof(txn_t));
memset(txn, 0, sizeof(txn_t));
txn->access = access;
txn->rv = version_;
txn->wv = UNDETERMINED_VERSION;
txn->state = TXN_RUNNING;
- txn->map = map_alloc(map_type);
+ txn->map = map;
if (isolation != TXN_READ_ONLY) {
txn->writes = nbd_malloc(sizeof(*txn->writes) * INITIAL_WRITES_SIZE);
txn->writes_size = INITIAL_WRITES_SIZE;
}
// Get most recent committed version prior to our read version.
-uint64_t tm_get (txn_t *txn, const char *key, uint32_t key_len) {
+uint64_t tm_get (txn_t *txn, void *key) {
// Iterate through update records associated with <key> to find the latest committed version.
// We can use the first matching version. Older updates always come later in the list.
- update_rec_t *update = (update_rec_t *) map_get(txn->map, key, key_len);
+ update_rec_t *update = (update_rec_t *) map_get(txn->map, key);
for (; update != NULL; update = update->prev) {
uint64_t writer_version = update->version;
if (writer_version < txn->rv)
return DOES_NOT_EXIST;
}
-void tm_set (txn_t *txn, const char *key, uint32_t key_len, uint64_t value) {
+void tm_set (txn_t *txn, void *key, uint64_t value) {
// create a new update record
update_rec_t *update = alloc_update_rec();
// push the new update record onto <key>'s update list
uint64_t update_prev;
do {
- update->prev = (update_rec_t *) map_get(txn->map, key, key_len);
+ update->prev = (update_rec_t *) map_get(txn->map, key);
update_prev = (uint64_t)update->prev;
- } while (map_cas(txn->map, key, key_len, update_prev, (uint64_t)update) != update_prev);
+ } while (map_cas(txn->map, key, update_prev, (uint64_t)update) != update_prev);
// add <key> to the write set for commit-time validation
if (txn->writes_count == txn->writes_size) {