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

#pragma once

#include "lid_gid_key_comparator.h"
#include "i_store.h"
#include <vespa/vespalib/btree/btreeiterator.h>
#include <vespa/searchlib/attribute/attributesaver.h>

namespace proton {

/*
 * Class holding the necessary context for saving a document meta
 * store.  The generation guard in the parent class prevents lids from
 * being reused during the save operation, but timestamp and
 * bucketusedbits can reflect future operations relative to when the
 * document meta store was logically saved.  Thus it is important to
 * replay the same operations at startup.
 */
class DocumentMetaStoreSaver : public search::AttributeSaver
{
public:
    using KeyComp = documentmetastore::LidGidKeyComparator;
    using DocId = documentmetastore::IStore::DocId;
    using GidIterator = vespalib::btree::BTreeConstIterator<
        documentmetastore::GidToLidMapKey,
        vespalib::btree::BTreeNoLeafData,
        vespalib::btree::NoAggregated,
        const KeyComp &>;
    using MetaDataView = vespalib::ConstArrayRef<RawDocumentMetaData>;

private:
    GidIterator _gidIterator; // iterator over frozen tree
    MetaDataView _metaDataView;
    bool _writeDocSize;

    bool onSave(search::IAttributeSaveTarget &saveTarget) override;
public:
    DocumentMetaStoreSaver(vespalib::GenerationHandler::Guard &&guard,
                           const search::attribute::AttributeHeader &header,
                           const GidIterator &gidIterator,
                           MetaDataView metaDataView);

    ~DocumentMetaStoreSaver() override;
};

} // namespace proton