On Thu, Sep 21, 2023 at 1:50 AM Robert Haas <robertmh...@gmail.com> wrote: > > On Mon, Sep 18, 2023 at 2:57 PM Robert Haas <robertmh...@gmail.com> wrote: > > I've been brainstorming about this today, trying to figure out some > > ideas to make it work. > > Here are some patches. > > 0001 refactors XLogInsertRecord to unify a couple of separate tests of > isLogSwitch, hopefully making it cleaner and cheaper to add more > special cases.
Yeah, this looks improvement as it removes one isLogSwitch from the code. > 0002 is a very minimal patch to add XLOG_CHECKPOINT_REDO without using > it for anything. > > 0003 modifies CreateCheckPoint() to insert an XLOG_CHECKPOINT_REDO > record for any non-shutdown checkpoint, and modifies > XLogInsertRecord() to treat that as a new special case, wherein after > inserting the record the redo pointer is reset while still holding the > WAL insertion locks. Yeah from a design POV, it looks fine to me because the main goal was to insert the XLOG_CHECKPOINT_REDO record and set the "RedoRecPtr" under the same exclusive wal insertion lock and this patch is doing this. As you already mentioned it is an improvement over my first patch because a) it holds the exclusive WAL insersion lock for a very short duration b) not increasing the number of branches in XLogInsertRecord(). Some review 1. I feel we can reduce one more branch to the normal path by increasing one branch in this special case i.e. Your code is if (class == WALINSERT_SPECIAL_SWITCH) { /*execute isSwitch case */ } else if (class == WALINSERT_SPECIAL_CHECKPOINT) { /*execute checkpoint redo case */ } else { /* common case*/ } My suggestion if (xl_rmid == RM_XLOG_ID) { if (class == WALINSERT_SPECIAL_SWITCH) { /*execute isSwitch case */ } else if (class == WALINSERT_SPECIAL_CHECKPOINT) { /*execute checkpoint redo case */ } } else { /* common case*/ } 2. In fact, I feel that we can remove this branch as well right? I mean why do we need to have this separate thing called "class"? we can very much use "info" for that purpose. right? + /* Does this record type require special handling? */ + if (rechdr->xl_rmid == RM_XLOG_ID) + { + if (info == XLOG_SWITCH) + class = WALINSERT_SPECIAL_SWITCH; + else if (XLOG_CHECKPOINT_REDO) + class = WALINSERT_SPECIAL_CHECKPOINT; + } So if we remove this then we do not have this class and the above case would look like if (xl_rmid == RM_XLOG_ID) { if (info == XLOG_SWITCH) { /*execute isSwitch case */ } else if (info == XLOG_CHECKPOINT_REDO) { /*execute checkpoint redo case */ } } else { /* common case*/ } 3. + /* Does this record type require special handling? */ + if (rechdr->xl_rmid == RM_XLOG_ID) + { + if (info == XLOG_SWITCH) + class = WALINSERT_SPECIAL_SWITCH; + else if (XLOG_CHECKPOINT_REDO) + class = WALINSERT_SPECIAL_CHECKPOINT; + } + the above check-in else if is wrong I mean else if (XLOG_CHECKPOINT_REDO) should be else if (info == XLOG_CHECKPOINT_REDO) That's all I have for now. -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com