13
13
#include < util/folder/path.h>
14
14
#include < util/stream/file.h>
15
15
#include < util/thread/pool.h>
16
+ #include < util/generic/guid.h>
17
+ #include < util/folder/iterator.h>
18
+ #include < util/generic/vector.h>
16
19
17
20
namespace NYql ::NDq {
18
21
@@ -159,6 +162,7 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
159
162
EvCloseFileResponse = TEvDqSpillingLocalFile::EEv::LastEvent + 1 ,
160
163
EvWriteFileResponse,
161
164
EvReadFileResponse,
165
+ EvRemoveOldTmp,
162
166
163
167
LastEvent
164
168
};
@@ -189,6 +193,15 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
189
193
bool Removed = false ;
190
194
TMaybe<TString> Error;
191
195
};
196
+
197
+ struct TEvRemoveOldTmp : public TEventLocal <TEvRemoveOldTmp, EvRemoveOldTmp> {
198
+ TFsPath TmpRoot;
199
+ ui32 NodeId;
200
+ TString GuidString;
201
+
202
+ TEvRemoveOldTmp (TFsPath tmpRoot, ui32 nodeId, TString guidString)
203
+ : TmpRoot(std::move(tmpRoot)), NodeId(nodeId), GuidString(std::move(guidString)) {}
204
+ };
192
205
};
193
206
194
207
struct TFileDesc ;
@@ -206,7 +219,13 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
206
219
207
220
void Bootstrap () {
208
221
Root_ = Config_.Root ;
209
- Root_ /= (TStringBuilder () << " node_" << SelfId ().NodeId ());
222
+ const auto nodeId = SelfId ().NodeId ();
223
+ const auto guidString = TGUID::Create ().AsGuidString ();
224
+
225
+ Send (SelfId (), MakeHolder<TEvPrivate::TEvRemoveOldTmp>(Root_, nodeId, guidString));
226
+
227
+ Root_ /= (TStringBuilder () << " node_" << nodeId << " _" << guidString);
228
+ Cerr << " Root from config: " << Config_.Root << " , Root_: " << Root_ << " \n " ;
210
229
211
230
LOG_I (" Init DQ local file spilling service at " << Root_ << " , actor: " << SelfId ());
212
231
@@ -271,6 +290,7 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
271
290
hFunc(TEvPrivate::TEvWriteFileResponse, HandleWork)
272
291
hFunc(TEvDqSpilling::TEvRead, HandleWork)
273
292
hFunc(TEvPrivate::TEvReadFileResponse, HandleWork)
293
+ hFunc(TEvPrivate::TEvRemoveOldTmp, HandleWork)
274
294
hFunc(NMon::TEvHttpInfo, HandleWork)
275
295
cFunc(TEvents::TEvPoison::EventType, PassAway)
276
296
);
@@ -712,6 +732,37 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
712
732
Send (ev->Sender , new NMon::TEvHttpInfoRes (s.Str ()));
713
733
}
714
734
735
+ void HandleWork (TEvPrivate::TEvRemoveOldTmp::TPtr& ev) {
736
+ auto & msg = *ev->Get ();
737
+ auto & root = msg.TmpRoot ;
738
+ auto nodeIdString = ToString (msg.NodeId );
739
+ auto & guidString = msg.GuidString ;
740
+
741
+ LOG_I (" [RemoveOldTmp] removing at root: " << root);
742
+
743
+ TDirIterator iter (root, TDirIterator::TOptions ().SetMaxLevel (1 ));
744
+
745
+ TVector<TString> oldTmps;
746
+ for (const auto &dirEntry : iter) {
747
+ if (dirEntry.fts_info == FTS_DP) {
748
+ // skip postorder visit
749
+ continue ;
750
+ }
751
+ TString dirName = dirEntry.fts_name ;
752
+ TVector<TString> parts;
753
+ StringSplitter (dirName).Split (' _' ).Collect (&parts);
754
+
755
+ if (parts.size () == 3 && parts[0 ] == " node" && parts[1 ] == nodeIdString && parts[2 ] != guidString) {
756
+ LOG_D (" [RemoveOldTmp] found old temporary at " << (root / dirName));
757
+ oldTmps.emplace_back (std::move (dirName));
758
+ }
759
+ }
760
+
761
+ ForEach (oldTmps.begin (), oldTmps.end (), [&root](const auto & dirName) {
762
+ (root / dirName).ForceDelete ();
763
+ });
764
+ }
765
+
715
766
private:
716
767
void RunOp (TStringBuf opName, THolder<IObjectInQueue> op, TFileDesc& fd) {
717
768
if (fd.HasActiveOp ) {
0 commit comments