Skip to content

Commit 3789bdb

Browse files
committed
Merge remote-tracking branch 'origin/candidate-9.8.x'
Signed-off-by: Gordon Smith <[email protected]> # Conflicts: # commons-hpcc/pom.xml # dfsclient/pom.xml # pom.xml # wsclient/pom.xml
2 parents 4501cc5 + 8936914 commit 3789bdb

File tree

5 files changed

+496
-163
lines changed

5 files changed

+496
-163
lines changed

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

+71-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.ArrayList;
2424
import java.util.Arrays;
2525
import java.io.BufferedInputStream;
26+
import java.io.Console;
2627
import java.io.File;
2728
import java.io.FileInputStream;
2829
import java.io.FileOutputStream;
@@ -74,6 +75,9 @@ public class FileUtility
7475
private static final int NUM_DEFAULT_THREADS = 4;
7576
static private final int DEFAULT_ACCESS_EXPIRY_SECONDS = 120;
7677

78+
static private final int DEFAULT_READ_REQUEST_SIZE = 4096;
79+
static private final int DEFAULT_READ_REQUEST_DELAY = 0;
80+
7781
private static boolean otelInitialized = false;
7882

7983
private static class TaskContext
@@ -322,6 +326,28 @@ public JSONArray generateResultsMessage()
322326
}
323327
};
324328

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+
325351
private static enum FileFormat
326352
{
327353
THOR,
@@ -548,6 +574,8 @@ private static Options getReadTestOptions()
548574
options.addOption("pass", true, "Specifies the password used to connect. Defaults to null.");
549575
options.addOption("num_threads", true, "Specifies the number of parallel to use to perform operations.");
550576
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.");
551579

552580
options.addOption(Option.builder("file_parts")
553581
.argName("_file_parts")
@@ -801,7 +829,7 @@ public void run()
801829
}
802830
}
803831

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
805833
{
806834
Runnable[] tasks = new Runnable[fileParts.length];
807835
for (int i = 0; i < tasks.length; i++)
@@ -818,7 +846,9 @@ public void run()
818846
HpccRemoteFileReader.FileReadContext readContext = new HpccRemoteFileReader.FileReadContext();
819847
readContext.parentSpan = context.getCurrentOperation().operationSpan;
820848
readContext.originalRD = recordDef;
849+
readContext.readSizeKB = readRequestSize;
821850
HpccRemoteFileReader<HPCCRecord> fileReader = new HpccRemoteFileReader<HPCCRecord>(readContext, filePart, new HPCCRecordBuilder(recordDef));
851+
fileReader.getInputStream().setReadRequestDelay(readRequestDelay);
822852

823853
while (fileReader.hasNext())
824854
{
@@ -1198,8 +1228,10 @@ private static void performRead(String[] args, TaskContext context)
11981228
}
11991229

12001230
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];
12031235

12041236
String outputPath = cmd.getOptionValue("out",".");
12051237

@@ -1376,8 +1408,10 @@ private static void performReadTest(String[] args, TaskContext context)
13761408
}
13771409

13781410
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];
13811415

13821416
String outputPath = cmd.getOptionValue("out",".");
13831417

@@ -1405,6 +1439,30 @@ private static void performReadTest(String[] args, TaskContext context)
14051439
+ numThreadsStr + ", must be an integer. Defaulting to: " + DEFAULT_ACCESS_EXPIRY_SECONDS + "s.");
14061440
}
14071441

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+
14081466
String formatStr = cmd.getOptionValue("format");
14091467
if (formatStr == null)
14101468
{
@@ -1477,6 +1535,7 @@ private static void performReadTest(String[] args, TaskContext context)
14771535
context.addWarn("InvalidParams: Skipping invalid file part index: " + filePartsStrs[i]);
14781536
}
14791537
}
1538+
fileParts = filePartList.toArray(new DataPartition[0]);
14801539
}
14811540

14821541
Runnable[] tasks = null;
@@ -1485,7 +1544,7 @@ private static void performReadTest(String[] args, TaskContext context)
14851544
switch (format)
14861545
{
14871546
case THOR:
1488-
tasks = createReadTestTasks(fileParts, recordDef, context);
1547+
tasks = createReadTestTasks(fileParts, recordDef, context, readRequestSize, readRequestDelay);
14891548
break;
14901549
case PARQUET:
14911550
default:
@@ -1560,8 +1619,9 @@ private static void performCopy(String[] args, TaskContext context)
15601619
+ numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads.");
15611620
}
15621621

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];
15651625

15661626
String destClusterName = cmd.getOptionValue("dest_cluster");
15671627

@@ -1741,8 +1801,9 @@ private static void performWrite(String[] args, TaskContext context)
17411801
+ numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads.");
17421802
}
17431803

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];
17461807

17471808
String destClusterName = cmd.getOptionValue("dest_cluster");
17481809

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

+32-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.opentelemetry.api.common.AttributeKey;
2222
import io.opentelemetry.api.common.Attributes;
2323
import io.opentelemetry.api.trace.Span;
24+
import io.opentelemetry.api.trace.StatusCode;
2425
import io.opentelemetry.semconv.ServerAttributes;
2526

2627
import org.apache.logging.log4j.Logger;
@@ -142,8 +143,9 @@ public HPCCRemoteFileWriter(FileWriteContext ctx, DataPartition dp, IRecordAcces
142143

143144
this.recordAccessor = recordAccessor;
144145

145-
this.writeSpanName = "HPCCRemoteFileWriter.RowService/Write_" + dp.getFileName() + "_" + dp.getThisPart();
146+
this.writeSpanName = "HPCCRemoteFileWriter/Write_" + dp.getFileName() + "_" + dp.getThisPart();
146147
this.writeSpan = Utils.createChildSpan(context.parentSpan, writeSpanName);
148+
this.writeSpan.setStatus(StatusCode.OK);
147149

148150
String primaryIP = dp.getCopyIP(0);
149151
String secondaryIP = "";
@@ -154,7 +156,7 @@ public HPCCRemoteFileWriter(FileWriteContext ctx, DataPartition dp, IRecordAcces
154156

155157
Attributes attributes = Attributes.of( AttributeKey.stringKey("server.0.address"), primaryIP,
156158
AttributeKey.stringKey("server.1.address"), secondaryIP,
157-
ServerAttributes.SERVER_PORT, Long.valueOf(dp.getPort()));
159+
AttributeKey.stringKey("server.port"), Integer.toString(dp.getPort()));
158160
writeSpan.setAllAttributes(attributes);
159161

160162
this.outputStream = new RowServiceOutputStream(dataPartition.getCopyIP(0), dataPartition.getPort(), dataPartition.getUseSsl(),
@@ -181,8 +183,20 @@ public HPCCRemoteFileWriter(FileWriteContext ctx, DataPartition dp, IRecordAcces
181183
*/
182184
public void writeRecord(T record) throws Exception
183185
{
184-
this.binaryRecordWriter.writeRecord(record);
185-
this.recordsWritten++;
186+
try
187+
{
188+
this.binaryRecordWriter.writeRecord(record);
189+
this.recordsWritten++;
190+
}
191+
catch (Exception e)
192+
{
193+
log.error("HPCCRemoteFileWriter: Error writing record: " + e.getMessage());
194+
this.writeSpan.recordException(e);
195+
this.writeSpan.setStatus(StatusCode.ERROR);
196+
this.writeSpan.end();
197+
198+
throw e;
199+
}
186200
}
187201

188202
/**
@@ -197,7 +211,20 @@ public void writeRecords(Iterator<T> it) throws Exception
197211
{
198212
while (it.hasNext())
199213
{
200-
this.binaryRecordWriter.writeRecord(it.next());
214+
try
215+
{
216+
this.binaryRecordWriter.writeRecord(it.next());
217+
this.recordsWritten++;
218+
}
219+
catch (Exception e)
220+
{
221+
log.error("HPCCRemoteFileWriter: Error writing record: " + e.getMessage());
222+
this.writeSpan.recordException(e);
223+
this.writeSpan.setStatus(StatusCode.ERROR);
224+
this.writeSpan.end();
225+
226+
throw e;
227+
}
201228
this.recordsWritten++;
202229
}
203230
}

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

+46-25
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.opentelemetry.api.common.AttributeKey;
2222
import io.opentelemetry.api.common.Attributes;
2323
import io.opentelemetry.api.trace.Span;
24+
import io.opentelemetry.api.trace.StatusCode;
2425
import io.opentelemetry.semconv.ServerAttributes;
2526

2627
import org.apache.logging.log4j.Logger;
@@ -73,6 +74,7 @@ public static class FileReadContext
7374
public int recordReadLimit = -1;
7475
public boolean createPrefetchThread = true;
7576
public int readSizeKB = -1;
77+
public int readRequestSpanBatchSize = -1; // The number of read requests before creating a new span
7678
public Span parentSpan = null;
7779
};
7880

@@ -266,21 +268,7 @@ public HpccRemoteFileReader(FileReadContext ctx, DataPartition dp, IRecordBuilde
266268
this.dataPartition = dp;
267269
this.recordBuilder = recBuilder;
268270

269-
String readSpanName = "HPCCRemoteFileReader.RowService/Read_" + dataPartition.getFileName() + "_" + dataPartition.getThisPart();
270-
this.readSpan = Utils.createChildSpan(context.parentSpan, readSpanName);
271-
272-
String primaryIP = dp.getCopyIP(0);
273-
String secondaryIP = "";
274-
if (dp.getCopyCount() > 1)
275-
{
276-
secondaryIP = dp.getCopyIP(1);
277-
}
278-
279-
Attributes attributes = Attributes.of( AttributeKey.stringKey("server.0.address"), primaryIP,
280-
AttributeKey.stringKey("server.1.address"), secondaryIP,
281-
ServerAttributes.SERVER_PORT, Long.valueOf(dp.getPort()),
282-
AttributeKey.longKey("read.size"), Long.valueOf(context.readSizeKB*1000));
283-
this.readSpan.setAllAttributes(attributes);
271+
this.readSpan = createReadSpan(ctx, dp);
284272

285273
if (context.originalRD == null)
286274
{
@@ -304,6 +292,7 @@ public HpccRemoteFileReader(FileReadContext ctx, DataPartition dp, IRecordBuilde
304292
this.inputStream = new RowServiceInputStream(this.dataPartition, context.originalRD, projectedRecordDefinition, context.connectTimeout,
305293
context.recordReadLimit, context.createPrefetchThread, context.readSizeKB, null,
306294
false, context.socketOpTimeoutMS, this.readSpan);
295+
this.inputStream.setReadRequestSpanBatchSize(context.readRequestSpanBatchSize);
307296
this.binaryRecordReader = new BinaryRecordReader(this.inputStream);
308297
this.binaryRecordReader.initialize(this.recordBuilder);
309298

@@ -321,13 +310,15 @@ public HpccRemoteFileReader(FileReadContext ctx, DataPartition dp, IRecordBuilde
321310
this.inputStream = new RowServiceInputStream(this.dataPartition, context.originalRD, projectedRecordDefinition, context.connectTimeout,
322311
context.recordReadLimit, context.createPrefetchThread, context.readSizeKB, restartInfo,
323312
false, context.socketOpTimeoutMS, this.readSpan);
313+
this.inputStream.setReadRequestSpanBatchSize(context.readRequestSpanBatchSize);
324314

325315
long bytesToSkip = resumeInfo.recordReaderStreamPos - resumeInfo.inputStreamPos;
326316
if (bytesToSkip < 0)
327317
{
328318
Exception e = new Exception("Unable to restart read stream, unexpected stream position in record reader.");
329319
this.readSpan.recordException(e);
330320
this.readSpan.end();
321+
throw e;
331322
}
332323
this.inputStream.skip(bytesToSkip);
333324

@@ -344,6 +335,35 @@ public HpccRemoteFileReader(FileReadContext ctx, DataPartition dp, IRecordBuilde
344335
openTimeMs = System.currentTimeMillis();
345336
}
346337

338+
private static Span createReadSpan(FileReadContext context, DataPartition dp)
339+
{
340+
String readSpanName = "HPCCRemoteFileReader/Read_" + dp.getFileName() + "_" + dp.getThisPart();
341+
Span readSpan = Utils.createChildSpan(context.parentSpan, readSpanName);
342+
readSpan.setStatus(StatusCode.OK);
343+
344+
String primaryIP = dp.getCopyIP(0);
345+
String secondaryIP = "";
346+
if (dp.getCopyCount() > 1)
347+
{
348+
secondaryIP = dp.getCopyIP(1);
349+
}
350+
351+
long readSize = context.readSizeKB;
352+
if (readSize < 0)
353+
{
354+
readSize = RowServiceInputStream.DEFAULT_MAX_READ_SIZE_KB;
355+
}
356+
readSize *= 1000;
357+
358+
Attributes attributes = Attributes.of( AttributeKey.stringKey("server.0.address"), primaryIP,
359+
AttributeKey.stringKey("server.1.address"), secondaryIP,
360+
AttributeKey.stringKey("server.port"), Integer.toString(dp.getPort()),
361+
AttributeKey.longKey("read.size"), Long.valueOf(readSize));
362+
readSpan.setAllAttributes(attributes);
363+
364+
return readSpan;
365+
}
366+
347367
private boolean retryRead()
348368
{
349369
if (retryCount < maxReadRetries)
@@ -364,20 +384,12 @@ private boolean retryRead()
364384

365385
try
366386
{
367-
String readSpanName = "HPCCRemoteFileReader.RowService/Read_" + dataPartition.getFileName() + "_" + dataPartition.getThisPart();
368-
if (context.parentSpan != null)
369-
{
370-
this.readSpan = Utils.createChildSpan(context.parentSpan, readSpanName);
371-
}
372-
else
373-
{
374-
this.readSpan = Utils.createSpan(readSpanName);
375-
}
387+
this.readSpan = createReadSpan(context, dataPartition);
376388

377389
this.inputStream = new RowServiceInputStream(this.dataPartition, context.originalRD,this.recordBuilder.getRecordDefinition(),
378390
context.connectTimeout, context.recordReadLimit, context.createPrefetchThread,
379391
context.readSizeKB, restartInfo, false, context.socketOpTimeoutMS, this.readSpan);
380-
392+
this.inputStream.setReadRequestSpanBatchSize(context.readRequestSpanBatchSize);
381393
long bytesToSkip = resumeInfo.recordReaderStreamPos - resumeInfo.inputStreamPos;
382394
if (bytesToSkip < 0)
383395
{
@@ -391,6 +403,7 @@ private boolean retryRead()
391403
catch (Exception e)
392404
{
393405
this.readSpan.recordException(e);
406+
this.readSpan.setStatus(StatusCode.ERROR);
394407
this.readSpan.end();
395408
log.error("Failed to retry read for " + this.dataPartition.toString() + " " + e.getMessage(), e);
396409
return false;
@@ -529,6 +542,10 @@ public boolean hasNext()
529542
}
530543
catch (HpccFileException e)
531544
{
545+
this.readSpan.recordException(e);
546+
this.readSpan.setStatus(StatusCode.ERROR);
547+
this.readSpan.end();
548+
532549
if (!retryRead())
533550
{
534551
canReadNext = false;
@@ -564,6 +581,10 @@ public T next()
564581
}
565582
catch (HpccFileException e)
566583
{
584+
this.readSpan.recordException(e);
585+
this.readSpan.setStatus(StatusCode.ERROR);
586+
this.readSpan.end();
587+
567588
if (!retryRead())
568589
{
569590
log.error("Read failure for " + this.dataPartition.toString() + " " + e.getMessage(), e);

0 commit comments

Comments
 (0)