Skip to content

Commit

Permalink
Fix lost message issues 12221 (apache#12223)
Browse files Browse the repository at this point in the history
Fixes apache#12221

*(or if this PR is one task of a github issue, please add `Master Issue: #<xyz>` to link to the master issue.)*

Master Issue: apache#12221 

### Motivation
There  are three way to create new ledger when one ledger is full.
first: after add last entry for full ledger, it will handle create ledger processing.
second: check ledger is or not full, when ledger is full and appendingAddEntries is not empty, it will handle create ledger processing.
third: check ledger is or not full, when ledger is full, it will handle create ledger processing.

 So we need check it is or not creating or has created when concurrent create new ledger. avoid to create three new ledgers one  time.

(cherry picked from commit eb9d9d4)
  • Loading branch information
baomingyu authored and codelipenghui committed Oct 6, 2021
1 parent 349e4da commit e3c8386
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,12 @@ synchronized void ledgerClosed(final LedgerHandle lh) {

if (!pendingAddEntries.isEmpty()) {
// Need to create a new ledger to write pending entries
createLedgerAfterClosed();
}
}

synchronized void createLedgerAfterClosed() {
if(isNeededCreateNewLedgerAfterCloseLedger()) {
log.info("[{}] Creating a new ledger", name);
STATE_UPDATER.set(this, State.CreatingLedger);
this.lastLedgerCreationInitiationTimestamp = System.currentTimeMillis();
Expand All @@ -1592,11 +1598,12 @@ synchronized void ledgerClosed(final LedgerHandle lh) {
}
}

synchronized void createLedgerAfterClosed() {
STATE_UPDATER.set(this, State.CreatingLedger);
this.lastLedgerCreationInitiationTimestamp = System.currentTimeMillis();
mbean.startDataLedgerCreateOp();
asyncCreateLedger(bookKeeper, config, digestType, this, Collections.emptyMap());
boolean isNeededCreateNewLedgerAfterCloseLedger() {
final State state = STATE_UPDATER.get(this);
if (state != State.CreatingLedger && state != State.LedgerOpened) {
return true;
}
return false;
}

@VisibleForTesting
Expand Down

0 comments on commit e3c8386

Please sign in to comment.