Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
coderzc committed Dec 28, 2023
1 parent 76d9849 commit 3a2bf54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3448,10 +3448,13 @@ public void readEntryFailed(ManagedLedgerException exception, Object ctx) {
public synchronized void triggerCompaction()
throws PulsarServerException, AlreadyRunningException {
if (currentCompaction.isDone()) {
if (!lock.readLock().tryLock()) {
log.info("[{}] Topic is closing or deleting, skip triggering compaction -lock", topic);
return;
}
try {
lock.writeLock().lock();
if (isClosingOrDeleting) {
log.info("[{}] Topic is closing or deleting, skip triggering compaction", topic);
log.info("[{}] Topic is closing or deleting, skip triggering compaction -flag", topic);
return;
}

Expand All @@ -3461,14 +3464,14 @@ public synchronized void triggerCompaction()
} else {
currentCompaction = topicCompactionService.compact().thenApply(x -> null);
}
currentCompaction.whenComplete((ignore, ex) -> {
if (ex != null) {
log.warn("[{}] Compaction failure.", topic, ex);
}
});
} finally {
lock.writeLock().unlock();
lock.readLock().unlock();
}
currentCompaction.whenComplete((ignore, ex) -> {
if (ex != null) {
log.warn("[{}] Compaction failure.", topic, ex);
}
});
} else {
throw new AlreadyRunningException("Compaction already in progress");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,7 @@ public void testDeleteCompactedLedger() throws Exception {

@Test
public void testDeleteCompactedLedgerWithSlowAck() throws Exception {
// Disable topic level policies, since block ack thread will block topic level policies deleted
// Disable topic level policies, since block ack thread may also block thread of delete topic policies.
conf.setTopicLevelPoliciesEnabled(false);
restartBroker();

Expand Down

0 comments on commit 3a2bf54

Please sign in to comment.