In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the use and influence of PostgreSQL pre-written log flag bit". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "PostgreSQL pre-write log flag bit of the use and impact" bar!
This article continues to demonstrate and explain how to find the functionality you need from the code, taking the logical copy plug-in as an example. In the process, it is inevitable to read a lot of extraneous code, this part does not need to be verbose, as the code familiarity increases, the overhead in these development processes will be reduced.
1. Plug-in initialization setting callback function commit_cb
It handles transaction commit information, but you don't get much here, and the transaction status is not included in the LogicalDecodingContext.
2. Logic decoding
Src/backend/replication/logical/logical.c
The callback function commit_cb is encapsulated in commit_cb_wrapper and set to the callback of the next layer:
/ * commit callback signature * / typedef void (* ReorderBufferCommitCB) (ReorderBuffer * rb, ReorderBufferTXN * txn) XLogRecPtr commit_lsn)
Without saying much about the definition, our goal is to find out whether the transaction has a control flag, set what the flow is, and see for yourself the details of the code.
3. Decoding
To move on, the function to decode the transaction commit is: DecodeCommit.
Src/backend/replication/logical/decode.c
As you can see here, there is also a special handler for rollback transactions: DecodeAbort, which directly releases the decoded structure.
4. Transaction flag bit
If (parsed- > xinfo & XACT_XINFO_HAS_ORIGIN) {origin_lsn = parsed- > origin_lsn; commit_time = parsed- > origin_timest}
With the deepening of the code, it finally appeared. The extension flag bit xinfo says that the extension is guessed by the name.
/ * does this record have a 'xinfo' field or not * / # define XLOG_XACT_HAS_INFO 0x80
Whether or not xinfo is confirmed by this flag, more information can be learned according to the code or comments.
5. When was it set up
Src/backend/access/transam/xact.c function XactLogCommitRecord
Write according to the status when the transaction is committed.
6. What else can we see
Skip some transactions based on the filter
If (SnapBuildXactNeedsSkip (ctx- > snapshot_builder, buf- > origptr) | | (parsed- > dbId! = InvalidOid & & parsed- > dbId! = ctx- > slot- > data.database) | | ctx- > fast_forward | | FilterByOrigin (ctx, origin_id) {for (I = 0; I
< parsed->Nsubxacts; iTunes +) {ReorderBufferForget (ctx- > reorder, parsed- > subxacts [I], buf- > origptr);} ReorderBufferForget (ctx- > reorder, xid, buf- > origptr); return;}
So, if we want to control whether the transaction is decoded or not, we can use this logic without worrying at all.
7. There are more
Continue to the previous point, whether the transaction needs to be copied or not, it needs to be decoded, and then released according to the filter conditions, that is, there is some meaningless overhead.
In fact, there are a lot of irrelevant code reading in this process, which can be ignored if you are sure that it is irrelevant. Only the influential parts are listed here.
At this point, I believe you have a deeper understanding of "the use and impact of PostgreSQL pre-written log flag bits". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.