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

#include "document_subdb_explorer.h"
#include <vespa/searchcore/proton/attribute/attribute_manager_explorer.h>
#include <vespa/searchcore/proton/attribute/attribute_writer_explorer.h>
#include <vespa/searchcore/proton/docsummary/document_store_explorer.h>
#include <vespa/searchcore/proton/documentmetastore/document_meta_store_explorer.h>
#include <vespa/searchcorespi/index/index_manager_explorer.h>

using searchcorespi::IndexManagerExplorer;
using vespalib::slime::Inserter;
using vespalib::StateExplorer;

namespace proton {

namespace {

const vespalib::string DOCUMENT_META_STORE = "documentmetastore";
const vespalib::string DOCUMENT_STORE = "documentstore";
const vespalib::string ATTRIBUTE = "attribute";
const vespalib::string ATTRIBUTE_WRITER = "attributewriter";
const vespalib::string INDEX = "index";

}

DocumentSubDBExplorer::DocumentSubDBExplorer(const IDocumentSubDB &subDb)
    : _subDb(subDb)
{
}

void
DocumentSubDBExplorer::get_state(const Inserter &inserter, bool full) const
{
    (void) full;
    inserter.insertObject();
}

std::vector<vespalib::string>
DocumentSubDBExplorer::get_children_names() const
{
    std::vector<vespalib::string> children = {DOCUMENT_META_STORE, DOCUMENT_STORE};
    if (_subDb.getAttributeManager()) {
        children.push_back(ATTRIBUTE);
    }
    if (_subDb.get_attribute_writer()) {
        children.push_back(ATTRIBUTE_WRITER);
    }
    if (_subDb.getIndexManager()) {
        children.push_back(INDEX);
    }
    return children;
}

std::unique_ptr<StateExplorer>
DocumentSubDBExplorer::get_child(vespalib::stringref name) const
{
    if (name == DOCUMENT_META_STORE) {
        // TODO(geirst): Avoid const cast by adding const interface to
        // IDocumentMetaStoreContext as seen from IDocumentSubDB.
        return std::make_unique<DocumentMetaStoreExplorer>(
                (const_cast<IDocumentSubDB &>(_subDb)).getDocumentMetaStoreContext().getReadGuard());
    } else if (name == DOCUMENT_STORE) {
        return std::make_unique<DocumentStoreExplorer>(_subDb.getSummaryManager());
    } else if (name == ATTRIBUTE) {
        auto attrMgr = _subDb.getAttributeManager();
        if (attrMgr) {
            return std::make_unique<AttributeManagerExplorer>(attrMgr);
        }
    } else if (name == ATTRIBUTE_WRITER) {
        auto writer = _subDb.get_attribute_writer();
        if (writer) {
            return std::make_unique<AttributeWriterExplorer>(std::move(writer));
        }
    } else if (name == INDEX) {
        auto idxMgr = _subDb.getIndexManager();
        if (idxMgr) {
            return std::make_unique<IndexManagerExplorer>(std::move(idxMgr));
        }
    }
    return {};
}

}