summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-07-25 15:37:31 +0200
committerGitHub <noreply@github.com>2018-07-25 15:37:31 +0200
commit7ffbc291ea4623c7877628fa0bc3274b7232cadd (patch)
tree08d1cf4dde8fc0381b0e611130097a934b93bfa2 /searchcore
parent18ca677a601d5d889c8c9b67c20f3d109e154937 (diff)
parent31d2e654e5d08024712e64ca817ec68d3d31121a (diff)
Merge pull request #6468 from vespa-engine/toregge/track-document-db-destruction
Track document db destruction.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/proton_configurer/proton_configurer_test.cpp20
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt2
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/document_db_config_owner.cpp21
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/document_db_config_owner.h25
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/document_db_directory_holder.cpp33
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/document_db_directory_holder.h20
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/documentdb.cpp2
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/documentdb.h4
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/i_proton_configurer_owner.h14
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/proton.cpp8
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/proton.h2
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/proton_configurer.cpp14
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/proton_configurer.h3
13 files changed, 137 insertions, 31 deletions
diff --git a/searchcore/src/tests/proton/proton_configurer/proton_configurer_test.cpp b/searchcore/src/tests/proton/proton_configurer/proton_configurer_test.cpp
index 045c8de9384..a89f2e3f0ff 100644
--- a/searchcore/src/tests/proton/proton_configurer/proton_configurer_test.cpp
+++ b/searchcore/src/tests/proton/proton_configurer/proton_configurer_test.cpp
@@ -12,7 +12,7 @@
#include <vespa/searchcore/proton/server/bootstrapconfig.h>
#include <vespa/searchcore/proton/server/bootstrapconfigmanager.h>
#include <vespa/searchcore/proton/server/documentdbconfigmanager.h>
-#include <vespa/searchcore/proton/server/i_document_db_config_owner.h>
+#include <vespa/searchcore/proton/server/document_db_config_owner.h>
#include <vespa/searchcore/proton/server/proton_config_snapshot.h>
#include <vespa/searchcore/proton/server/proton_configurer.h>
#include <vespa/searchcore/proton/server/i_proton_configurer_owner.h>
@@ -208,13 +208,13 @@ struct ConfigFixture {
struct MyProtonConfigurerOwner;
-struct MyDocumentDBConfigOwner : public IDocumentDBConfigOwner
+struct MyDocumentDBConfigOwner : public DocumentDBConfigOwner
{
vespalib::string _name;
MyProtonConfigurerOwner &_owner;
MyDocumentDBConfigOwner(const vespalib::string &name,
MyProtonConfigurerOwner &owner)
- : IDocumentDBConfigOwner(),
+ : DocumentDBConfigOwner(),
_name(name),
_owner(owner)
{
@@ -240,12 +240,12 @@ struct MyProtonConfigurerOwner : public IProtonConfigurerOwner
}
virtual ~MyProtonConfigurerOwner() { }
- virtual IDocumentDBConfigOwner *addDocumentDB(const DocTypeName &docTypeName,
- document::BucketSpace bucketSpace,
- const vespalib::string &configId,
- const std::shared_ptr<BootstrapConfig> &bootstrapConfig,
- const std::shared_ptr<DocumentDBConfig> &documentDBConfig,
- InitializeThreads initializeThreads) override
+ virtual std::shared_ptr<DocumentDBConfigOwner> addDocumentDB(const DocTypeName &docTypeName,
+ document::BucketSpace bucketSpace,
+ const vespalib::string &configId,
+ const std::shared_ptr<BootstrapConfig> &bootstrapConfig,
+ const std::shared_ptr<DocumentDBConfig> &documentDBConfig,
+ InitializeThreads initializeThreads) override
{
(void) bucketSpace;
(void) configId;
@@ -257,7 +257,7 @@ struct MyProtonConfigurerOwner : public IProtonConfigurerOwner
std::ostringstream os;
os << "add db " << docTypeName.getName() << " " << documentDBConfig->getGeneration();
_log.push_back(os.str());
- return db.get();
+ return db;
}
virtual void removeDocumentDB(const DocTypeName &docTypeName) override {
ASSERT_FALSE(_dbs.find(docTypeName) == _dbs.end());
diff --git a/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt
index b371439dd0e..87aa19fb1b2 100644
--- a/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt
+++ b/searchcore/src/vespa/searchcore/proton/server/CMakeLists.txt
@@ -13,6 +13,8 @@ vespa_add_library(searchcore_server STATIC
disk_mem_usage_sampler.cpp
disk_mem_usage_forwarder.cpp
docstorevalidator.cpp
+ document_db_config_owner.cpp
+ document_db_directory_holder.cpp
document_db_explorer.cpp
document_db_flush_config.cpp
document_db_maintenance_config.cpp
diff --git a/searchcore/src/vespa/searchcore/proton/server/document_db_config_owner.cpp b/searchcore/src/vespa/searchcore/proton/server/document_db_config_owner.cpp
new file mode 100644
index 00000000000..28492c5d39a
--- /dev/null
+++ b/searchcore/src/vespa/searchcore/proton/server/document_db_config_owner.cpp
@@ -0,0 +1,21 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "document_db_config_owner.h"
+#include "document_db_directory_holder.h"
+
+namespace proton {
+
+DocumentDBConfigOwner::DocumentDBConfigOwner()
+ : _holder(std::make_shared<DocumentDBDirectoryHolder>())
+{
+}
+
+DocumentDBConfigOwner::~DocumentDBConfigOwner() = default;
+
+std::shared_ptr<DocumentDBDirectoryHolder>
+DocumentDBConfigOwner::getDocumentDBDirectoryHolder()
+{
+ return _holder;
+};
+
+} // namespace proton
diff --git a/searchcore/src/vespa/searchcore/proton/server/document_db_config_owner.h b/searchcore/src/vespa/searchcore/proton/server/document_db_config_owner.h
new file mode 100644
index 00000000000..cc19bc14fab
--- /dev/null
+++ b/searchcore/src/vespa/searchcore/proton/server/document_db_config_owner.h
@@ -0,0 +1,25 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "i_document_db_config_owner.h"
+
+namespace proton {
+
+class DocumentDBDirectoryHolder;
+
+/*
+ * Abstract class meant to be a base class for DocumentDB where a
+ * directory holder exists until the document db instance is
+ * destroyed.
+ */
+class DocumentDBConfigOwner : public IDocumentDBConfigOwner
+{
+ std::shared_ptr<DocumentDBDirectoryHolder> _holder;
+public:
+ DocumentDBConfigOwner();
+ virtual ~DocumentDBConfigOwner();
+ std::shared_ptr<DocumentDBDirectoryHolder> getDocumentDBDirectoryHolder();
+};
+
+} // namespace proton
diff --git a/searchcore/src/vespa/searchcore/proton/server/document_db_directory_holder.cpp b/searchcore/src/vespa/searchcore/proton/server/document_db_directory_holder.cpp
new file mode 100644
index 00000000000..d0807a3b8a7
--- /dev/null
+++ b/searchcore/src/vespa/searchcore/proton/server/document_db_directory_holder.cpp
@@ -0,0 +1,33 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "document_db_directory_holder.h"
+#include <mutex>
+#include <condition_variable>
+
+namespace proton {
+
+namespace {
+
+std::mutex mutex;
+std::condition_variable cv;
+
+}
+
+DocumentDBDirectoryHolder::DocumentDBDirectoryHolder()
+{
+}
+
+DocumentDBDirectoryHolder::~DocumentDBDirectoryHolder()
+{
+ std::lock_guard guard(mutex);
+ cv.notify_all();
+}
+
+void
+DocumentDBDirectoryHolder::waitUntilDestroyed(const std::weak_ptr<DocumentDBDirectoryHolder> &holder)
+{
+ std::unique_lock guard(mutex);
+ cv.wait(guard, [&]() { return !holder.lock(); });
+}
+
+} // namespace proton
diff --git a/searchcore/src/vespa/searchcore/proton/server/document_db_directory_holder.h b/searchcore/src/vespa/searchcore/proton/server/document_db_directory_holder.h
new file mode 100644
index 00000000000..65df1b7bd8e
--- /dev/null
+++ b/searchcore/src/vespa/searchcore/proton/server/document_db_directory_holder.h
@@ -0,0 +1,20 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "i_document_db_config_owner.h"
+
+namespace proton {
+
+/*
+ * class holding onto a document db directory.
+ */
+class DocumentDBDirectoryHolder
+{
+public:
+ DocumentDBDirectoryHolder();
+ ~DocumentDBDirectoryHolder();
+ static void waitUntilDestroyed(const std::weak_ptr<DocumentDBDirectoryHolder> &holder);
+};
+
+} // namespace proton
diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp
index ad7a2d57c89..24d40e15677 100644
--- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp
@@ -90,7 +90,7 @@ DocumentDB::DocumentDB(const vespalib::string &baseDir,
ConfigStore::UP config_store,
InitializeThreads initializeThreads,
const HwInfo &hwInfo)
- : IDocumentDBConfigOwner(),
+ : DocumentDBConfigOwner(),
IReplayConfig(),
IFeedHandlerOwner(),
IDocumentSubDBOwner(),
diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.h b/searchcore/src/vespa/searchcore/proton/server/documentdb.h
index e25f1fe66fc..1a64a4013de 100644
--- a/searchcore/src/vespa/searchcore/proton/server/documentdb.h
+++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.h
@@ -10,7 +10,7 @@
#include "documentsubdbcollection.h"
#include "executorthreadingservice.h"
#include "feedhandler.h"
-#include "i_document_db_config_owner.h"
+#include "document_db_config_owner.h"
#include "i_document_subdb_owner.h"
#include "i_feed_handler_owner.h"
#include "i_lid_space_compaction_handler.h"
@@ -53,7 +53,7 @@ namespace matching { class SessionManager; }
* to ensure that there are never multiple writers. Unless explicitly stated,
* none of the methods of this class are thread-safe.
*/
-class DocumentDB : public IDocumentDBConfigOwner,
+class DocumentDB : public DocumentDBConfigOwner,
public IReplayConfig,
public IFeedHandlerOwner,
public IDocumentSubDBOwner,
diff --git a/searchcore/src/vespa/searchcore/proton/server/i_proton_configurer_owner.h b/searchcore/src/vespa/searchcore/proton/server/i_proton_configurer_owner.h
index 242e99fffbf..fec8430e41d 100644
--- a/searchcore/src/vespa/searchcore/proton/server/i_proton_configurer_owner.h
+++ b/searchcore/src/vespa/searchcore/proton/server/i_proton_configurer_owner.h
@@ -10,7 +10,7 @@ namespace vespalib { class ThreadStackExecutorBase; }
namespace proton {
-class IDocumentDBConfigOwner;
+class DocumentDBConfigOwner;
/*
* Interface class for owner of a proton configurer, with callback methods
@@ -21,12 +21,12 @@ class IProtonConfigurerOwner
using InitializeThreads = std::shared_ptr<vespalib::ThreadStackExecutorBase>;
public:
virtual ~IProtonConfigurerOwner() { }
- virtual IDocumentDBConfigOwner *addDocumentDB(const DocTypeName &docTypeName,
- document::BucketSpace bucketSpace,
- const vespalib::string &configId,
- const std::shared_ptr<BootstrapConfig> &bootstrapConfig,
- const std::shared_ptr<DocumentDBConfig> &documentDBConfig,
- InitializeThreads initializeThreads) = 0;
+ virtual std::shared_ptr<DocumentDBConfigOwner> addDocumentDB(const DocTypeName &docTypeName,
+ document::BucketSpace bucketSpace,
+ const vespalib::string &configId,
+ const std::shared_ptr<BootstrapConfig> &bootstrapConfig,
+ const std::shared_ptr<DocumentDBConfig> &documentDBConfig,
+ InitializeThreads initializeThreads) = 0;
virtual void removeDocumentDB(const DocTypeName &docTypeName) = 0;
virtual void applyConfig(const std::shared_ptr<BootstrapConfig> &bootstrapConfig) = 0;
};
diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp
index 6ffb82a2ad3..9a7d5a5141e 100644
--- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp
@@ -352,7 +352,7 @@ Proton::applyConfig(const BootstrapConfig::SP & configSnapshot)
}
}
-IDocumentDBConfigOwner *
+std::shared_ptr<DocumentDBConfigOwner>
Proton::addDocumentDB(const DocTypeName &docTypeName,
document::BucketSpace bucketSpace,
const vespalib::string &configId,
@@ -366,21 +366,21 @@ Proton::addDocumentDB(const DocTypeName &docTypeName,
if (docType != NULL) {
LOG(info, "Add document database: doctypename(%s), configid(%s)",
docTypeName.toString().c_str(), configId.c_str());
- return addDocumentDB(*docType, bucketSpace, bootstrapConfig, documentDBConfig, initializeThreads).get();
+ return addDocumentDB(*docType, bucketSpace, bootstrapConfig, documentDBConfig, initializeThreads);
} else {
LOG(warning,
"Did not find document type '%s' in the document manager. "
"Skipping creating document database for this type",
docTypeName.toString().c_str());
- return nullptr;
+ return std::shared_ptr<DocumentDBConfigOwner>();
}
} catch (const document::DocumentTypeNotFoundException & e) {
LOG(warning,
"Did not find document type '%s' in the document manager. "
"Skipping creating document database for this type",
docTypeName.toString().c_str());
- return nullptr;
+ return std::shared_ptr<DocumentDBConfigOwner>();
}
}
diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.h b/searchcore/src/vespa/searchcore/proton/server/proton.h
index dd2b42d94cf..a3c596d7b0b 100644
--- a/searchcore/src/vespa/searchcore/proton/server/proton.h
+++ b/searchcore/src/vespa/searchcore/proton/server/proton.h
@@ -130,7 +130,7 @@ private:
std::mutex _nodeUpLock;
std::set<BucketSpace> _nodeUp; // bucketspaces where node is up
- IDocumentDBConfigOwner *
+ std::shared_ptr<DocumentDBConfigOwner>
addDocumentDB(const DocTypeName & docTypeName, BucketSpace bucketSpace, const vespalib::string & configid,
const BootstrapConfig::SP & bootstrapConfig, const std::shared_ptr<DocumentDBConfig> &documentDBConfig,
InitializeThreads initializeThreads) override;
diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_configurer.cpp b/searchcore/src/vespa/searchcore/proton/server/proton_configurer.cpp
index 07ed83fd8c6..f871f36b042 100644
--- a/searchcore/src/vespa/searchcore/proton/server/proton_configurer.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/proton_configurer.cpp
@@ -4,7 +4,8 @@
#include "proton_config_snapshot.h"
#include "bootstrapconfig.h"
#include "i_proton_configurer_owner.h"
-#include "i_document_db_config_owner.h"
+#include "document_db_config_owner.h"
+#include "document_db_directory_holder.h"
#include <vespa/vespalib/util/lambdatask.h>
#include <vespa/vespalib/util/threadstackexecutorbase.h>
#include <vespa/document/bucket/fixed_bucket_spaces.h>
@@ -162,13 +163,15 @@ ProtonConfigurer::configureDocumentDB(const ProtonConfigSnapshot &configSnapshot
const auto &documentDBConfig = cfgitr->second;
auto dbitr(_documentDBs.find(docTypeName));
if (dbitr == _documentDBs.end()) {
- auto *newdb = _owner.addDocumentDB(docTypeName, bucketSpace, configId, bootstrapConfig, documentDBConfig, initializeThreads);
- if (newdb != nullptr) {
- auto insres = _documentDBs.insert(std::make_pair(docTypeName, newdb));
+ auto newdb = _owner.addDocumentDB(docTypeName, bucketSpace, configId, bootstrapConfig, documentDBConfig, initializeThreads);
+ if (newdb) {
+ auto insres = _documentDBs.insert(std::make_pair(docTypeName, std::make_pair(newdb, newdb->getDocumentDBDirectoryHolder())));
assert(insres.second);
}
} else {
- dbitr->second->reconfigure(documentDBConfig);
+ auto documentDB = dbitr->second.first.lock();
+ assert(documentDB);
+ documentDB->reconfigure(documentDBConfig);
}
}
@@ -189,6 +192,7 @@ ProtonConfigurer::pruneDocumentDBs(const ProtonConfigSnapshot &configSnapshot)
auto found(newDocTypes.find(dbitr->first));
if (found == newDocTypes.end()) {
_owner.removeDocumentDB(dbitr->first);
+ DocumentDBDirectoryHolder::waitUntilDestroyed(dbitr->second.second);
dbitr = _documentDBs.erase(dbitr);
} else {
++dbitr;
diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_configurer.h b/searchcore/src/vespa/searchcore/proton/server/proton_configurer.h
index 149be3a9e62..ac0f6197fd7 100644
--- a/searchcore/src/vespa/searchcore/proton/server/proton_configurer.h
+++ b/searchcore/src/vespa/searchcore/proton/server/proton_configurer.h
@@ -12,6 +12,7 @@
namespace proton {
+class DocumentDBDirectoryHolder;
class IDocumentDBConfigOwner;
class IProtonConfigurerOwner;
class BootstrapConfig;
@@ -22,7 +23,7 @@ class BootstrapConfig;
*/
class ProtonConfigurer : public IProtonConfigurer
{
- using DocumentDBs = std::map<DocTypeName, IDocumentDBConfigOwner *>;
+ using DocumentDBs = std::map<DocTypeName, std::pair<std::weak_ptr<IDocumentDBConfigOwner>, std::weak_ptr<DocumentDBDirectoryHolder>>>;
using InitializeThreads = std::shared_ptr<vespalib::ThreadStackExecutorBase>;
ExecutorThreadService _executor;