Push int directly to stack for getApproximateSize

This commit is contained in:
Jingyu Zhou 2019-07-05 15:31:07 -07:00
parent 0802df2c8f
commit 5d1437c8e0
11 changed files with 25 additions and 23 deletions

View File

@ -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((<approximate_size>,))` onto the stack.
Calls get_approximate_size and pushes the integer size onto the stack.
#### WAIT_FUTURE

View File

@ -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)

View File

@ -19,6 +19,7 @@
*/
#include "Tester.actor.h"
#include <cinttypes>
#ifdef __linux__
#include <string.h>
#endif
@ -710,13 +711,9 @@ struct GetApproximateSizeFunc : InstructionFunc {
ACTOR static Future<Void> call(Reference<FlowTesterData> data, Reference<InstructionData> 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<StringRef>(ref));
Tuple f;
f.append(size);
data->stack.push(f.pack());
return Void();
}
};

View File

@ -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":

View File

@ -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) {

View File

@ -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());

View File

@ -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()

View File

@ -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"):

View File

@ -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"

View File

@ -202,7 +202,7 @@ ThreadFuture<int64_t> DLTransaction::getApproximateSize() {
FdbCApi::FDBFuture *f = api->transactionGetApproximateSize(tr);
return toThreadFuture<int64_t>(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;

View File

@ -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) ),