|
@@ -9,7 +9,6 @@
|
|
|
#include "init.h"
|
|
|
#include "lock.h"
|
|
|
#include "operation.h"
|
|
|
-#include "retry_transaction.h"
|
|
|
#include "retryful_writer.h"
|
|
|
#include "transaction.h"
|
|
|
#include "transaction_pinger.h"
|
|
@@ -123,7 +122,11 @@ void TClientBase::Remove(
|
|
|
const TYPath& path,
|
|
|
const TRemoveOptions& options)
|
|
|
{
|
|
|
- return NRawClient::Remove(ClientRetryPolicy_->CreatePolicyForGenericRequest(), Context_, TransactionId_, path, options);
|
|
|
+ RequestWithRetry<void>(
|
|
|
+ ClientRetryPolicy_->CreatePolicyForGenericRequest(),
|
|
|
+ [this, &path, &options] (TMutationId& mutationId) {
|
|
|
+ RawClient_->Remove(mutationId, TransactionId_, path, options);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
bool TClientBase::Exists(
|
|
@@ -176,7 +179,11 @@ TNode::TListType TClientBase::List(
|
|
|
const TYPath& path,
|
|
|
const TListOptions& options)
|
|
|
{
|
|
|
- return NRawClient::List(ClientRetryPolicy_->CreatePolicyForGenericRequest(), Context_, TransactionId_, path, options);
|
|
|
+ return RequestWithRetry<TNode::TListType>(
|
|
|
+ ClientRetryPolicy_->CreatePolicyForGenericRequest(),
|
|
|
+ [this, &path, &options] (TMutationId /*mutationId*/) {
|
|
|
+ return RawClient_->List(TransactionId_, path, options);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
TNodeId TClientBase::Copy(
|
|
@@ -193,16 +200,14 @@ TNodeId TClientBase::Copy(
|
|
|
} catch (const TErrorResponse& e) {
|
|
|
if (e.GetError().ContainsErrorCode(NClusterErrorCodes::NObjectClient::CrossCellAdditionalPath)) {
|
|
|
// Do transaction for cross cell copying.
|
|
|
-
|
|
|
- std::function<TNodeId(ITransactionPtr)> lambda = [this, &sourcePath, &destinationPath, &options](ITransactionPtr transaction) {
|
|
|
- TMutationId mutationId;
|
|
|
- return RawClient_->CopyWithoutRetries(mutationId, transaction->GetId(), sourcePath, destinationPath, options);
|
|
|
- };
|
|
|
- return RetryTransactionWithPolicy<TNodeId>(
|
|
|
- this,
|
|
|
- lambda,
|
|
|
- ClientRetryPolicy_->CreatePolicyForGenericRequest()
|
|
|
- );
|
|
|
+ return RequestWithRetry<TNodeId>(
|
|
|
+ ClientRetryPolicy_->CreatePolicyForGenericRequest(),
|
|
|
+ [this, &sourcePath, &destinationPath, &options] (TMutationId /*mutationId*/) {
|
|
|
+ auto transaction = StartTransaction(TStartTransactionOptions());
|
|
|
+ auto nodeId = RawClient_->CopyWithoutRetries(transaction->GetId(), sourcePath, destinationPath, options);
|
|
|
+ transaction->Commit();
|
|
|
+ return nodeId;
|
|
|
+ });
|
|
|
} else {
|
|
|
throw;
|
|
|
}
|
|
@@ -215,19 +220,22 @@ TNodeId TClientBase::Move(
|
|
|
const TMoveOptions& options)
|
|
|
{
|
|
|
try {
|
|
|
- return NRawClient::MoveInsideMasterCell(ClientRetryPolicy_->CreatePolicyForGenericRequest(), Context_, TransactionId_, sourcePath, destinationPath, options);
|
|
|
+ return RequestWithRetry<TNodeId>(
|
|
|
+ ClientRetryPolicy_->CreatePolicyForGenericRequest(),
|
|
|
+ [this, &sourcePath, &destinationPath, &options] (TMutationId& mutationId) {
|
|
|
+ return RawClient_->MoveInsideMasterCell(mutationId, TransactionId_, sourcePath, destinationPath, options);
|
|
|
+ });
|
|
|
} catch (const TErrorResponse& e) {
|
|
|
if (e.GetError().ContainsErrorCode(NClusterErrorCodes::NObjectClient::CrossCellAdditionalPath)) {
|
|
|
// Do transaction for cross cell moving.
|
|
|
-
|
|
|
- std::function<TNodeId(ITransactionPtr)> lambda = [this, &sourcePath, &destinationPath, &options](ITransactionPtr transaction) {
|
|
|
- return NRawClient::MoveWithoutRetries(Context_, transaction->GetId(), sourcePath, destinationPath, options);
|
|
|
- };
|
|
|
- return RetryTransactionWithPolicy<TNodeId>(
|
|
|
- this,
|
|
|
- lambda,
|
|
|
- ClientRetryPolicy_->CreatePolicyForGenericRequest()
|
|
|
- );
|
|
|
+ return RequestWithRetry<TNodeId>(
|
|
|
+ ClientRetryPolicy_->CreatePolicyForGenericRequest(),
|
|
|
+ [this, &sourcePath, &destinationPath, &options] (TMutationId /*mutationId*/) {
|
|
|
+ auto transaction = StartTransaction(TStartTransactionOptions());
|
|
|
+ auto nodeId = RawClient_->MoveWithoutRetries(transaction->GetId(), sourcePath, destinationPath, options);
|
|
|
+ transaction->Commit();
|
|
|
+ return nodeId;
|
|
|
+ });
|
|
|
} else {
|
|
|
throw;
|
|
|
}
|
|
@@ -239,7 +247,11 @@ TNodeId TClientBase::Link(
|
|
|
const TYPath& linkPath,
|
|
|
const TLinkOptions& options)
|
|
|
{
|
|
|
- return NRawClient::Link(ClientRetryPolicy_->CreatePolicyForGenericRequest(), Context_, TransactionId_, targetPath, linkPath, options);
|
|
|
+ return RequestWithRetry<TNodeId>(
|
|
|
+ ClientRetryPolicy_->CreatePolicyForGenericRequest(),
|
|
|
+ [this, &targetPath, &linkPath, &options] (TMutationId& mutationId) {
|
|
|
+ return RawClient_->Link(mutationId, TransactionId_, targetPath, linkPath, options);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
void TClientBase::Concatenate(
|
|
@@ -247,15 +259,21 @@ void TClientBase::Concatenate(
|
|
|
const TRichYPath& destinationPath,
|
|
|
const TConcatenateOptions& options)
|
|
|
{
|
|
|
- std::function<void(ITransactionPtr)> lambda = [&sourcePaths, &destinationPath, &options, this](ITransactionPtr transaction) {
|
|
|
- if (!options.Append_ && !sourcePaths.empty() && !transaction->Exists(destinationPath.Path_)) {
|
|
|
- auto typeNode = transaction->Get(CanonizeYPath(sourcePaths.front()).Path_ + "/@type");
|
|
|
- auto type = FromString<ENodeType>(typeNode.AsString());
|
|
|
- transaction->Create(destinationPath.Path_, type, TCreateOptions().IgnoreExisting(true));
|
|
|
- }
|
|
|
- NRawClient::Concatenate(this->Context_, transaction->GetId(), sourcePaths, destinationPath, options);
|
|
|
- };
|
|
|
- RetryTransactionWithPolicy(this, lambda, ClientRetryPolicy_->CreatePolicyForGenericRequest());
|
|
|
+ RequestWithRetry<void>(
|
|
|
+ ClientRetryPolicy_->CreatePolicyForGenericRequest(),
|
|
|
+ [this, &sourcePaths, &destinationPath, &options] (TMutationId /*mutationId*/) {
|
|
|
+ auto transaction = StartTransaction(TStartTransactionOptions());
|
|
|
+
|
|
|
+ if (!options.Append_ && !sourcePaths.empty() && !transaction->Exists(destinationPath.Path_)) {
|
|
|
+ auto typeNode = transaction->Get(CanonizeYPath(sourcePaths.front()).Path_ + "/@type");
|
|
|
+ auto type = FromString<ENodeType>(typeNode.AsString());
|
|
|
+ transaction->Create(destinationPath.Path_, type, TCreateOptions().IgnoreExisting(true));
|
|
|
+ }
|
|
|
+
|
|
|
+ RawClient_->Concatenate(transaction->GetId(), sourcePaths, destinationPath, options);
|
|
|
+
|
|
|
+ transaction->Commit();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
TRichYPath TClientBase::CanonizeYPath(const TRichYPath& path)
|
|
@@ -947,7 +965,11 @@ ILockPtr TTransaction::Lock(
|
|
|
ELockMode mode,
|
|
|
const TLockOptions& options)
|
|
|
{
|
|
|
- auto lockId = NRawClient::Lock(ClientRetryPolicy_->CreatePolicyForGenericRequest(), Context_, TransactionId_, path, mode, options);
|
|
|
+ auto lockId = RequestWithRetry<TLockId>(
|
|
|
+ ClientRetryPolicy_->CreatePolicyForGenericRequest(),
|
|
|
+ [this, &path, &mode, &options] (TMutationId& mutationId) {
|
|
|
+ return RawClient_->Lock(mutationId, TransactionId_, path, mode, options);
|
|
|
+ });
|
|
|
return ::MakeIntrusive<TLock>(lockId, GetParentClientImpl(), options.Waitable_);
|
|
|
}
|
|
|
|
|
@@ -955,7 +977,11 @@ void TTransaction::Unlock(
|
|
|
const TYPath& path,
|
|
|
const TUnlockOptions& options)
|
|
|
{
|
|
|
- NRawClient::Unlock(ClientRetryPolicy_->CreatePolicyForGenericRequest(), Context_, TransactionId_, path, options);
|
|
|
+ RequestWithRetry<void>(
|
|
|
+ ClientRetryPolicy_->CreatePolicyForGenericRequest(),
|
|
|
+ [this, &path, &options] (TMutationId& mutationId) {
|
|
|
+ RawClient_->Unlock(mutationId, TransactionId_, path, options);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
void TTransaction::Commit()
|