aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/attribute/attributedisklayout.h
blob: 2654ae3b5dc2f6b680d609a46cf7511db02f28ac (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/common/serialnum.h>
#include <vespa/vespalib/stllike/string.h>
#include <mutex>
#include <shared_mutex>
#include <map>
#include <vector>
#include <memory>

namespace proton {

class AttributeDirectory;
/**
 * Class with utility functions for handling the disk directory layout for attribute vectors.
 */
class AttributeDiskLayout : public std::enable_shared_from_this<AttributeDiskLayout>
{
private:
    const vespalib::string _baseDir;
    mutable std::shared_mutex _mutex;
    std::map<vespalib::string, std::shared_ptr<AttributeDirectory>> _dirs;

    void scanDir();
    struct PrivateConstructorTag { };
public:
    explicit AttributeDiskLayout(const vespalib::string &baseDir, PrivateConstructorTag tag);
    ~AttributeDiskLayout();
    std::vector<vespalib::string> listAttributes();
    const vespalib::string &getBaseDir() const { return _baseDir; }
    std::shared_ptr<AttributeDirectory> getAttributeDir(const vespalib::string &name);
    std::shared_ptr<AttributeDirectory> createAttributeDir(const vespalib::string &name);
    void removeAttributeDir(const vespalib::string &name, search::SerialNum serialNum);
    static std::shared_ptr<AttributeDiskLayout> create(const vespalib::string &baseDir);
    static std::shared_ptr<AttributeDiskLayout> createSimple(const vespalib::string &baseDir);
};

} // namespace proton