RE: [Patch] Optimize dropping of relation buffers using dlist
tsunakawa.takay@fujitsu.com <tsunakawa.takay@fujitsu.com>
From: "tsunakawa.takay@fujitsu.com" <tsunakawa.takay@fujitsu.com>
To: "k.jamison@fujitsu.com" <k.jamison@fujitsu.com>, 'Amit Kapila' <amit.kapila16@gmail.com>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>, "tgl@sss.pgh.pa.us" <tgl@sss.pgh.pa.us>, "andres@anarazel.de" <andres@anarazel.de>, "robertmhaas@gmail.com" <robertmhaas@gmail.com>, "tomas.vondra@2ndquadrant.com" <tomas.vondra@2ndquadrant.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2020-10-08T06:37:39Z
Lists: pgsql-hackers
Hi Kirk san,
(1)
+ * This returns an InvalidBlockNumber when smgr_cached_nblocks is not
+ * available and when not in recovery path.
+ /*
+ * We cannot believe the result from smgr_nblocks is always accurate
+ * because lseek of buggy Linux kernels doesn't account for a recent
+ * write.
+ */
+ if (!InRecovery && result == InvalidBlockNumber)
+ return InvalidBlockNumber;
+
These are unnecessary, because mdnblocks() never returns InvalidBlockNumber and conseuently smgrnblocks() doesn't return InvalidBlockNumber.
(2)
+smgrnblocks(SMgrRelation reln, ForkNumber forknum, bool *isCached)
I think it's better to make the argument name iscached so that camel case aligns with forknum, which is not forkNum.
(3)
+ * This is caused by buggy Linux kernels that might not have accounted
+ * the recent write. If a fork's nblocks is invalid, exit loop.
"accounted for" is the right English?
I think The second sentence should be described in terms of its meaning, not the program logic. For example, something like "Give up the optimization if the block count of any fork cannot be trusted."
Likewise, express the following part in semantics.
+ * Do explicit hashtable lookup if the total of nblocks of relation's forks
+ * is not invalid and the nblocks to be invalidated is less than the
(4)
+ if (nForkBlocks[i] == InvalidBlockNumber)
+ {
+ nTotalBlocks = InvalidBlockNumber;
+ break;
+ }
Use isCached in if condition because smgrnblocks() doesn't return InvalidBlockNumber.
(5)
+ nBlocksToInvalidate = nTotalBlocks - firstDelBlock[i];
should be
+ nBlocksToInvalidate += (nForkBlocks[i] - firstDelBlock[i]);
(6)
+ bufHdr->tag.blockNum >= firstDelBlock[j])
+ InvalidateBuffer(bufHdr); /* releases spinlock */
The right side of >= should be cur_block.
Regards
Takayuki Tsunakawa
Commits
-
Fix size overflow in calculation introduced by commits d6ad34f3 and bea449c6.
- 519e4c9ee21a 14.0 landed
-
Optimize DropRelFileNodesAllBuffers() for recovery.
- bea449c635c0 14.0 landed
-
Optimize DropRelFileNodeBuffers() for recovery.
- d6ad34f3410f 14.0 landed
-
Cache smgrnblocks() results in recovery.
- c5315f4f4484 14.0 cited
-
Add a check to prevent overwriting valid data if smgrnblocks() gives a
- ffae5cc5a602 8.2.0 cited