aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/operations/external/putoperation.h
blob: 9cfc699a9bc6d4598ba882106e5ae028a7bd8784 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "check_condition.h"
#include <vespa/storage/distributor/operations/sequenced_operation.h>
#include <vespa/storage/distributor/persistencemessagetracker.h>

namespace document { class Document; }

namespace storage::lib { class Distribution; }

namespace storage::api {
class CreateBucketReply;
class PutCommand;
}

namespace storage::distributor {

class DistributorBucketSpace;
class OperationTargetList;

class PutOperation : public SequencedOperation
{
public:
    PutOperation(const DistributorNodeContext& node_ctx,
                 DistributorStripeOperationContext& op_ctx,
                 DistributorBucketSpace& bucketSpace,
                 std::shared_ptr<api::PutCommand> msg,
                 PersistenceOperationMetricSet& metric,
                 PersistenceOperationMetricSet& condition_probe_metrics,
                 SequencingHandle sequencingHandle = SequencingHandle());
    ~PutOperation() override;

    void onStart(DistributorStripeMessageSender& sender) override;
    const char* getName() const noexcept override { return "put"; };
    std::string getStatus() const override { return ""; };
    void onReceive(DistributorStripeMessageSender& sender, const std::shared_ptr<api::StorageReply>&) override;
    void onClose(DistributorStripeMessageSender& sender) override;

private:
    PersistenceMessageTracker          _tracker;
    std::shared_ptr<api::PutCommand>   _msg;
    document::BucketId                 _doc_id_bucket_id;
    const DistributorNodeContext&      _node_ctx;
    DistributorStripeOperationContext& _op_ctx;
    PersistenceOperationMetricSet&     _condition_probe_metrics;
    DistributorBucketSpace&            _bucket_space;
    std::shared_ptr<CheckCondition>    _check_condition;

    void start_direct_put_dispatch(DistributorStripeMessageSender& sender);
    void start_conditional_put(DistributorStripeMessageSender& sender);
    void on_completed_check_condition(CheckCondition::Outcome& outcome,
                                      DistributorStripeMessageSender& sender);
    void insertDatabaseEntryAndScheduleCreateBucket(const OperationTargetList& copies, bool setOneActive,
                                                    const api::StorageCommand& originalCommand,
                                                    std::vector<MessageTracker::ToSend>& messagesToSend);

    void sendPutToBucketOnNode(document::BucketSpace bucketSpace, const document::BucketId& bucketId,
                               uint16_t node, std::vector<PersistenceMessageTracker::ToSend>& putBatch);

    void on_cancel(DistributorStripeMessageSender& sender, const CancelScope& cancel_scope) override;

    [[nodiscard]] bool shouldImplicitlyActivateReplica(const OperationTargetList& targets) const;

    [[nodiscard]] bool has_unavailable_targets_in_pending_state(const OperationTargetList& targets) const;
    [[nodiscard]] bool at_least_one_storage_node_is_available() const;
    [[nodiscard]] bool has_condition() const noexcept;
};

}