mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-24 16:20:15 +08:00
Add Python txn get_approximate_size API and test
This commit is contained in:
parent
4c0e824456
commit
c91e712576
bindings/python
@ -541,6 +541,11 @@ class Transaction(TransactionRead):
|
||||
self.capi.fdb_transaction_get_committed_version(self.tpointer, ctypes.byref(version))
|
||||
return version.value
|
||||
|
||||
def get_approximate_size(self):
|
||||
size = ctypes.c_int()
|
||||
self.capi.fdb_transaction_get_approximate_size(self.tpointer, ctypes.byref(size))
|
||||
return size.value
|
||||
|
||||
def get_versionstamp(self):
|
||||
return Key(self.capi.fdb_transaction_get_versionstamp(self.tpointer))
|
||||
|
||||
@ -1453,6 +1458,10 @@ def init_c_api():
|
||||
_capi.fdb_transaction_get_committed_version.restype = ctypes.c_int
|
||||
_capi.fdb_transaction_get_committed_version.errcheck = check_error_code
|
||||
|
||||
_capi.fdb_transaction_get_approximate_size.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_int)]
|
||||
_capi.fdb_transaction_get_approximate_size.restype = ctypes.c_int
|
||||
_capi.fdb_transaction_get_approximate_size.errcheck = check_error_code
|
||||
|
||||
_capi.fdb_transaction_get_versionstamp.argtypes = [ctypes.c_void_p]
|
||||
_capi.fdb_transaction_get_versionstamp.restype = ctypes.c_void_p
|
||||
|
||||
|
@ -68,9 +68,36 @@ def test_size_limit_option(db):
|
||||
except fdb.FDBError as e:
|
||||
assert(e.code == 2101) # Transaction exceeds byte limit (2101)
|
||||
|
||||
@fdb.transactional
|
||||
def test_get_approximate_size(tr):
|
||||
tr[b'key1'] = b'value1'
|
||||
s1 = tr.get_approximate_size()
|
||||
print "s1: ", s1
|
||||
|
||||
tr[b'key2'] = b'value2'
|
||||
s2 = tr.get_approximate_size()
|
||||
print "s2: ", s2
|
||||
assert(s1 < s2)
|
||||
|
||||
tr.clear(b'key3')
|
||||
s3 = tr.get_approximate_size()
|
||||
print "s3: ", s3
|
||||
assert(s2 < s3)
|
||||
|
||||
tr.add_read_conflict_key(b'key3')
|
||||
s4 = tr.get_approximate_size()
|
||||
print "s4: ", s4
|
||||
assert(s3 < s4)
|
||||
|
||||
tr.add_write_conflict_key(b'key4')
|
||||
s5 = tr.get_approximate_size()
|
||||
print "s5: ", s5
|
||||
assert(s4 < s5)
|
||||
|
||||
# Expect a cluster file as input. This test will write to the FDB cluster, so
|
||||
# be aware of potential side effects.
|
||||
if __name__ == '__main__':
|
||||
clusterFile = sys.argv[1]
|
||||
db = fdb.open(clusterFile)
|
||||
test_size_limit_option(db)
|
||||
test_get_approximate_size(db)
|
||||
|
Loading…
x
Reference in New Issue
Block a user