diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-05-05 10:06:41 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-05-05 10:06:41 +0000 |
commit | bbfebdcf506f8b638ce40b28e47c3657cf002055 (patch) | |
tree | a176b0bf30c7e74e3e792fa393ec3ba805c789cd /persistence | |
parent | 2b83b031718d466df9fc0c4abd89f7fe0bcdbbf8 (diff) |
Add async update and followup on PR comments.
Diffstat (limited to 'persistence')
6 files changed, 55 insertions, 45 deletions
diff --git a/persistence/src/vespa/persistence/dummyimpl/dummypersistence.cpp b/persistence/src/vespa/persistence/dummyimpl/dummypersistence.cpp index 984bbcd845f..5720a0ba662 100644 --- a/persistence/src/vespa/persistence/dummyimpl/dummypersistence.cpp +++ b/persistence/src/vespa/persistence/dummyimpl/dummypersistence.cpp @@ -4,6 +4,7 @@ #include <vespa/document/select/parser.h> #include <vespa/document/base/documentid.h> #include <vespa/document/fieldvalue/document.h> +#include <vespa/document/update/documentupdate.h> #include <vespa/document/bucket/fixed_bucket_spaces.h> #include <vespa/vespalib/util/crc.h> #include <vespa/document/fieldset/fieldsetrepo.h> @@ -30,7 +31,7 @@ BucketContent::BucketContent() _outdatedInfo(true), _active(false) { } -BucketContent::~BucketContent() { } +BucketContent::~BucketContent() = default; uint32_t BucketContent::computeEntryChecksum(const BucketEntry& e) const @@ -306,11 +307,10 @@ DummyPersistence::DummyPersistence( _clusterState() {} -DummyPersistence::~DummyPersistence() {} +DummyPersistence::~DummyPersistence() = default; document::select::Node::UP -DummyPersistence::parseDocumentSelection(const string& documentSelection, - bool allowLeaf) +DummyPersistence::parseDocumentSelection(const string& documentSelection, bool allowLeaf) { document::select::Node::UP ret; try { @@ -464,6 +464,37 @@ DummyPersistence::put(const Bucket& b, Timestamp t, Document::SP doc, Context&) return Result(); } +UpdateResult +DummyPersistence::update(const Bucket& bucket, Timestamp ts, DocumentUpdateSP upd, Context& context) +{ + GetResult getResult = get(bucket, document::AllFields(), upd->getId(), context); + + if (getResult.hasError()) { + return UpdateResult(getResult.getErrorCode(), getResult.getErrorMessage()); + } + + auto docToUpdate = getResult.getDocumentPtr(); + Timestamp updatedTs = getResult.getTimestamp(); + if (!docToUpdate) { + if (!upd->getCreateIfNonExistent()) { + return UpdateResult(); + } else { + docToUpdate = std::make_shared<document::Document>(upd->getType(), upd->getId()); + updatedTs = ts; + } + } + + upd->applyTo(*docToUpdate); + + Result putResult = put(bucket, ts, std::move(docToUpdate), context); + + if (putResult.hasError()) { + return UpdateResult(putResult.getErrorCode(), putResult.getErrorMessage()); + } + + return UpdateResult(updatedTs); +} + RemoveResult DummyPersistence::remove(const Bucket& b, Timestamp t, const DocumentId& did, Context&) { diff --git a/persistence/src/vespa/persistence/dummyimpl/dummypersistence.h b/persistence/src/vespa/persistence/dummyimpl/dummypersistence.h index 27ed95bd6ee..94c2e1cd9a4 100644 --- a/persistence/src/vespa/persistence/dummyimpl/dummypersistence.h +++ b/persistence/src/vespa/persistence/dummyimpl/dummypersistence.h @@ -156,6 +156,7 @@ public: Result put(const Bucket&, Timestamp, DocumentSP, Context&) override; GetResult get(const Bucket&, const document::FieldSet&, const DocumentId&, Context&) const override; RemoveResult remove(const Bucket& b, Timestamp t, const DocumentId& did, Context&) override; + UpdateResult update(const Bucket&, Timestamp, DocumentUpdateSP, Context&) override; CreateIteratorResult createIterator(const Bucket&, const document::FieldSet& fs, diff --git a/persistence/src/vespa/persistence/spi/abstractpersistenceprovider.cpp b/persistence/src/vespa/persistence/spi/abstractpersistenceprovider.cpp index 99a8b244431..45c2c7901f9 100644 --- a/persistence/src/vespa/persistence/spi/abstractpersistenceprovider.cpp +++ b/persistence/src/vespa/persistence/spi/abstractpersistenceprovider.cpp @@ -8,39 +8,6 @@ namespace storage::spi { -UpdateResult -AbstractPersistenceProvider::update(const Bucket& bucket, Timestamp ts, - const DocumentUpdate::SP& upd, Context& context) -{ - GetResult getResult = get(bucket, document::AllFields(), upd->getId(), context); - - if (getResult.hasError()) { - return UpdateResult(getResult.getErrorCode(), getResult.getErrorMessage()); - } - - auto docToUpdate = getResult.getDocumentPtr(); - Timestamp updatedTs = getResult.getTimestamp(); - if (!docToUpdate) { - if (!upd->getCreateIfNonExistent()) { - return UpdateResult(); - } else { - docToUpdate = std::make_shared<document::Document>(upd->getType(), upd->getId()); - updatedTs = ts; - } - } - - upd->applyTo(*docToUpdate); - - Result putResult = put(bucket, ts, std::move(docToUpdate), context); - - if (putResult.hasError()) { - return UpdateResult(putResult.getErrorCode(), - putResult.getErrorMessage()); - } - - return UpdateResult(updatedTs); -} - RemoveResult AbstractPersistenceProvider::removeIfFound(const Bucket& b, Timestamp timestamp, const DocumentId& id, Context& context) @@ -50,7 +17,7 @@ AbstractPersistenceProvider::removeIfFound(const Bucket& b, Timestamp timestamp, void AbstractPersistenceProvider::removeIfFoundAsync(const Bucket& b, Timestamp timestamp, - const DocumentId& id, Context& context, OperationComplete::UP onComplete) + const DocumentId& id, Context& context, OperationComplete::UP onComplete) { removeAsync(b, timestamp, id, context, std::move(onComplete)); } diff --git a/persistence/src/vespa/persistence/spi/abstractpersistenceprovider.h b/persistence/src/vespa/persistence/spi/abstractpersistenceprovider.h index 9de96944c31..813050222a9 100644 --- a/persistence/src/vespa/persistence/spi/abstractpersistenceprovider.h +++ b/persistence/src/vespa/persistence/spi/abstractpersistenceprovider.h @@ -20,12 +20,6 @@ public: Result initialize() override { return Result(); }; /** - * Updates the document by calling get(), updating the document, - * then calling put() on the result. - */ - UpdateResult update(const Bucket&, Timestamp, const DocumentUpdateSP&, Context&) override; - - /** * Default impl empty. */ Result createBucket(const Bucket&, Context&) override { return Result(); } diff --git a/persistence/src/vespa/persistence/spi/persistenceprovider.cpp b/persistence/src/vespa/persistence/spi/persistenceprovider.cpp index b00ae340fa6..38fcd2fd072 100644 --- a/persistence/src/vespa/persistence/spi/persistenceprovider.cpp +++ b/persistence/src/vespa/persistence/spi/persistenceprovider.cpp @@ -74,4 +74,20 @@ PersistenceProvider::removeIfFoundAsync(const Bucket &bucket, Timestamp timestam onComplete->onComplete(std::make_unique<RemoveResult>(result)); } +UpdateResult +PersistenceProvider::update(const Bucket& bucket, Timestamp timestamp, DocumentUpdateSP upd, Context& context) { + auto catcher = std::make_unique<CatchResult>(); + auto future = catcher->future_result(); + updateAsync(bucket, timestamp, std::move(upd), context, std::move(catcher)); + return dynamic_cast<const UpdateResult &>(*future.get()); +} + +void +PersistenceProvider::updateAsync(const Bucket &bucket, Timestamp timestamp, DocumentUpdateSP upd, Context &context, + OperationComplete::UP onComplete) +{ + UpdateResult result = update(bucket, timestamp, std::move(upd), context); + onComplete->onComplete(std::make_unique<UpdateResult>(result)); +} + } diff --git a/persistence/src/vespa/persistence/spi/persistenceprovider.h b/persistence/src/vespa/persistence/spi/persistenceprovider.h index 6a5e3e05933..2e7d215fc33 100644 --- a/persistence/src/vespa/persistence/spi/persistenceprovider.h +++ b/persistence/src/vespa/persistence/spi/persistenceprovider.h @@ -204,7 +204,8 @@ struct PersistenceProvider * @param timestamp The timestamp to use for the new update entry. * @param update The document update to apply to the stored document. */ - virtual UpdateResult update(const Bucket&, Timestamp timestamp, const DocumentUpdateSP& update, Context&) = 0; + virtual UpdateResult update(const Bucket&, Timestamp timestamp, DocumentUpdateSP update, Context&); + virtual void updateAsync(const Bucket&, Timestamp timestamp, DocumentUpdateSP update, Context&, OperationComplete::UP); /** * Retrieves the latest version of the document specified by the |