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
|
#pragma once
#include <ydb/public/api/grpc/draft/ydb_long_tx_v1.grpc.pb.h>
#include <ydb/public/sdk/cpp/client/ydb_driver/driver.h>
#include <ydb/public/sdk/cpp/client/ydb_types/operation/operation.h>
namespace NYdb {
namespace NLongTx {
class TLongTxBeginResult : public TOperation {
public:
explicit TLongTxBeginResult(TStatus&& status)
: TOperation(std::move(status))
{}
TLongTxBeginResult(TStatus&& status, Ydb::Operations::Operation&& operation)
: TOperation(std::move(status), std::move(operation))
{}
Ydb::LongTx::BeginTransactionResult GetResult() {
Ydb::LongTx::BeginTransactionResult result;
GetProto().result().UnpackTo(&result);
return result;
}
};
class TLongTxCommitResult : public TOperation {
public:
explicit TLongTxCommitResult(TStatus&& status)
: TOperation(std::move(status))
{}
TLongTxCommitResult(TStatus&& status, Ydb::Operations::Operation&& operation)
: TOperation(std::move(status), std::move(operation))
{}
Ydb::LongTx::CommitTransactionResult GetResult() {
Ydb::LongTx::CommitTransactionResult result;
GetProto().result().UnpackTo(&result);
return result;
}
};
class TLongTxRollbackResult : public TOperation {
public:
explicit TLongTxRollbackResult(TStatus&& status)
: TOperation(std::move(status))
{}
TLongTxRollbackResult(TStatus&& status, Ydb::Operations::Operation&& operation)
: TOperation(std::move(status), std::move(operation))
{}
Ydb::LongTx::RollbackTransactionResult GetResult() {
Ydb::LongTx::RollbackTransactionResult result;
GetProto().result().UnpackTo(&result);
return result;
}
};
class TLongTxWriteResult : public TOperation {
public:
explicit TLongTxWriteResult(TStatus&& status)
: TOperation(std::move(status))
{}
TLongTxWriteResult(TStatus&& status, Ydb::Operations::Operation&& operation)
: TOperation(std::move(status), std::move(operation))
{}
Ydb::LongTx::WriteResult GetResult() {
Ydb::LongTx::WriteResult result;
GetProto().result().UnpackTo(&result);
return result;
}
};
class TLongTxReadResult : public TOperation {
public:
explicit TLongTxReadResult(TStatus&& status)
: TOperation(std::move(status))
{}
TLongTxReadResult(TStatus&& status, Ydb::Operations::Operation&& operation)
: TOperation(std::move(status), std::move(operation))
{}
Ydb::LongTx::ReadResult GetResult() {
Ydb::LongTx::ReadResult result;
GetProto().result().UnpackTo(&result);
return result;
}
};
struct TClientSettings : public TCommonClientSettingsBase<TClientSettings> {
using TSelf = TClientSettings;
};
class TClient {
public:
using TAsyncBeginTxResult = NThreading::TFuture<TLongTxBeginResult>;
using TAsyncCommitTxResult = NThreading::TFuture<TLongTxCommitResult>;
using TAsyncRollbackTxResult = NThreading::TFuture<TLongTxRollbackResult>;
using TAsyncWriteResult = NThreading::TFuture<TLongTxWriteResult>;
using TAsyncReadResult = NThreading::TFuture<TLongTxReadResult>;
TClient(const TDriver& driver, const TClientSettings& settings = TClientSettings());
TAsyncBeginTxResult BeginWriteTx();
TAsyncBeginTxResult BeginReadTx();
TAsyncCommitTxResult CommitTx(const TString& txId);
TAsyncRollbackTxResult RollbackTx(const TString& txId);
TAsyncWriteResult Write(const TString& txId, const TString& table, const TString& dedupId,
const TString& data, Ydb::LongTx::Data::Format format);
TAsyncReadResult Read(const TString& txId, const TString& table);
private:
class TImpl;
std::shared_ptr<TImpl> Impl_;
};
} // namespace NLongTx
} // namespace NYdb
|