[Bug] Always one orphan ledger is created
- Dominant language
- Java
- Stars
- 2k
- Forks
- 976
- Avg merge
- 6d 15h
- Merged PRs (30d)
- 7
Description
**BUG REPORT**
***Describe the bug***
Each time after a ledger is created, there will be one more orphan ledger with size 0 created as well, which can't be tracked.
***To Reproduce***
Steps to reproduce the behavior:
1. list ledgers before creation
2. DistributedLogManager#openLogWriter
3. LogWriter#write(LogRecord)
4. LogWriter#close
5. list ledgers. Compared with 1. you will find 2 more ledgers
***Expected behavior***
Should be only 1 ledger
***Screenshots***
N/A
***Root Cause***
The root cause lies in the **BKLogWriteHandler#doStartLogSegment**
line 571: it calls **logSegmentAllocator.allocate();**, which is, in fact, SimpleLedgerAllocator#allocate.
Then inside SimpleLedgerAllocator#allocate, whenComplete -> onSuccess, it will mark phase: **ALLOCATED**.
But just one line after, inside **completeAllocation**, it adds one ZKSetVersionTxn (together with SimpleLedgerAllocator as listner) and marks the phase back to **HANDING_OVER**
So here now we back to **BKLogWriteHandler#doStartLogSegment**,
line 579, started a ZK Transactiion
line 661, txn.execute -> ZKTransaction#processResult -> ZKSetVersionTxn#commitOpResult -> listener#onCommit() (listener is SimpleLedgerAllocator, so it is SimpleLedgerAllocator#onCommit) --> SimpleLedgerAllocator#confirmObtain.
Inside the SimpleLedgerAllocator#confirmObtain, as the phase is changed back to **HANDING_OVER**, there **shouldAllocate = true;**, and this is the where the orphan ledger comes from
Contributor guide
Assessment
This issue has not been assessed yet.