@@ -161,22 +161,34 @@ class TWorkloadCommandImport::TUploadCommand::TFileWriter: public IWriter {
161
161
void TWorkloadCommandImport::TUploadCommand::ProcessDataGenerator (std::shared_ptr<NYdbWorkload::IBulkDataGenerator> dataGen) noexcept try {
162
162
TAtomic counter = 0 ;
163
163
for (auto portions = dataGen->GenerateDataPortion (); !portions.empty () && !AtomicGet (ErrorsCount); portions = dataGen->GenerateDataPortion ()) {
164
+ TVector<TAsyncStatus> sendingResults;
164
165
for (const auto & data: portions) {
165
166
AtomicIncrement (counter);
166
- Writer->WriteDataPortion (data).Apply (
167
- [data, this , &counter, g = MakeAtomicShared<TGuard<TFastSemaphore>>(*InFlightSemaphore)](const TAsyncStatus& result) {
168
- const auto & res = result.GetValueSync ();
169
- data->SetSendResult (res);
170
- auto guard = Guard (Lock);
171
- if (!res.IsSuccess ()) {
172
- Cerr << " Bulk upset to " << data->GetTable () << " failed, " << res.GetStatus () << " , " << res.GetIssues ().ToString () << Endl;
173
- AtomicIncrement (ErrorsCount);
174
- } else if (data->GetSize ()) {
175
- Bar->AddProgress (data->GetSize ());
176
- }
177
- AtomicDecrement (counter);
178
- });
167
+ sendingResults.emplace_back (Writer->WriteDataPortion (data).Apply ([&counter, g = MakeAtomicShared<TGuard<TFastSemaphore>>(*InFlightSemaphore)](const TAsyncStatus& result) {
168
+ AtomicDecrement (counter);
169
+ return result.GetValueSync ();
170
+ }));
179
171
}
172
+ NThreading::WaitAll (sendingResults).Apply ([this , sendingResults, portions](const NThreading::TFuture<void >&) {
173
+ bool success = true ;
174
+ for (size_t i = 0 ; i < portions.size (); ++i) {
175
+ const auto & data = portions[i];
176
+ const auto & res = sendingResults[i].GetValueSync ();
177
+ auto guard = Guard (Lock);
178
+ if (!res.IsSuccess ()) {
179
+ Cerr << " Bulk upset to " << data->GetTable () << " failed, " << res.GetStatus () << " , " << res.GetIssues ().ToString () << Endl;
180
+ AtomicIncrement (ErrorsCount);
181
+ success = false ;
182
+ } else if (data->GetSize ()) {
183
+ Bar->AddProgress (data->GetSize ());
184
+ }
185
+ }
186
+ if (success) {
187
+ for (size_t i = 0 ; i < portions.size (); ++i) {
188
+ portions[i]->SetSendResult (sendingResults[i].GetValueSync ());
189
+ }
190
+ }
191
+ });
180
192
if (AtomicGet (ErrorsCount)) {
181
193
break ;
182
194
}
0 commit comments