aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/client/retry_heavy_write_request.h
blob: 052bbfb860b24db56994fd2b0251f4416054e8b7 (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
#pragma once

#include <yt/cpp/mapreduce/client/transaction.h>
#include <yt/cpp/mapreduce/common/fwd.h>

#include <yt/cpp/mapreduce/http/context.h>
#include <yt/cpp/mapreduce/http/requests.h>

namespace NYT {

///////////////////////////////////////////////////////////////////////////////

class THeavyRequestRetrier
{
public:
    struct TParameters
    {
        IClientRetryPolicyPtr ClientRetryPolicy;
        ITransactionPingerPtr TransactionPinger;
        TClientContext Context;
        TTransactionId TransactionId;
        THttpHeader Header;
    };

    using TStreamFactory = std::function<THolder<IInputStream>()>;

public:
    explicit THeavyRequestRetrier(TParameters parameters);
    ~THeavyRequestRetrier();

    void Update(TStreamFactory streamFactory);
    void Finish();

private:
    void Retry(const std::function<void()>& function);

    void TryStartAttempt();

private:
    const TParameters Parameters_;
    const IRequestRetryPolicyPtr RequestRetryPolicy_;

    struct TAttempt
    {
        std::unique_ptr<TPingableTransaction> Transaction;
        TString RequestId;
        NHttpClient::IHttpRequestPtr Request;
        ssize_t Offset = 0;
    };
    std::unique_ptr<TAttempt> Attempt_;

    TStreamFactory StreamFactory_;
};

///////////////////////////////////////////////////////////////////////////////

void RetryHeavyWriteRequest(
    const IClientRetryPolicyPtr& clientRetryPolicy,
    const ITransactionPingerPtr& transactionPinger,
    const TClientContext& context,
    const TTransactionId& parentId,
    THttpHeader& header,
    std::function<THolder<IInputStream>()> streamMaker);

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT