Merge branch 'master' of bitbucket.org:bluetradesys/spark into simplify_md_sdk

This commit is contained in:
Eric Harding committed 2018-11-16 11:23:51 -05:00
commit e22649c19d
69 files changed
+2026 -560

No files matched your search

+63 -7
View File
@@ -2,12 +2,13 @@
#include "lib/logging/logging.h"
#include "lib/os/os.h"
#include "lib/persistence/persistence_utils.h"
#include "lib/utils/Sqlite_utils.h"
#include "lib/utils/bts_assert.h"
#include "lib/utils/bts_chrono.h"
#include "lib/utils/bts_no_copy.h"
#include "lib/utils/defer.h"
#include "lib/utils/file_utils.h"
#include "lib/persistence/persistence_utils.h"
#include <boost/filesystem.hpp>
#include <sqlite/sqlite3.h>
@@ -15,10 +16,9 @@
namespace bts {
namespace persistence {
struct SqliteStore::PImpl {
PImpl(std::string const &store_root, std::string const &db_name)
: db(db_name), db_path(persistence::storage_location(db,store_root)),
: db(db_name), db_path(persistence::storage_location(db, store_root)),
conn(nullptr, sqlite3_close), insert(nullptr, sqlite3_finalize),
remove(nullptr, sqlite3_finalize),
remove_all(nullptr, sqlite3_finalize),
@@ -156,7 +156,22 @@ void SqliteStore::remove(std::string const &ns,
SQLITE_CHK(sqlite3_bind_text(me->remove.get(), 2, k.c_str(), k.size(),
SQLITE_TRANSIENT),
me->conn);
bts_assert(sqlite3_step(me->remove.get()) == SQLITE_DONE);
auto r = sqlite3_step(me->remove.get());
if (r != SQLITE_DONE) {
LOG(persist, Error,
"Could not delete row in store. Will retry once. error_code: {} "
"ns:{}, k: {}",
r, ns, k);
sleep_for(2s);
r = sqlite3_step(me->remove.get());
if (r != SQLITE_DONE) {
LOG(persist, Error,
"Failed a second time to delete row. Bailing out. error_code: "
"{}",
r);
bts_assert(r == SQLITE_DONE);
}
}
SQLITE_CHK(sqlite3_reset(me->remove.get()), me->conn);
}
}
@@ -166,7 +181,22 @@ void SqliteStore::remove_all(std::string const &ns) {
SQLITE_CHK(sqlite3_bind_text(me->remove_all.get(), 1, ns.c_str(), ns.size(),
SQLITE_TRANSIENT),
me->conn);
bts_assert(sqlite3_step(me->remove_all.get()) == SQLITE_DONE);
auto r = sqlite3_step(me->remove_all.get());
if (r != SQLITE_DONE) {
LOG(persist, Error,
"Could not delete all rows in store. Will retry once. error_code: {} "
"ns:{}",
r, ns);
sleep_for(2s);
r = sqlite3_step(me->remove_all.get());
if (r != SQLITE_DONE) {
LOG(persist, Error,
"Failed a second time to delete all rows. Bailing out. error_code: "
"{}",
r);
bts_assert(r == SQLITE_DONE);
}
}
SQLITE_CHK(sqlite3_reset(me->remove_all.get()), me->conn);
}
@@ -182,7 +212,20 @@ void SqliteStore::insert(std::string const &ns, std::string const &k,
SQLITE_TRANSIENT),
me->conn);
auto r = sqlite3_step(me->insert.get());
bts_assert(r == SQLITE_DONE);
if (r != SQLITE_DONE) {
LOG(persist, Error,
"Could not insert row in store. Will retry once. error_code: {} ns: "
"{}, k: {}, v: {}",
r, ns, k, v);
sleep_for(2s);
r = sqlite3_step(me->insert.get());
if (r != SQLITE_DONE) {
LOG(persist, Error,
"Failed a second time to insert row. Bailing out. error_code: {}",
r);
bts_assert(r == SQLITE_DONE);
}
}
SQLITE_CHK(sqlite3_reset(me->insert.get()), me->conn);
}
@@ -198,7 +241,20 @@ void SqliteStore::update(std::string const &ns, std::string const &k,
SQLITE_TRANSIENT),
me->conn);
auto r = sqlite3_step(me->update.get());
bts_assert(r == SQLITE_DONE);
if (r != SQLITE_DONE) {
LOG(persist, Error,
"Could not update row in store. Will retry once. error_code: {} ns: "
"{}, k: {}, v: {}",
r, ns, k, v);
sleep_for(2s);
r = sqlite3_step(me->update.get());
if (r != SQLITE_DONE) {
LOG(persist, Error,
"Failed a second time to update row. Bailing out. error_code: {}",
r);
bts_assert(r == SQLITE_DONE);
}
}
SQLITE_CHK(sqlite3_reset(me->update.get()), me->conn);
}