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
|
#pragma once
#include "public.h"
#include <yt/yt/client/table_client/table_upload_options.h>
#include <yt/yt/client/chunk_client/public.h>
#include <yt/yt/client/table_client/key.h>
#include <yt/yt/client/ypath/rich.h>
#include <yt/yt/core/ytree/yson_struct.h>
namespace NYT::NApi {
////////////////////////////////////////////////////////////////////////////////
YT_DEFINE_STRONG_TYPEDEF(TDistributedWriteSessionId, TGuid);
////////////////////////////////////////////////////////////////////////////////
// Used by distributed table writer to patch
// its config based on table data.
// NB(arkady-e1ppa): TableUploadOptions are
// encoded in RichPath + TableAttributes and thus
// are not required to be stored directly.
struct TTableWriterPatchInfo
: public NYTree::TYsonStructLite
{
public:
NObjectClient::TObjectId ObjectId;
NYPath::TRichYPath RichPath;
// NB(arkady-e1ppa): Empty writer last key Serialization into Deserialization
// somehow results in a []; row which is considered non-empty for some reason.
// This matters too little for me to bother saving up the std::optional wrapper.
std::optional<NTableClient::TLegacyOwningKey> WriterLastKey;
int MaxHeavyColumns;
NTableClient::TMasterTableSchemaId ChunkSchemaId;
NTableClient::TTableSchemaPtr ChunkSchema;
NYTree::INodePtr TableAttributes;
NObjectClient::TCellTag ExternalCellTag;
NTransactionClient::TTimestamp Timestamp;
TTableWriterPatchInfo(
NYPath::TRichYPath richPath,
NObjectClient::TObjectId objectId,
NObjectClient::TCellTag externalCellTag,
NTableClient::TMasterTableSchemaId chunkSchemaId,
NTableClient::TTableSchemaPtr chunkSchema,
std::optional<NTableClient::TLegacyOwningKey> writerLastKey,
int maxHeavyColumns,
NTransactionClient::TTimestamp timestamp,
const NYTree::IAttributeDictionary& tableAttributes);
REGISTER_YSON_STRUCT_LITE(TTableWriterPatchInfo)
static void Register(TRegistrar registrar);
};
////////////////////////////////////////////////////////////////////////////////
struct TFragmentWriteResult
: public NYTree::TYsonStructLite
{
NTableClient::TLegacyOwningKey MinBoundaryKey;
NTableClient::TLegacyOwningKey MaxBoundaryKey;
NChunkClient::TChunkListId ChunkListId;
REGISTER_YSON_STRUCT_LITE(TFragmentWriteResult)
static void Register(TRegistrar registrar);
};
////////////////////////////////////////////////////////////////////////////////
class TFragmentWriteCookie
: public NYTree::TYsonStruct
{
public:
const TTableWriterPatchInfo& GetPatchInfo() const;
NCypressClient::TTransactionId GetMainTransactionId() const;
NCypressClient::TTransactionId GetUploadTransactionId() const;
private:
TDistributedWriteSessionId Id_;
NCypressClient::TTransactionId MainTxId_;
NCypressClient::TTransactionId UploadTxId_;
TTableWriterPatchInfo PatchInfo_;
std::vector<TFragmentWriteResult> WriteResults_;
REGISTER_YSON_STRUCT(TFragmentWriteCookie);
static void Register(TRegistrar registrar);
friend class TDistributedWriteSession;
friend struct IDistributedTableClientBase;
};
DEFINE_REFCOUNTED_TYPE(TFragmentWriteCookie);
////////////////////////////////////////////////////////////////////////////////
class TDistributedWriteSession
: public NYTree::TYsonStruct
{
public:
TDistributedWriteSession(
NCypressClient::TTransactionId mainTxId,
NCypressClient::TTransactionId uploadTxId,
NChunkClient::TChunkListId rootChunkListId,
TTableWriterPatchInfo patchInfo);
NCypressClient::TTransactionId GetMainTransactionId() const;
NCypressClient::TTransactionId GetUploadTransactionId() const;
const TTableWriterPatchInfo& GetPatchInfo() const Y_LIFETIME_BOUND;
NChunkClient::TChunkListId GetRootChunkListId() const;
TFragmentWriteCookiePtr GiveCookie();
void TakeCookie(TFragmentWriteCookiePtr cookie);
TFuture<void> Ping(IClientPtr client);
REGISTER_YSON_STRUCT(TDistributedWriteSession);
static void Register(TRegistrar registrar);
private:
TDistributedWriteSessionId Id_;
NCypressClient::TTransactionId MainTxId_;
NCypressClient::TTransactionId UploadTxId_;
NChunkClient::TChunkListId RootChunkListId_;
TTableWriterPatchInfo PatchInfo_;
// This is used to commit changes when session is over.
std::vector<TFragmentWriteResult> WriteResults_;
friend struct IDistributedTableClientBase;
};
DEFINE_REFCOUNTED_TYPE(TDistributedWriteSession);
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NApi
|