aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/operations/idealstate/setbucketstateoperation.h
blob: 4299e369b15c4f715d8b7a2ce920fadbeb01b17d (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
// Copyright Vespa.ai. 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 SetBucketStateOperation : public IdealStateOperation
{
public:
    SetBucketStateOperation(const ClusterContext& cluster_ctx,
                            const BucketAndNodes& nodes,
                            const std::vector<uint16_t>& wantedActiveNodes);
    ~SetBucketStateOperation() override;

    void onStart(DistributorStripeMessageSender&) override;
    void onReceive(DistributorStripeMessageSender&, const std::shared_ptr<api::StorageReply>&) override;
    const char* getName() const noexcept override { return "setbucketstate"; }
    Type getType() const noexcept override { return SET_BUCKET_STATE; }
protected:
    MessageTracker _tracker;
    std::vector<uint16_t> _wantedActiveNodes;

private:
    void enqueueSetBucketStateCommand(uint16_t node, bool active);
    void activateNode(DistributorStripeMessageSender& sender);
    void deactivateNodes(DistributorStripeMessageSender& sender);
    bool shouldBeActive(uint16_t node) const;
};

}