diff options
author | Tor Brede Vekterli <vekterli@oath.com> | 2018-05-29 12:31:30 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@oath.com> | 2018-07-12 13:30:25 +0000 |
commit | cebec020f6257d1d19f7c1c1bd0952343f884b49 (patch) | |
tree | 86f4c538d0903c5e5102b3060ae31aee814054ec /storageapi | |
parent | 063c7b3c4308a23b9e76d3831bf1c063168e7a3d (diff) |
Add support for exclusive/shared persistence bucket locking
Operations that are tagged as only requiring shared locking may run
concurrently with other shared lock operations. Operations requiring
exclusive locking (all mutations) can't run concurrently with any
other operations, shared or not.
Let operations be able to explicitly specify their locking requirements.
Default is exclusive locking, which shall give the same behavior as before.
Since this locking happens at a stripe granularity, it's vital that operations
are routed deterministically to the correct stripe based on their bucket.
Diffstat (limited to 'storageapi')
-rw-r--r-- | storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp | 10 | ||||
-rw-r--r-- | storageapi/src/vespa/storageapi/messageapi/storagemessage.h | 16 |
2 files changed, 26 insertions, 0 deletions
diff --git a/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp b/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp index f970091f695..3413feeeeab 100644 --- a/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp +++ b/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp @@ -302,4 +302,14 @@ StorageMessage::getSummary() const { return toString(); } +const char* to_string(LockingRequirements req) noexcept { + switch (req) { + case LockingRequirements::Exclusive: + return "Exclusive"; + case LockingRequirements::Shared: + return "Shared"; + } + assert(false); +} + } diff --git a/storageapi/src/vespa/storageapi/messageapi/storagemessage.h b/storageapi/src/vespa/storageapi/messageapi/storagemessage.h index dadb68c644d..90261c2b9b1 100644 --- a/storageapi/src/vespa/storageapi/messageapi/storagemessage.h +++ b/storageapi/src/vespa/storageapi/messageapi/storagemessage.h @@ -306,6 +306,18 @@ struct TransportContext { virtual ~TransportContext() = 0; }; +enum class LockingRequirements : uint8_t { + // Operations with exclusive locking can only be executed iff no other + // exclusive or shared locks are taken for its bucket. + Exclusive = 0, + // Operations with shared locking can only be executed iff no exclusive + // lock is taken for its bucket. Should only be used for read-only operations + // that cannot mutate a bucket's state. + Shared +}; + +const char* to_string(LockingRequirements req) noexcept; + class StorageMessage : public vespalib::Printable { friend class StorageMessageTest; // Used for testing only @@ -421,6 +433,10 @@ public: virtual document::Bucket getBucket() const { return getDummyBucket(); } document::BucketId getBucketId() const { return getBucket().getBucketId(); } virtual bool hasSingleBucketId() const { return false; } + virtual LockingRequirements lockingRequirements() const noexcept { + // Safe default: assume exclusive locking is required. + return LockingRequirements::Exclusive; + } }; } |