Skip to content

Commit be177ec

Browse files
authored
HPCC4J-635 DFSClient: FileUtility add additional testing / debug options (#742)
Signed-off-by: James McMullan [email protected]
1 parent 0ced7ed commit be177ec

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public class FileUtility
7474
private static final int NUM_DEFAULT_THREADS = 4;
7575
static private final int DEFAULT_ACCESS_EXPIRY_SECONDS = 120;
7676

77+
static private final int DEFAULT_READ_REQUEST_SIZE = 4096;
78+
static private final int DEFAULT_READ_REQUEST_DELAY = 0;
79+
7780
private static boolean otelInitialized = false;
7881

7982
private static class TaskContext
@@ -548,6 +551,8 @@ private static Options getReadTestOptions()
548551
options.addOption("pass", true, "Specifies the password used to connect. Defaults to null.");
549552
options.addOption("num_threads", true, "Specifies the number of parallel to use to perform operations.");
550553
options.addOption("access_expiry_seconds", true, "Access token expiration seconds.");
554+
options.addOption("read_request_size", true, "The size of the read requests in KB sent to the rowservice.");
555+
options.addOption("read_request_delay", true, "The delay in MS between read requests sent to the rowservice.");
551556

552557
options.addOption(Option.builder("file_parts")
553558
.argName("_file_parts")
@@ -801,7 +806,7 @@ public void run()
801806
}
802807
}
803808

804-
private static Runnable[] createReadTestTasks(DataPartition[] fileParts, FieldDef recordDef, TaskContext context) throws Exception
809+
private static Runnable[] createReadTestTasks(DataPartition[] fileParts, FieldDef recordDef, TaskContext context, int readRequestSize, int readRequestDelay) throws Exception
805810
{
806811
Runnable[] tasks = new Runnable[fileParts.length];
807812
for (int i = 0; i < tasks.length; i++)
@@ -818,7 +823,9 @@ public void run()
818823
HpccRemoteFileReader.FileReadContext readContext = new HpccRemoteFileReader.FileReadContext();
819824
readContext.parentSpan = context.getCurrentOperation().operationSpan;
820825
readContext.originalRD = recordDef;
826+
readContext.readSizeKB = readRequestSize;
821827
HpccRemoteFileReader<HPCCRecord> fileReader = new HpccRemoteFileReader<HPCCRecord>(readContext, filePart, new HPCCRecordBuilder(recordDef));
828+
fileReader.getInputStream().setReadRequestDelay(readRequestDelay);
822829

823830
while (fileReader.hasNext())
824831
{
@@ -1405,6 +1412,30 @@ private static void performReadTest(String[] args, TaskContext context)
14051412
+ numThreadsStr + ", must be an integer. Defaulting to: " + DEFAULT_ACCESS_EXPIRY_SECONDS + "s.");
14061413
}
14071414

1415+
int readRequestSize = DEFAULT_READ_REQUEST_SIZE;
1416+
String readRequestSizeStr = cmd.getOptionValue("read_request_size", "" + readRequestSize);
1417+
try
1418+
{
1419+
readRequestSize = Integer.parseInt(readRequestSizeStr);
1420+
}
1421+
catch(Exception e)
1422+
{
1423+
System.out.println("Invalid option value for read_request_size: "
1424+
+ readRequestSizeStr + ", must be an integer. Defaulting to: " + DEFAULT_READ_REQUEST_SIZE + "KB.");
1425+
}
1426+
1427+
int readRequestDelay = DEFAULT_READ_REQUEST_DELAY;
1428+
String readRequestDelayStr = cmd.getOptionValue("read_request_delay", "" + readRequestDelay);
1429+
try
1430+
{
1431+
readRequestDelay = Integer.parseInt(readRequestDelayStr);
1432+
}
1433+
catch(Exception e)
1434+
{
1435+
System.out.println("Invalid option value for read_request_delay: "
1436+
+ readRequestDelayStr + ", must be an integer. Defaulting to: " + DEFAULT_READ_REQUEST_DELAY + "ms.");
1437+
}
1438+
14081439
String formatStr = cmd.getOptionValue("format");
14091440
if (formatStr == null)
14101441
{
@@ -1477,6 +1508,7 @@ private static void performReadTest(String[] args, TaskContext context)
14771508
context.addWarn("InvalidParams: Skipping invalid file part index: " + filePartsStrs[i]);
14781509
}
14791510
}
1511+
fileParts = filePartList.toArray(new DataPartition[0]);
14801512
}
14811513

14821514
Runnable[] tasks = null;
@@ -1485,7 +1517,7 @@ private static void performReadTest(String[] args, TaskContext context)
14851517
switch (format)
14861518
{
14871519
case THOR:
1488-
tasks = createReadTestTasks(fileParts, recordDef, context);
1520+
tasks = createReadTestTasks(fileParts, recordDef, context, readRequestSize, readRequestDelay);
14891521
break;
14901522
case PARQUET:
14911523
default:

dfsclient/src/main/java/org/hpccsystems/dfs/client/RowServiceInputStream.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public class RowServiceInputStream extends InputStream implements IProfilable
108108
private long mutexWaitTimeNS = 0;
109109
private long waitTimeNS = 0;
110110
private long sleepTimeNS = 0;
111+
private int readRequestDelayMS = 0;
111112
private long fetchStartTimeNS = 0;
112113
private long fetchTimeNS = 0;
113114
private long fetchFinishTimeNS = 0;
@@ -668,6 +669,15 @@ public int getHandle()
668669
return handle;
669670
}
670671

672+
/**
673+
* The delay in milliseconds between read requests. Primarily used for testing.
674+
* @param sleepTimeMS
675+
*/
676+
public void setReadRequestDelay(int sleepTimeMS)
677+
{
678+
this.readRequestDelayMS = sleepTimeMS;
679+
}
680+
671681
/**
672682
* Simulate a handle failure and use the file token instead. The handle is set to an invalid value so the THOR node
673683
* will indicate that the handle is unknown and request a otken.
@@ -1150,6 +1160,18 @@ private void finishFetch()
11501160

11511161
if (inFetchingMode == false)
11521162
{
1163+
if (readRequestDelayMS > 0)
1164+
{
1165+
try
1166+
{
1167+
Thread.sleep(readRequestDelayMS);
1168+
}
1169+
catch (InterruptedException e)
1170+
{
1171+
// We don't care about waking early
1172+
}
1173+
}
1174+
11531175
if (readSpan != null)
11541176
{
11551177
Attributes attributes = Attributes.of( AttributeKey.longKey("server.index"), Long.valueOf(getFilePartCopy()),
@@ -1158,7 +1180,6 @@ private void finishFetch()
11581180
readSpan.addEvent("RowServiceInputStream.readRequest", attributes);
11591181
}
11601182

1161-
11621183
// Create the read ahead request
11631184
if (this.simulateFail) this.handle = -1;
11641185
String readAheadRequest = (this.forceTokenUse) ? this.makeTokenRequest() : this.makeHandleRequest();

0 commit comments

Comments
 (0)