Simplify VersionCountingBlockStore::store()

This commit is contained in:
Sebastian Messmer 2017-07-07 17:21:52 +02:00
parent c4c0bda6d0
commit 6bdefc56a4
2 changed files with 5 additions and 16 deletions

View File

@ -48,22 +48,9 @@ public:
boost::future<void> store(const Key &key, const cpputils::Data &data) override { boost::future<void> store(const Key &key, const cpputils::Data &data) override {
_checkNoPastIntegrityViolations(); _checkNoPastIntegrityViolations();
//TODO There's a bug in the next branch in override(). They have to load and read the old version number too. uint64_t version = _knownBlockVersions.incrementVersion(key);
return load(key).then([this, key, data = data.copy()] (boost::future<boost::optional<cpputils::Data>> loaded_) { cpputils::Data dataWithHeader = _prependHeaderToData(_knownBlockVersions.myClientId(), version, data);
auto loaded = loaded_.get(); return _baseBlockStore->store(key, dataWithHeader);
if (boost::none == loaded) {
return tryCreate(key, data).then([] (boost::future<bool> success) {
if (!success.get()) {
throw std::runtime_error("Could neither store nor create the block in VersionCountingBlockStore::store");
}
});
}
// Loading the block already read the newest version number into _knownBlockVersions, now we only have to increment it
// TODO Check that (with a caching blockstore below) this doesn't impact performance
uint64_t version = _knownBlockVersions.incrementVersion(key);
cpputils::Data dataWithHeader = _prependHeaderToData(_knownBlockVersions.myClientId(), version, data);
return _baseBlockStore->store(key, dataWithHeader);
});
} }
private: private:

View File

@ -22,6 +22,8 @@ public:
virtual boost::future<bool> remove(const Key &key) = 0; virtual boost::future<bool> remove(const Key &key) = 0;
virtual boost::future<boost::optional<cpputils::Data>> load(const Key &key) const = 0; virtual boost::future<boost::optional<cpputils::Data>> load(const Key &key) const = 0;
// Store the block with the given key. If it doesn't exist, it is created.
virtual boost::future<void> store(const Key &key, const cpputils::Data &data) = 0; virtual boost::future<void> store(const Key &key, const cpputils::Data &data) = 0;
boost::future<Key> create(cpputils::Data data) { boost::future<Key> create(cpputils::Data data) {