Exemplo n.º 1
0
def duplicate_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.put(b"ab02", b"val-c0", txn=t)

    with kvdb.transaction() as t:
        with kvs.cursor(filt=b"ab", txn=t) as c:
            if cursor_sync:
                kvdb.sync()

            # Point Get
            assert kvs.get(b"ab01", txn=t) == b"val-cn"
            assert kvs.get(b"ab02", txn=t) == b"val-c0"

            # Probe
            cnt, *kv = kvs.prefix_probe(b"ab0", txn=t)
            assert cnt == hse.KvsPfxProbeCnt.MUL
            assert kv == [b"ab02", b"val-c0"]

            # Read all keys
            assert c.read() == (b"ab01", b"val-cn")
            assert c.read() == (b"ab02", b"val-c0")
            assert c.read() == (None, None) and c.eof == True

            # Seek, read
            c.seek(b"ab00")
            assert c.read() == (b"ab01", b"val-cn")
            c.seek(b"ab01")
            assert c.read() == (b"ab01", b"val-cn")
            c.seek(b"ab02")
            assert c.read() == (b"ab02", b"val-c0")
            c.seek(b"ab03")
            assert c.read() == (None, None) and c.eof == True

            # Read, update, read
            c.seek(b"ab01")
            ##c.update()
            assert c.read() == (b"ab01", b"val-cn")
            ##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"ab01", b"val-cn")
            c.seek(b"ab02")
            ##c.update()
            assert c.read() == (b"ab02", b"val-c0")
            c.seek(b"ab03")
            ##c.update()
            assert c.read() == (None, None) and c.eof == True
Exemplo n.º 2
0
def separate_keys(kvdb: hse.Kvdb, kvs: hse.Kvs):
    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.put(b"ab03", b"val-c0", txn=t)

    with kvdb.transaction() as t:
        # Point Get
        assert kvs.get(b"ab01", txn=t) == b"val-cn"
        assert kvs.get(b"ab02", txn=t) == b"val-lc"
        assert kvs.get(b"ab03", txn=t) == b"val-c0"

        # Probe
        cnt, *kv = kvs.prefix_probe(b"ab0", txn=t)
        assert cnt == hse.KvsPfxProbeCnt.MUL
        assert kv == [b"ab03", b"val-c0"]

        # Cursor
        with kvs.cursor(filt=b"ab", txn=t) as c:
            # Read all keys
            assert c.read() == (b"ab01", b"val-cn")
            assert c.read() == (b"ab02", b"val-lc")
            assert c.read() == (b"ab03", b"val-c0")
            assert c.read() == (None, None) and c.eof == True

            # Seek, read
            c.seek(b"ab01")
            assert c.read() == (b"ab01", b"val-cn")
            c.seek(b"ab02")
            assert c.read() == (b"ab02", b"val-lc")
            c.seek(b"ab03")
            assert c.read() == (b"ab03", b"val-c0")

            # Read, update, read
            c.seek(b"ab01")
            ##c.update()
            assert c.read() == (b"ab01", b"val-cn")
            ##c.update()
            assert c.read() == (b"ab02", b"val-lc")
            ##c.update()
            assert c.read() == (b"ab03", 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"ab01", b"val-cn")
            c.seek(b"ab02")
            ##c.update()
            assert c.read() == (b"ab02", b"val-lc")
            c.seek(b"ab03")
            ##c.update()
            assert c.read() == (b"ab03", b"val-c0")
Exemplo n.º 3
0
def tombs_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.delete(b"ab02", txn=t)

    # Cursor
    with kvs.cursor(filt=b"ab") as c:
        if cursor_sync:
            kvdb.sync()

        # Point Get
        assert kvs.get(b"ab01")[0] == b"val-cn"
        assert kvs.get(b"ab02")[0] == None

        # Probe
        cnt, k, _, v, _ = kvs.prefix_probe(b"ab0")
        assert cnt == hse.KvsPfxProbeCnt.ONE
        assert (k, v) == (b"ab01", b"val-cn")

        # Read all keys
        assert c.read() == (b"ab01", b"val-cn")
        assert c.read() == (None, None) and c.eof == True

        # Seek, read
        c.seek(b"ab00")
        assert c.read() == (b"ab01", b"val-cn")
        c.seek(b"ab01")
        assert c.read() == (b"ab01", b"val-cn")
        c.seek(b"ab02")
        assert c.read() == (None, None) and c.eof == True

        # Read, update, read
        c.seek(b"ab01")
        c.update_view()
        assert c.read() == (b"ab01", b"val-cn")
        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() == (b"ab01", b"val-cn")
        c.seek(b"ab02")
        c.update_view()
        assert c.read() == (None, None) and c.eof == True
Exemplo n.º 4
0
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 kvdb.transaction() as t:
        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) == None

            # Probe
            cnt, *_ = kvs.prefix_probe(b"ab0", txn=t)
            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()
            assert c.read() == (None, None) and c.eof == True

            # Seek, update, read
            c.seek(b"ab01")
            ##c.update()
            assert c.read() == (None, None) and c.eof == True
            c.seek(b"ab02")
            ##c.update()
            assert c.read() == (None, None) and c.eof == True
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
def duplicate_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.put(b"ab01", b"val-lc", 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") as c:
        probe_kv = (b"ab02", b"val-c0")
        if cursor_sync:
            probe_kv = (b"ab01", b"val-lc")
            kvdb.sync()

        # Point Get
        assert kvs.get(b"ab01")[0] == b"val-lc"
        assert kvs.get(b"ab02")[0] == b"val-c0"

        # Probe
        cnt, k, _, v, _ = kvs.prefix_probe(b"ab0")
        assert cnt == hse.KvsPfxProbeCnt.MUL
        assert (k, v) == probe_kv

        # Read all keys
        assert c.read() == (b"ab01", b"val-lc")
        assert c.read() == (b"ab02", b"val-c0")
        assert c.read() == (None, None) and c.eof == True

        # Seek, read
        c.seek(b"ab00")
        assert c.read() == (b"ab01", b"val-lc")
        c.seek(b"ab01")
        assert c.read() == (b"ab01", b"val-lc")
        c.seek(b"ab02")
        assert c.read() == (b"ab02", b"val-c0")
        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() == (b"ab01", b"val-lc")
        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_view, read
        c.seek(b"ab01")
        c.update_view()
        assert c.read() == (b"ab01", b"val-lc")
        c.seek(b"ab02")
        c.update_view()
        assert c.read() == (b"ab02", b"val-c0")
        c.seek(b"ab03")
        c.update_view()
        assert c.read() == (None, None) and c.eof == True