aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/client/client_writer.cpp
blob: ee14ee0eb2caaffd923d2ae62222ed41f6ecc12e (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "client_writer.h"

#include "retryful_writer.h"
#include "retryless_writer.h"
#include "retryful_writer_v2.h"

#include <yt/cpp/mapreduce/interface/io.h>
#include <yt/cpp/mapreduce/common/fwd.h>
#include <yt/cpp/mapreduce/common/helpers.h>

namespace NYT {

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

TClientWriter::TClientWriter(
    const TRichYPath& path,
    IClientRetryPolicyPtr clientRetryPolicy,
    ITransactionPingerPtr transactionPinger,
    const TClientContext& context,
    const TTransactionId& transactionId,
    const TMaybe<TFormat>& format,
    const TTableWriterOptions& options)
    : BufferSize_(options.BufferSize_)
    , AutoFinish_(options.AutoFinish_)
{
    if (options.SingleHttpRequest_) {
        RawWriter_.Reset(new TRetrylessWriter(
            context,
            transactionId,
            GetWriteTableCommand(context.Config->ApiVersion),
            format,
            path,
            BufferSize_,
            options));
    } else {
        bool useV2Writer = context.Config->TableWriterVersion == ETableWriterVersion::V2;
        if (useV2Writer) {
            auto serializedWriterOptions = FormIORequestParameters(options);

            RawWriter_ = MakeIntrusive<NPrivate::TRetryfulWriterV2>(
                    std::move(clientRetryPolicy),
                    std::move(transactionPinger),
                    context,
                    transactionId,
                    GetWriteTableCommand(context.Config->ApiVersion),
                    format,
                    path,
                    serializedWriterOptions,
                    static_cast<ssize_t>(options.BufferSize_),
                    options.CreateTransaction_);
        } else {
            RawWriter_.Reset(new TRetryfulWriter(
                std::move(clientRetryPolicy),
                std::move(transactionPinger),
                context,
                transactionId,
                GetWriteTableCommand(context.Config->ApiVersion),
                format,
                path,
                options));
        }
    }
}

TClientWriter::~TClientWriter()
{
    NDetail::FinishOrDie(this, AutoFinish_, "TClientWriter");
}

void TClientWriter::Finish()
{
    RawWriter_->Finish();
}

size_t TClientWriter::GetStreamCount() const
{
    return 1;
}

IOutputStream* TClientWriter::GetStream(size_t tableIndex) const
{
    Y_UNUSED(tableIndex);
    return RawWriter_.Get();
}

void TClientWriter::OnRowFinished(size_t)
{
    RawWriter_->NotifyRowEnd();
}

void TClientWriter::Abort()
{
    RawWriter_->Abort();
}

size_t TClientWriter::GetBufferMemoryUsage() const
{
    return RawWriter_->GetBufferMemoryUsage();
}

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

} // namespace NYT