@@ -15,7 +15,7 @@ TSchemePrinterBase::TSchemePrinterBase(const TDriver& driver, TSettings&& settin
15
15
{}
16
16
17
17
void TSchemePrinterBase::Print () {
18
- PrintDirectoryRecursive (Settings.Path , " " );
18
+ PrintDirectoryRecursive (Settings.Path , " " ). GetValueSync () ;
19
19
}
20
20
21
21
bool TSchemePrinterBase::IsDirectoryLike (const NScheme::TSchemeEntry& entry) {
@@ -24,30 +24,41 @@ bool TSchemePrinterBase::IsDirectoryLike(const NScheme::TSchemeEntry& entry) {
24
24
|| entry.Type == NScheme::ESchemeEntryType::ColumnStore;
25
25
}
26
26
27
- void TSchemePrinterBase::PrintDirectoryRecursive (const TString& fullPath, const TString& relativePath) {
28
- NScheme::TListDirectoryResult result = SchemeClient.ListDirectory (
27
+ NThreading::TFuture< void > TSchemePrinterBase::PrintDirectoryRecursive (const TString& fullPath, const TString& relativePath) {
28
+ return SchemeClient.ListDirectory (
29
29
fullPath,
30
30
Settings.ListDirectorySettings
31
- ).GetValueSync ();
32
- ThrowOnError (result);
31
+ ).Apply ([this , fullPath, relativePath](const NScheme::TAsyncListDirectoryResult& resultFuture) {
32
+ const auto & result = resultFuture.GetValueSync ();
33
+ ThrowOnError (result);
33
34
34
- if (relativePath || IsDirectoryLike (result.GetEntry ())) {
35
- PrintDirectory (relativePath, result);
36
- } else {
37
- PrintEntry (relativePath, result.GetEntry ());
38
- }
35
+ if (relativePath || IsDirectoryLike (result.GetEntry ())) {
36
+ std::lock_guard g (Lock);
37
+ PrintDirectory (relativePath, result);
38
+ } else {
39
+ std::lock_guard g (Lock);
40
+ PrintEntry (relativePath, result.GetEntry ());
41
+ }
39
42
40
- if (Settings.Recursive ) {
41
- for (const auto & child : result.GetChildren ()) {
42
- TString childRelativePath = relativePath + (relativePath ? " /" : " " ) + child.Name ;
43
- TString childFullPath = fullPath + " /" + child.Name ;
44
- if (IsDirectoryLike (child)) {
45
- PrintDirectoryRecursive (childFullPath, childRelativePath);
46
- } else {
47
- PrintEntry (childRelativePath, child);
43
+ TVector<NThreading::TFuture<void >> childFutures;
44
+ if (Settings.Recursive ) {
45
+ for (const auto & child : result.GetChildren ()) {
46
+ TString childRelativePath = relativePath + (relativePath ? " /" : " " ) + child.Name ;
47
+ TString childFullPath = fullPath + " /" + child.Name ;
48
+ if (IsDirectoryLike (child)) {
49
+ childFutures.push_back (PrintDirectoryRecursive (childFullPath, childRelativePath));
50
+ if (!Settings.Multithread ) {
51
+ childFutures.back ().Wait ();
52
+ childFutures.back ().TryRethrow ();
53
+ }
54
+ } else {
55
+ std::lock_guard g (Lock);
56
+ PrintEntry (childRelativePath, child);
57
+ }
48
58
}
49
59
}
50
- }
60
+ return NThreading::WaitExceptionOrAll (childFutures);
61
+ });
51
62
}
52
63
53
64
NTable::TDescribeTableResult TSchemePrinterBase::DescribeTable (const TString& relativePath) {
0 commit comments