aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageapi/buckets/bucketinfo.h
blob: 4b7847ef9619a677c2415f6256e0f5863f21dac7 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * @class BucketInfo
 * @ingroup bucket
 *
 * @brief Contains metadata about a bucket.
 *
 * This class contains metadata about a bucket. It is used to send metadata
 * within storage nodes and to distributors.
 *
 * @version $Id$
 */

#pragma once

#include <vespa/storageapi/defs.h>
#include <vespa/vespalib/stllike/string.h>

namespace vespalib::xml { class XmlOutputStream; }
namespace storage::api {

class BucketInfo
{
    Timestamp _lastModified;
    uint32_t  _checksum;
    uint32_t  _docCount;
    uint32_t  _totDocSize;
    uint32_t  _metaCount;
    uint32_t  _usedFileSize;
    bool      _ready;
    bool      _active;

public:
    BucketInfo() noexcept;
    BucketInfo(uint32_t checksum, uint32_t docCount, uint32_t totDocSize) noexcept;
    BucketInfo(uint32_t checksum, uint32_t docCount, uint32_t totDocSize,
               uint32_t metaCount, uint32_t usedFileSize) noexcept;
    BucketInfo(uint32_t checksum, uint32_t docCount, uint32_t totDocSize,
               uint32_t metaCount, uint32_t usedFileSize,
               bool ready, bool active) noexcept;
    BucketInfo(uint32_t checksum, uint32_t docCount, uint32_t totDocSize,
               uint32_t metaCount, uint32_t usedFileSize,
               bool ready, bool active, Timestamp lastModified) noexcept;

    Timestamp getLastModified() const noexcept { return _lastModified; }
    uint32_t getChecksum() const noexcept { return _checksum; }
    uint32_t getDocumentCount() const noexcept { return _docCount; }
    uint32_t getTotalDocumentSize() const noexcept { return _totDocSize; }
    uint32_t getMetaCount() const noexcept { return _metaCount; }
    uint32_t getUsedFileSize() const noexcept { return _usedFileSize; }
    bool isReady() const noexcept { return _ready; }
    bool isActive() const noexcept { return _active; }

    void setChecksum(uint32_t crc) noexcept { _checksum = crc; }
    void setDocumentCount(uint32_t count) noexcept { _docCount = count; }
    void setTotalDocumentSize(uint32_t size) noexcept { _totDocSize = size; }
    void setMetaCount(uint32_t count) noexcept { _metaCount = count; }
    void setUsedFileSize(uint32_t size) noexcept { _usedFileSize = size; }
    void setReady(bool ready = true) noexcept { _ready = ready; }
    void setActive(bool active = true) noexcept { _active = active; }
    void setLastModified(Timestamp lastModified) noexcept { _lastModified = lastModified; }

    /**
     * Only compare checksum, total document count and document
     * size, not meta count or used file size.
     */
    bool equalDocumentInfo(const BucketInfo& other) const noexcept {
        return (_checksum == other._checksum
                && _docCount == other._docCount
                && _totDocSize == other._totDocSize);
    }

    bool operator==(const BucketInfo& info) const noexcept;
    bool valid() const noexcept { return (_docCount > 0 || _totDocSize == 0); }
    bool empty() const noexcept {
        return _metaCount == 0 && _usedFileSize == 0 && _checksum == 0;
    }
    vespalib::string toString() const;
    void printXml(vespalib::xml::XmlOutputStream&) const;
};

std::ostream & operator << (std::ostream & os, const BucketInfo & bucketInfo);

}