diff --git a/bindings/bindingtester/spec/bindingApiTester.md b/bindings/bindingtester/spec/bindingApiTester.md index 2953ef3c63..7ecbd6b280 100644 --- a/bindings/bindingtester/spec/bindingApiTester.md +++ b/bindings/bindingtester/spec/bindingApiTester.md @@ -279,7 +279,7 @@ futures must apply the following rules to the result: #### GET_APPROXIMATE_SIZE - Calls get_approximate_size and pushes the string `fdb.tuple.pack((,))` onto the stack. + Calls get_approximate_size and pushes the integer size onto the stack. #### WAIT_FUTURE diff --git a/bindings/bindingtester/tests/api.py b/bindings/bindingtester/tests/api.py index be6350ece6..5b8db87c71 100644 --- a/bindings/bindingtester/tests/api.py +++ b/bindings/bindingtester/tests/api.py @@ -438,7 +438,7 @@ class ApiTest(Test): elif op == 'GET_APPROXIMATE_SIZE': instructions.append(op) - self.add_strings(1) + self.add_stack_items(1) elif op == 'TUPLE_PACK' or op == 'TUPLE_RANGE': tup = self.random.random_tuple(10) diff --git a/bindings/flow/tester/Tester.actor.cpp b/bindings/flow/tester/Tester.actor.cpp index 856f28f96d..7b2c535d2d 100644 --- a/bindings/flow/tester/Tester.actor.cpp +++ b/bindings/flow/tester/Tester.actor.cpp @@ -19,6 +19,7 @@ */ #include "Tester.actor.h" +#include #ifdef __linux__ #include #endif @@ -710,13 +711,9 @@ struct GetApproximateSizeFunc : InstructionFunc { ACTOR static Future call(Reference data, Reference instruction) { int64_t size = wait(instruction->tr->getApproximateSize()); - char buf[128]; - memset(buf, 0, 128); - buf[0] = 1; // String starts with \x01. - snprintf(buf+1, 127, "%d", size); - printf("C: %s\n", buf+1); - StringRef ref((uint8_t*)buf, strlen(buf)+1); - data->stack.push(Standalone(ref)); + Tuple f; + f.append(size); + data->stack.push(f.pack()); return Void(); } }; diff --git a/bindings/go/src/_stacktester/stacktester.go b/bindings/go/src/_stacktester/stacktester.go index d9c12be307..23174ad733 100644 --- a/bindings/go/src/_stacktester/stacktester.go +++ b/bindings/go/src/_stacktester/stacktester.go @@ -592,7 +592,8 @@ func (sm *StackMachine) processInst(idx int, inst tuple.Tuple) { sm.store(idx, []byte("GOT_COMMITTED_VERSION")) case op == "GET_APPROXIMATE_SIZE": approximateSize := sm.currentTransaction().GetApproximateSize().MustGet() - sm.store(idx, []byte(strconv.FormatInt(approximateSize, 10))) + var x *big.Int = big.NewInt(approximateSize) + sm.store(idx, x) case op == "GET_VERSIONSTAMP": sm.store(idx, sm.currentTransaction().GetVersionstamp()) case op == "GET_KEY": diff --git a/bindings/java/src/test/com/apple/foundationdb/test/AsyncStackTester.java b/bindings/java/src/test/com/apple/foundationdb/test/AsyncStackTester.java index e8eb64d298..876115fff7 100644 --- a/bindings/java/src/test/com/apple/foundationdb/test/AsyncStackTester.java +++ b/bindings/java/src/test/com/apple/foundationdb/test/AsyncStackTester.java @@ -284,8 +284,7 @@ public class AsyncStackTester { } else if(op == StackOperation.GET_APPROXIMATE_SIZE) { return inst.tr.getApproximateSize().thenAcceptAsync(size -> { - Long approximateSize = size; - inst.push(approximateSize.toString().getBytes()); + inst.push(BigInteger.valueOf(size)); }, FDB.DEFAULT_EXECUTOR); } else if(op == StackOperation.GET_VERSIONSTAMP) { diff --git a/bindings/java/src/test/com/apple/foundationdb/test/StackTester.java b/bindings/java/src/test/com/apple/foundationdb/test/StackTester.java index 0f7e11f864..acd8069980 100644 --- a/bindings/java/src/test/com/apple/foundationdb/test/StackTester.java +++ b/bindings/java/src/test/com/apple/foundationdb/test/StackTester.java @@ -262,8 +262,8 @@ public class StackTester { inst.push("GOT_COMMITTED_VERSION".getBytes()); } else if(op == StackOperation.GET_APPROXIMATE_SIZE) { - Long approximateSize = inst.tr.getApproximateSize().join(); - inst.push(approximateSize.toString().getBytes()); + Long size = inst.tr.getApproximateSize().join(); + inst.push(BigInteger.valueOf(size)); } else if(op == StackOperation.GET_VERSIONSTAMP) { inst.push(inst.tr.getVersionstamp()); diff --git a/bindings/python/fdb/impl.py b/bindings/python/fdb/impl.py index e3f68e98c9..ded93bb76a 100644 --- a/bindings/python/fdb/impl.py +++ b/bindings/python/fdb/impl.py @@ -543,7 +543,7 @@ class Transaction(TransactionRead): def get_approximate_size(self): """Get the approximate commit size of the transaction.""" - return FutureVersion(self.capi.fdb_transaction_get_approximate_size(self.tpointer)) + return FutureInt64(self.capi.fdb_transaction_get_approximate_size(self.tpointer)) def get_versionstamp(self): return Key(self.capi.fdb_transaction_get_versionstamp(self.tpointer)) @@ -699,6 +699,14 @@ class FutureVersion(Future): return version.value +class FutureInt64(Future): + def wait(self): + self.block_until_ready() + size = ctypes.c_int64() + self.capi.fdb_future_get_version(self.fpointer, ctypes.byref(size)) + return size.value + + class FutureKeyValueArray(Future): def wait(self): self.block_until_ready() diff --git a/bindings/python/tests/tester.py b/bindings/python/tests/tester.py index d50007be8f..89bcd371b2 100644 --- a/bindings/python/tests/tester.py +++ b/bindings/python/tests/tester.py @@ -477,8 +477,7 @@ class Tester: inst.push(b"GOT_COMMITTED_VERSION") elif inst.op == six.u("GET_APPROXIMATE_SIZE"): approximate_size = inst.tr.get_approximate_size().wait() - print("P: " + str(approximate_size)) - inst.push(str(approximate_size)) + inst.push(approximate_size) elif inst.op == six.u("GET_VERSIONSTAMP"): inst.push(inst.tr.get_versionstamp()) elif inst.op == six.u("TUPLE_PACK"): diff --git a/bindings/ruby/tests/tester.rb b/bindings/ruby/tests/tester.rb index 0682c1e923..d31ed778e0 100755 --- a/bindings/ruby/tests/tester.rb +++ b/bindings/ruby/tests/tester.rb @@ -382,9 +382,7 @@ class Tester @last_version = inst.tr.get_committed_version inst.push("GOT_COMMITTED_VERSION") when "GET_APPROXIMATE_SIZE" - approximate_size = inst.tr.get_approximate_size.to_i - puts(approximate_size.to_s) - inst.push(approximate_size.to_s) + inst.push(inst.tr.get_approximate_size.to_i) when "GET_VERSIONSTAMP" inst.push(inst.tr.get_versionstamp) when "TUPLE_PACK" diff --git a/fdbclient/MultiVersionTransaction.actor.cpp b/fdbclient/MultiVersionTransaction.actor.cpp index bb5c186461..22c54c695a 100644 --- a/fdbclient/MultiVersionTransaction.actor.cpp +++ b/fdbclient/MultiVersionTransaction.actor.cpp @@ -202,7 +202,7 @@ ThreadFuture DLTransaction::getApproximateSize() { FdbCApi::FDBFuture *f = api->transactionGetApproximateSize(tr); return toThreadFuture(api, f, [](FdbCApi::FDBFuture *f, FdbCApi *api) { - int64_t size; + int64_t size = 0; FdbCApi::fdb_error_t error = api->futureGetInt64(f, &size); ASSERT(!error); return size; diff --git a/fdbclient/ReadYourWrites.actor.cpp b/fdbclient/ReadYourWrites.actor.cpp index ad5bc42071..29d5fc4b0f 100644 --- a/fdbclient/ReadYourWrites.actor.cpp +++ b/fdbclient/ReadYourWrites.actor.cpp @@ -1123,7 +1123,7 @@ public: } }; -ReadYourWritesTransaction::ReadYourWritesTransaction( Database const& cx ) : cache(&arena), writes(&arena), tr(cx), retries(0), creationTime(now()), commitStarted(false), options(tr), deferredError(cx->deferredError) { +ReadYourWritesTransaction::ReadYourWritesTransaction( Database const& cx ) : cache(&arena), writes(&arena), tr(cx), retries(0), approximateSize(0), creationTime(now()), commitStarted(false), options(tr), deferredError(cx->deferredError) { std::copy(cx.getTransactionDefaults().begin(), cx.getTransactionDefaults().end(), std::back_inserter(persistentOptions)); applyPersistentOptions(); } @@ -1880,7 +1880,7 @@ ReadYourWritesTransaction::ReadYourWritesTransaction(ReadYourWritesTransaction&& arena( std::move(r.arena) ), reading( std::move(r.reading) ), retries( r.retries ), - approximateSize(0), + approximateSize(r.approximateSize), creationTime( r.creationTime ), deferredError( std::move(r.deferredError) ), timeoutActor( std::move(r.timeoutActor) ),