aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/distributor/operations/external/updateoperation.h
blob: 2e69a52a6447255d8d494cda8a20b9635fca1619 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/storage/distributor/persistencemessagetracker.h>

namespace document {
class Document;
}

namespace storage {

namespace api {
class UpdateCommand;
class CreateBucketReply;
}

class UpdateMetricSet;

namespace distributor {

class DistributorBucketSpace;

class UpdateOperation : public Operation
{
public:
    UpdateOperation(DistributorComponent& manager,
                    DistributorBucketSpace &bucketSpace,
                    const std::shared_ptr<api::UpdateCommand> & msg,
                    UpdateMetricSet& metric);

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

    std::pair<document::BucketId, uint16_t> getNewestTimestampLocation() const {
        return _newestTimestampLocation;
    }

private:
    PersistenceMessageTrackerImpl _trackerInstance;
    PersistenceMessageTracker& _tracker;
    std::shared_ptr<api::UpdateCommand> _msg;
    const api::Timestamp _new_timestamp;
    const bool _is_auto_create_update;

    DistributorComponent& _manager;
    DistributorBucketSpace &_bucketSpace;
    std::pair<document::BucketId, uint16_t> _newestTimestampLocation;
    api::BucketInfo _infoAtSendTime; // Should be same across all replicas

    bool anyStorageNodesAvailable() const;

    class PreviousDocumentVersion {
    public:
        PreviousDocumentVersion(document::BucketId b, const api::BucketInfo& info, uint64_t o, uint16_t node) noexcept :
            bucketId(b), bucketInfo(info), oldTs(o), nodeId(node) {}

        document::BucketId bucketId;
        api::BucketInfo bucketInfo;
        uint64_t oldTs;
        uint16_t nodeId;
    };

    std::vector<PreviousDocumentVersion> _results;
    UpdateMetricSet& _metrics;

    api::Timestamp adjusted_received_old_timestamp(api::Timestamp old_ts_from_node) const;
};

}

}