summaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-10-20 09:05:35 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-10-20 09:05:35 +0000
commiteb66d9f6ace62d9f8918f62ad3bee0431e12eefb (patch)
treee7c09d6d24c2c5fdbcd0858344a728b33db04dbb /storage
parent45c15e502a9655355071a59f529b0acf93af6a1c (diff)
Add a registered threadlocal persistence handler.
Diffstat (limited to 'storage')
-rw-r--r--storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp21
-rw-r--r--storage/src/vespa/storage/persistence/filestorage/filestormanager.h22
2 files changed, 27 insertions, 16 deletions
diff --git a/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp b/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp
index c8789f765c7..34e8f599f8f 100644
--- a/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp
+++ b/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp
@@ -42,17 +42,17 @@ FileStorManager(const config::ConfigUri & configUri, spi::PersistenceProvider& p
_provider(&_providerErrorWrapper),
_init_handler(init_handler),
_bucketIdFactory(_component.getBucketIdFactory()),
- _configUri(configUri),
_persistenceHandlers(),
_threads(),
_bucketOwnershipNotifier(std::make_unique<BucketOwnershipNotifier>(_component, *this)),
- _configFetcher(_configUri.getContext()),
+ _configFetcher(configUri.getContext()),
_threadLockCheckInterval(60),
_failDiskOnError(false),
_metrics(std::make_unique<FileStorMetrics>(_component.getLoadTypes()->getMetricLoadTypes())),
- _closed(false)
+ _closed(false),
+ _lock()
{
- _configFetcher.subscribe(_configUri.getConfigId(), this);
+ _configFetcher.subscribe(configUri.getConfigId(), this);
_configFetcher.start();
_component.registerMetric(*_metrics);
_component.registerStatusPage(*this);
@@ -114,11 +114,14 @@ createThreadName(size_t stripeId) {
return fmt("PersistenceThread-%zu", stripeId);
}
+thread_local PersistenceHandler * _G_threadLocalHandler = nullptr;
+
}
PersistenceHandler &
-FileStorManager::createRegisteredHandler(ServiceLayerComponent & component)
+FileStorManager::createRegisteredHandler(const ServiceLayerComponent & component)
{
+ std::lock_guard guard(_lock);
size_t index = _persistenceHandlers.size();
assert(index < _metrics->disks[0]->threads.size());
_persistenceHandlers.push_back(
@@ -127,6 +130,14 @@ FileStorManager::createRegisteredHandler(ServiceLayerComponent & component)
*_bucketOwnershipNotifier, *_metrics->disks[0]->threads[index]));
return *_persistenceHandlers.back();
}
+
+PersistenceHandler &
+FileStorManager::getThreadLocalHandler() {
+ if (_G_threadLocalHandler == nullptr) {
+ _G_threadLocalHandler = & createRegisteredHandler(_component);
+ }
+ return *_G_threadLocalHandler;
+}
/**
* If live configuration, assuming storageserver makes sure no messages are
* incoming during reconfiguration
diff --git a/storage/src/vespa/storage/persistence/filestorage/filestormanager.h b/storage/src/vespa/storage/persistence/filestorage/filestormanager.h
index 691470478cf..38df7e752a5 100644
--- a/storage/src/vespa/storage/persistence/filestorage/filestormanager.h
+++ b/storage/src/vespa/storage/persistence/filestorage/filestormanager.h
@@ -49,15 +49,13 @@ class FileStorManager : public StorageLinkQueued,
private config::IFetcherCallback<vespa::config::content::StorFilestorConfig>,
public MessageSender
{
- ServiceLayerComponentRegister & _compReg;
- ServiceLayerComponent _component;
- spi::PersistenceProvider & _providerCore;
- ProviderErrorWrapper _providerErrorWrapper;
- spi::PersistenceProvider * _provider;
- DoneInitializeHandler& _init_handler;
-
- const document::BucketIdFactory& _bucketIdFactory;
- config::ConfigUri _configUri;
+ ServiceLayerComponentRegister & _compReg;
+ ServiceLayerComponent _component;
+ spi::PersistenceProvider & _providerCore;
+ ProviderErrorWrapper _providerErrorWrapper;
+ spi::PersistenceProvider * _provider;
+ DoneInitializeHandler& _init_handler;
+ const document::BucketIdFactory & _bucketIdFactory;
std::vector<std::unique_ptr<ServiceLayerComponent>> _persistenceComponents;
std::vector<std::unique_ptr<PersistenceHandler>> _persistenceHandlers;
@@ -71,7 +69,8 @@ class FileStorManager : public StorageLinkQueued,
std::shared_ptr<FileStorMetrics> _metrics;
std::unique_ptr<FileStorHandler> _filestorHandler;
std::unique_ptr<vespalib::ISequencedTaskExecutor> _sequencedExecutor;
- bool _closed;
+ bool _closed;
+ std::mutex _lock;
friend struct FileStorManagerTest;
@@ -109,7 +108,8 @@ public:
private:
void configure(std::unique_ptr<vespa::config::content::StorFilestorConfig> config) override;
- PersistenceHandler & createRegisteredHandler(ServiceLayerComponent & component);
+ PersistenceHandler & createRegisteredHandler(const ServiceLayerComponent & component);
+ PersistenceHandler & getThreadLocalHandler();
void replyWithBucketNotFound(api::StorageMessage&, const document::Bucket&);