aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/buckethandler.h
blob: 1121c9fd9a64f30a90b2de8a7d183a5bb73a045e (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "iclusterstatechangedhandler.h"
#include "ibucketstatechangednotifier.h"
#include <vespa/searchcore/proton/documentmetastore/i_bucket_handler.h>
#include <vespa/searchcore/proton/persistenceengine/resulthandler.h>
#include <vespa/vespalib/util/executor.h>

namespace proton {

class IBucketStateChangedhandler;


/**
 * Class handling bucket operations in IPersistenceHandler that are not persisted
 * in the transaction log for a document database.
 */
class BucketHandler : public IClusterStateChangedHandler,
                      public IBucketStateChangedNotifier
{
private:
    vespalib::Executor                       &_executor;
    documentmetastore::IBucketHandler        *_ready;
    std::vector<IBucketStateChangedHandler *> _changedHandlers;
    bool                                      _nodeUp;
    bool                                      _nodeMaintenance;

    void performSetCurrentState(document::BucketId bucketId,
                                storage::spi::BucketInfo::ActiveState newState,
                                IGenericResultHandler *resultHandler);

    void performPopulateActiveBuckets(document::BucketId::List buckets,
                                      IGenericResultHandler *resultHandler);
    /**
     * Deactivate all active buckets when this node transitions from
     * up to down in cluster state.  Called by document db executor thread.
     */
    void deactivateAllActiveBuckets();

public:
    /**
     * Create a new bucket handler.
     *
     * @param executor The executor in which to run all tasks.
     */
    explicit BucketHandler(vespalib::Executor &executor);
    ~BucketHandler() override;

    void setReadyBucketHandler(documentmetastore::IBucketHandler &ready);

    /**
     * Implements the bucket aspect of IPersistenceHandler.
     */
    void handleListBuckets(IBucketIdListResultHandler &resultHandler);
    void handleSetCurrentState(const document::BucketId &bucketId,
                               storage::spi::BucketInfo::ActiveState newState,
                               std::shared_ptr<IGenericResultHandler> resultHandler);
    void handleGetBucketInfo(const storage::spi::Bucket &bucket,
                             IBucketInfoResultHandler &resultHandler);
    void handleListActiveBuckets(IBucketIdListResultHandler &resultHandler);
    void handlePopulateActiveBuckets(document::BucketId::List buckets,
                                     IGenericResultHandler &resultHandler);
    bool hasBucket(const storage::spi::Bucket &bucket);

    // Implements IClusterStateChangedHandler
    void notifyClusterStateChanged(const std::shared_ptr<IBucketStateCalculator> &newCalc) override;

    // Implement IBucketStateChangedNotifier
    void addBucketStateChangedHandler(IBucketStateChangedHandler *handler) override;
    void removeBucketStateChangedHandler(IBucketStateChangedHandler *handler) override;
};

} // namespace proton