Convert size from int to string before pushing onto stack

Using int is troublesome because the size of int can be different from the
desired 64 bits. So, using a string representation seems to be more consistent.
This commit is contained in:
Jingyu Zhou 2019-07-05 10:09:13 -07:00
parent 9d12843a26
commit 0802df2c8f
12 changed files with 23 additions and 14 deletions

View File

@ -220,8 +220,8 @@ fdb_error_t fdb_future_get_version( FDBFuture* f, int64_t* out_version ) {
}
extern "C" DLLEXPORT
fdb_error_t fdb_future_get_int64( FDBFuture* f, int64_t* out_version ) {
CATCH_AND_RETURN( *out_version = TSAV(Version, f)->get(); );
fdb_error_t fdb_future_get_int64( FDBFuture* f, int64_t* out ) {
CATCH_AND_RETURN( *out = TSAV(Version, f)->get(); );
}
extern "C" DLLEXPORT

View File

@ -124,7 +124,7 @@ extern "C" {
fdb_future_get_version( FDBFuture* f, int64_t* out_version );
DLLEXPORT WARN_UNUSED_RESULT fdb_error_t
fdb_future_get_int64( FDBFuture* f, int64_t* out_version );
fdb_future_get_int64( FDBFuture* f, int64_t* out );
DLLEXPORT WARN_UNUSED_RESULT fdb_error_t
fdb_future_get_key( FDBFuture* f, uint8_t const** out_key,

View File

@ -412,7 +412,7 @@ namespace FDB {
Future<int64_t> TransactionImpl::getApproximateSize() {
return backToFuture<int64_t>(fdb_transaction_get_approximate_size(tr), [](Reference<CFuture> f) {
int64_t size;
int64_t size = 0;
throw_on_error(fdb_future_get_int64(f->f, &size));
return size;
});

View File

@ -710,9 +710,13 @@ struct GetApproximateSizeFunc : InstructionFunc {
ACTOR static Future<Void> call(Reference<FlowTesterData> data, Reference<InstructionData> instruction) {
int64_t size = wait(instruction->tr->getApproximateSize());
Tuple tuple;
tuple.append(size);
data->stack.pushTuple(tuple.pack());
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));
return Void();
}
};

View File

@ -592,7 +592,7 @@ 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(tuple.Tuple{approximateSize}.Pack()))
sm.store(idx, []byte(strconv.FormatInt(approximateSize, 10)))
case op == "GET_VERSIONSTAMP":
sm.store(idx, sm.currentTransaction().GetVersionstamp())
case op == "GET_KEY":

View File

@ -285,7 +285,7 @@ public class AsyncStackTester {
else if(op == StackOperation.GET_APPROXIMATE_SIZE) {
return inst.tr.getApproximateSize().thenAcceptAsync(size -> {
Long approximateSize = size;
inst.push(Tuple.from(approximateSize).pack());
inst.push(approximateSize.toString().getBytes());
}, FDB.DEFAULT_EXECUTOR);
}
else if(op == StackOperation.GET_VERSIONSTAMP) {

View File

@ -263,7 +263,7 @@ public class StackTester {
}
else if(op == StackOperation.GET_APPROXIMATE_SIZE) {
Long approximateSize = inst.tr.getApproximateSize().join();
inst.push(Tuple.from(approximateSize).pack());
inst.push(approximateSize.toString().getBytes());
}
else if(op == StackOperation.GET_VERSIONSTAMP) {
inst.push(inst.tr.getVersionstamp());

View File

@ -477,7 +477,8 @@ class Tester:
inst.push(b"GOT_COMMITTED_VERSION")
elif inst.op == six.u("GET_APPROXIMATE_SIZE"):
approximate_size = inst.tr.get_approximate_size().wait()
inst.push(fdb.tuple.pack((approximate_size,)))
print("P: " + str(approximate_size))
inst.push(str(approximate_size))
elif inst.op == six.u("GET_VERSIONSTAMP"):
inst.push(inst.tr.get_versionstamp())
elif inst.op == six.u("TUPLE_PACK"):

View File

@ -383,7 +383,8 @@ class Tester
inst.push("GOT_COMMITTED_VERSION")
when "GET_APPROXIMATE_SIZE"
approximate_size = inst.tr.get_approximate_size.to_i
inst.push(FDB::Tuple.pack([approximate_size]))
puts(approximate_size.to_s)
inst.push(approximate_size.to_s)
when "GET_VERSIONSTAMP"
inst.push(inst.tr.get_versionstamp)
when "TUPLE_PACK"

View File

@ -203,7 +203,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;
FdbCApi::fdb_error_t error = api->futureGetVersion(f, &size);
FdbCApi::fdb_error_t error = api->futureGetInt64(f, &size);
ASSERT(!error);
return size;
});
@ -311,6 +311,7 @@ void DLApi::init() {
loadClientFunction(&api->futureGetDatabase, lib, fdbCPath, "fdb_future_get_database");
loadClientFunction(&api->futureGetVersion, lib, fdbCPath, "fdb_future_get_version");
loadClientFunction(&api->futureGetInt64, lib, fdbCPath, "fdb_future_get_int64");
loadClientFunction(&api->futureGetError, lib, fdbCPath, "fdb_future_get_error");
loadClientFunction(&api->futureGetKey, lib, fdbCPath, "fdb_future_get_key");
loadClientFunction(&api->futureGetValue, lib, fdbCPath, "fdb_future_get_value");

View File

@ -96,6 +96,7 @@ struct FdbCApi : public ThreadSafeReferenceCounted<FdbCApi> {
//Future
fdb_error_t (*futureGetDatabase)(FDBFuture *f, FDBDatabase **outDb);
fdb_error_t (*futureGetVersion)(FDBFuture *f, int64_t *outVersion);
fdb_error_t (*futureGetInt64)(FDBFuture *f, int64_t *outVersion);
fdb_error_t (*futureGetError)(FDBFuture *f);
fdb_error_t (*futureGetKey)(FDBFuture *f, uint8_t const **outKey, int *outKeyLength);
fdb_error_t (*futureGetValue)(FDBFuture *f, fdb_bool_t *outPresent, uint8_t const **outValue, int *outValueLength);

View File

@ -275,7 +275,8 @@ Version ThreadSafeTransaction::getCommittedVersion() {
}
ThreadFuture<int64_t> ThreadSafeTransaction::getApproximateSize() {
return onMainThread([this]() -> Future<int64_t> { return tr->getApproximateSize(); });
ReadYourWritesTransaction *tr = this->tr;
return onMainThread([tr]() -> Future<int64_t> { return tr->getApproximateSize(); });
}
ThreadFuture<Standalone<StringRef>> ThreadSafeTransaction::getVersionstamp() {