22
22
#include " velox/common/base/Fs.h"
23
23
#include " velox/common/encode/Base64.h"
24
24
#include " velox/common/file/FileSystems.h"
25
+ #include " velox/common/file/tests/FaultyFileSystem.h"
25
26
#include " velox/connectors/hive/HiveConnector.h"
26
27
#include " velox/connectors/hive/HiveConnectorSplit.h"
27
28
#include " velox/connectors/hive/TableHandle.h"
@@ -123,7 +124,8 @@ class WriterFuzzer {
123
124
const std::vector<std::string>& bucketColumns,
124
125
int32_t sortColumnOffset,
125
126
const std::vector<std::shared_ptr<const HiveSortingColumn>>& sortBy,
126
- const std::string& outputDirectoryPath);
127
+ const std::string& outputDirectoryPath,
128
+ const bool writeErrorInjected);
127
129
128
130
// Generates table column handles based on table column properties
129
131
std::unordered_map<std::string, std::shared_ptr<connector::ColumnHandle>>
@@ -256,7 +258,8 @@ void writerFuzzer(
256
258
257
259
std::vector<std::string> listFolders (std::string_view path) {
258
260
std::vector<std::string> folders;
259
- auto fileSystem = filesystems::getFileSystem (" /" , nullptr );
261
+ auto fileSystem = std::dynamic_pointer_cast<tests::utils::FaultyFileSystem>(
262
+ filesystems::getFileSystem (" /" , nullptr ));
260
263
for (auto & p : std::filesystem::recursive_directory_iterator (
261
264
fileSystem->extractPath (path))) {
262
265
if (p.is_directory ())
@@ -340,7 +343,26 @@ void WriterFuzzer::go() {
340
343
}
341
344
auto input = generateInputData (names, types, partitionOffset);
342
345
343
- auto tempDirPath = exec::test::TempDirectoryPath::create ();
346
+ auto tempDirPath = exec::test::TempDirectoryPath::create (true );
347
+
348
+ bool writeErrorInjected = false ;
349
+ auto fs = std::dynamic_pointer_cast<tests::utils::FaultyFileSystem>(
350
+ filesystems::getFileSystem (tempDirPath->getPath (), {}));
351
+ if (partitionKeys.empty () && vectorFuzzer_.coinToss (1 )) {
352
+ fs->setFileInjectionError (
353
+ std::make_exception_ptr (VeloxRuntimeError (
354
+ " file_name" ,
355
+ 1 ,
356
+ " function_name()" ,
357
+ " operator()" ,
358
+ " test message" ,
359
+ " " ,
360
+ error_code::kArithmeticError ,
361
+ false )),
362
+ {tests::utils::FaultFileOperation::Type::kWrite });
363
+ writeErrorInjected = true ;
364
+ }
365
+
344
366
verifyWriter (
345
367
input,
346
368
names,
@@ -351,7 +373,10 @@ void WriterFuzzer::go() {
351
373
bucketColumns,
352
374
sortColumnOffset,
353
375
sortBy,
354
- tempDirPath->getPath ());
376
+ tempDirPath->getPath (),
377
+ writeErrorInjected);
378
+
379
+ fs->clearFileFaultInjections ();
355
380
356
381
LOG (INFO) << " ==============================> Done with iteration "
357
382
<< iteration++;
@@ -423,7 +448,8 @@ void WriterFuzzer::verifyWriter(
423
448
const std::vector<std::string>& bucketColumns,
424
449
const int32_t sortColumnOffset,
425
450
const std::vector<std::shared_ptr<const HiveSortingColumn>>& sortBy,
426
- const std::string& outputDirectoryPath) {
451
+ const std::string& outputDirectoryPath,
452
+ const bool writeErrorInjected) {
427
453
const auto plan = PlanBuilder ()
428
454
.values (input)
429
455
.tableWrite (
@@ -436,7 +462,14 @@ void WriterFuzzer::verifyWriter(
436
462
437
463
const auto maxDrivers =
438
464
boost::random ::uniform_int_distribution<int32_t >(1 , 16 )(rng_);
439
- const auto result = veloxToPrestoResult (execute (plan, maxDrivers));
465
+ RowVectorPtr result;
466
+ try {
467
+ result = veloxToPrestoResult (execute (plan, maxDrivers));
468
+ } catch (VeloxRuntimeError&) {
469
+ VELOX_CHECK (
470
+ writeErrorInjected, " write plan failed with no writeErrorInjected" );
471
+ return ;
472
+ }
440
473
441
474
const auto dropSql = " DROP TABLE IF EXISTS tmp_write" ;
442
475
const auto sql = referenceQueryRunner_->toSql (plan).value ();
@@ -661,7 +694,8 @@ void WriterFuzzer::comparePartitionAndBucket(
661
694
// static
662
695
std::map<std::string, int32_t > WriterFuzzer::getPartitionNameAndFilecount (
663
696
const std::string& tableDirectoryPath) {
664
- auto fileSystem = filesystems::getFileSystem (" /" , nullptr );
697
+ auto fileSystem = std::dynamic_pointer_cast<tests::utils::FaultyFileSystem>(
698
+ filesystems::getFileSystem (" /" , nullptr ));
665
699
auto directories = listFolders (tableDirectoryPath);
666
700
std::map<std::string, int32_t > partitionNameAndFileCount;
667
701
0 commit comments