Skip to content

Commit 27cb50a

Browse files
author
Vladislav Lukachik
committed
Move removing to event handler
1 parent da6f670 commit 27cb50a

File tree

1 file changed

+46
-28
lines changed

1 file changed

+46
-28
lines changed

ydb/library/yql/dq/actors/spilling/spilling_file.cpp

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
162162
EvCloseFileResponse = TEvDqSpillingLocalFile::EEv::LastEvent + 1,
163163
EvWriteFileResponse,
164164
EvReadFileResponse,
165+
EvRemoveOldTmp,
165166

166167
LastEvent
167168
};
@@ -192,6 +193,15 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
192193
bool Removed = false;
193194
TMaybe<TString> Error;
194195
};
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+
};
195205
};
196206

197207
struct TFileDesc;
@@ -209,40 +219,16 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
209219

210220
void Bootstrap() {
211221
Root_ = Config_.Root;
212-
const auto root = Root_;
213-
214-
const auto nodeIdString = ToString(SelfId().NodeId());
222+
const auto nodeId = SelfId().NodeId();
215223
const auto guidString = TGUID::Create().AsGuidString();
216224

217-
Root_ /= (TStringBuilder() << "node_" << nodeIdString << "_" << guidString);
225+
Send(SelfId(), MakeHolder<TEvPrivate::TEvRemoveOldTmp>(Root_, nodeId, guidString));
226+
227+
Root_ /= (TStringBuilder() << "node_" << nodeId << "_" << guidString);
218228
Cerr << "Root from config: " << Config_.Root << ", Root_: " << Root_ << "\n";
219229

220230
LOG_I("Init DQ local file spilling service at " << Root_ << ", actor: " << SelfId());
221231

222-
{
223-
Cerr << "Traverse:\n";
224-
TDirIterator iter(root, TDirIterator::TOptions().SetMaxLevel(1));
225-
TVector<TString> old_tmps;
226-
for (const auto &dir_entry : iter) {
227-
if (dir_entry.fts_info == FTS_DP) {
228-
// skip postorder visit
229-
continue;
230-
}
231-
TString dir_name = dir_entry.fts_name;
232-
TVector<TString> parts;
233-
StringSplitter(dir_name).Split('_').Collect(&parts);
234-
235-
if (parts.size() == 3 && parts[0] == "node" && parts[1] == nodeIdString && parts[2] != guidString) {
236-
Cerr << "Found old temporary at '" << (root / dir_name) << "'\n";
237-
old_tmps.emplace_back(std::move(dir_name));
238-
}
239-
}
240-
241-
ForEach(old_tmps.begin(), old_tmps.end(), [&root](const auto& dir_name) {
242-
(root / dir_name).ForceDelete();
243-
});
244-
}
245-
246232
try {
247233
if (Root_.IsSymlink()) {
248234
throw TIoException() << Root_ << " is a symlink, can not start Spilling Service";
@@ -304,6 +290,7 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
304290
hFunc(TEvPrivate::TEvWriteFileResponse, HandleWork)
305291
hFunc(TEvDqSpilling::TEvRead, HandleWork)
306292
hFunc(TEvPrivate::TEvReadFileResponse, HandleWork)
293+
hFunc(TEvPrivate::TEvRemoveOldTmp, HandleWork)
307294
hFunc(NMon::TEvHttpInfo, HandleWork)
308295
cFunc(TEvents::TEvPoison::EventType, PassAway)
309296
);
@@ -745,6 +732,37 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
745732
Send(ev->Sender, new NMon::TEvHttpInfoRes(s.Str()));
746733
}
747734

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+
748766
private:
749767
void RunOp(TStringBuf opName, THolder<IObjectInQueue> op, TFileDesc& fd) {
750768
if (fd.HasActiveOp) {

0 commit comments

Comments
 (0)