Skip to content

Commit

Permalink
Fix lost message issues 12221 (#12223)
Browse files Browse the repository at this point in the history
Fixes #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: #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.
  • Loading branch information
baomingyu authored Sep 30, 2021
1 parent 039079e commit eb9d9d4
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,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 @@ -1591,11 +1597,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 eb9d9d4

Please sign in to comment.