ApsaraDB / PolarDB-for-PostgreSQL

A cloud-native database based on PostgreSQL developed by Alibaba Cloud.
https://apsaradb.github.io/PolarDB-for-PostgreSQL/zh/
Apache License 2.0
2.89k stars 480 forks source link

[Question] About mini transaction #361

Closed wangyao2016 closed 1 year ago

wangyao2016 commented 1 year ago

Describe the problem Hello, I have a question about Mini Transaction when read docs chapter Logindex. According to the document content “This causes inconsistency between the memory data structure of Page_0 and that of Page_1.” , I can't understand, what problems will be caused when ' the memory data structure inconsistency ' ? In my opinion, in pg's stand-alone mode, eg: when lsn replayed for page0 than page0 is visiable, in this case the memory data structure also inconsistency. I lack theoretical knowledge of database. I hope to get an answer. Thank you! ... image

polardb-bot[bot] commented 1 year ago

Hi @wangyao2016 ~ Thanks for opening this issue! 🎉

Please make sure you have provided enough information for subsequent discussion.

We will get back to you as soon as possible. ❤️

wangyao2016 commented 1 year ago

@mrdrivingduck Please help~ ^_^

Ccxikka commented 1 year ago

Hi @wangyao2016, data is replayed in units of wal record in pg, if a wal record lsn1 modified multiple pages, all corresponding pages will be updated to lsn1 after lsn1 is replayed.

But in PolarDB with logindex, the backend process replays only the pages it must access, if lsn1 modified both page0 and page1, the startup process parses wal metadata and sequentially inserts lsn1 into the lsn list of each page. when mini transaction lock is unavailable, the startup process may completes the update of the lsn list of page0 but does not complete the update of the lsn list of page1. when backend access page0 and page1, page 0 will be updated to lsn1, however page1 won't be updated to lsn1 because lsn1 haven't been inserted to the lsn list of page1.

If this corresponds to an index split scenario, page0 will be updated to the value after split, but page1 still keeps the same value as before, which caused inconsistency between the memory data structure.

mrdrivingduck commented 1 year ago

@Ccxikka 👍👍👍🔥

wangyao2016 commented 1 year ago

Thanks @Ccxikka