@@ -15,7 +15,7 @@ TSchemePrinterBase::TSchemePrinterBase(const TDriver& driver, TSettings&& settin
1515{}
1616
1717void TSchemePrinterBase::Print () {
18- PrintDirectoryRecursive (Settings.Path , " " );
18+ PrintDirectoryRecursive (Settings.Path , " " ). GetValueSync () ;
1919}
2020
2121bool TSchemePrinterBase::IsDirectoryLike (const NScheme::TSchemeEntry& entry) {
@@ -24,30 +24,41 @@ bool TSchemePrinterBase::IsDirectoryLike(const NScheme::TSchemeEntry& entry) {
2424 || entry.Type == NScheme::ESchemeEntryType::ColumnStore;
2525}
2626
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 (
2929 fullPath,
3030 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);
3334
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+ }
3942
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+ }
4858 }
4959 }
50- }
60+ return NThreading::WaitExceptionOrAll (childFutures);
61+ });
5162}
5263
5364NTable::TDescribeTableResult TSchemePrinterBase::DescribeTable (const TString& relativePath) {
0 commit comments