bookkeeper icon indicating copy to clipboard operation
bookkeeper copied to clipboard

Fix the concurrency problem of the compaction process and the regular…

Open 1559924775 opened this issue 3 years ago • 6 comments

… write process

Descriptions of the changes in this PR: add a synchronized createNewLog method in EntryLogManagerForSingleEntryLog.

Motivation

we use SortedLedgerStorage+EntryLogManagerForSingleEntryLog. When the entrylog file managed by EntryLogManagerForSingleEntryLog reaches the upper limit, the createNewLog method is executed. This operation is not locked, which will conflict with the addEntry executed in the compaction process, resulting in disordered entryLog file data. 14e56f8a3e057508f446abb1ccd7b687 ae141da9c0fa6d51373775c19e0860ad There is a concurrency problem with the two operations shown above. In our case we found this code execution order: 1.logChannel.flush(); 2.logChannel.write(sizeBuffer); 3.logChannel.appendLedgersMap(); 4.logChannel.write(entry);

The correct entryLog file format should be like this: header entrySize1+entryData1 entrySize2+entryData2 ... entrySizen+entryDatan ledgersMap

The wrong entrylog is as follows: header entrySize1+entryData1 entrySize2+entryData2 ... entrySizen ledgersMap entryDatan

Changes

add a synchronized createNewLog method in EntryLogManagerForSingleEntryLog.

Master Issue: #3604

I used the scanEntryLog method in EntryLogger to parse an error file. The phenomenon is as follows: image image

1559924775 avatar Nov 04 '22 07:11 1559924775

@hangc0276 PTAL. Thanks.

wenbingshen avatar Nov 04 '22 08:11 wenbingshen

I don't think it's nice to lock the method, the createNewLog should be a separate process and should eliminate the point of thread insecurity

Do you have any concerns about this modification? Could you be more specific? @StevenLuMT

1559924775 avatar Nov 07 '22 07:11 1559924775

getCurrentLogForLedgerForAddEntry

image The createNewLog does not lock the activeLogChannel

1559924775 avatar Nov 23 '22 09:11 1559924775

@zymap @horizonzy Please help take a look at this PR, thanks a lot.

hangc0276 avatar Jan 11 '23 07:01 hangc0276

Could you add a test to cover the function? Thanks.

horizonzy avatar Jan 14 '23 05:01 horizonzy

Close this since it is open for a long time without any updates. Feel free to reopen it if you want to continue

zymap avatar Dec 04 '23 03:12 zymap