summaryrefslogtreecommitdiffstats
path: root/slobrok
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-05-13 09:02:48 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-05-13 09:02:48 +0000
commit030e6ee88436aa6516cf989211f3270d12314679 (patch)
tree19b7eba82bd5e4eb95861c97b6bf6c4907a9dc64 /slobrok
parentc9f89a485d3dee9ddffb5107b31bf0bae91b18d4 (diff)
GC unused ancient api
Diffstat (limited to 'slobrok')
-rw-r--r--slobrok/CMakeLists.txt1
-rw-r--r--slobrok/src/tests/oldapi/.gitignore4
-rw-r--r--slobrok/src/tests/oldapi/CMakeLists.txt9
-rw-r--r--slobrok/src/tests/oldapi/mirror.cpp173
-rw-r--r--slobrok/src/tests/oldapi/mirror.h126
-rw-r--r--slobrok/src/tests/oldapi/old.cpp221
6 files changed, 0 insertions, 534 deletions
diff --git a/slobrok/CMakeLists.txt b/slobrok/CMakeLists.txt
index 448ea66fbd8..6601dda9304 100644
--- a/slobrok/CMakeLists.txt
+++ b/slobrok/CMakeLists.txt
@@ -20,7 +20,6 @@ vespa_define_module(
src/tests/backoff
src/tests/configure
src/tests/mirrorapi
- src/tests/oldapi
src/tests/registerapi
src/tests/standalone
src/tests/startsome
diff --git a/slobrok/src/tests/oldapi/.gitignore b/slobrok/src/tests/oldapi/.gitignore
deleted file mode 100644
index 9eea175edb0..00000000000
--- a/slobrok/src/tests/oldapi/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-/.depend
-/Makefile
-/oldapi_test
-slobrok_oldapi_test_app
diff --git a/slobrok/src/tests/oldapi/CMakeLists.txt b/slobrok/src/tests/oldapi/CMakeLists.txt
deleted file mode 100644
index e2d127d74af..00000000000
--- a/slobrok/src/tests/oldapi/CMakeLists.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(slobrok_oldapi_test_app TEST
- SOURCES
- old.cpp
- mirror.cpp
- DEPENDS
- slobrok_slobrokserver
-)
-vespa_add_test(NAME slobrok_oldapi_test_app COMMAND slobrok_oldapi_test_app)
diff --git a/slobrok/src/tests/oldapi/mirror.cpp b/slobrok/src/tests/oldapi/mirror.cpp
deleted file mode 100644
index 2004620d57b..00000000000
--- a/slobrok/src/tests/oldapi/mirror.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include "mirror.h"
-#include <vespa/fnet/frt/supervisor.h>
-#include <vespa/fnet/frt/target.h>
-
-#include <vespa/log/log.h>
-LOG_SETUP(".slobrok.mirror");
-
-namespace slobrok::api {
-
-
-MirrorOld::MirrorOld(FRT_Supervisor &orb, const std::vector<std::string> &slobroks)
- : FNET_Task(orb.GetScheduler()),
- _orb(orb),
- _lock(),
- _reqDone(false),
- _specs(),
- _specsGen(),
- _updates(),
- _slobrokspecs(),
- _idx(0),
- _backOff(),
- _target(0),
- _req(0)
-{
- _slobrokspecs = slobroks;
- for (uint32_t i = 0; i < slobroks.size(); ++i) { // randomize order
- uint32_t x = random() % slobroks.size();
- if (x != i) {
- std::swap(_slobrokspecs[i], _slobrokspecs[x]);
- }
- }
- if (_slobrokspecs.size() <= 0) {
- LOG(error, "no service location brokers!");
- }
- ScheduleNow();
-}
-
-
-MirrorOld::~MirrorOld()
-{
- Kill();
- if (_req != 0) {
- _req->Abort();
- _req->SubRef();
- }
- if (_target != 0) {
- _target->SubRef();
- }
-}
-
-
-MirrorOld::SpecList
-MirrorOld::lookup(const std::string & pattern) const
-{
- SpecList ret;
- std::lock_guard<std::mutex> guard(_lock);
- SpecList::const_iterator end = _specs.end();
- for (SpecList::const_iterator it = _specs.begin(); it != end; ++it) {
- if (match(it->first.c_str(), pattern.c_str())) {
- ret.push_back(*it);
- }
- }
- return ret;
-}
-
-
-bool
-IMirrorOld::match(const char *name, const char *pattern)
-{
- LOG_ASSERT(name != NULL);
- LOG_ASSERT(pattern != NULL);
- while (*pattern != '\0') {
- if (*name == *pattern) {
- ++name;
- ++pattern;
- } else if (*pattern == '*') {
- ++pattern;
- while (*name != '/' && *name != '\0') {
- ++name;
- }
- } else {
- return false;
- }
- }
- return (*name == *pattern);
-}
-
-
-void
-MirrorOld::PerformTask()
-{
- if (_reqDone) {
- _reqDone = false;
- if (_req->IsError()
- || strcmp(_req->GetReturnSpec(), "SSi") != 0
- || (_req->GetReturn()->GetValue(0)._string_array._len !=
- _req->GetReturn()->GetValue(1)._string_array._len))
- {
- if (_target != 0) {
- _target->SubRef();
- }
- _target = 0;
- ScheduleNow(); // try next slobrok
- return;
- }
-
- FRT_Values &answer = *(_req->GetReturn());
-
- if (_specsGen != answer[2]._intval32) {
- SpecList specs;
- uint32_t numNames = answer[0]._string_array._len;
- FRT_StringValue *n = answer[0]._string_array._pt;
- FRT_StringValue *s = answer[1]._string_array._pt;
-
- for (uint32_t idx = 0; idx < numNames; idx++) {
- specs.push_back(std::make_pair(std::string(n[idx]._str),
- std::string(s[idx]._str)));
- }
-
- {
- std::lock_guard<std::mutex> guard(_lock);
- std::swap(specs, _specs);
- _updates.add();
- }
- _specsGen.setFromInt(answer[2]._intval32);
- }
- _backOff.reset();
- Schedule(0.1); // be nice
- return;
- }
- if (_target == 0) {
- if (_idx >= _slobrokspecs.size()) {
- _idx = 0;
- double delay = _backOff.get();
- Schedule(delay);
- if (_slobrokspecs.size() < 1) {
- // we already logged an error for this
- return;
- }
- if (_backOff.shouldWarn()) {
- std::string cps = _slobrokspecs[0];
- for (size_t ss = 1; ss < _slobrokspecs.size(); ++ss) {
- cps += " or at ";
- cps += _slobrokspecs[ss];
- }
- LOG(warning, "cannot connect to location broker at %s "
- "(retry in %f seconds)", cps.c_str(), delay);
- }
- return;
- }
- _target = _orb.GetTarget(_slobrokspecs[_idx++].c_str());
- LOG_ASSERT(_target != 0); // just in case (tm)
- _specsGen.reset();
- }
- _req = _orb.AllocRPCRequest(_req);
- _req->SetMethodName("slobrok.mirror.fetch");
- _req->GetParams()->AddInt32(_specsGen.getAsInt()); // gencnt
- _req->GetParams()->AddInt32(5000); // mstimeout
- _target->InvokeAsync(_req, 40.0, this);
-}
-
-
-void
-MirrorOld::RequestDone(FRT_RPCRequest *req)
-{
- LOG_ASSERT(req == _req && !_reqDone);
- (void) req;
- _reqDone = true;
- ScheduleNow();
-}
-
-} // namespace slobrok::api
diff --git a/slobrok/src/tests/oldapi/mirror.h b/slobrok/src/tests/oldapi/mirror.h
deleted file mode 100644
index fb150b5d64f..00000000000
--- a/slobrok/src/tests/oldapi/mirror.h
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include <vespa/vespalib/util/gencnt.h>
-#include <vespa/slobrok/backoff.h>
-#include <vespa/fnet/frt/invoker.h>
-
-class FRT_Target;
-
-namespace slobrok::api {
-
-/**
- * @brief Defines an interface for the name server lookup.
- **/
-class IMirrorOld {
-protected:
- static bool match(const char *name, const char *pattern);
-
-public:
- /**
- * @brief Release any allocated resources.
- **/
- virtual ~IMirrorOld() { }
-
- /**
- * @brief vector of <name, connectionspec> pairs.
- *
- * The first element of each pair is a string containing the
- * service name. The second is the connection spec, typically
- * "tcp/foo.bar.com:42"
- **/
- typedef std::vector< std::pair<std::string, std::string> > SpecList;
-
- /**
- * Obtain all the services matching a given pattern.
- *
- * The pattern is matched against all service names in the local
- * mirror repository. A service name may contain '/' as a
- * separator token. A pattern may contain '*' to match anything up
- * to the next '/' (or the end of the name). This means that the
- * pattern 'foo/<!-- slash-star -->*<!-- star-slash -->/baz' would
- * match the service names 'foo/bar/baz' and 'foo/xyz/baz'. The
- * pattern 'foo/b*' would match 'foo/bar', but neither 'foo/xyz'
- * nor 'foo/bar/baz'. The pattern 'a*b' will never match anything.
- *
- * @return a list of all matching services, with corresponding connect specs
- * @param pattern The pattern used for matching
- **/
- virtual SpecList lookup(const std::string & pattern) const = 0;
-
- /**
- * Obtain the number of updates seen by this mirror. The value may
- * wrap, but will never become 0 again. This can be used for name
- * lookup optimization, because the results returned by lookup()
- * will never change unless this number also changes.
- *
- * @return number of slobrok updates seen
- **/
- virtual uint32_t updates() const = 0;
-};
-
-/**
- * @brief A MirrorOld object is used to keep track of the services
- * registered with a slobrok cluster.
- *
- * Updates to the service repository are fetched in the
- * background. Lookups against this object is done using an internal
- * mirror of the service repository.
- **/
-class MirrorOld : public FNET_Task,
- public FRT_IRequestWait,
- public IMirrorOld
-{
-public:
- /**
- * @brief Create a new MirrorOld using the given Supervisor and slobrok
- * connect specs.
- *
- * @param orb the Supervisor to use
- * @param slobroks slobrok connect spec list
- **/
- MirrorOld(FRT_Supervisor &orb, const std::vector<std::string> &slobroks);
-
- /**
- * @brief Clean up.
- **/
- ~MirrorOld();
-
- SpecList lookup(const std::string & pattern) const override;
- uint32_t updates() const override { return _updates.getAsInt(); }
-
- /**
- * @brief Ask if the MirrorOld has got any useful information from
- * the Slobrok
- *
- * On application startup it is often useful to run the event loop
- * for some time until this functions returns true (or if it never
- * does, time out and tell the user there was no answer from any
- * Service Location Broker).
- *
- * @return true if the MirrorOld object has
- * asked for updates from a Slobrok and got any answer back
- **/
- bool ready() const { return _updates.getAsInt() != 0; }
-
-private:
- MirrorOld(const MirrorOld &);
- MirrorOld &operator=(const MirrorOld &);
-
- void PerformTask() override;
- void RequestDone(FRT_RPCRequest *req) override;
-
- FRT_Supervisor &_orb;
- mutable std::mutex _lock;
- bool _reqDone;
- SpecList _specs;
- vespalib::GenCnt _specsGen;
- vespalib::GenCnt _updates;
- std::vector<std::string> _slobrokspecs;
- uint32_t _idx;
- BackOff _backOff;
- FRT_Target *_target;
- FRT_RPCRequest *_req;
-};
-
-} // namespace slobrok::api
diff --git a/slobrok/src/tests/oldapi/old.cpp b/slobrok/src/tests/oldapi/old.cpp
deleted file mode 100644
index fc380acfb9d..00000000000
--- a/slobrok/src/tests/oldapi/old.cpp
+++ /dev/null
@@ -1,221 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
-#include "mirror.h"
-#include <vespa/config-slobroks.h>
-#include <vespa/slobrok/server/slobrokserver.h>
-#include <vespa/fnet/frt/supervisor.h>
-#include <vespa/fnet/frt/target.h>
-#include <vespa/fnet/transport.h>
-
-#include <vespa/log/log.h>
-LOG_SETUP("mirrorapi_test");
-
-using slobrok::api::MirrorOld;
-using slobrok::SlobrokServer;
-
-TEST_SETUP(Test);
-
-//-----------------------------------------------------------------------------
-
-class Server : public FRT_Invokable
-{
-private:
- fnet::frt::StandaloneFRT _server;
- std::string _name;
- std::string _slobrokSpec;
-
-public:
- Server(std::string name, int port, std::string slobrokSpec);
- ~Server();
- void rpc_listNamesServed(FRT_RPCRequest *req);
- void reg();
-};
-
-
-Server::Server(std::string name, int port, std::string slobrokSpec)
- : _server(),
- _name(name),
- _slobrokSpec(slobrokSpec)
-{
- {
- FRT_ReflectionBuilder rb(&_server.supervisor());
- //---------------------------------------------------------------------
- rb.DefineMethod("slobrok.callback.listNamesServed", "", "S",
- FRT_METHOD(Server::rpc_listNamesServed), this);
- rb.MethodDesc("Look up a rpcserver");
- rb.ReturnDesc("names", "The rpcserver names on this server");
- //---------------------------------------------------------------------
- }
- _server.supervisor().Listen(port);
-}
-
-
-void
-Server::reg()
-{
- char spec[64];
- sprintf(spec, "tcp/localhost:%d", _server.supervisor().GetListenPort());
-
- FRT_RPCRequest *req = _server.supervisor().AllocRPCRequest();
- req->SetMethodName("slobrok.registerRpcServer");
- req->GetParams()->AddString(_name.c_str());
- req->GetParams()->AddString(spec);
-
- FRT_Target *sb = _server.supervisor().GetTarget(_slobrokSpec.c_str());
- sb->InvokeSync(req, 5.0);
- sb->SubRef();
- req->SubRef();
-}
-
-
-void
-Server::rpc_listNamesServed(FRT_RPCRequest *req)
-{
- FRT_Values &dst = *req->GetReturn();
- FRT_StringValue *names = dst.AddStringArray(1);
- dst.SetString(&names[0], _name.c_str());
-}
-
-
-Server::~Server() = default;
-
-//-----------------------------------------------------------------------------
-
-struct SpecList
-{
- MirrorOld::SpecList _specList;
- SpecList() : _specList() {}
- SpecList(MirrorOld::SpecList input) : _specList(input) {}
- SpecList &add(const char *name, const char *spec) {
- _specList.push_back(make_pair(std::string(name),
- std::string(spec)));
- return *this;
- }
- void sort() {
- std::sort(_specList.begin(), _specList.end());
- }
- bool operator==(SpecList &rhs) { // NB: MUTATE!
- sort();
- rhs.sort();
- return _specList == rhs._specList;
- }
-};
-
-
-bool
-compare(MirrorOld &api, const char *pattern, SpecList expect)
-{
- for (int i = 0; i < 250; ++i) {
- SpecList actual(api.lookup(pattern));
- if (actual == expect) {
- return true;
- }
- FastOS_Thread::Sleep(100);
- }
- return false;
-}
-
-
-int
-Test::Main()
-{
- TEST_INIT("mirrorapi_test");
-
- SlobrokServer mock(18531);
- FastOS_Thread::Sleep(300);
-
- Server a("A/x/w", 18532, "tcp/localhost:18531");
- Server b("B/x", 18533, "tcp/localhost:18531");
- Server c("C/x/z", 18534, "tcp/localhost:18531");
- Server d("D/y/z", 18535, "tcp/localhost:18531");
- Server e("E/y", 18536, "tcp/localhost:18531");
- Server f("F/y/w", 18537, "tcp/localhost:18531");
-
- std::vector<std::string> slobrokSpecs;
- slobrokSpecs.push_back("tcp/localhost:18531");
- FastOS_ThreadPool threadPool(0x10000);
- FNET_Transport transport;
- FRT_Supervisor supervisor(&transport);
- MirrorOld mirror(supervisor, slobrokSpecs);
- EXPECT_TRUE(!mirror.ready());
- transport.Start(&threadPool);
- FastOS_Thread::Sleep(1000);
-
- a.reg();
- EXPECT_TRUE(compare(mirror, "A/x/w", SpecList().add("A/x/w", "tcp/localhost:18532")));
- EXPECT_TRUE(compare(mirror, "*/*", SpecList()));
- EXPECT_TRUE(compare(mirror, "*/*/*", SpecList().add("A/x/w", "tcp/localhost:18532")));
- EXPECT_TRUE(mirror.ready());
-
- TEST_FLUSH();
- b.reg();
- EXPECT_TRUE(compare(mirror, "B/x", SpecList().add("B/x", "tcp/localhost:18533")));
- EXPECT_TRUE(compare(mirror, "*/*", SpecList().add("B/x", "tcp/localhost:18533")));
- EXPECT_TRUE(compare(mirror, "*/*/*", SpecList().add("A/x/w", "tcp/localhost:18532")));
-
- TEST_FLUSH();
- c.reg();
- EXPECT_TRUE(compare(mirror, "C/x/z", SpecList().add("C/x/z", "tcp/localhost:18534")));
- EXPECT_TRUE(compare(mirror, "*/*", SpecList().add("B/x", "tcp/localhost:18533")));
- EXPECT_TRUE(compare(mirror, "*/*/*", SpecList()
- .add("A/x/w", "tcp/localhost:18532")
- .add("C/x/z", "tcp/localhost:18534")));
-
- TEST_FLUSH();
- d.reg();
- EXPECT_TRUE(compare(mirror, "D/y/z", SpecList().add("D/y/z", "tcp/localhost:18535")));
- EXPECT_TRUE(compare(mirror, "*/*", SpecList().add("B/x", "tcp/localhost:18533")));
- EXPECT_TRUE(compare(mirror, "*/*/*", SpecList()
- .add("A/x/w", "tcp/localhost:18532")
- .add("C/x/z", "tcp/localhost:18534")
- .add("D/y/z", "tcp/localhost:18535")));
-
- TEST_FLUSH();
- e.reg();
- EXPECT_TRUE(compare(mirror, "E/y", SpecList().add("E/y", "tcp/localhost:18536")));
- EXPECT_TRUE(compare(mirror, "*/*", SpecList()
- .add("B/x", "tcp/localhost:18533")
- .add("E/y", "tcp/localhost:18536")));
- EXPECT_TRUE(compare(mirror, "*/*/*", SpecList()
- .add("A/x/w", "tcp/localhost:18532")
- .add("C/x/z", "tcp/localhost:18534")
- .add("D/y/z", "tcp/localhost:18535")));
-
- TEST_FLUSH();
- f.reg();
- EXPECT_TRUE(compare(mirror, "F/y/w", SpecList().add("F/y/w", "tcp/localhost:18537")));
- EXPECT_TRUE(compare(mirror, "*/*", SpecList()
- .add("B/x", "tcp/localhost:18533")
- .add("E/y", "tcp/localhost:18536")));
- EXPECT_TRUE(compare(mirror, "*/*/*", SpecList()
- .add("A/x/w", "tcp/localhost:18532")
- .add("C/x/z", "tcp/localhost:18534")
- .add("D/y/z", "tcp/localhost:18535")
- .add("F/y/w", "tcp/localhost:18537")));
-
-
- EXPECT_TRUE(compare(mirror, "*", SpecList()));
-
- EXPECT_TRUE(compare(mirror, "B/*", SpecList()
- .add("B/x", "tcp/localhost:18533")));
-
- EXPECT_TRUE(compare(mirror, "*/y", SpecList()
- .add("E/y", "tcp/localhost:18536")));
-
- EXPECT_TRUE(compare(mirror, "*/x/*", SpecList()
- .add("A/x/w", "tcp/localhost:18532")
- .add("C/x/z", "tcp/localhost:18534")));
-
- EXPECT_TRUE(compare(mirror, "*/*/z", SpecList()
- .add("C/x/z", "tcp/localhost:18534")
- .add("D/y/z", "tcp/localhost:18535")));
-
- EXPECT_TRUE(compare(mirror, "A/*/z", SpecList()));
-
- EXPECT_TRUE(compare(mirror, "A/*/w", SpecList()
- .add("A/x/w", "tcp/localhost:18532")));
-
- mock.stop();
- transport.ShutDown(true);
- TEST_DONE();
-}