summaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/operations/idealstate/setbucketstateoperation.h
blob: 3fb0c81421e98f30f8c2836abf32c8d82ea4cb8b (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 2017 Yahoo Holdings. 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 std::string& clusterName,
                            const BucketAndNodes& nodes,
                            const std::vector<uint16_t>& wantedActiveNodes);
    ~SetBucketStateOperation();

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

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

}