nicer error logging for BTree Repacker
recoverAll was really just sitting there
This commit is contained in:
parent
b2afd65144
commit
ffc1f95789
@ -196,6 +196,11 @@ void BTreeDatabase::forAll(function<void(ByteArray, ByteArray)> v) {
|
||||
m_impl.forAll(std::move(v));
|
||||
}
|
||||
|
||||
void BTreeDatabase::recoverAll(function<void(ByteArray, ByteArray)> v, function<void(String const&, std::exception const&)> e) {
|
||||
ReadLocker readLocker(m_lock);
|
||||
m_impl.recoverAll(std::move(v), std::move(e));
|
||||
}
|
||||
|
||||
bool BTreeDatabase::insert(ByteArray const& k, ByteArray const& data) {
|
||||
WriteLocker writeLocker(m_lock);
|
||||
checkKeySize(k);
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
|
||||
void forEach(ByteArray const& lower, ByteArray const& upper, function<void(ByteArray, ByteArray)> v);
|
||||
void forAll(function<void(ByteArray, ByteArray)> v);
|
||||
void recoverAll(function<void(ByteArray, ByteArray)> v, function<void(String const&, std::exception const&)> e);
|
||||
|
||||
// Returns true if a value was overwritten
|
||||
bool insert(ByteArray const& k, ByteArray const& data);
|
||||
|
@ -36,11 +36,16 @@ int main(int argc, char** argv) {
|
||||
newDb.open();
|
||||
coutf("Repacking {}...\n", bTreePath);
|
||||
//copy the data over
|
||||
unsigned count = 0;
|
||||
db.forAll([&count, &newDb](ByteArray key, ByteArray data) {
|
||||
newDb.insert(key, data);
|
||||
unsigned count = 0, overwritten = 0;
|
||||
auto visitor = [&](ByteArray key, ByteArray data) {
|
||||
if (newDb.insert(key, data))
|
||||
++overwritten;
|
||||
++count;
|
||||
});
|
||||
};
|
||||
auto errorHandler = [&](String const& error, std::exception const& e) {
|
||||
coutf("{}: {}\n", error, e.what());
|
||||
};
|
||||
db.recoverAll(visitor, errorHandler);
|
||||
|
||||
//close the old db
|
||||
db.close();
|
||||
@ -48,7 +53,7 @@ int main(int argc, char** argv) {
|
||||
newDb.commit();
|
||||
newDb.close();
|
||||
|
||||
coutf("Repacked BTree to {} in {}s\n", outputFilename, Time::monotonicTime() - startTime);
|
||||
coutf("Repacked BTree to {} in {:.6f}s\n({} inserts, {} overwritten)\n", outputFilename, Time::monotonicTime() - startTime, count, overwritten);
|
||||
return 0;
|
||||
|
||||
} catch (std::exception const& e) {
|
||||
|
Loading…
Reference in New Issue
Block a user