Skip to content

Commit 2f51839

Browse files
committed
MLE-17095 Fixed streaming issue where progress wasn't logged
1 parent 0de6123 commit 2f51839

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
This guide covers how to develop and test this project. It assumes that you have cloned this repository to your local
22
workstation.
33

4-
Due to the use of the Sonar plugin for Gradle, you must use Java 11 or higher for developing and testing the project.
5-
The `build.gradle` file for this project ensures that the connector is built to run on Java 8 or higher.
4+
You must use Java 11 or higher for developing, testing, and building this project.
65

76
# Setup
87

src/main/java/com/marklogic/spark/writer/WriteBatcherDataWriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ private void writeDocumentViaPutOperation(DocumentWriteOperation writeOp) {
260260
final String uri = replaceSpacesInUriForPutEndpoint(writeOp.getUri());
261261
try {
262262
this.documentManager.write(uri, writeOp.getMetadata(), (GenericWriteHandle) writeOp.getContent());
263+
writeContext.logBatchOnSuccess(1, 0);
263264
this.successItemCount.incrementAndGet();
264265
} catch (RuntimeException ex) {
265266
captureFailure(ex.getMessage(), uri);

src/main/java/com/marklogic/spark/writer/WriteContext.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,22 @@ private void addRestTransformParams(ServerTransform transform, String paramsValu
246246
}
247247

248248
private void logBatchOnSuccess(WriteBatch batch) {
249-
int docCount = batch.getItems().length;
250-
if (docCount > 0) {
249+
int documentCount = batch.getItems().length;
250+
if (documentCount > 0) {
251251
WriteEvent firstEvent = batch.getItems()[0];
252252
// If the first event is the item added by DMSDK for the default metadata object, ignore it when showing
253253
// the count of documents in the batch.
254254
if (firstEvent.getTargetUri() == null && firstEvent.getMetadata() != null) {
255-
docCount--;
255+
documentCount--;
256256
}
257257
}
258-
WriteProgressLogger.logProgressIfNecessary(docCount);
259-
if (logger.isTraceEnabled()) {
260-
logger.trace("Wrote batch; length: {}; job batch number: {}", docCount, batch.getJobBatchNumber());
258+
logBatchOnSuccess(documentCount, batch.getJobBatchNumber());
259+
}
260+
261+
public void logBatchOnSuccess(int documentCount, long optionalJobBatchNumber) {
262+
WriteProgressLogger.logProgressIfNecessary(documentCount);
263+
if (logger.isTraceEnabled() && optionalJobBatchNumber > 0) {
264+
logger.trace("Wrote batch; length: {}; job batch number: {}", documentCount, optionalJobBatchNumber);
261265
}
262266
}
263267

src/test/java/com/marklogic/spark/reader/file/ReadGenericFilesStreamingTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void stream() throws Exception {
3535

3636
defaultWrite(dataset.write().format(CONNECTOR_IDENTIFIER)
3737
.option(Options.STREAM_FILES, true)
38+
.option(Options.WRITE_LOG_PROGRESS, 1) // Included for manual verification of logging.
3839
.option(Options.WRITE_COLLECTIONS, "streamed-files")
3940
.option(Options.WRITE_URI_REPLACE, ".*/mixed-files,''"));
4041

0 commit comments

Comments
 (0)