aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageapi/message/bucketsplitting.cpp
blob: 784ba6edbd1f0a7fd16ffb1922ffdbfbd9ada371 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "bucketsplitting.h"
#include <ostream>
#include <limits>

namespace storage::api {

IMPLEMENT_COMMAND(SplitBucketCommand, SplitBucketReply)
IMPLEMENT_REPLY(SplitBucketReply)
IMPLEMENT_COMMAND(JoinBucketsCommand, JoinBucketsReply)
IMPLEMENT_REPLY(JoinBucketsReply)

SplitBucketCommand::SplitBucketCommand(const document::Bucket &bucket)
    : MaintenanceCommand(MessageType::SPLITBUCKET, bucket),
      _minSplitBits(0),
      _maxSplitBits(58),
      _minByteSize(std::numeric_limits<uint32_t>::max()),
      _minDocCount(std::numeric_limits<uint32_t>::max())
{
    // By default, set very large sizes, to ensure we trigger 'already big
    // enough' behaviour, only splitting one step by default. The distributor
    // should always overwrite one of these values to get correct behaviour.
}

void
SplitBucketCommand::print(std::ostream& out, bool verbose,
                          const std::string& indent) const
{
    out << "SplitBucketCommand(" << getBucketId();
    if (_minDocCount != std::numeric_limits<uint32_t>::max()
        || _minByteSize != std::numeric_limits<uint32_t>::max())
    {
        out << "Max doc count: " << _minDocCount
            << ", Max total doc size: " << _minByteSize;
    } else if (_maxSplitBits != 58) {
        out << "Max split bits to use: " << _maxSplitBits;
    }
    out << ")";
    out << " Reasons to start: " << _reason;
    if (verbose) {
        out << " : ";
        BucketCommand::print(out, verbose, indent);
    }
}

SplitBucketReply::SplitBucketReply(const SplitBucketCommand& cmd)
    : BucketReply(cmd)
{
}

void
SplitBucketReply::print(std::ostream& out, bool verbose,
                          const std::string& indent) const
{
    out << "SplitBucketReply(" << getBucketId();
    if (_result.empty()) {
        out << " - No target files created.";
    } else {
        out << " ->";
        for (uint32_t i=0; i<_result.size(); ++i) {
            out << "\n" << indent << "  " << _result[i].first << ": "
                << _result[i].second;
        }
    }
    out << ")";
    if (verbose) {
        out << " : ";
        BucketReply::print(out, verbose, indent);
    }
}

JoinBucketsCommand::JoinBucketsCommand(const document::Bucket &target)
    : MaintenanceCommand(MessageType::JOINBUCKETS, target),
      _minJoinBits(0)
{
}

void
JoinBucketsCommand::print(std::ostream& out, bool verbose,
                          const std::string& indent) const
{
    out << "JoinBucketsCommand(" << getBucketId();
    if (_sources.empty()) {
        out << " - No files to join.";
    } else {
        out << " <-";
        for (uint32_t i=0; i<_sources.size(); ++i) {
            out << " " << _sources[i];
        }
    }
    out << ")";
    out << " Reasons to start: " << _reason;
    if (verbose) {
        out << " : ";
        BucketCommand::print(out, verbose, indent);
    }
}


JoinBucketsReply::JoinBucketsReply(const JoinBucketsCommand& cmd)
    : BucketInfoReply(cmd),
      _sources(cmd.getSourceBuckets())
{
}

JoinBucketsReply::JoinBucketsReply(const JoinBucketsCommand& cmd, const BucketInfo& bucketInfo)
    : BucketInfoReply(cmd),
      _sources(cmd.getSourceBuckets())
{
    setBucketInfo(bucketInfo);
}

void
JoinBucketsReply::print(std::ostream& out, bool verbose,
                        const std::string& indent) const
{
    out << "JoinBucketsReply(" << getBucketId();
    if (_sources.empty()) {
        out << " - No files to join.";
    } else {
        out << " <-";
        for (uint32_t i=0; i<_sources.size(); ++i) {
            out << " " << _sources[i];
        }
    }
    out << ")";
    if (verbose) {
        out << " : ";
        BucketReply::print(out, verbose, indent);
    }
}

}