blob: 05ce3ee71a68addba7285d5fe1e26151de137a5f (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "attribute_usage_stats.h"
#include "attribute_usage_filter_config.h"
#include <vespa/searchcore/proton/persistenceengine/i_resource_write_filter.h>
#include <mutex>
#include <atomic>
#include <memory>
namespace proton {
class IAttributeUsageListener;
/**
* Class to filter write operations based on sampled information about
* attribute resource usage (e.g. enum store and multivalue mapping).
* If resource limit is reached then further writes are denied in
* order to prevent entering an unrecoverable state.
*/
class AttributeUsageFilter : public IResourceWriteFilter {
public:
using Mutex = std::mutex;
using Guard = std::lock_guard<Mutex>;
using Config = AttributeUsageFilterConfig;
private:
mutable Mutex _lock; // protect _attributeStats, _config, _state
AttributeUsageStats _attributeStats;
Config _config;
State _state;
std::atomic<bool> _acceptWrite;
std::unique_ptr<IAttributeUsageListener> _listener;
void recalcState(const Guard &guard); // called with _lock held
public:
AttributeUsageFilter();
~AttributeUsageFilter() override;
void setAttributeStats(AttributeUsageStats attributeStats_in);
AttributeUsageStats getAttributeUsageStats() const;
void setConfig(Config config);
void set_listener(std::unique_ptr<IAttributeUsageListener> listener);
bool acceptWriteOperation() const override;
State getAcceptState() const override;
};
} // namespace proton
|