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

#include "bucket_db_explorer.h"
#include <vespa/vespalib/data/slime/cursor.h>
#include <vespa/vespalib/stllike/asciistream.h>

using document::BucketId;
using vespalib::slime::Cursor;
using vespalib::slime::Inserter;

namespace proton {

namespace {

vespalib::string
bucketIdToString(const BucketId &bucketId)
{
    vespalib::asciistream stream;
    stream << "0x" << vespalib::hex << vespalib::setw(sizeof(BucketId::Type)*2)
           << vespalib::setfill('0') << bucketId.getId();
    return stream.str();
}

vespalib::string
checksumToString(storage::spi::BucketChecksum checksum)
{
    vespalib::asciistream stream;
    stream << "0x" << vespalib::hex << checksum;
    return stream.str();
}

void
convertBucketsToSlime(const BucketDB &bucketDb, Cursor &array)
{
    BucketId::List buckets = bucketDb.getBuckets();
    for (BucketId bucketId : buckets) {
        Cursor &object = array.addObject();
        object.setString("id", bucketIdToString(bucketId));
        bucketdb::BucketState state = bucketDb.get(bucketId);
        object.setString("checksum", checksumToString(state.getChecksum()));
        object.setLong("readyCount", state.getReadyCount());
        object.setLong("notReadyCount", state.getNotReadyCount());
        object.setLong("removedCount", state.getRemovedCount());
        object.setLong("readyDocSizes", state.getReadyDocSizes());
        object.setLong("notReadyDocSizes", state.getNotReadyDocSizes());
        object.setLong("removedDocSizes", state.getRemovedDocSizes());
        object.setBool("active", state.isActive());
    }
}

}

BucketDBExplorer::BucketDBExplorer(bucketdb::Guard bucketDb)
    : _bucketDb(std::move(bucketDb))
{
}

BucketDBExplorer::~BucketDBExplorer() = default;

void
BucketDBExplorer::get_state(const Inserter &inserter, bool full) const
{
    Cursor &object = inserter.insertObject();
    if (full) {
        object.setLong("numBuckets", _bucketDb->size());
        convertBucketsToSlime(*_bucketDb, object.setArray("buckets"));
    } else {
        object.setLong("numBuckets", _bucketDb->size());
    }
}

} // namespace proton