diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-05-08 21:17:27 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-05-08 21:17:27 +0000 |
commit | dae38cdf2f8bd74de485130c3fe63fb91729fce1 (patch) | |
tree | e414bc66981ac0dc85f348161217c8dec231691c /storage | |
parent | 8eec2e8a69d68875ef0ecb3486cf59eeed371dee (diff) |
Use a lock to ensure it is thread safe.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/src/tests/persistence/common/persistenceproviderwrapper.cpp | 9 | ||||
-rw-r--r-- | storage/src/tests/persistence/common/persistenceproviderwrapper.h | 15 |
2 files changed, 18 insertions, 6 deletions
diff --git a/storage/src/tests/persistence/common/persistenceproviderwrapper.cpp b/storage/src/tests/persistence/common/persistenceproviderwrapper.cpp index 13a254e7a76..dd9ce6e6cba 100644 --- a/storage/src/tests/persistence/common/persistenceproviderwrapper.cpp +++ b/storage/src/tests/persistence/common/persistenceproviderwrapper.cpp @@ -9,11 +9,13 @@ { \ std::ostringstream logStream; \ logStream << ops; \ + Guard guard(_lock); \ _log.push_back(logStream.str()); \ } #define CHECK_ERROR(className, failType) \ { \ + Guard guard(_lock); \ if (_result.getErrorCode() != spi::Result::ErrorType::NONE && (_failureMask & (failType))) { \ return className(_result.getErrorCode(), _result.getErrorMessage()); \ } \ @@ -42,16 +44,18 @@ includedVersionsToString(spi::IncludedVersions versions) PersistenceProviderWrapper::PersistenceProviderWrapper(spi::PersistenceProvider& spi) : _spi(spi), _result(spi::Result(spi::Result::ErrorType::NONE, "")), + _lock(), _log(), _failureMask(0) { } -PersistenceProviderWrapper::~PersistenceProviderWrapper() {} +PersistenceProviderWrapper::~PersistenceProviderWrapper() = default; std::string PersistenceProviderWrapper::toString() const { std::ostringstream ss; + Guard guard(_lock); for (size_t i = 0; i < _log.size(); ++i) { ss << _log[i] << "\n"; } @@ -74,8 +78,7 @@ PersistenceProviderWrapper::listBuckets(BucketSpace bucketSpace, spi::PartitionI } spi::Result -PersistenceProviderWrapper::createBucket(const spi::Bucket& bucket, - spi::Context& context) +PersistenceProviderWrapper::createBucket(const spi::Bucket& bucket, spi::Context& context) { LOG_SPI("createBucket(" << bucket << ")"); CHECK_ERROR(spi::Result, FAIL_CREATE_BUCKET); diff --git a/storage/src/tests/persistence/common/persistenceproviderwrapper.h b/storage/src/tests/persistence/common/persistenceproviderwrapper.h index 9ca08becabe..059bb4dea00 100644 --- a/storage/src/tests/persistence/common/persistenceproviderwrapper.h +++ b/storage/src/tests/persistence/common/persistenceproviderwrapper.h @@ -19,6 +19,7 @@ #include <vespa/persistence/spi/abstractpersistenceprovider.h> #include <vector> #include <string> +#include <mutex> namespace storage { @@ -50,8 +51,10 @@ public: private: spi::PersistenceProvider& _spi; spi::Result _result; + mutable std::mutex _lock; mutable std::vector<std::string> _log; uint32_t _failureMask; + using Guard = std::unique_lock<std::mutex>; public: PersistenceProviderWrapper(spi::PersistenceProvider& spi); ~PersistenceProviderWrapper() override; @@ -61,12 +64,16 @@ public: * return the given error without the wrapped SPI ever being invoked. */ void setResult(const spi::Result& result) { + Guard guard(_lock); _result = result; } void clearResult() { _result = spi::Result(spi::Result::ErrorType::NONE, ""); } - const spi::Result& getResult() const { return _result; } + spi::Result getResult() const { + Guard guard(_lock); + return _result; + } /** * Set a mask for operations to fail with _result */ @@ -81,8 +88,10 @@ public: /** * Clear log of all operations performed. */ - void clearOperationLog() { _log.clear(); } - const std::vector<std::string>& getOperationLog() const { return _log; } + void clearOperationLog() { + Guard guard(_lock); + _log.clear(); + } spi::Result createBucket(const spi::Bucket&, spi::Context&) override; spi::PartitionStateListResult getPartitionStates() const override; |