aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastorecontext.h
blob: daebd05ada1105138c05df6eb1a7e23ec69bc3fc (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "i_document_meta_store_context.h"
#include <vespa/searchcommon/common/growstrategy.h>

namespace proton {

class DocumentMetaStore;

/**
 * Class providing write and read interface to the document meta store.
 */
class DocumentMetaStoreContext : public IDocumentMetaStoreContext
{
public:
    class ReadGuard : public IDocumentMetaStoreContext::IReadGuard
    {
    private:
        search::AttributeGuard   _guard;
        const DocumentMetaStore &_store;
    public:
        explicit ReadGuard(const std::shared_ptr<search::AttributeVector> &metaStoreAttr);
        const search::IDocumentMetaStore &get() const override;
    };
private:
    std::shared_ptr<search::AttributeVector>  _metaStoreAttr;
    std::shared_ptr<IDocumentMetaStore>       _metaStore;
public:

    explicit DocumentMetaStoreContext(std::shared_ptr<bucketdb::BucketDBOwner> bucketDB);
    /**
     * Create a new context instantiating a document meta store
     * with the given name, grow strategy, and comparator.
     */
    DocumentMetaStoreContext(std::shared_ptr<bucketdb::BucketDBOwner> bucketDB,
                             const vespalib::string &name,
                             const search::GrowStrategy &grow);
    ~DocumentMetaStoreContext() override;
    /**
     * Create a new context with the given document meta store encapsulated
     * as an attribute vector.
     */
    explicit DocumentMetaStoreContext(std::shared_ptr<search::AttributeVector> metaStoreAttr);

    std::shared_ptr<proton::IDocumentMetaStore>   getSP() const override { return _metaStore; }
    proton::IDocumentMetaStore &       get()       override { return *_metaStore; }
    IReadGuard::SP getReadGuard() const override {
        return std::make_shared<ReadGuard>(_metaStoreAttr);
    }

    void constructFreeList() override;
};

} // namespace proton