aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageapi/buckets/bucketinfo.cpp
blob: 8305b999afcc2fc0aaf4f578e3459f91f85549b2 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "bucketinfo.h"
#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/vespalib/util/xmlstream.h>

namespace storage::api {

static_assert(sizeof(BucketInfo) == 32, "BucketInfo should be 32 bytes");

BucketInfo::BucketInfo() noexcept
    : _lastModified(0),
      _checksum(0),
      _docCount(0),
      _totDocSize(1),
      _metaCount(0),
      _usedFileSize(1),
      _ready(false),
      _active(false)
{}

BucketInfo::BucketInfo(uint32_t checksum, uint32_t docCount, uint32_t totDocSize) noexcept
    : _lastModified(0),
      _checksum(checksum),
      _docCount(docCount),
      _totDocSize(totDocSize),
      _metaCount(docCount),
      _usedFileSize(totDocSize),
      _ready(false),
      _active(false)
{}

BucketInfo::BucketInfo(uint32_t checksum, uint32_t docCount,
                       uint32_t totDocSize, uint32_t metaCount,
                       uint32_t usedFileSize) noexcept
    : _lastModified(0),
      _checksum(checksum),
      _docCount(docCount),
      _totDocSize(totDocSize),
      _metaCount(metaCount),
      _usedFileSize(usedFileSize),
      _ready(false),
      _active(false)
{}

BucketInfo::BucketInfo(uint32_t checksum, uint32_t docCount,
                       uint32_t totDocSize, uint32_t metaCount,
                       uint32_t usedFileSize,
                       bool ready, bool active) noexcept
    : _lastModified(0),
      _checksum(checksum),
      _docCount(docCount),
      _totDocSize(totDocSize),
      _metaCount(metaCount),
      _usedFileSize(usedFileSize),
      _ready(ready),
      _active(active)
{}

BucketInfo::BucketInfo(uint32_t checksum, uint32_t docCount,
                       uint32_t totDocSize, uint32_t metaCount,
                       uint32_t usedFileSize,
                       bool ready, bool active, Timestamp lastModified) noexcept
    : _lastModified(lastModified),
      _checksum(checksum),
      _docCount(docCount),
      _totDocSize(totDocSize),
      _metaCount(metaCount),
      _usedFileSize(usedFileSize),
      _ready(ready),
      _active(active)
{}

bool
BucketInfo::operator==(const BucketInfo& info) const noexcept
{
    return (_checksum == info._checksum &&
            _docCount == info._docCount &&
            _totDocSize == info._totDocSize &&
            _metaCount == info._metaCount &&
            _usedFileSize == info._usedFileSize &&
            _ready == info._ready &&
            _active == info._active);
}

// TODO: add ready/active to printing
vespalib::string
BucketInfo::toString() const
{
    vespalib::asciistream out;
    out << "BucketInfo(";
    if (valid()) {
        out << "crc 0x" << vespalib::hex << _checksum << vespalib::dec
            << ", docCount " << _docCount
            << ", totDocSize " << _totDocSize;
        if (_totDocSize != _usedFileSize) {
            out << ", metaCount " << _metaCount
                << ", usedFileSize " << _usedFileSize;
        }
        out << ", ready " << (_ready ? "true" : "false")
            << ", active " << (_active ? "true" : "false");

        if (_lastModified != 0) {
            out << ", last modified " << _lastModified;
        }
    } else {
        out << "invalid";
    }
    out << ")";
    return out.str();
}

void
BucketInfo::printXml(vespalib::xml::XmlOutputStream& xos) const
{
    using namespace vespalib::xml;
    xos << XmlAttribute("checksum", _checksum, XmlAttribute::HEX)
        << XmlAttribute("docs", _docCount)
        << XmlAttribute("size", _totDocSize)
        << XmlAttribute("metacount", _metaCount)
        << XmlAttribute("usedfilesize", _usedFileSize)
        << XmlAttribute("ready", _ready)
        << XmlAttribute("active", _active)
        << XmlAttribute("lastmodified", _lastModified);
}

std::ostream &
operator << (std::ostream & os, const BucketInfo & bucketInfo) {
    return os << bucketInfo.toString();
}

}