mirror of
https://github.com/postgres/postgres.git
synced 2025-07-18 17:42:25 +03:00
Move mdwriteback() to better place
The previous order in the file didn't make sense and matched neither the header file nor the smgr API. Discussion: https://www.postgresql.org/message-id/flat/22fed8ba-01c3-2008-a256-4ea912d68fab%40enterprisedb.com
This commit is contained in:
@ -733,63 +733,6 @@ mdprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* mdwriteback() -- Tell the kernel to write pages back to storage.
|
|
||||||
*
|
|
||||||
* This accepts a range of blocks because flushing several pages at once is
|
|
||||||
* considerably more efficient than doing so individually.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
mdwriteback(SMgrRelation reln, ForkNumber forknum,
|
|
||||||
BlockNumber blocknum, BlockNumber nblocks)
|
|
||||||
{
|
|
||||||
Assert((io_direct_flags & IO_DIRECT_DATA) == 0);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Issue flush requests in as few requests as possible; have to split at
|
|
||||||
* segment boundaries though, since those are actually separate files.
|
|
||||||
*/
|
|
||||||
while (nblocks > 0)
|
|
||||||
{
|
|
||||||
BlockNumber nflush = nblocks;
|
|
||||||
off_t seekpos;
|
|
||||||
MdfdVec *v;
|
|
||||||
int segnum_start,
|
|
||||||
segnum_end;
|
|
||||||
|
|
||||||
v = _mdfd_getseg(reln, forknum, blocknum, true /* not used */ ,
|
|
||||||
EXTENSION_DONT_OPEN);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We might be flushing buffers of already removed relations, that's
|
|
||||||
* ok, just ignore that case. If the segment file wasn't open already
|
|
||||||
* (ie from a recent mdwrite()), then we don't want to re-open it, to
|
|
||||||
* avoid a race with PROCSIGNAL_BARRIER_SMGRRELEASE that might leave
|
|
||||||
* us with a descriptor to a file that is about to be unlinked.
|
|
||||||
*/
|
|
||||||
if (!v)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* compute offset inside the current segment */
|
|
||||||
segnum_start = blocknum / RELSEG_SIZE;
|
|
||||||
|
|
||||||
/* compute number of desired writes within the current segment */
|
|
||||||
segnum_end = (blocknum + nblocks - 1) / RELSEG_SIZE;
|
|
||||||
if (segnum_start != segnum_end)
|
|
||||||
nflush = RELSEG_SIZE - (blocknum % ((BlockNumber) RELSEG_SIZE));
|
|
||||||
|
|
||||||
Assert(nflush >= 1);
|
|
||||||
Assert(nflush <= nblocks);
|
|
||||||
|
|
||||||
seekpos = (off_t) BLCKSZ * (blocknum % ((BlockNumber) RELSEG_SIZE));
|
|
||||||
|
|
||||||
FileWriteback(v->mdfd_vfd, seekpos, (off_t) BLCKSZ * nflush, WAIT_EVENT_DATA_FILE_FLUSH);
|
|
||||||
|
|
||||||
nblocks -= nflush;
|
|
||||||
blocknum += nflush;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mdread() -- Read the specified block from a relation.
|
* mdread() -- Read the specified block from a relation.
|
||||||
*/
|
*/
|
||||||
@ -923,6 +866,63 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
|
|||||||
register_dirty_segment(reln, forknum, v);
|
register_dirty_segment(reln, forknum, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* mdwriteback() -- Tell the kernel to write pages back to storage.
|
||||||
|
*
|
||||||
|
* This accepts a range of blocks because flushing several pages at once is
|
||||||
|
* considerably more efficient than doing so individually.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
mdwriteback(SMgrRelation reln, ForkNumber forknum,
|
||||||
|
BlockNumber blocknum, BlockNumber nblocks)
|
||||||
|
{
|
||||||
|
Assert((io_direct_flags & IO_DIRECT_DATA) == 0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Issue flush requests in as few requests as possible; have to split at
|
||||||
|
* segment boundaries though, since those are actually separate files.
|
||||||
|
*/
|
||||||
|
while (nblocks > 0)
|
||||||
|
{
|
||||||
|
BlockNumber nflush = nblocks;
|
||||||
|
off_t seekpos;
|
||||||
|
MdfdVec *v;
|
||||||
|
int segnum_start,
|
||||||
|
segnum_end;
|
||||||
|
|
||||||
|
v = _mdfd_getseg(reln, forknum, blocknum, true /* not used */ ,
|
||||||
|
EXTENSION_DONT_OPEN);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We might be flushing buffers of already removed relations, that's
|
||||||
|
* ok, just ignore that case. If the segment file wasn't open already
|
||||||
|
* (ie from a recent mdwrite()), then we don't want to re-open it, to
|
||||||
|
* avoid a race with PROCSIGNAL_BARRIER_SMGRRELEASE that might leave
|
||||||
|
* us with a descriptor to a file that is about to be unlinked.
|
||||||
|
*/
|
||||||
|
if (!v)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* compute offset inside the current segment */
|
||||||
|
segnum_start = blocknum / RELSEG_SIZE;
|
||||||
|
|
||||||
|
/* compute number of desired writes within the current segment */
|
||||||
|
segnum_end = (blocknum + nblocks - 1) / RELSEG_SIZE;
|
||||||
|
if (segnum_start != segnum_end)
|
||||||
|
nflush = RELSEG_SIZE - (blocknum % ((BlockNumber) RELSEG_SIZE));
|
||||||
|
|
||||||
|
Assert(nflush >= 1);
|
||||||
|
Assert(nflush <= nblocks);
|
||||||
|
|
||||||
|
seekpos = (off_t) BLCKSZ * (blocknum % ((BlockNumber) RELSEG_SIZE));
|
||||||
|
|
||||||
|
FileWriteback(v->mdfd_vfd, seekpos, (off_t) BLCKSZ * nflush, WAIT_EVENT_DATA_FILE_FLUSH);
|
||||||
|
|
||||||
|
nblocks -= nflush;
|
||||||
|
blocknum += nflush;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mdnblocks() -- Get the number of blocks stored in a relation.
|
* mdnblocks() -- Get the number of blocks stored in a relation.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user