aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/client/batch_request_impl.cpp
blob: 6afa5665f124a3a29385304f33e370015dfd5d4b (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "batch_request_impl.h"

#include "lock.h"

#include <yt/cpp/mapreduce/common/helpers.h>
#include <yt/cpp/mapreduce/common/retry_lib.h>

#include <yt/cpp/mapreduce/http/retry_request.h>

#include <yt/cpp/mapreduce/interface/config.h>

#include <yt/cpp/mapreduce/interface/logging/yt_log.h>

#include <library/cpp/yson/node/node.h>
#include <library/cpp/yson/node/serialize.h>

#include <yt/cpp/mapreduce/raw_client/raw_requests.h>
#include <yt/cpp/mapreduce/raw_client/raw_batch_request.h>
#include <yt/cpp/mapreduce/raw_client/rpc_parameters_serialization.h>

#include <util/generic/guid.h>
#include <util/string/builder.h>

#include <exception>

namespace NYT {
namespace NDetail {

using namespace NRawClient;

using ::NThreading::TFuture;
using ::NThreading::TPromise;
using ::NThreading::NewPromise;

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

TBatchRequest::TBatchRequest(const TTransactionId& defaultTransaction, ::TIntrusivePtr<TClient> client)
    : DefaultTransaction_(defaultTransaction)
    , Impl_(MakeIntrusive<TRawBatchRequest>(client->GetContext().Config))
    , Client_(client)
{ }

TBatchRequest::TBatchRequest(TRawBatchRequest* impl, ::TIntrusivePtr<TClient> client)
    : Impl_(impl)
    , Client_(std::move(client))
{ }

TBatchRequest::~TBatchRequest() = default;

IBatchRequestBase& TBatchRequest::WithTransaction(const TTransactionId& transactionId)
{
    if (!TmpWithTransaction_) {
        TmpWithTransaction_.Reset(new TBatchRequest(Impl_.Get(), Client_));
    }
    TmpWithTransaction_->DefaultTransaction_ = transactionId;
    return *TmpWithTransaction_;
}

TFuture<TNode> TBatchRequest::Get(
    const TYPath& path,
    const TGetOptions& options)
{
    return Impl_->Get(DefaultTransaction_, path, options);
}

TFuture<void> TBatchRequest::Set(const TYPath& path, const TNode& node, const TSetOptions& options)
{
    return Impl_->Set(DefaultTransaction_, path, node, options);
}

TFuture<TNode::TListType> TBatchRequest::List(const TYPath& path, const TListOptions& options)
{
    return Impl_->List(DefaultTransaction_, path, options);
}

TFuture<bool> TBatchRequest::Exists(const TYPath& path, const TExistsOptions& options)
{
    return Impl_->Exists(DefaultTransaction_, path, options);
}

TFuture<ILockPtr> TBatchRequest::Lock(
    const TYPath& path,
    ELockMode mode,
    const TLockOptions& options)
{
    auto convert = [waitable=options.Waitable_, client=Client_] (TFuture<TNodeId> nodeIdFuture) -> ILockPtr {
        return ::MakeIntrusive<TLock>(nodeIdFuture.GetValue(), client, waitable);
    };
    return Impl_->Lock(DefaultTransaction_, path, mode, options).Apply(convert);
}

::NThreading::TFuture<void> TBatchRequest::Unlock(
    const TYPath& path,
    const TUnlockOptions& options = TUnlockOptions())
{
    return Impl_->Unlock(DefaultTransaction_, path, options);
}

TFuture<TLockId> TBatchRequest::Create(
    const TYPath& path,
    ENodeType type,
    const TCreateOptions& options)
{
    return Impl_->Create(DefaultTransaction_, path, type, options);
}

TFuture<void> TBatchRequest::Remove(
    const TYPath& path,
    const TRemoveOptions& options)
{
    return Impl_->Remove(DefaultTransaction_, path, options);
}

TFuture<TNodeId> TBatchRequest::Move(
    const TYPath& sourcePath,
    const TYPath& destinationPath,
    const TMoveOptions& options)
{
    return Impl_->Move(DefaultTransaction_, sourcePath, destinationPath, options);
}

TFuture<TNodeId> TBatchRequest::Copy(
    const TYPath& sourcePath,
    const TYPath& destinationPath,
    const TCopyOptions& options)
{
    return Impl_->Copy(DefaultTransaction_, sourcePath, destinationPath, options);
}

TFuture<TNodeId> TBatchRequest::Link(
    const TYPath& targetPath,
    const TYPath& linkPath,
    const TLinkOptions& options)
{
    return Impl_->Link(DefaultTransaction_, targetPath, linkPath, options);
}

TFuture<void> TBatchRequest::AbortOperation(const NYT::TOperationId& operationId)
{
    return Impl_->AbortOperation(operationId);
}

TFuture<void> TBatchRequest::CompleteOperation(const NYT::TOperationId& operationId)
{
    return Impl_->CompleteOperation(operationId);
}

TFuture<void> TBatchRequest::SuspendOperation(
    const TOperationId& operationId,
    const TSuspendOperationOptions& options)
{
    return Impl_->SuspendOperation(operationId, options);
}

TFuture<void> TBatchRequest::ResumeOperation(
    const TOperationId& operationId,
    const TResumeOperationOptions& options)
{
    return Impl_->ResumeOperation(operationId, options);
}

TFuture<void> TBatchRequest::UpdateOperationParameters(
    const NYT::TOperationId& operationId,
    const NYT::TUpdateOperationParametersOptions& options)
{
    return Impl_->UpdateOperationParameters(operationId, options);
}

TFuture<TRichYPath> TBatchRequest::CanonizeYPath(const TRichYPath& path)
{
    return Impl_->CanonizeYPath(path);
}

TFuture<TVector<TTableColumnarStatistics>> TBatchRequest::GetTableColumnarStatistics(
    const TVector<TRichYPath>& paths,
    const NYT::TGetTableColumnarStatisticsOptions& options)
{
    return Impl_->GetTableColumnarStatistics(DefaultTransaction_, paths, options);
}

TFuture<TCheckPermissionResponse> TBatchRequest::CheckPermission(
    const TString& user,
    EPermission permission,
    const TYPath& path,
    const TCheckPermissionOptions& options)
{
    return Impl_->CheckPermission(user, permission, path, options);
}

void TBatchRequest::ExecuteBatch(const TExecuteBatchOptions& options)
{
    NYT::NDetail::ExecuteBatch(Client_->GetRetryPolicy()->CreatePolicyForGenericRequest(), Client_->GetContext(), *Impl_, options);
}

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

} // namespace NDetail
} // namespace NYT