Source:
<code>private void replicate() throws DatabaseNotFoundException, ExecutionException, InterruptedException, DocumentException, DocumentStoreException { logger.info("Pull replication started"); long startTime = System.currentTimeMillis(); if (this.state.cancel) { return; } if (!this.sourceDb.exists()) { throw new DatabaseNotFoundException( "Database not found " + this.sourceDb.getIdentifier()); } this.state.documentCounter = 0; <START> while(!this.state.cancel) { <END> this.state.batchCounter++; String msg = String.format( "Batch %s started (completed %s changes so far)", this.state.batchCounter, this.state.documentCounter ); logger.info(msg); long batchStartTime = System.currentTimeMillis(); ChangesResultWrapper changeFeeds = this.nextBatch(); int batchChangesProcessed = 0; msg = String.format( "Batch %s contains %s changes", this.state.batchCounter, changeFeeds.size() ); logger.info(msg); if (changeFeeds.size() > 0) { batchChangesProcessed = processOneChangesBatch(changeFeeds); state.documentCounter += batchChangesProcessed; } long batchEndTime = System.currentTimeMillis(); msg = String.format( "Batch %s completed in %sms (batch was %s changes)", this.state.batchCounter, batchEndTime - batchStartTime, batchChangesProcessed ); logger.info(msg); if (changeFeeds.size() < this.changeLimitPerBatch) { break; } } long endTime = System.currentTimeMillis(); long deltaTime = endTime - startTime; String msg = String.format( "Pull completed in %sms (%s total changes processed)", deltaTime, this.state.documentCounter ); logger.info(msg); }</code><technical_language>This change while loop means if replication cancelled, get logging loop indicating pull completed, prove misleading debugging logs</technical_language>

Target:
private void replicate() throws DatabaseNotFoundException, ExecutionException, InterruptedException, DocumentException, DocumentStoreException { logger.info("Pull replication started"); long startTime = System.currentTimeMillis(); if (this.state.cancel) { return; } if (!this.sourceDb.exists()) { throw new DatabaseNotFoundException( "Database not found " + this.sourceDb.getIdentifier()); } this.state.documentCounter = 0; while(!this.state.cancel) { this.state.batchCounter++; String msg = String.format( "Batch %s started (completed %s changes so far)", this.state.batchCounter, this.state.documentCounter ); logger.info(msg); long batchStartTime = System.currentTimeMillis(); ChangesResultWrapper changeFeeds = this.nextBatch(); int batchChangesProcessed = 0; msg = String.format( "Batch %s contains %s changes", this.state.batchCounter, changeFeeds.size() ); logger.info(msg); if (changeFeeds.size() > 0) { batchChangesProcessed = processOneChangesBatch(changeFeeds); state.documentCounter += batchChangesProcessed; } long batchEndTime = System.currentTimeMillis(); msg = String.format( "Batch %s completed in %sms (batch was %s changes)", this.state.batchCounter, batchEndTime - batchStartTime, batchChangesProcessed ); logger.info(msg); if (changeFeeds.size() < this.changeLimitPerBatch) { break; } } long endTime = System.currentTimeMillis(); long deltaTime = endTime - startTime; String msg; if (this.state.cancel) { msg = String.format(Locale.ENGLISH, "Pull canceled after %sms (%s changes processed)", deltaTime, this.state.documentCounter); } else { msg = String.format(Locale.ENGLISH, "Pull completed in %sms (%s total changes processed)", deltaTime, this.state.documentCounter ); } logger.info(msg); }