aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/operations/idealstate/joinoperation.h
blob: 88fb301065482f88b56c181eb88ca4afa866bf7d (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "idealstateoperation.h"
#include <vespa/storage/distributor/messagetracker.h>

namespace storage::distributor {

class JoinOperation : public IdealStateOperation
{
public:
    /**
     * Creates a new join operation.
     *
     * @param clusterName The name of this storage cluster.
     * @param bucketAndNodes The bucket to join into, along with the nodes this operation uses.
     * @param bucketsToJoin The buckets to join together. The size of this array should always be either one or two.
     */
    JoinOperation(const  ClusterContext& cluster_ctx,
                  const BucketAndNodes& nodes,
                  const std::vector<document::BucketId>& bucketsToJoin);

    ~JoinOperation() override;

    void onStart(DistributorStripeMessageSender& sender) override;

    void onReceive(DistributorStripeMessageSender& sender,
                   const std::shared_ptr<api::StorageReply>&) override;

    const char* getName() const noexcept override {
        return "join";
    }

    Type getType() const noexcept override {
        return JOIN_BUCKET;
    }

    bool isBlocked(const DistributorStripeOperationContext& ctx,
                   const OperationSequencer& op_seq) const override;

protected:
    using NodeToBuckets = std::map<uint16_t, std::vector<document::BucketId>>;
    NodeToBuckets resolveSourceBucketsPerTargetNode() const;

    void fillMissingSourceBucketsForInconsistentJoins(
            NodeToBuckets& nodeToBuckets) const;

    /**
     * Returns true if any messages were enqueued, false otherwise.
     */
    bool enqueueJoinMessagePerTargetNode(const NodeToBuckets& nodeToBuckets);

    document::Bucket getJoinBucket(size_t idx) const;

    MessageTracker _tracker;
    std::vector<document::BucketId> _bucketsToJoin;
};

}