summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2021-09-10 14:30:57 +0200
committerTor Egge <Tor.Egge@online.no>2021-09-10 14:30:57 +0200
commit44c672b40e31043b8e717abe229718511ec8e2bf (patch)
tree9cc1cbfcaa6c6febb8b46d8a275445176ebbd541 /searchcore
parentc8beeb61f595019c22ee6eca137ab47625c5712a (diff)
Refactor port number assignment.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp5
-rw-r--r--searchcore/src/vespa/searchcore/bmcluster/bm_cluster.cpp37
-rw-r--r--searchcore/src/vespa/searchcore/bmcluster/bm_cluster.h9
-rw-r--r--searchcore/src/vespa/searchcore/bmcluster/bm_node.cpp72
-rw-r--r--searchcore/src/vespa/searchcore/bmcluster/bm_node.h16
5 files changed, 98 insertions, 41 deletions
diff --git a/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp b/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp
index 9752a4b5c36..5a7ba37d67c 100644
--- a/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp
+++ b/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp
@@ -49,6 +49,7 @@ using vespalib::makeLambdaTask;
namespace {
vespalib::string base_dir = "testdb";
+constexpr int base_port = 9017;
std::shared_ptr<DocumenttypesConfig> make_document_types() {
using Struct = document::config_builder::Struct;
@@ -155,8 +156,8 @@ struct PersistenceProviderFixture {
PersistenceProviderFixture::PersistenceProviderFixture(const BMParams& params)
: _document_types(make_document_types()),
_repo(document::DocumentTypeRepoFactory::make(*_document_types)),
- _bm_cluster(std::make_unique<BmCluster>(params, _repo)),
- _bm_node(BmNode::create(params, _document_types)),
+ _bm_cluster(std::make_unique<BmCluster>(base_dir, base_port, params, _document_types, _repo)),
+ _bm_node(_bm_cluster->make_bm_node(0)),
_feed(_repo),
_feed_handler(nullptr)
{
diff --git a/searchcore/src/vespa/searchcore/bmcluster/bm_cluster.cpp b/searchcore/src/vespa/searchcore/bmcluster/bm_cluster.cpp
index 5a0b05f5c54..6c2ed526498 100644
--- a/searchcore/src/vespa/searchcore/bmcluster/bm_cluster.cpp
+++ b/searchcore/src/vespa/searchcore/bmcluster/bm_cluster.cpp
@@ -1,12 +1,15 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "bm_cluster.h"
+#include "bm_node.h"
#include "bm_message_bus.h"
#include <vespa/config/common/configcontext.h>
#include <vespa/storage/storageserver/rpc/shared_rpc_resources.h>
#include <vespa/messagebus/config-messagebus.h>
#include <vespa/messagebus/testlib/slobrok.h>
#include <vespa/slobrok/sbmirror.h>
+#include <vespa/vespalib/io/fileutil.h>
+#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <thread>
@@ -25,6 +28,18 @@ namespace {
vespalib::string message_bus_config_id("bm-message-bus");
vespalib::string rpc_client_config_id("bm-rpc-client");
+enum class PortBias
+{
+ SLOBROK_PORT = 0,
+ RPC_CLIENT_PORT = 1,
+ NUM_PORTS = 2
+};
+
+int port_number(int base_port, PortBias bias)
+{
+ return base_port + static_cast<int>(bias);
+}
+
void
make_slobroks_config(SlobroksConfigBuilder& slobroks, int slobrok_port)
{
@@ -76,10 +91,10 @@ struct BmCluster::RpcClientConfigSet {
BmCluster::RpcClientConfigSet::~RpcClientConfigSet() = default;
-BmCluster::BmCluster(const BmClusterParams& params, std::shared_ptr<const document::DocumentTypeRepo> repo)
+BmCluster::BmCluster(const vespalib::string& base_dir, int base_port, const BmClusterParams& params, std::shared_ptr<DocumenttypesConfig> document_types, std::shared_ptr<const document::DocumentTypeRepo> repo)
: _params(params),
- _slobrok_port(9018),
- _rpc_client_port(9019),
+ _slobrok_port(port_number(base_port, PortBias::SLOBROK_PORT)),
+ _rpc_client_port(port_number(base_port, PortBias::RPC_CLIENT_PORT)),
_message_bus_config(std::make_unique<MessageBusConfigSet>(message_bus_config_id, _slobrok_port)),
_rpc_client_config(std::make_unique<RpcClientConfigSet>(rpc_client_config_id, _slobrok_port)),
_config_set(std::make_unique<config::ConfigSet>()),
@@ -87,11 +102,15 @@ BmCluster::BmCluster(const BmClusterParams& params, std::shared_ptr<const docume
_slobrok(),
_message_bus(),
_rpc_client(),
- _repo(repo)
+ _base_dir(base_dir),
+ _base_port(base_port),
+ _document_types(std::move(document_types)),
+ _repo(std::move(repo))
{
_message_bus_config->add_builders(*_config_set);
_rpc_client_config->add_builders(*_config_set);
+ vespalib::mkdir(_base_dir, false);
}
BmCluster::~BmCluster()
@@ -177,4 +196,14 @@ BmCluster::stop_rpc_client()
}
}
+std::unique_ptr<BmNode>
+BmCluster::make_bm_node(int node_idx)
+{
+ vespalib::asciistream s;
+ s << _base_dir << "/n" << node_idx;
+ vespalib::string node_base_dir(s.str());
+ int node_base_port = port_number(_base_port, PortBias::NUM_PORTS) + BmNode::num_ports() * node_idx;
+ return BmNode::create(node_base_dir, node_base_port, node_idx, _params, _document_types, _slobrok_port);
+}
+
}
diff --git a/searchcore/src/vespa/searchcore/bmcluster/bm_cluster.h b/searchcore/src/vespa/searchcore/bmcluster/bm_cluster.h
index 9a41ec5b415..3fdc0dba045 100644
--- a/searchcore/src/vespa/searchcore/bmcluster/bm_cluster.h
+++ b/searchcore/src/vespa/searchcore/bmcluster/bm_cluster.h
@@ -13,12 +13,14 @@ class ConfigSet;
}
namespace document { class DocumentTypeRepo; }
+namespace document::internal { class InternalDocumenttypesType; }
namespace mbus { class Slobrok; }
namespace storage::rpc { class SharedRpcResources; }
namespace search::bmcluster {
class BmMessageBus;
+class BmNode;
/*
* Class representing a benchmark cluster with one or more benchmark nodes.
@@ -26,6 +28,7 @@ class BmMessageBus;
class BmCluster {
struct MessageBusConfigSet;
struct RpcClientConfigSet;
+ using DocumenttypesConfig = const document::internal::InternalDocumenttypesType;
BmClusterParams _params;
int _slobrok_port;
int _rpc_client_port;
@@ -36,10 +39,13 @@ class BmCluster {
std::unique_ptr<mbus::Slobrok> _slobrok;
std::unique_ptr<BmMessageBus> _message_bus;
std::unique_ptr<storage::rpc::SharedRpcResources> _rpc_client;
+ vespalib::string _base_dir;
+ int _base_port;
+ std::shared_ptr<DocumenttypesConfig> _document_types;
std::shared_ptr<const document::DocumentTypeRepo> _repo;
public:
- BmCluster(const BmClusterParams& params, std::shared_ptr<const document::DocumentTypeRepo> repo);
+ BmCluster(const vespalib::string& base_dir, int base_port, const BmClusterParams& params, std::shared_ptr<DocumenttypesConfig> document_types, std::shared_ptr<const document::DocumentTypeRepo> repo);
~BmCluster();
void start_slobrok();
void stop_slobrok();
@@ -50,6 +56,7 @@ public:
void stop_rpc_client();
storage::rpc::SharedRpcResources &get_rpc_client() { return *_rpc_client; }
BmMessageBus& get_message_bus() { return *_message_bus; }
+ std::unique_ptr<BmNode> make_bm_node(int node_idx);
};
}
diff --git a/searchcore/src/vespa/searchcore/bmcluster/bm_node.cpp b/searchcore/src/vespa/searchcore/bmcluster/bm_node.cpp
index 808ca348622..07d86ef5710 100644
--- a/searchcore/src/vespa/searchcore/bmcluster/bm_node.cpp
+++ b/searchcore/src/vespa/searchcore/bmcluster/bm_node.cpp
@@ -125,7 +125,27 @@ using vespalib::compression::CompressionConfig;
namespace search::bmcluster {
-vespalib::string base_dir = "testdb";
+namespace {
+
+enum PortBias
+{
+ TLS_LISTEN_PORT,
+ SERVICE_LAYER_MBUS_PORT,
+ SERVICE_LAYER_RPC_PORT,
+ SERVICE_LAYER_STATUS_PORT,
+ DISTRIBUTOR_MBUS_PORT,
+ DISTRIBUTOR_RPC_PORT,
+ DISTRIBUTOR_STATUS_PORT,
+ NUM_PORTS,
+
+};
+
+int port_number(int base_port, PortBias bias)
+{
+ return base_port + static_cast<int>(bias);
+}
+
+}
std::shared_ptr<AttributesConfig> make_attributes_config() {
AttributesConfigBuilder builder;
@@ -389,22 +409,19 @@ struct DistributorConfigSet : public StorageConfigSet
DistributorConfigSet::~DistributorConfigSet() = default;
-BmNode::BmNode(std::shared_ptr<document::DocumenttypesConfig> document_types)
- : _document_types(std::move(document_types)),
- _repo(document::DocumentTypeRepoFactory::make(*_document_types)),
- _doc_type_name("test"),
- _document_type(_repo->getDocumentType(_doc_type_name.getName())),
- _field(_document_type->getField("int"))
-{
-}
+BmNode::BmNode() = default;
BmNode::~BmNode() = default;
class MyBmNode : public BmNode
{
+ std::shared_ptr<DocumenttypesConfig> _document_types;
+ std::shared_ptr<const DocumentTypeRepo> _repo;
+ proton::DocTypeName _doc_type_name;
std::shared_ptr<DocumentDBConfig> _document_db_config;
vespalib::string _base_dir;
search::index::DummyFileHeaderContext _file_header_context;
+ int _node_idx;
int _tls_listen_port;
int _slobrok_port;
int _service_layer_mbus_port;
@@ -441,7 +458,7 @@ class MyBmNode : public BmNode
void create_document_db(const BmClusterParams& params);
public:
- MyBmNode(const BmClusterParams& params, std::shared_ptr<document::DocumenttypesConfig> document_types);
+ MyBmNode(const vespalib::string &base_dir, int base_port, int node_idx, const BmClusterParams& params, std::shared_ptr<document::DocumenttypesConfig> document_types, int slobrok_port);
~MyBmNode() override;
std::unique_ptr<SpiBmFeedHandler> make_create_bucket_feed_handler(bool skip_get_spi_bucket_info) override;
void start_service_layer(const BmClusterParams& params) override;
@@ -455,19 +472,23 @@ public:
PersistenceProvider* get_persistence_provider() override;
};
-MyBmNode::MyBmNode(const BmClusterParams& params, std::shared_ptr<document::DocumenttypesConfig> document_types)
- : BmNode(std::move(document_types)),
+MyBmNode::MyBmNode(const vespalib::string& base_dir, int base_port, int node_idx, const BmClusterParams& params, std::shared_ptr<document::DocumenttypesConfig> document_types, int slobrok_port)
+ : BmNode(),
+ _document_types(std::move(document_types)),
+ _repo(document::DocumentTypeRepoFactory::make(*_document_types)),
+ _doc_type_name("test"),
_document_db_config(make_document_db_config(_document_types, _repo, _doc_type_name)),
_base_dir(base_dir),
_file_header_context(),
- _tls_listen_port(9017),
- _slobrok_port(9018),
- _service_layer_mbus_port(9020),
- _service_layer_rpc_port(9021),
- _service_layer_status_port(9022),
- _distributor_mbus_port(9023),
- _distributor_rpc_port(9024),
- _distributor_status_port(9025),
+ _node_idx(node_idx),
+ _tls_listen_port(port_number(base_port, PortBias::TLS_LISTEN_PORT)),
+ _slobrok_port(slobrok_port),
+ _service_layer_mbus_port(port_number(base_port, PortBias::SERVICE_LAYER_MBUS_PORT)),
+ _service_layer_rpc_port(port_number(base_port, PortBias::SERVICE_LAYER_RPC_PORT)),
+ _service_layer_status_port(port_number(base_port, PortBias::SERVICE_LAYER_STATUS_PORT)),
+ _distributor_mbus_port(port_number(base_port, PortBias::DISTRIBUTOR_MBUS_PORT)),
+ _distributor_rpc_port(port_number(base_port, PortBias::DISTRIBUTOR_RPC_PORT)),
+ _distributor_status_port(port_number(base_port, PortBias::DISTRIBUTOR_STATUS_PORT)),
_tls("tls", _tls_listen_port, _base_dir, _file_header_context),
_tls_spec(vespalib::make_string("tcp/localhost:%d", _tls_listen_port)),
_query_limiter(),
@@ -514,7 +535,6 @@ MyBmNode::~MyBmNode()
}
}
-
void
MyBmNode::create_document_db(const BmClusterParams& params)
{
@@ -666,10 +686,16 @@ MyBmNode::get_persistence_provider()
return _persistence_engine.get();
}
+unsigned int
+BmNode::num_ports()
+{
+ return static_cast<unsigned int>(PortBias::NUM_PORTS);
+}
+
std::unique_ptr<BmNode>
-BmNode::create(const BmClusterParams& params, std::shared_ptr<document::DocumenttypesConfig> document_types)
+BmNode::create(const vespalib::string& base_dir, int base_port, int node_idx, const BmClusterParams& params, std::shared_ptr<document::DocumenttypesConfig> document_types, int slobrok_port)
{
- return std::make_unique<MyBmNode>(params, std::move(document_types));
+ return std::make_unique<MyBmNode>(base_dir, base_port, node_idx, params, std::move(document_types), slobrok_port);
}
}
diff --git a/searchcore/src/vespa/searchcore/bmcluster/bm_node.h b/searchcore/src/vespa/searchcore/bmcluster/bm_node.h
index 1212aeb4b5a..a8f117e61db 100644
--- a/searchcore/src/vespa/searchcore/bmcluster/bm_node.h
+++ b/searchcore/src/vespa/searchcore/bmcluster/bm_node.h
@@ -3,7 +3,6 @@
#pragma once
#include <memory>
-#include <vespa/document/config/config-documenttypes.h>
#include <vespa/searchcore/proton/common/doctypename.h>
namespace document {
@@ -14,6 +13,8 @@ class Field;
};
+namespace document::internal { class InternalDocumenttypesType; }
+
namespace storage::spi { struct PersistenceProvider; }
namespace search::bmcluster {
@@ -28,13 +29,8 @@ class SpiBmFeedHandler;
*/
class BmNode {
protected:
- std::shared_ptr<document::DocumenttypesConfig> _document_types;
- std::shared_ptr<const document::DocumentTypeRepo> _repo;
- proton::DocTypeName _doc_type_name;
- const document::DocumentType* _document_type;
- const document::Field& _field;
- BmNode(std::shared_ptr<document::DocumenttypesConfig> document_types);
+ BmNode();
public:
virtual ~BmNode();
virtual std::unique_ptr<SpiBmFeedHandler> make_create_bucket_feed_handler(bool skip_get_spi_bucket_info) = 0;
@@ -47,10 +43,8 @@ public:
virtual void shutdown_service_layer() = 0;
virtual IBmFeedHandler* get_feed_handler() = 0;
virtual storage::spi::PersistenceProvider *get_persistence_provider() = 0;
- static std::unique_ptr<BmNode> create(const BmClusterParams& params, std::shared_ptr<document::DocumenttypesConfig> document_types);
- const proton::DocTypeName& get_doc_type_name() const noexcept { return _doc_type_name; }
- const document::DocumentType *get_document_type() const noexcept { return _document_type; }
- const document::Field& get_field() const noexcept { return _field; }
+ static unsigned int num_ports();
+ static std::unique_ptr<BmNode> create(const vespalib::string &base_dir, int base_port, int node_idx, const BmClusterParams& params, std::shared_ptr<const document::internal::InternalDocumenttypesType> document_types, int slobrok_port);
};
}