10
10
#include < ydb/core/protos/schemeshard/operations.pb.h>
11
11
#include < ydb/core/tx/schemeshard/schemeshard_build_index.h>
12
12
#include < ydb/core/tx/tx_proxy/proxy.h>
13
+ #include < ydb/library/aclib/aclib.h>
13
14
#include < ydb/services/metadata/abstract/kqp_common.h>
14
15
15
16
@@ -45,6 +46,7 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
45
46
enum EEv {
46
47
EvResult = EventSpaceBegin (TEvents::ES_PRIVATE),
47
48
EvMakeTempDirResult,
49
+ EvMakeSessionDirResult,
48
50
};
49
51
50
52
struct TEvResult : public TEventLocal <TEvResult, EEv::EvResult> {
@@ -54,6 +56,10 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
54
56
struct TEvMakeTempDirResult : public TEventLocal <TEvMakeTempDirResult, EEv::EvMakeTempDirResult> {
55
57
IKqpGateway::TGenericResult Result;
56
58
};
59
+
60
+ struct TEvMakeSessionDirResult : public TEventLocal <TEvMakeSessionDirResult, EEv::EvMakeSessionDirResult> {
61
+ IKqpGateway::TGenericResult Result;
62
+ };
57
63
};
58
64
public:
59
65
static constexpr NKikimrServices::TActivity::EType ActorActivityType () {
@@ -95,6 +101,46 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
95
101
auto ev = MakeHolder<TEvTxUserProxy::TEvProposeTransaction>();
96
102
auto & record = ev->Record ;
97
103
104
+ record.SetDatabaseName (Database);
105
+ record.SetUserToken (NACLib::TSystemUsers::Tmp ().SerializeAsString ());
106
+ record.SetPeerName (ClientAddress);
107
+
108
+ auto * modifyScheme = record.MutableTransaction ()->MutableModifyScheme ();
109
+ modifyScheme->SetWorkingDir (GetTmpDirPath (Database));
110
+ modifyScheme->SetOperationType (NKikimrSchemeOp::EOperationType::ESchemeOpMkDir);
111
+ modifyScheme->SetAllowCreateInTempDir (false );
112
+ modifyScheme->SetInternal (true );
113
+
114
+ auto * makeDir = modifyScheme->MutableMkDir ();
115
+ makeDir->SetName (GetSessionDirName ());
116
+
117
+ NACLib::TDiffACL diffAcl;
118
+ diffAcl.AddAccess (
119
+ NACLib::EAccessType::Allow,
120
+ NACLib::EAccessRights::CreateDirectory | NACLib::EAccessRights::DescribeSchema,
121
+ AppData ()->AllAuthenticatedUsers );
122
+
123
+ auto * modifyAcl = modifyScheme->MutableModifyACL ();
124
+ modifyAcl->SetDiffACL (diffAcl.SerializeAsString ());
125
+
126
+ auto promise = NewPromise<IKqpGateway::TGenericResult>();
127
+ IActor* requestHandler = new TSchemeOpRequestHandler (ev.Release (), promise, false );
128
+ RegisterWithSameMailbox (requestHandler);
129
+
130
+ auto actorSystem = TActivationContext::ActorSystem ();
131
+ auto selfId = SelfId ();
132
+ promise.GetFuture ().Subscribe ([actorSystem, selfId](const TFuture<IKqpGateway::TGenericResult>& future) {
133
+ auto ev = MakeHolder<TEvPrivate::TEvMakeTempDirResult>();
134
+ ev->Result = future.GetValue ();
135
+ actorSystem->Send (selfId, ev.Release ());
136
+ });
137
+ Become (&TKqpSchemeExecuter::ExecuteState);
138
+ }
139
+
140
+ void CreateSessionDirectory () {
141
+ auto ev = MakeHolder<TEvTxUserProxy::TEvProposeTransaction>();
142
+ auto & record = ev->Record ;
143
+
98
144
record.SetDatabaseName (Database);
99
145
if (UserToken) {
100
146
record.SetUserToken (UserToken->GetSerializedToken ());
@@ -105,22 +151,31 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
105
151
modifyScheme->SetWorkingDir (GetSessionDirsBasePath (Database));
106
152
modifyScheme->SetOperationType (NKikimrSchemeOp::EOperationType::ESchemeOpMkDir);
107
153
modifyScheme->SetAllowCreateInTempDir (false );
154
+
108
155
auto * makeDir = modifyScheme->MutableMkDir ();
109
156
makeDir->SetName (SessionId);
110
157
ActorIdToProto (KqpTempTablesAgentActor, modifyScheme->MutableTempDirOwnerActorId ());
111
158
159
+ NACLib::TDiffACL diffAcl;
160
+ diffAcl.RemoveAccess (
161
+ NACLib::EAccessType::Allow,
162
+ NACLib::EAccessRights::CreateDirectory | NACLib::EAccessRights::DescribeSchema,
163
+ AppData ()->AllAuthenticatedUsers );
164
+
165
+ auto * modifyAcl = modifyScheme->MutableModifyACL ();
166
+ modifyAcl->SetDiffACL (diffAcl.SerializeAsString ());
167
+
112
168
auto promise = NewPromise<IKqpGateway::TGenericResult>();
113
169
IActor* requestHandler = new TSchemeOpRequestHandler (ev.Release (), promise, false );
114
170
RegisterWithSameMailbox (requestHandler);
115
171
116
- auto actorSystem = TActivationContext:: ActorSystem ();
172
+ auto actorSystem = TlsActivationContext-> ActorSystem ();
117
173
auto selfId = SelfId ();
118
174
promise.GetFuture ().Subscribe ([actorSystem, selfId](const TFuture<IKqpGateway::TGenericResult>& future) {
119
- auto ev = MakeHolder<TEvPrivate::TEvMakeTempDirResult >();
175
+ auto ev = MakeHolder<TEvPrivate::TEvMakeSessionDirResult >();
120
176
ev->Result = future.GetValue ();
121
177
actorSystem->Send (selfId, ev.Release ());
122
178
});
123
- Become (&TKqpSchemeExecuter::ExecuteState);
124
179
}
125
180
126
181
TString GetDatabaseForLoginOperation () const {
@@ -527,6 +582,7 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
527
582
switch (ev->GetTypeRewrite ()) {
528
583
hFunc (TEvPrivate::TEvResult, HandleExecute);
529
584
hFunc (TEvPrivate::TEvMakeTempDirResult, Handle);
585
+ hFunc (TEvPrivate::TEvMakeSessionDirResult, Handle);
530
586
hFunc (TEvKqp::TEvAbortExecution, HandleAbortExecution);
531
587
hFunc (TEvTxUserProxy::TEvAllocateTxIdResult, Handle);
532
588
hFunc (TEvTxProxySchemeCache::TEvNavigateKeySetResult, Handle);
@@ -560,7 +616,17 @@ class TKqpSchemeExecuter : public TActorBootstrapped<TKqpSchemeExecuter> {
560
616
void Handle (TEvPrivate::TEvMakeTempDirResult::TPtr& result) {
561
617
if (!result->Get ()->Result .Success ()) {
562
618
InternalError (TStringBuilder ()
563
- << " Error creating temporary directory for session " << SessionId
619
+ << " Error creating temporary directory: "
620
+ << result->Get ()->Result .Issues ().ToString (true ));
621
+ }
622
+
623
+ CreateSessionDirectory ();
624
+ }
625
+
626
+ void Handle (TEvPrivate::TEvMakeSessionDirResult::TPtr& result) {
627
+ if (!result->Get ()->Result .Success ()) {
628
+ InternalError (TStringBuilder ()
629
+ << " Error creating directory for session " << SessionId
564
630
<< " : " << result->Get ()->Result .Issues ().ToString (true ));
565
631
}
566
632
MakeSchemeOperationRequest ();
0 commit comments