blob: 182b35a0e987d092805c84abbaed6356155c6fb1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "externslobrokpolicy.h"
#include <vespa/documentapi/messagebus/messages/wrongdistributionreply.h>
#include <vespa/vdslib/distribution/distribution.h>
#include <vespa/document/bucket/bucketidfactory.h>
#include <vespa/messagebus/routing/hop.h>
#include <mutex>
namespace config {
class ICallback;
class ConfigFetcher;
}
namespace storage::lib {
class Distribution;
class ClusterState;
}
namespace documentapi {
class ContentPolicy : public ExternSlobrokPolicy
{
private:
document::BucketIdFactory _bucketIdFactory;
mutable std::mutex _lock;
std::shared_ptr<const storage::lib::ClusterState> _state;
string _clusterName;
string _clusterConfigId;
std::unique_ptr<config::ICallback> _callBack;
std::unique_ptr<config::ConfigFetcher> _configFetcher;
std::shared_ptr<const storage::lib::Distribution> _distribution;
using StateSnapshot = std::pair<std::shared_ptr<const storage::lib::ClusterState>,
std::shared_ptr<const storage::lib::Distribution>>;
// Acquires _lock
[[nodiscard]] StateSnapshot internal_state_snapshot();
mbus::Hop getRecipient(mbus::RoutingContext& context, int distributor);
// Acquires _lock
void updateStateFromReply(WrongDistributionReply& reply);
// Acquires _lock
void reset_state();
public:
explicit ContentPolicy(const string& param);
~ContentPolicy() override;
void doSelect(mbus::RoutingContext &context) override;
void merge(mbus::RoutingContext &context) override;
/**
* @return a pointer to the system state registered with this policy. If
* we haven't received a system state yet, returns nullptr.
*/
std::shared_ptr<const storage::lib::ClusterState> getSystemState() const noexcept;
virtual void configure(std::unique_ptr<storage::lib::Distribution::DistributionConfig> config);
string init() override;
private:
static string createConfigId(const string & clusterName);
static string createPattern(const string & clusterName, int distributor);
};
}
|