aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.h
blob: c310aeb2a2b03874956b676ac307cf80fdc22147 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "fast_access_doc_subdb.h"
#include "searchable_doc_subdb_configurer.h"
#include "searchable_feed_view.h"
#include "searchview.h"
#include "summaryadapter.h"
#include <vespa/eval/eval/value_cache/constant_tensor_loader.h>
#include <vespa/eval/eval/value_cache/constant_value_cache.h>
#include <vespa/searchcore/proton/attribute/attributemanager.h>
#include <vespa/searchcore/proton/common/doctypename.h>
#include <vespa/searchcore/proton/docsummary/summarymanager.h>
#include <vespa/searchcore/proton/documentmetastore/documentmetastorecontext.h>
#include <vespa/searchcore/proton/index/i_index_writer.h>
#include <vespa/searchcore/proton/index/indexmanager.h>
#include <vespa/searchcore/proton/matching/constant_value_repo.h>
#include <vespa/searchcorespi/index/iindexmanager.h>
#include <vespa/vespalib/util/blockingthreadstackexecutor.h>
#include <vespa/vespalib/util/varholder.h>

namespace proton {

class DocumentDBConfig;
struct IDocumentDBReferenceResolver;
struct MetricsWireService;
class GidToLidChangeHandler;

/**
 * The searchable sub database supports searching and keeps all attribute fields in memory and
 * inserts all index fields into the memory index in addition to storing documents in the
 * underlying document store.
 *
 * This class is used directly by the "0.ready" sub database for handling all ready documents.
 */
class
SearchableDocSubDB : public FastAccessDocSubDB,
                     public searchcorespi::IIndexManager::Reconfigurer

{
public:
    struct Config {
        const FastAccessDocSubDB::Config _fastUpdCfg;
        const size_t _numSearcherThreads;

        Config(const FastAccessDocSubDB::Config &fastUpdCfg, size_t numSearcherThreads)
            : _fastUpdCfg(fastUpdCfg),
              _numSearcherThreads(numSearcherThreads)
        { }
    };

    struct Context {
        const FastAccessDocSubDB::Context  _fastUpdCtx;
        matching::QueryLimiter            &_queryLimiter;
        const vespalib::Clock             &_clock;
        vespalib::SyncableThreadExecutor  &_warmupExecutor;

        Context(const FastAccessDocSubDB::Context &fastUpdCtx,
                matching::QueryLimiter &queryLimiter,
                const vespalib::Clock &clock,
                vespalib::SyncableThreadExecutor &warmupExecutor)
            : _fastUpdCtx(fastUpdCtx),
              _queryLimiter(queryLimiter),
              _clock(clock),
              _warmupExecutor(warmupExecutor)
        { }
    };

private:
    typedef FastAccessDocSubDB Parent;
    using IFlushTargetList = std::vector<std::shared_ptr<searchcorespi::IFlushTarget>>;

    searchcorespi::IIndexManager::SP            _indexMgr;
    IIndexWriter::SP                            _indexWriter;
    vespalib::VarHolder<SearchView::SP>         _rSearchView;
    vespalib::VarHolder<SearchableFeedView::SP> _rFeedView;
    vespalib::eval::ConstantTensorLoader        _tensorLoader;
    vespalib::eval::ConstantValueCache          _constantValueCache;
    matching::ConstantValueRepo                 _constantValueRepo;
    SearchableDocSubDBConfigurer                _configurer;
    vespalib::SyncableThreadExecutor           &_warmupExecutor;
    std::shared_ptr<GidToLidChangeHandler>      _realGidToLidChangeHandler;
    DocumentDBFlushConfig                       _flushConfig;
    bool                                        _nodeRetired;

    // Note: lifetime of indexManager must be handled by caller.
    std::shared_ptr<initializer::InitializerTask>
    createIndexManagerInitializer(const DocumentDBConfig &configSnapshot, SerialNum configSerialNum,
                                  const IndexConfig &indexCfg,
                                  std::shared_ptr<searchcorespi::IIndexManager::SP> indexManager) const;

    void setupIndexManager(searchcorespi::IIndexManager::SP indexManager);
    void initFeedView(IAttributeWriter::SP attrWriter, const DocumentDBConfig &configSnapshot);
    void reconfigureMatchingMetrics(const vespa::config::search::RankProfilesConfig &config);

    bool reconfigure(std::unique_ptr<Configure> configure) override;
    void reconfigureIndexSearchable();
    void syncViews();
    void applyFlushConfig(const DocumentDBFlushConfig &flushConfig);
    void propagateFlushConfig();
protected:
    IFlushTargetList getFlushTargetsInternal() override;
public:
    SearchableDocSubDB(const Config &cfg, const Context &ctx);
    ~SearchableDocSubDB() override;

    std::unique_ptr<DocumentSubDbInitializer>
    createInitializer(const DocumentDBConfig &configSnapshot, SerialNum configSerialNum,
                      const IndexConfig &indexCfg) const override;

    void setup(const DocumentSubDbInitializerResult &initResult) override;
    void initViews(const DocumentDBConfig &configSnapshot, const SessionManagerSP &sessionManager)  override;

    IReprocessingTask::List
    applyConfig(const DocumentDBConfig &newConfigSnapshot, const DocumentDBConfig &oldConfigSnapshot,
                SerialNum serialNum, const ReconfigParams &params, IDocumentDBReferenceResolver &resolver) override;
    void setBucketStateCalculator(const std::shared_ptr<IBucketStateCalculator> &calc) override;

    void clearViews() override;

    proton::IAttributeManager::SP getAttributeManager() const override {
        return _rSearchView.get()->getAttributeManager();
    }

    const searchcorespi::IIndexManager::SP &getIndexManager() const override {
        return _indexMgr;
    }

    const IIndexWriter::SP &getIndexWriter() const override {
        return _indexWriter;
    }

    SerialNum getOldestFlushedSerial() override;
    SerialNum getNewestFlushedSerial() override;
    void setIndexSchema(const Schema::SP &schema, SerialNum serialNum) override;
    size_t getNumActiveDocs() const override;
    search::SearchableStats getSearchableStats() const override ;
    IDocumentRetriever::UP getDocumentRetriever() override;
    matching::MatchingStats getMatcherStats(const vespalib::string &rankProfile) const override;
    void close() override;
    std::shared_ptr<IDocumentDBReference> getDocumentDBReference() override;
    void tearDownReferences(IDocumentDBReferenceResolver &resolver) override;
};

} // namespace proton