|
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 |
|
@@ -206,10 +209,40 @@ class TDqLocalFileSpillingService : public TActorBootstrapped<TDqLocalFileSpilli
|
206 | 209 |
|
207 | 210 | void Bootstrap() {
|
208 | 211 | Root_ = Config_.Root;
|
209 |
| - Root_ /= (TStringBuilder() << "node_" << SelfId().NodeId()); |
| 212 | + const auto root = Root_; |
| 213 | + |
| 214 | + const auto nodeIdString = ToString(SelfId().NodeId()); |
| 215 | + const auto guidString = TGUID::Create().AsGuidString(); |
| 216 | + |
| 217 | + Root_ /= (TStringBuilder() << "node_" << nodeIdString << "_" << guidString); |
| 218 | + Cerr << "Root from config: " << Config_.Root << ", Root_: " << Root_ << "\n"; |
210 | 219 |
|
211 | 220 | LOG_I("Init DQ local file spilling service at " << Root_ << ", actor: " << SelfId());
|
212 | 221 |
|
| 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 | + |
213 | 246 | try {
|
214 | 247 | if (Root_.IsSymlink()) {
|
215 | 248 | throw TIoException() << Root_ << " is a symlink, can not start Spilling Service";
|
|
0 commit comments