def run_test_2(kvdb: hse.Kvdb, kvs: hse.Kvs): t1 = kvdb.transaction() t1.begin() kvs.prefix_delete(b"def", txn=t1) # LC kvdb.sync() kvs.prefix_delete(b"def", txn=t1) # LC kvdb.sync() with kvdb.transaction() as t: kvs.put(b"def01", b"val1", txn=t) # C0 kvs.put(b"def02", b"val1", txn=t) # C0 kvs.put(b"def03", b"val1", txn=t) # C0 kvs.put(b"def04", b"val1", txn=t) # C0 t1.commit() # ptomb has higher seqno with kvs.cursor(filt=b"def") as c: c.read() assert c.eof is True ##c.update() c.read() assert c.eof is True c.seek(b"def03") c.read() assert c.eof is True c.seek(b"def02") ##c.update() c.read() assert c.eof is True
def pdel_before_put(kvdb: hse.Kvdb, kvs: hse.Kvs): with kvdb.transaction() as t: kvs.put(b"ab01", b"old", txn=t) t1 = kvdb.transaction() t1.begin() kvs.prefix_delete(b"ab", txn=t1) t2 = kvdb.transaction() t2.begin() try: kvs.put(b"ab01", b"val", txn=t2) assert False except hse.HseException as e: assert e.returncode == errno.ECANCELED t2.commit() assert kvs.get(b"ab01")[0] == b"old" t1.commit() assert kvs.get(b"ab01")[0] == None with kvdb.transaction() as t: kvs.put(b"ab01", b"new", txn=t) assert kvs.get(b"ab01")[0] == b"new"
def run_test_1(kvdb: hse.Kvdb, kvs: hse.Kvs): with kvdb.transaction() as t: kvs.put(b"abc01", b"val0", txn=t) # LC kvs.put(b"abc02", b"val0", txn=t) # LC kvs.prefix_delete(b"abc", txn=t) # LC kvdb.sync() kvs.put(b"abc01", b"val1", txn=t) # C0 kvs.put(b"abc02", b"val1", txn=t) # C0 kvs.put(b"abc03", b"val1", txn=t) # C0 kvs.put(b"abc04", b"val1", txn=t) # C0 with kvs.cursor(filt=b"abc", txn=t) as c: kv = c.read() assert kv == (b"abc01", b"val1") kv = c.read() assert kv == (b"abc02", b"val1") ##c.update() kv = c.read() assert kv == (b"abc03", b"val1") c.seek(b"abc02") ##c.update() kv = c.read() assert kv == (b"abc02", b"val1")
def ptombs_lc_cn(kvdb: hse.Kvdb, kvs: hse.Kvs, cursor_sync: bool = False): with kvdb.transaction() as t: kvs.put(b"ab01", b"val-cn", txn=t) with kvdb.transaction() as t: kvs.prefix_delete(b"ab", txn=t) kvdb.sync() with kvdb.transaction() as t: kvs.put(b"ab02", b"val-c0", txn=t) with kvdb.transaction() as t: # Cursor with kvs.cursor(filt=b"ab", txn=t) as c: if cursor_sync: kvdb.sync() # Point Get assert kvs.get(b"ab01", txn=t) == None assert kvs.get(b"ab02", txn=t) == b"val-c0" # Probe cnt, *kv = kvs.prefix_probe(b"ab0", txn=t) assert cnt == hse.KvsPfxProbeCnt.ONE assert kv == [b"ab02", b"val-c0"] # Read all keys assert c.read() == (b"ab02", b"val-c0") assert c.read() == (None, None) and c.eof == True # Seek, read c.seek(b"ab01") assert c.read() == (b"ab02", b"val-c0") c.seek(b"ab02") assert c.read() == (b"ab02", b"val-c0") # Read, update, read c.seek(b"ab01") ##c.update() assert c.read() == (b"ab02", b"val-c0") ##c.update() assert c.read() == (None, None) and c.eof == True # Seek, update, read c.seek(b"ab01") ##c.update() assert c.read() == (b"ab02", b"val-c0") c.seek(b"ab02") ##c.update() assert c.read() == (b"ab02", b"val-c0")
def ptombs_c0_lc(kvdb: hse.Kvdb, kvs: hse.Kvs, cursor_sync: bool = False): with kvdb.transaction() as t: kvs.put(b"ab01", b"val-cn", txn=t) with kvdb.transaction() as t: kvs.put(b"ab02", b"val-lc", txn=t) kvdb.sync() with kvdb.transaction() as t: kvs.prefix_delete(b"ab", txn=t) # Cursor with kvs.cursor(filt=b"ab") as c: if cursor_sync: kvdb.sync() # Point Get assert kvs.get(b"ab01") == None assert kvs.get(b"ab02") == None # Probe cnt, *_ = kvs.prefix_probe(b"ab0") assert cnt == hse.KvsPfxProbeCnt.ZERO # Read all keys assert c.read() == (None, None) and c.eof == True # Seek, read c.seek(b"ab00") assert c.read() == (None, None) and c.eof == True c.seek(b"ab01") assert c.read() == (None, None) and c.eof == True c.seek(b"ab02") assert c.read() == (None, None) and c.eof == True c.seek(b"ab03") assert c.read() == (None, None) and c.eof == True # Read, update, read c.seek(b"ab01") c.update_view() assert c.read() == (None, None) and c.eof == True # Seek, update, read c.seek(b"ab01") c.update_view() assert c.read() == (None, None) and c.eof == True c.seek(b"ab02") c.update_view() assert c.read() == (None, None) and c.eof == True
def run_test_4(kvdb: hse.Kvdb, kvs: hse.Kvs): with kvdb.transaction() as t: kvs.put(b"jkl01", b"val1", txn=t) kvs.put(b"jkl02", b"val1", txn=t) kvs.put(b"jkl03", b"val1", txn=t) with kvdb.transaction() as t: kvs.prefix_delete(b"jkl", txn=t) kvs.put(b"jkl03", b"val2", txn=t) kvdb.sync() assert kvs.get(b"jkl01", txn=t) is None assert kvs.get(b"jkl03", txn=t) == b"val2" cnt, *kv = kvs.prefix_probe(b"jkl", txn=t) assert cnt == hse.KvsPfxProbeCnt.ONE assert kv == [b"jkl03", b"val2"] pass
def run_test_3(kvdb: hse.Kvdb, kvs: hse.Kvs): with kvdb.transaction() as t: kvs.put(b"jkl01", b"val1", txn=t) kvs.put(b"jkl02", b"val1", txn=t) kvs.put(b"jkl03", b"val1", txn=t) with kvdb.transaction() as t: kvs.prefix_delete(b"jkl", txn=t) kvs.put(b"jkl03", b"val2", txn=t) kvdb.sync() assert kvs.get(b"jkl01", txn=t)[0] is None assert kvs.get(b"jkl03", txn=t)[0] == b"val2" cnt, k, _, v, _ = kvs.prefix_probe(b"jkl", txn=t) assert cnt == hse.KvsPfxProbeCnt.ONE assert (k, v) == (b"jkl03", b"val2") pass
def short_put(kvdb: hse.Kvdb, kvs: hse.Kvs): with kvdb.transaction() as t: kvs.put(b"ab01", b"old", txn=t) t1 = kvdb.transaction() t1.begin() t2 = kvdb.transaction() t2.begin() kvs.put(b"ab01", b"val", txn=t1) t1.commit() try: kvs.prefix_delete(b"ab", txn=t2) assert False except hse.HseException as e: assert e.returncode == errno.ECANCELED t2.abort()
def ptombs_lc_cn(kvdb: hse.Kvdb, kvs: hse.Kvs, cursor_sync: bool = False): with kvdb.transaction() as t: kvs.put(b"ab01", b"val-cn", txn=t) with kvdb.transaction() as t: kvs.prefix_delete(b"ab", txn=t) kvdb.sync() with kvdb.transaction() as t: kvs.put(b"ab02", b"val-c0", txn=t) # Cursor with kvs.cursor(filt=b"ab", flags=hse.CursorFlag.REVERSE) as c: if cursor_sync: kvdb.sync() # Read all keys assert c.read() == (b"ab02", b"val-c0") x = c.read() assert c.read() == (None, None) and c.eof == True # Seek, read c.seek(b"ab03") assert c.read() == (b"ab02", b"val-c0") c.seek(b"ab02") assert c.read() == (b"ab02", b"val-c0") # Read, update, read c.seek(b"ab03") c.update_view() assert c.read() == (b"ab02", b"val-c0") c.update_view() assert c.read() == (None, None) and c.eof == True # Seek, update, read c.seek(b"ab03") c.update_view() assert c.read() == (b"ab02", b"val-c0") c.seek(b"ab02") c.update_view() assert c.read() == (b"ab02", b"val-c0")
def pdel_commits(kvdb: hse.Kvdb, kvs: hse.Kvs): with kvdb.transaction() as t: kvs.put(b"ab01", b"old", txn=t) t1 = kvdb.transaction() t1.begin() kvs.prefix_delete(b"ab", txn=t1) t2 = kvdb.transaction() t2.begin() # Commit pdel. t2 began before this point, so it should not allow puts. t1.commit() try: kvs.put(b"ab01", b"val", txn=t2) assert False except hse.HseException as e: assert e.returncode == errno.ECANCELED t2.commit() assert kvs.get(b"ab01")[0] == None