Skip to content

Commit 472feff

Browse files
committed
We don't need to take the manager lock in Writer#sync
1 parent 2ed948c commit 472feff

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

phoenix-core-server/src/main/java/org/apache/phoenix/replication/ReplicationLogManager.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -455,34 +455,28 @@ public void append(String tableName, long commitId, Mutation mutation) throws IO
455455

456456
/**
457457
* Performs a sync operation, but only after verifying that the writer's generation stamp
458-
* is still valid. Acquires the manager's lock during the check and the delegate sync
459-
* operation. It is therefore impossible for a sync of the underlying writer and a log
460-
* roll to happen concurrently. We are guaranteed the sync will succeed (or fail) without
461-
* interference from the manager.
458+
* is still valid.
462459
* @throws IOException if the underlying sync fails.
463460
* @throws StaleLogWriterException if the writer instance has been rotated
464461
* out since it was acquired.
465462
*/
466463
@Override
467464
public void sync() throws IOException {
468-
lock.lock(); // Acquire the manager's lock so sync doesn't race with a roll.
469-
try {
470-
long current = writerGeneration;
471-
if (this.generation != current) {
472-
throw new StaleLogWriterException(
473-
"Log writer rotated during operation. Expected generation " + generation
474-
+ ", found " + current);
475-
}
476-
// Generation is still valid, proceed with sync on the delegate writer
477-
if (LOG.isTraceEnabled()) {
478-
LOG.trace("Syncing writer {} with generation {}", delegate, generation);
479-
}
480-
delegate.sync();
481-
if (LOG.isTraceEnabled()) {
482-
LOG.trace("Sync successful for writer {} with generation {}", delegate, generation);
483-
}
484-
} finally {
485-
lock.unlock(); // Release the manager's lock
465+
long current = writerGeneration;
466+
if (this.generation != current) {
467+
throw new StaleLogWriterException(
468+
"Log writer rotated during operation. Expected generation " + generation
469+
+ ", found " + current);
470+
}
471+
// Generation is still valid, proceed with sync on the delegate writer
472+
if (LOG.isTraceEnabled()) {
473+
LOG.trace("Syncing writer {} with generation {}", delegate, generation);
474+
}
475+
// We can drop the lock to do the actual sync. We only needed the lock to know the
476+
// writer is still valid at the time we go to invoke sync on the delegate.
477+
delegate.sync();
478+
if (LOG.isTraceEnabled()) {
479+
LOG.trace("Sync successful for writer {} with generation {}", delegate, generation);
486480
}
487481
}
488482

0 commit comments

Comments
 (0)