Skip to content

Commit bd1d544

Browse files
authored
Merge pull request #258 from marklogic/feature/log-progress-fix
Fixing logging of progress
2 parents d6e1e36 + e600b36 commit bd1d544

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ WriteBatcher newWriteBatcher(DataMovementManager dataMovementManager) {
102102
.newWriteBatcher()
103103
.withBatchSize(batchSize)
104104
.withThreadCount(threadCount)
105-
.withTemporalCollection(getStringOption(Options.WRITE_TEMPORAL_COLLECTION));
105+
.withTemporalCollection(getStringOption(Options.WRITE_TEMPORAL_COLLECTION))
106+
.onBatchSuccess(this::logBatchOnSuccess);
106107

107-
if (logger.isDebugEnabled()) {
108-
writeBatcher.onBatchSuccess(this::logBatchOnSuccess);
109-
}
110108
Optional<ServerTransform> transform = makeRestTransform();
111109
if (transform.isPresent()) {
112110
writeBatcher.withTransform(transform.get());
@@ -254,23 +252,26 @@ private void logBatchOnSuccess(WriteBatch batch) {
254252
WriteEvent firstEvent = batch.getItems()[0];
255253
// If the first event is the item added by DMSDK for the default metadata object, ignore it when showing
256254
// the count of documents in the batch.
257-
// the count of documents in the batch.
258255
if (firstEvent.getTargetUri() == null && firstEvent.getMetadata() != null) {
259256
docCount--;
260257
}
261258
}
262259
if (this.logProgress > 0) {
263260
logProgressIfNecessary(docCount);
264261
}
265-
logger.debug("Wrote batch; length: {}; job batch number: {}", docCount, batch.getJobBatchNumber());
262+
if (logger.isDebugEnabled()) {
263+
logger.debug("Wrote batch; length: {}; job batch number: {}", docCount, batch.getJobBatchNumber());
264+
}
266265
}
267266

268267
private void logProgressIfNecessary(int docCount) {
269268
int sum = progressTracker.addAndGet(docCount);
270-
int lowerBound = sum / (this.logProgress);
271-
int upperBound = (lowerBound * this.logProgress) + this.batchSize;
272-
if (sum >= lowerBound && sum < upperBound) {
273-
Util.MAIN_LOGGER.info("Documents written: {}", sum);
269+
if (sum >= logProgress) {
270+
int lowerBound = sum / (this.logProgress);
271+
int upperBound = (lowerBound * this.logProgress) + this.batchSize;
272+
if (sum >= lowerBound && sum < upperBound) {
273+
Util.MAIN_LOGGER.info("Documents written: {}", sum);
274+
}
274275
}
275276
}
276277

0 commit comments

Comments
 (0)