Skip to content

Commit

Permalink
Fixed bugs in persistent test
Browse files Browse the repository at this point in the history
The persistent_test program (src/persistent/test.cpp) had a few bugs
that made it sometimes fail even when the persistence system was working
correctly:

* Multiple test Persistent objects were declared as static variables,
  which meant they could be initialized in any order and could be
  initialized before the PersistentRegistry object they depend on due to
  the Static Initialization Order Fiasco.
* The VariableBytes::from_bytes function declared an unused local
  VariableBytes object that could overflow the stack from trying to
  allocate its "buf" member.

I fixed both of these bugs.
  • Loading branch information
etremel committed Jun 26, 2020
1 parent f8aa0fe commit 0215404
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/core/git_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace derecho {
const int MAJOR_VERSION = 2;
const int MINOR_VERSION = 0;
const int PATCH_VERSION = 0;
const int COMMITS_AHEAD_OF_VERSION = 2;
const int COMMITS_AHEAD_OF_VERSION = 5;
const char* VERSION_STRING = "2.0.0";
const char* VERSION_STRING_PLUS_COMMITS = "2.0.0+2";
const char* VERSION_STRING_PLUS_COMMITS = "2.0.0+5";

}
24 changes: 11 additions & 13 deletions src/persistent/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class X {
class ReplicatedT {
};

PersistentRegistry pr(nullptr, typeid(ReplicatedT), 123, 321);

#define MAX_VB_SIZE (1ull << 30)
// A variable that can change the length of its value
class VariableBytes : public ByteRepresentable {
Expand Down Expand Up @@ -67,7 +65,6 @@ class VariableBytes : public ByteRepresentable {
};

static std::unique_ptr<VariableBytes> from_bytes(DeserializationManager* dsm, char const* const v) {
VariableBytes vb;
std::unique_ptr<VariableBytes> pvb = std::make_unique<VariableBytes>();
strcpy(pvb->buf, v);
pvb->data_len = strlen(v) + 1;
Expand Down Expand Up @@ -149,14 +146,6 @@ printhelp() {
<< "to remove this limitation." << endl;
}

Persistent<X> px1([]() { return std::make_unique<X>(); }, nullptr, &pr);
//Persistent<X> px1;
Persistent<VariableBytes> npx([]() { return std::make_unique<VariableBytes>(); }, nullptr, &pr),
npx_logtail([]() { return std::make_unique<VariableBytes>(); });
//Persistent<X,ST_MEM> px2;
Volatile<X> px2([]() { return std::make_unique<X>(); });
Persistent<IntegerWithDelta> dx([]() { return std::make_unique<IntegerWithDelta>(); }, nullptr, &pr);

template <typename OT, StorageType st = ST_FILE>
void listvar(Persistent<OT, st>& var) {
int64_t nv = var.getNumOfVersions();
Expand Down Expand Up @@ -232,6 +221,15 @@ int main(int argc, char** argv) {
return 0;
}

PersistentRegistry pr(nullptr, typeid(ReplicatedT), 123, 321);
Persistent<X> px1([]() { return std::make_unique<X>(); }, "PersistentXObject", &pr);
//Persistent<X> px1;
Persistent<VariableBytes> npx([]() { return std::make_unique<VariableBytes>(); }, "PersistentVariableBytes", &pr),
npx_logtail([]() { return std::make_unique<VariableBytes>(); }, "VariableBytesLogTail");
//Persistent<X,ST_MEM> px2;
Volatile<X> px2([]() { return std::make_unique<X>(); }, "VolatileXObject");
Persistent<IntegerWithDelta> dx([]() { return std::make_unique<IntegerWithDelta>(); }, "PersistentIntegerWithDelta", &pr);

std::cout << "command:" << argv[1] << std::endl;

try {
Expand All @@ -248,7 +246,7 @@ int main(int argc, char** argv) {
// by lambda
/*
npx.getByIndex(nv,
[&](VariableBytes& x) {
[&](VariableBytes& x) {
cout<<"["<<nv<<"]\t"<<x.to_string()<<"\t//by lambda"<<endl;
});
*/
Expand All @@ -259,7 +257,7 @@ int main(int argc, char** argv) {
/*
// by lambda
npx.get(ver,
[&](VariableBytes& x) {
[&](VariableBytes& x) {
cout<<"["<<(uint64_t)(ver>>64)<<"."<<(uint64_t)ver<<"]\t"<<x.to_string()<<"\t//by lambda"<<endl;
});
*/
Expand Down

0 comments on commit 0215404

Please sign in to comment.