blob: 88d4633afcae7ab7f84edfe01bad87703d91a3ba (
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
68
69
70
71
72
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "attributeguard.h"
#include "iattributemanager.h"
#include "interlock.h"
#include <vespa/searchlib/common/indexmetainfo.h>
#include <vespa/vespalib/stllike/hash_map.h>
#include <mutex>
namespace search::attribute { class Config; }
namespace search {
/**
* You use the attribute manager to get access to attributes. You must specify what kind
* of access you want to have.
**/
class AttributeManager : public IAttributeManager
{
private:
using Config = attribute::Config;
public:
using StringVector = std::vector<string>;
using Snapshot = search::IndexMetaInfo::Snapshot;
using AttributeList = std::vector<AttributeGuard>;
using VectorHolder = std::shared_ptr<AttributeVector>;
AttributeManager();
AttributeManager(const string & base);
~AttributeManager() override;
/**
* This will give you a handle to an attributevector. It
* guarantees that backed attribute is valid. But no guarantees
* about the content of the attribute. If that is required some of
* the other getAttributeXX methods must be used.
**/
const VectorHolder * getAttributeRef(const string & name) const;
AttributeGuard::UP getAttribute(const string & name) const override;
std::unique_ptr<attribute::AttributeReadGuard> getAttributeReadGuard(const string &name, bool stableEnumGuard) const override;
void asyncForAttribute(const vespalib::string &name, std::unique_ptr<attribute::IAttributeFunctor> func) const override;
/**
* This will load attributes in the most memory economical way by loading largest first.
*/
bool addVector(const string & name, const Config & config);
bool add(const VectorHolder & vector);
void getAttributeList(AttributeList & list) const override;
attribute::IAttributeContext::UP createContext() const override;
std::shared_ptr<attribute::ReadableAttributeVector> readable_attribute_vector(const string& name) const override;
const Snapshot & getSnapshot() const { return _snapShot; }
const string & getBaseDir() const { return _baseDir; }
void setBaseDir(const string & base);
uint64_t getMemoryFootprint() const;
protected:
using AttributeMap = vespalib::hash_map<string, VectorHolder>;
AttributeMap _attributes;
mutable std::mutex _loadLock;
private:
const VectorHolder * findAndLoadAttribute(const string & name) const;
string createBaseFileName(const string & name) const;
string _baseDir;
Snapshot _snapShot;
std::shared_ptr<attribute::Interlock> _interlock;
};
}
|