throw(KNOT_EINVAL, RDB_EMALF);
}
+ uint16_t counter = knot_wire_read_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, counter));
for (txn->id = TXN_MIN; txn->id <= TXN_MAX; ++txn->id) {
- if (meta->lock[txn->id] == 0) {
- meta->counter = MAX(meta->counter + 1, 1);
- meta->lock[txn->id] = meta->counter;
+ uint16_t lock = knot_wire_read_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, lock[txn->id]));
+ if (lock == 0) {
+ counter = MAX((uint16_t)(counter + 1), (uint16_t)1);
+ knot_wire_write_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, counter), counter);
+ knot_wire_write_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, lock[txn->id]), counter);
break;
}
}
return KNOT_EINVAL;
}
- uint16_t id = meta->lock[txn->id];
+ uint16_t id = knot_wire_read_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, lock[txn->id]));
if (id == 0) {
RedisModule_CloseKey(meta_key);
return KNOT_EEXIST;
}
size_t len = 0;
const upd_meta_storage_t *transaction = (const upd_meta_storage_t *)RedisModule_StringDMA(key, &len, REDISMODULE_WRITE);
- if (transaction->lock[txn->id] == 0) {
+ uint16_t lock = knot_wire_read_u16((uint8_t *)transaction + offsetof(upd_meta_storage_t, lock[txn->id]));
+ if (lock == 0) {
RedisModule_CloseKey(key);
return NULL;
}
size_t len = 0;
upd_meta_storage_t *meta = (upd_meta_storage_t *)RedisModule_StringDMA(meta_key, &len, REDISMODULE_WRITE);
RedisModule_Assert(len == sizeof(*meta));
- meta->depth = 0;
+ knot_wire_write_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, depth), 0);
}
RedisModule_CloseKey(meta_key);
size_t len = 0;
upd_meta_storage_t *meta = (upd_meta_storage_t *)RedisModule_StringDMA(key, &len, REDISMODULE_WRITE);
RedisModule_Assert(len == sizeof(*meta));
- meta->lock[id] = 0;
+ knot_wire_write_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, lock[id]), 0);
}
static exception_t upd_abort(RedisModuleCtx *ctx, const arg_dname_t *origin, rdb_txn_t *txn)
RedisModule_ReplyWithError(ctx, RDB_EHISTORY);
return;
}
- meta->depth -= counter;
+ uint16_t depth = knot_wire_read_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, depth));
+ knot_wire_write_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, depth), depth - counter);
// Commit the update.
index_k new_upd_key = get_commited_upd_index(ctx, origin, upd_txn, serial_new, REDISMODULE_READ | REDISMODULE_WRITE);
RedisModule_CloseKey(diff_key);
}
- ++meta->depth;
+ knot_wire_write_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, depth), ++depth);
RedisModule_DeleteKey(upd_key);
RedisModule_CloseKey(upd_key);
e = upd_trim_history(ctx, origin, upd_txn, rdb_upd_history_len);
if (e.ret == KNOT_EOK) {
- meta->depth = MIN(meta->depth, rdb_upd_history_len);
+ knot_wire_write_u16((uint8_t *)meta + offsetof(upd_meta_storage_t, depth), MIN(depth, rdb_upd_history_len));
}
upd_meta_unlock(ctx, meta_key, upd_txn->id);