blob: b992893a42cea8aed2ba7a01332cd91ca94b66fb (
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
|
#include "file_fragment_writer.h"
#include <yt/cpp/mapreduce/common/retry_request.h>
#include <yt/cpp/mapreduce/interface/raw_client.h>
#include <library/cpp/yson/node/node_io.h>
namespace NYT::NDetail {
////////////////////////////////////////////////////////////////////////////////
class TFileFragmentWriter
: public IFileFragmentWriter
{
public:
explicit TFileFragmentWriter(std::unique_ptr<IOutputStreamWithResponse> stream)
: Underlying_(std::move(stream))
{ }
TWriteFileFragmentResult GetWriteFragmentResult() const override
{
return TWriteFileFragmentResult(NodeFromYsonString(Underlying_->GetResponse()));
}
private:
std::unique_ptr<IOutputStreamWithResponse> Underlying_;
void DoWrite(const void* buf, size_t len) override
{
Underlying_->Write(buf, len);
}
void DoFinish() override
{
Underlying_->Finish();
}
};
////////////////////////////////////////////////////////////////////////////////
IFileFragmentWriterPtr CreateFileFragmentWriter(
const IRawClientPtr& rawClient,
const IRequestRetryPolicyPtr& retryPolicy,
const TDistributedWriteFileCookie& cookie,
const TFileFragmentWriterOptions& options)
{
auto stream = NDetail::RequestWithRetry<std::unique_ptr<IOutputStreamWithResponse>>(
retryPolicy,
[&] (TMutationId /*mutationId*/) {
return rawClient->WriteFileFragment(cookie, options);
}
);
return MakeIntrusive<TFileFragmentWriter>(std::move(stream));
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NDetail
|