23
23
import java .util .ArrayList ;
24
24
import java .util .Arrays ;
25
25
import java .io .BufferedInputStream ;
26
+ import java .io .Console ;
26
27
import java .io .File ;
27
28
import java .io .FileInputStream ;
28
29
import java .io .FileOutputStream ;
@@ -74,6 +75,9 @@ public class FileUtility
74
75
private static final int NUM_DEFAULT_THREADS = 4 ;
75
76
static private final int DEFAULT_ACCESS_EXPIRY_SECONDS = 120 ;
76
77
78
+ static private final int DEFAULT_READ_REQUEST_SIZE = 4096 ;
79
+ static private final int DEFAULT_READ_REQUEST_DELAY = 0 ;
80
+
77
81
private static boolean otelInitialized = false ;
78
82
79
83
private static class TaskContext
@@ -322,6 +326,28 @@ public JSONArray generateResultsMessage()
322
326
}
323
327
};
324
328
329
+ private static String [] getCredentials (CommandLine cmd )
330
+ {
331
+ Console console = System .console ();
332
+
333
+ String user = cmd .getOptionValue ("user" );
334
+ boolean userIsEmpty = user == null || user .isEmpty ();
335
+ if (userIsEmpty )
336
+ {
337
+ user = new String (console .readLine ("Enter username: " ));
338
+ userIsEmpty = user == null || user .isEmpty ();
339
+ }
340
+
341
+ String pass = cmd .getOptionValue ("pass" );
342
+ boolean passIsEmpty = pass == null || pass .isEmpty ();
343
+ if (!userIsEmpty && passIsEmpty )
344
+ {
345
+ pass = new String (console .readPassword ("Enter password for " + user + ": " ));
346
+ }
347
+
348
+ return new String [] {user , pass };
349
+ }
350
+
325
351
private static enum FileFormat
326
352
{
327
353
THOR ,
@@ -548,6 +574,8 @@ private static Options getReadTestOptions()
548
574
options .addOption ("pass" , true , "Specifies the password used to connect. Defaults to null." );
549
575
options .addOption ("num_threads" , true , "Specifies the number of parallel to use to perform operations." );
550
576
options .addOption ("access_expiry_seconds" , true , "Access token expiration seconds." );
577
+ options .addOption ("read_request_size" , true , "The size of the read requests in KB sent to the rowservice." );
578
+ options .addOption ("read_request_delay" , true , "The delay in MS between read requests sent to the rowservice." );
551
579
552
580
options .addOption (Option .builder ("file_parts" )
553
581
.argName ("_file_parts" )
@@ -801,7 +829,7 @@ public void run()
801
829
}
802
830
}
803
831
804
- private static Runnable [] createReadTestTasks (DataPartition [] fileParts , FieldDef recordDef , TaskContext context ) throws Exception
832
+ private static Runnable [] createReadTestTasks (DataPartition [] fileParts , FieldDef recordDef , TaskContext context , int readRequestSize , int readRequestDelay ) throws Exception
805
833
{
806
834
Runnable [] tasks = new Runnable [fileParts .length ];
807
835
for (int i = 0 ; i < tasks .length ; i ++)
@@ -818,7 +846,9 @@ public void run()
818
846
HpccRemoteFileReader .FileReadContext readContext = new HpccRemoteFileReader .FileReadContext ();
819
847
readContext .parentSpan = context .getCurrentOperation ().operationSpan ;
820
848
readContext .originalRD = recordDef ;
849
+ readContext .readSizeKB = readRequestSize ;
821
850
HpccRemoteFileReader <HPCCRecord > fileReader = new HpccRemoteFileReader <HPCCRecord >(readContext , filePart , new HPCCRecordBuilder (recordDef ));
851
+ fileReader .getInputStream ().setReadRequestDelay (readRequestDelay );
822
852
823
853
while (fileReader .hasNext ())
824
854
{
@@ -1198,8 +1228,10 @@ private static void performRead(String[] args, TaskContext context)
1198
1228
}
1199
1229
1200
1230
String connString = cmd .getOptionValue ("url" );
1201
- String user = cmd .getOptionValue ("user" );
1202
- String pass = cmd .getOptionValue ("pass" );
1231
+
1232
+ String [] creds = getCredentials (cmd );
1233
+ String user = creds [0 ];
1234
+ String pass = creds [1 ];
1203
1235
1204
1236
String outputPath = cmd .getOptionValue ("out" ,"." );
1205
1237
@@ -1376,8 +1408,10 @@ private static void performReadTest(String[] args, TaskContext context)
1376
1408
}
1377
1409
1378
1410
String connString = cmd .getOptionValue ("url" );
1379
- String user = cmd .getOptionValue ("user" );
1380
- String pass = cmd .getOptionValue ("pass" );
1411
+
1412
+ String [] creds = getCredentials (cmd );
1413
+ String user = creds [0 ];
1414
+ String pass = creds [1 ];
1381
1415
1382
1416
String outputPath = cmd .getOptionValue ("out" ,"." );
1383
1417
@@ -1405,6 +1439,30 @@ private static void performReadTest(String[] args, TaskContext context)
1405
1439
+ numThreadsStr + ", must be an integer. Defaulting to: " + DEFAULT_ACCESS_EXPIRY_SECONDS + "s." );
1406
1440
}
1407
1441
1442
+ int readRequestSize = DEFAULT_READ_REQUEST_SIZE ;
1443
+ String readRequestSizeStr = cmd .getOptionValue ("read_request_size" , "" + readRequestSize );
1444
+ try
1445
+ {
1446
+ readRequestSize = Integer .parseInt (readRequestSizeStr );
1447
+ }
1448
+ catch (Exception e )
1449
+ {
1450
+ System .out .println ("Invalid option value for read_request_size: "
1451
+ + readRequestSizeStr + ", must be an integer. Defaulting to: " + DEFAULT_READ_REQUEST_SIZE + "KB." );
1452
+ }
1453
+
1454
+ int readRequestDelay = DEFAULT_READ_REQUEST_DELAY ;
1455
+ String readRequestDelayStr = cmd .getOptionValue ("read_request_delay" , "" + readRequestDelay );
1456
+ try
1457
+ {
1458
+ readRequestDelay = Integer .parseInt (readRequestDelayStr );
1459
+ }
1460
+ catch (Exception e )
1461
+ {
1462
+ System .out .println ("Invalid option value for read_request_delay: "
1463
+ + readRequestDelayStr + ", must be an integer. Defaulting to: " + DEFAULT_READ_REQUEST_DELAY + "ms." );
1464
+ }
1465
+
1408
1466
String formatStr = cmd .getOptionValue ("format" );
1409
1467
if (formatStr == null )
1410
1468
{
@@ -1477,6 +1535,7 @@ private static void performReadTest(String[] args, TaskContext context)
1477
1535
context .addWarn ("InvalidParams: Skipping invalid file part index: " + filePartsStrs [i ]);
1478
1536
}
1479
1537
}
1538
+ fileParts = filePartList .toArray (new DataPartition [0 ]);
1480
1539
}
1481
1540
1482
1541
Runnable [] tasks = null ;
@@ -1485,7 +1544,7 @@ private static void performReadTest(String[] args, TaskContext context)
1485
1544
switch (format )
1486
1545
{
1487
1546
case THOR :
1488
- tasks = createReadTestTasks (fileParts , recordDef , context );
1547
+ tasks = createReadTestTasks (fileParts , recordDef , context , readRequestSize , readRequestDelay );
1489
1548
break ;
1490
1549
case PARQUET :
1491
1550
default :
@@ -1560,8 +1619,9 @@ private static void performCopy(String[] args, TaskContext context)
1560
1619
+ numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads." );
1561
1620
}
1562
1621
1563
- String user = cmd .getOptionValue ("user" );
1564
- String pass = cmd .getOptionValue ("pass" );
1622
+ String [] creds = getCredentials (cmd );
1623
+ String user = creds [0 ];
1624
+ String pass = creds [1 ];
1565
1625
1566
1626
String destClusterName = cmd .getOptionValue ("dest_cluster" );
1567
1627
@@ -1741,8 +1801,9 @@ private static void performWrite(String[] args, TaskContext context)
1741
1801
+ numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads." );
1742
1802
}
1743
1803
1744
- String user = cmd .getOptionValue ("user" );
1745
- String pass = cmd .getOptionValue ("pass" );
1804
+ String [] creds = getCredentials (cmd );
1805
+ String user = creds [0 ];
1806
+ String pass = creds [1 ];
1746
1807
1747
1808
String destClusterName = cmd .getOptionValue ("dest_cluster" );
1748
1809
0 commit comments