summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne H Juul <arnej27959@users.noreply.github.com>2021-07-13 15:07:05 +0200
committerGitHub <noreply@github.com>2021-07-13 15:07:05 +0200
commit02b1f56dc2b76f9b0bb59fd0a84c4353f8cba089 (patch)
tree7d10d782421adcf5e8d688c092e1759ce53677ca
parent3f5a585788a52f4d2fdfa6686c5af777a06ee8ce (diff)
parente8333f76c7c7437960b0a8c539584bb1a9af0897 (diff)
Merge pull request #18493 from vespa-engine/arnej/add-map-source-and-listener
add some new interfaces
-rw-r--r--slobrok/src/vespa/slobrok/server/CMakeLists.txt7
-rw-r--r--slobrok/src/vespa/slobrok/server/map_listener.cpp21
-rw-r--r--slobrok/src/vespa/slobrok/server/map_listener.h21
-rw-r--r--slobrok/src/vespa/slobrok/server/map_source.cpp10
-rw-r--r--slobrok/src/vespa/slobrok/server/map_source.h19
-rw-r--r--slobrok/src/vespa/slobrok/server/proxy_map_source.cpp44
-rw-r--r--slobrok/src/vespa/slobrok/server/proxy_map_source.h29
7 files changed, 149 insertions, 2 deletions
diff --git a/slobrok/src/vespa/slobrok/server/CMakeLists.txt b/slobrok/src/vespa/slobrok/server/CMakeLists.txt
index 5951e876ecc..5b9059af932 100644
--- a/slobrok/src/vespa/slobrok/server/CMakeLists.txt
+++ b/slobrok/src/vespa/slobrok/server/CMakeLists.txt
@@ -8,17 +8,20 @@ vespa_add_library(slobrok_slobrokserver
i_rpc_server_manager.cpp
managed_rpc_server.cpp
map_diff.cpp
+ map_listener.cpp
+ map_source.cpp
metrics_producer.cpp
monitor.cpp
named_service.cpp
+ proxy_map_source.cpp
reconfigurable_stateserver.cpp
remote_check.cpp
remote_slobrok.cpp
reserved_name.cpp
- rpchooks.cpp
- rpcmirror.cpp
rpc_server_manager.cpp
rpc_server_map.cpp
+ rpchooks.cpp
+ rpcmirror.cpp
sbenv.cpp
service_map_history.cpp
service_mapping.cpp
diff --git a/slobrok/src/vespa/slobrok/server/map_listener.cpp b/slobrok/src/vespa/slobrok/server/map_listener.cpp
new file mode 100644
index 00000000000..b77fde49c7d
--- /dev/null
+++ b/slobrok/src/vespa/slobrok/server/map_listener.cpp
@@ -0,0 +1,21 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "map_listener.h"
+#include <vespa/log/log.h>
+
+LOG_SETUP(".slobrok.server.map_listener");
+
+namespace slobrok {
+
+MapListener::~MapListener() = default;
+
+void MapListener::update(const ServiceMapping &old_mapping,
+ const ServiceMapping &new_mapping)
+{
+ LOG_ASSERT(old_mapping.name == new_mapping.name);
+ remove(old_mapping);
+ add(new_mapping);
+}
+
+} // namespace slobrok
+
diff --git a/slobrok/src/vespa/slobrok/server/map_listener.h b/slobrok/src/vespa/slobrok/server/map_listener.h
new file mode 100644
index 00000000000..e84f3bd5bd9
--- /dev/null
+++ b/slobrok/src/vespa/slobrok/server/map_listener.h
@@ -0,0 +1,21 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "service_mapping.h"
+
+namespace slobrok {
+
+/**
+ * Interface for getting incremental updates from a MapSource.
+ **/
+struct MapListener {
+ virtual void add(const ServiceMapping &mapping) = 0;
+ virtual void remove(const ServiceMapping &mapping) = 0;
+ virtual void update(const ServiceMapping &old_mapping,
+ const ServiceMapping &new_mapping);
+ virtual ~MapListener();
+};
+
+} // namespace slobrok
+
diff --git a/slobrok/src/vespa/slobrok/server/map_source.cpp b/slobrok/src/vespa/slobrok/server/map_source.cpp
new file mode 100644
index 00000000000..6c20835cf31
--- /dev/null
+++ b/slobrok/src/vespa/slobrok/server/map_source.cpp
@@ -0,0 +1,10 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "map_source.h"
+
+namespace slobrok {
+
+MapSource::~MapSource() = default;
+
+} // namespace slobrok
+
diff --git a/slobrok/src/vespa/slobrok/server/map_source.h b/slobrok/src/vespa/slobrok/server/map_source.h
new file mode 100644
index 00000000000..7ba2a0ec4d6
--- /dev/null
+++ b/slobrok/src/vespa/slobrok/server/map_source.h
@@ -0,0 +1,19 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "map_listener.h"
+
+namespace slobrok {
+
+/**
+ * Interface for sources of incremental map updates.
+ **/
+struct MapSource {
+ virtual void registerListener(MapListener &listener) = 0;
+ virtual void unregisterListener(MapListener &listener) = 0;
+ virtual ~MapSource();
+};
+
+} // namespace slobrok
+
diff --git a/slobrok/src/vespa/slobrok/server/proxy_map_source.cpp b/slobrok/src/vespa/slobrok/server/proxy_map_source.cpp
new file mode 100644
index 00000000000..97579a587e3
--- /dev/null
+++ b/slobrok/src/vespa/slobrok/server/proxy_map_source.cpp
@@ -0,0 +1,44 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "proxy_map_source.h"
+#include <vespa/log/log.h>
+
+LOG_SETUP(".slobrok.server.proxy_map_source");
+
+namespace slobrok {
+
+ProxyMapSource::ProxyMapSource() = default;
+
+ProxyMapSource::~ProxyMapSource() = default;
+
+void ProxyMapSource::registerListener(MapListener &listener) {
+ _listeners.insert(&listener);
+}
+
+void ProxyMapSource::unregisterListener(MapListener &listener) {
+ _listeners.erase(&listener);
+}
+
+void ProxyMapSource::add(const ServiceMapping &mapping) {
+ for (auto * listener : _listeners) {
+ listener->add(mapping);
+ }
+}
+
+void ProxyMapSource::remove(const ServiceMapping &mapping) {
+ for (auto * listener : _listeners) {
+ listener->remove(mapping);
+ }
+}
+
+void ProxyMapSource::update(const ServiceMapping &old_mapping,
+ const ServiceMapping &new_mapping)
+{
+ LOG_ASSERT(old_mapping.name == new_mapping.name);
+ for (auto * listener : _listeners) {
+ listener->update(old_mapping, new_mapping);
+ }
+}
+
+} // namespace slobrok
+
diff --git a/slobrok/src/vespa/slobrok/server/proxy_map_source.h b/slobrok/src/vespa/slobrok/server/proxy_map_source.h
new file mode 100644
index 00000000000..517c7150683
--- /dev/null
+++ b/slobrok/src/vespa/slobrok/server/proxy_map_source.h
@@ -0,0 +1,29 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "map_source.h"
+#include <set>
+
+namespace slobrok {
+
+/**
+ * Proof-of-concept implementation of MapSource broadcasting.
+ **/
+class ProxyMapSource : public MapSource, public MapListener {
+ std::set<MapListener *> _listeners;
+public:
+ ProxyMapSource();
+ ~ProxyMapSource();
+
+ void registerListener(MapListener &listener) override;
+ void unregisterListener(MapListener &listener) override;
+
+ void add(const ServiceMapping &mapping) override;
+ void remove(const ServiceMapping &mapping) override;
+ void update(const ServiceMapping &old_mapping,
+ const ServiceMapping &new_mapping) override;
+};
+
+} // namespace slobrok
+