Konstantin Knizhnik
2025-05-18 08:02:47 +03:00
committed by GitHub
parent e963129678
commit 81c557d87e
8 changed files with 76 additions and 32 deletions

View File

@@ -7,7 +7,7 @@ index 255e616..1c6edb7 100644
RelationGetRelationName(index)); RelationGetRelationName(index));
+#ifdef NEON_SMGR +#ifdef NEON_SMGR
+ smgr_start_unlogged_build(index->rd_smgr); + smgr_start_unlogged_build(RelationGetSmgr(index));
+#endif +#endif
+ +
initRumState(&buildstate.rumstate, index); initRumState(&buildstate.rumstate, index);
@@ -18,7 +18,7 @@ index 255e616..1c6edb7 100644
rumUpdateStats(index, &buildstate.buildStats, buildstate.rumstate.isBuild); rumUpdateStats(index, &buildstate.buildStats, buildstate.rumstate.isBuild);
+#ifdef NEON_SMGR +#ifdef NEON_SMGR
+ smgr_finish_unlogged_build_phase_1(index->rd_smgr); + smgr_finish_unlogged_build_phase_1(RelationGetSmgr(index));
+#endif +#endif
+ +
/* /*
@@ -29,7 +29,7 @@ index 255e616..1c6edb7 100644
} }
+#ifdef NEON_SMGR +#ifdef NEON_SMGR
+ smgr_end_unlogged_build(index->rd_smgr); + smgr_end_unlogged_build(RelationGetSmgr(index));
+#endif +#endif
+ +
/* /*

View File

@@ -86,7 +86,7 @@ InitBufferTag(BufferTag *tag, const RelFileNode *rnode,
#define InvalidRelFileNumber InvalidOid #define InvalidRelFileNumber InvalidOid
#define SMgrRelGetRelInfo(reln) \ #define SMgrRelGetRelInfo(reln) \
(reln->smgr_rnode.node) (reln->smgr_rnode.node)
#define DropRelationAllLocalBuffers DropRelFileNodeAllLocalBuffers #define DropRelationAllLocalBuffers DropRelFileNodeAllLocalBuffers
@@ -148,6 +148,12 @@ InitBufferTag(BufferTag *tag, const RelFileNode *rnode,
#define DropRelationAllLocalBuffers DropRelationAllLocalBuffers #define DropRelationAllLocalBuffers DropRelationAllLocalBuffers
#endif #endif
#define NRelFileInfoInvalidate(rinfo) do { \
NInfoGetSpcOid(rinfo) = InvalidOid; \
NInfoGetDbOid(rinfo) = InvalidOid; \
NInfoGetRelNumber(rinfo) = InvalidRelFileNumber; \
} while (0)
#if PG_MAJORVERSION_NUM < 17 #if PG_MAJORVERSION_NUM < 17
#define ProcNumber BackendId #define ProcNumber BackendId
#define INVALID_PROC_NUMBER InvalidBackendId #define INVALID_PROC_NUMBER InvalidBackendId

View File

@@ -108,7 +108,7 @@ typedef enum
UNLOGGED_BUILD_NOT_PERMANENT UNLOGGED_BUILD_NOT_PERMANENT
} UnloggedBuildPhase; } UnloggedBuildPhase;
static SMgrRelation unlogged_build_rel = NULL; static NRelFileInfo unlogged_build_rel_info;
static UnloggedBuildPhase unlogged_build_phase = UNLOGGED_BUILD_NOT_IN_PROGRESS; static UnloggedBuildPhase unlogged_build_phase = UNLOGGED_BUILD_NOT_IN_PROGRESS;
static bool neon_redo_read_buffer_filter(XLogReaderState *record, uint8 block_id); static bool neon_redo_read_buffer_filter(XLogReaderState *record, uint8 block_id);
@@ -912,8 +912,14 @@ neon_extend(SMgrRelation reln, ForkNumber forkNum, BlockNumber blkno,
{ {
case 0: case 0:
neon_log(ERROR, "cannot call smgrextend() on rel with unknown persistence"); neon_log(ERROR, "cannot call smgrextend() on rel with unknown persistence");
break;
case RELPERSISTENCE_PERMANENT: case RELPERSISTENCE_PERMANENT:
if (RelFileInfoEquals(unlogged_build_rel_info, InfoFromSMgrRel(reln)))
{
mdextend(reln, forkNum, blkno, buffer, skipFsync);
return;
}
break; break;
case RELPERSISTENCE_TEMP: case RELPERSISTENCE_TEMP:
@@ -1000,8 +1006,14 @@ neon_zeroextend(SMgrRelation reln, ForkNumber forkNum, BlockNumber blocknum,
{ {
case 0: case 0:
neon_log(ERROR, "cannot call smgrextend() on rel with unknown persistence"); neon_log(ERROR, "cannot call smgrextend() on rel with unknown persistence");
break;
case RELPERSISTENCE_PERMANENT: case RELPERSISTENCE_PERMANENT:
if (RelFileInfoEquals(unlogged_build_rel_info, InfoFromSMgrRel(reln)))
{
mdzeroextend(reln, forkNum, blocknum, nblocks, skipFsync);
return;
}
break; break;
case RELPERSISTENCE_TEMP: case RELPERSISTENCE_TEMP:
@@ -1376,8 +1388,14 @@ neon_read(SMgrRelation reln, ForkNumber forkNum, BlockNumber blkno, void *buffer
{ {
case 0: case 0:
neon_log(ERROR, "cannot call smgrread() on rel with unknown persistence"); neon_log(ERROR, "cannot call smgrread() on rel with unknown persistence");
break;
case RELPERSISTENCE_PERMANENT: case RELPERSISTENCE_PERMANENT:
if (RelFileInfoEquals(unlogged_build_rel_info, InfoFromSMgrRel(reln)))
{
mdread(reln, forkNum, blkno, buffer);
return;
}
break; break;
case RELPERSISTENCE_TEMP: case RELPERSISTENCE_TEMP:
@@ -1463,8 +1481,14 @@ neon_readv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
{ {
case 0: case 0:
neon_log(ERROR, "cannot call smgrread() on rel with unknown persistence"); neon_log(ERROR, "cannot call smgrread() on rel with unknown persistence");
break;
case RELPERSISTENCE_PERMANENT: case RELPERSISTENCE_PERMANENT:
if (RelFileInfoEquals(unlogged_build_rel_info, InfoFromSMgrRel(reln)))
{
mdreadv(reln, forknum, blocknum, buffers, nblocks);
return;
}
break; break;
case RELPERSISTENCE_TEMP: case RELPERSISTENCE_TEMP:
@@ -1597,6 +1621,15 @@ neon_write(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const vo
break; break;
case RELPERSISTENCE_PERMANENT: case RELPERSISTENCE_PERMANENT:
if (RelFileInfoEquals(unlogged_build_rel_info, InfoFromSMgrRel(reln)))
{
#if PG_MAJORVERSION_NUM >= 17
mdwritev(reln, forknum, blocknum, &buffer, 1, skipFsync);
#else
mdwrite(reln, forknum, blocknum, buffer, skipFsync);
#endif
return;
}
break; break;
case RELPERSISTENCE_TEMP: case RELPERSISTENCE_TEMP:
@@ -1666,6 +1699,11 @@ neon_writev(SMgrRelation reln, ForkNumber forknum, BlockNumber blkno,
break; break;
case RELPERSISTENCE_PERMANENT: case RELPERSISTENCE_PERMANENT:
if (RelFileInfoEquals(unlogged_build_rel_info, InfoFromSMgrRel(reln)))
{
mdwritev(reln, forknum, blkno, buffers, nblocks, skipFsync);
return;
}
break; break;
case RELPERSISTENCE_TEMP: case RELPERSISTENCE_TEMP:
@@ -1706,6 +1744,10 @@ neon_nblocks(SMgrRelation reln, ForkNumber forknum)
break; break;
case RELPERSISTENCE_PERMANENT: case RELPERSISTENCE_PERMANENT:
if (RelFileInfoEquals(unlogged_build_rel_info, InfoFromSMgrRel(reln)))
{
return mdnblocks(reln, forknum);
}
break; break;
case RELPERSISTENCE_TEMP: case RELPERSISTENCE_TEMP:
@@ -1775,6 +1817,11 @@ neon_truncate(SMgrRelation reln, ForkNumber forknum, BlockNumber old_blocks, Blo
break; break;
case RELPERSISTENCE_PERMANENT: case RELPERSISTENCE_PERMANENT:
if (RelFileInfoEquals(unlogged_build_rel_info, InfoFromSMgrRel(reln)))
{
mdtruncate(reln, forknum, old_blocks, nblocks);
return;
}
break; break;
case RELPERSISTENCE_TEMP: case RELPERSISTENCE_TEMP:
@@ -1913,7 +1960,6 @@ neon_start_unlogged_build(SMgrRelation reln)
*/ */
if (unlogged_build_phase != UNLOGGED_BUILD_NOT_IN_PROGRESS) if (unlogged_build_phase != UNLOGGED_BUILD_NOT_IN_PROGRESS)
neon_log(ERROR, "unlogged relation build is already in progress"); neon_log(ERROR, "unlogged relation build is already in progress");
Assert(unlogged_build_rel == NULL);
ereport(SmgrTrace, ereport(SmgrTrace,
(errmsg(NEON_TAG "starting unlogged build of relation %u/%u/%u", (errmsg(NEON_TAG "starting unlogged build of relation %u/%u/%u",
@@ -1930,7 +1976,7 @@ neon_start_unlogged_build(SMgrRelation reln)
case RELPERSISTENCE_TEMP: case RELPERSISTENCE_TEMP:
case RELPERSISTENCE_UNLOGGED: case RELPERSISTENCE_UNLOGGED:
unlogged_build_rel = reln; unlogged_build_rel_info = InfoFromSMgrRel(reln);
unlogged_build_phase = UNLOGGED_BUILD_NOT_PERMANENT; unlogged_build_phase = UNLOGGED_BUILD_NOT_PERMANENT;
#ifdef DEBUG_COMPARE_LOCAL #ifdef DEBUG_COMPARE_LOCAL
if (!IsParallelWorker()) if (!IsParallelWorker())
@@ -1951,12 +1997,9 @@ neon_start_unlogged_build(SMgrRelation reln)
neon_log(ERROR, "cannot perform unlogged index build, index is not empty "); neon_log(ERROR, "cannot perform unlogged index build, index is not empty ");
#endif #endif
unlogged_build_rel = reln; unlogged_build_rel_info = InfoFromSMgrRel(reln);
unlogged_build_phase = UNLOGGED_BUILD_PHASE_1; unlogged_build_phase = UNLOGGED_BUILD_PHASE_1;
/* Make the relation look like it's unlogged */
reln->smgr_relpersistence = RELPERSISTENCE_UNLOGGED;
/* /*
* Create the local file. In a parallel build, the leader is expected to * Create the local file. In a parallel build, the leader is expected to
* call this first and do it. * call this first and do it.
@@ -1983,17 +2026,16 @@ neon_start_unlogged_build(SMgrRelation reln)
static void static void
neon_finish_unlogged_build_phase_1(SMgrRelation reln) neon_finish_unlogged_build_phase_1(SMgrRelation reln)
{ {
Assert(unlogged_build_rel == reln); Assert(RelFileInfoEquals(unlogged_build_rel_info, InfoFromSMgrRel(reln)));
ereport(SmgrTrace, ereport(SmgrTrace,
(errmsg(NEON_TAG "finishing phase 1 of unlogged build of relation %u/%u/%u", (errmsg(NEON_TAG "finishing phase 1 of unlogged build of relation %u/%u/%u",
RelFileInfoFmt(InfoFromSMgrRel(reln))))); RelFileInfoFmt((unlogged_build_rel_info)))));
if (unlogged_build_phase == UNLOGGED_BUILD_NOT_PERMANENT) if (unlogged_build_phase == UNLOGGED_BUILD_NOT_PERMANENT)
return; return;
Assert(unlogged_build_phase == UNLOGGED_BUILD_PHASE_1); Assert(unlogged_build_phase == UNLOGGED_BUILD_PHASE_1);
Assert(reln->smgr_relpersistence == RELPERSISTENCE_UNLOGGED);
/* /*
* In a parallel build, (only) the leader process performs the 2nd * In a parallel build, (only) the leader process performs the 2nd
@@ -2001,7 +2043,7 @@ neon_finish_unlogged_build_phase_1(SMgrRelation reln)
*/ */
if (IsParallelWorker()) if (IsParallelWorker())
{ {
unlogged_build_rel = NULL; NRelFileInfoInvalidate(unlogged_build_rel_info);
unlogged_build_phase = UNLOGGED_BUILD_NOT_IN_PROGRESS; unlogged_build_phase = UNLOGGED_BUILD_NOT_IN_PROGRESS;
} }
else else
@@ -2022,11 +2064,11 @@ neon_end_unlogged_build(SMgrRelation reln)
{ {
NRelFileInfoBackend rinfob = InfoBFromSMgrRel(reln); NRelFileInfoBackend rinfob = InfoBFromSMgrRel(reln);
Assert(unlogged_build_rel == reln); Assert(RelFileInfoEquals(unlogged_build_rel_info, InfoFromSMgrRel(reln)));
ereport(SmgrTrace, ereport(SmgrTrace,
(errmsg(NEON_TAG "ending unlogged build of relation %u/%u/%u", (errmsg(NEON_TAG "ending unlogged build of relation %u/%u/%u",
RelFileInfoFmt(InfoFromNInfoB(rinfob))))); RelFileInfoFmt(unlogged_build_rel_info))));
if (unlogged_build_phase != UNLOGGED_BUILD_NOT_PERMANENT) if (unlogged_build_phase != UNLOGGED_BUILD_NOT_PERMANENT)
{ {
@@ -2034,7 +2076,6 @@ neon_end_unlogged_build(SMgrRelation reln)
BlockNumber nblocks; BlockNumber nblocks;
Assert(unlogged_build_phase == UNLOGGED_BUILD_PHASE_2); Assert(unlogged_build_phase == UNLOGGED_BUILD_PHASE_2);
Assert(reln->smgr_relpersistence == RELPERSISTENCE_UNLOGGED);
/* /*
* Update the last-written LSN cache. * Update the last-written LSN cache.
@@ -2055,9 +2096,6 @@ neon_end_unlogged_build(SMgrRelation reln)
InfoFromNInfoB(rinfob), InfoFromNInfoB(rinfob),
MAIN_FORKNUM); MAIN_FORKNUM);
/* Make the relation look permanent again */
reln->smgr_relpersistence = RELPERSISTENCE_PERMANENT;
/* Remove local copy */ /* Remove local copy */
for (int forknum = 0; forknum <= MAX_FORKNUM; forknum++) for (int forknum = 0; forknum <= MAX_FORKNUM; forknum++)
{ {
@@ -2078,7 +2116,7 @@ neon_end_unlogged_build(SMgrRelation reln)
mdunlink(rinfob, INIT_FORKNUM, true); mdunlink(rinfob, INIT_FORKNUM, true);
#endif #endif
} }
unlogged_build_rel = NULL; NRelFileInfoInvalidate(unlogged_build_rel_info);
unlogged_build_phase = UNLOGGED_BUILD_NOT_IN_PROGRESS; unlogged_build_phase = UNLOGGED_BUILD_NOT_IN_PROGRESS;
} }
@@ -2151,7 +2189,7 @@ AtEOXact_neon(XactEvent event, void *arg)
* Forget about any build we might have had in progress. The local * Forget about any build we might have had in progress. The local
* file will be unlinked by smgrDoPendingDeletes() * file will be unlinked by smgrDoPendingDeletes()
*/ */
unlogged_build_rel = NULL; NRelFileInfoInvalidate(unlogged_build_rel_info);
unlogged_build_phase = UNLOGGED_BUILD_NOT_IN_PROGRESS; unlogged_build_phase = UNLOGGED_BUILD_NOT_IN_PROGRESS;
break; break;
@@ -2163,7 +2201,7 @@ AtEOXact_neon(XactEvent event, void *arg)
case XACT_EVENT_PRE_PREPARE: case XACT_EVENT_PRE_PREPARE:
if (unlogged_build_phase != UNLOGGED_BUILD_NOT_IN_PROGRESS) if (unlogged_build_phase != UNLOGGED_BUILD_NOT_IN_PROGRESS)
{ {
unlogged_build_rel = NULL; NRelFileInfoInvalidate(unlogged_build_rel_info);
unlogged_build_phase = UNLOGGED_BUILD_NOT_IN_PROGRESS; unlogged_build_phase = UNLOGGED_BUILD_NOT_IN_PROGRESS;
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),

View File

@@ -1,18 +1,18 @@
{ {
"v17": [ "v17": [
"17.5", "17.5",
"e5374b72997b0afc8374137674e873f7a558120a" "8be779fd3ab9e87206da96a7e4842ef1abf04f44"
], ],
"v16": [ "v16": [
"16.9", "16.9",
"15710a76b7d07912110fcbbaf0c8ad6d7e5a9fbc" "0bf96bd6d70301a0b43b0b3457bb3cf8fb43c198"
], ],
"v15": [ "v15": [
"15.13", "15.13",
"daa81cffcf063c54b29a9aabdb6604625f675ad0" "de7640f55da07512834d5cc40c4b3fb376b5f04f"
], ],
"v14": [ "v14": [
"14.18", "14.18",
"4cca6f8083483dda9e12eae292cf788d45bd561f" "55c0d45abe6467c02084c2192bca117eda6ce1e7"
] ]
} }