Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
9858a8c8
Commit
9858a8c8
authored
Nov 26, 2008
by
Heikki Linnakangas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rely on relcache invalidation to update the cached size of the FSM.
parent
df559de9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
36 deletions
+39
-36
src/backend/access/transam/xlogutils.c
src/backend/access/transam/xlogutils.c
+2
-2
src/backend/storage/freespace/freespace.c
src/backend/storage/freespace/freespace.c
+26
-23
src/backend/utils/cache/relcache.c
src/backend/utils/cache/relcache.c
+8
-8
src/include/utils/rel.h
src/include/utils/rel.h
+3
-3
No files found.
src/backend/access/transam/xlogutils.c
View file @
9858a8c8
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.6
3 2008/11/19 10:34:50
heikki Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.6
4 2008/11/26 17:08:57
heikki Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -376,7 +376,7 @@ CreateFakeRelcacheEntry(RelFileNode rnode)
...
@@ -376,7 +376,7 @@ CreateFakeRelcacheEntry(RelFileNode rnode)
rel
->
rd_lockInfo
.
lockRelId
.
relId
=
rnode
.
relNode
;
rel
->
rd_lockInfo
.
lockRelId
.
relId
=
rnode
.
relNode
;
rel
->
rd_targblock
=
InvalidBlockNumber
;
rel
->
rd_targblock
=
InvalidBlockNumber
;
rel
->
rd_fsm_nblocks
_cache
=
InvalidBlockNumber
;
rel
->
rd_fsm_nblocks
=
InvalidBlockNumber
;
rel
->
rd_smgr
=
NULL
;
rel
->
rd_smgr
=
NULL
;
return
rel
;
return
rel
;
...
...
src/backend/storage/freespace/freespace.c
View file @
9858a8c8
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.6
7 2008/11/19 10:34:52
heikki Exp $
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.6
8 2008/11/26 17:08:57
heikki Exp $
*
*
*
*
* NOTES:
* NOTES:
...
@@ -101,7 +101,7 @@ static BlockNumber fsm_get_heap_blk(FSMAddress addr, uint16 slot);
...
@@ -101,7 +101,7 @@ static BlockNumber fsm_get_heap_blk(FSMAddress addr, uint16 slot);
static
BlockNumber
fsm_logical_to_physical
(
FSMAddress
addr
);
static
BlockNumber
fsm_logical_to_physical
(
FSMAddress
addr
);
static
Buffer
fsm_readbuf
(
Relation
rel
,
FSMAddress
addr
,
bool
extend
);
static
Buffer
fsm_readbuf
(
Relation
rel
,
FSMAddress
addr
,
bool
extend
);
static
void
fsm_extend
(
Relation
rel
,
BlockNumber
nfsmblocks
,
bool
createstorage
);
static
void
fsm_extend
(
Relation
rel
,
BlockNumber
fsm_nblocks
);
/* functions to convert amount of free space to a FSM category */
/* functions to convert amount of free space to a FSM category */
static
uint8
fsm_space_avail_to_cat
(
Size
avail
);
static
uint8
fsm_space_avail_to_cat
(
Size
avail
);
...
@@ -303,13 +303,13 @@ FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks)
...
@@ -303,13 +303,13 @@ FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks)
smgrtruncate
(
rel
->
rd_smgr
,
FSM_FORKNUM
,
new_nfsmblocks
,
rel
->
rd_istemp
);
smgrtruncate
(
rel
->
rd_smgr
,
FSM_FORKNUM
,
new_nfsmblocks
,
rel
->
rd_istemp
);
/*
/*
* Need to invalidate the relcache entry, because rd_fsm_nblocks
_cache
* Need to invalidate the relcache entry, because rd_fsm_nblocks
* seen by other backends is no longer valid.
* seen by other backends is no longer valid.
*/
*/
if
(
!
InRecovery
)
if
(
!
InRecovery
)
CacheInvalidateRelcache
(
rel
);
CacheInvalidateRelcache
(
rel
);
rel
->
rd_fsm_nblocks
_cache
=
new_nfsmblocks
;
rel
->
rd_fsm_nblocks
=
new_nfsmblocks
;
}
}
/*
/*
...
@@ -503,19 +503,20 @@ fsm_readbuf(Relation rel, FSMAddress addr, bool extend)
...
@@ -503,19 +503,20 @@ fsm_readbuf(Relation rel, FSMAddress addr, bool extend)
RelationOpenSmgr
(
rel
);
RelationOpenSmgr
(
rel
);
if
(
rel
->
rd_fsm_nblocks_cache
==
InvalidBlockNumber
||
/* If we haven't cached the size of the FSM yet, check it first */
rel
->
rd_fsm_nblocks_cache
<=
blkno
)
if
(
rel
->
rd_fsm_nblocks
==
InvalidBlockNumber
)
{
{
if
(
!
smgrexists
(
rel
->
rd_smgr
,
FSM_FORKNUM
))
if
(
smgrexists
(
rel
->
rd_smgr
,
FSM_FORKNUM
))
fsm_extend
(
rel
,
blkno
+
1
,
true
);
rel
->
rd_fsm_nblocks
=
smgrnblocks
(
rel
->
rd_smgr
,
FSM_FORKNUM
);
else
else
rel
->
rd_fsm_nblocks
_cache
=
smgrnblocks
(
rel
->
rd_smgr
,
FSM_FORKNUM
)
;
rel
->
rd_fsm_nblocks
=
0
;
}
}
if
(
blkno
>=
rel
->
rd_fsm_nblocks_cache
)
/* Handle requests beyond EOF */
if
(
blkno
>=
rel
->
rd_fsm_nblocks
)
{
{
if
(
extend
)
if
(
extend
)
fsm_extend
(
rel
,
blkno
+
1
,
false
);
fsm_extend
(
rel
,
blkno
+
1
);
else
else
return
InvalidBuffer
;
return
InvalidBuffer
;
}
}
...
@@ -536,13 +537,12 @@ fsm_readbuf(Relation rel, FSMAddress addr, bool extend)
...
@@ -536,13 +537,12 @@ fsm_readbuf(Relation rel, FSMAddress addr, bool extend)
/*
/*
* Ensure that the FSM fork is at least n_fsmblocks long, extending
* Ensure that the FSM fork is at least n_fsmblocks long, extending
* it if necessary with empty pages. And by empty, I mean pages filled
* it if necessary with empty pages. And by empty, I mean pages filled
* with zeros, meaning there's no free space. If createstorage is true,
* with zeros, meaning there's no free space.
* the FSM file might need to be created first.
*/
*/
static
void
static
void
fsm_extend
(
Relation
rel
,
BlockNumber
n_fsmblocks
,
bool
createstorage
)
fsm_extend
(
Relation
rel
,
BlockNumber
fsm_nblocks
)
{
{
BlockNumber
n_fsm
blocks_now
;
BlockNumber
fsm_n
blocks_now
;
Page
pg
;
Page
pg
;
pg
=
(
Page
)
palloc
(
BLCKSZ
);
pg
=
(
Page
)
palloc
(
BLCKSZ
);
...
@@ -561,27 +561,30 @@ fsm_extend(Relation rel, BlockNumber n_fsmblocks, bool createstorage)
...
@@ -561,27 +561,30 @@ fsm_extend(Relation rel, BlockNumber n_fsmblocks, bool createstorage)
LockRelationForExtension
(
rel
,
ExclusiveLock
);
LockRelationForExtension
(
rel
,
ExclusiveLock
);
/* Create the FSM file first if it doesn't exist */
/* Create the FSM file first if it doesn't exist */
if
(
createstorage
&&
!
smgrexists
(
rel
->
rd_smgr
,
FSM_FORKNUM
))
if
((
rel
->
rd_fsm_nblocks
==
0
||
rel
->
rd_fsm_nblocks
==
InvalidBlockNumber
)
&&
!
smgrexists
(
rel
->
rd_smgr
,
FSM_FORKNUM
))
{
{
smgrcreate
(
rel
->
rd_smgr
,
FSM_FORKNUM
,
false
);
smgrcreate
(
rel
->
rd_smgr
,
FSM_FORKNUM
,
false
);
n_fsm
blocks_now
=
0
;
fsm_n
blocks_now
=
0
;
}
}
else
else
n_fsm
blocks_now
=
smgrnblocks
(
rel
->
rd_smgr
,
FSM_FORKNUM
);
fsm_n
blocks_now
=
smgrnblocks
(
rel
->
rd_smgr
,
FSM_FORKNUM
);
while
(
n_fsmblocks_now
<
n_fsm
blocks
)
while
(
fsm_nblocks_now
<
fsm_n
blocks
)
{
{
smgrextend
(
rel
->
rd_smgr
,
FSM_FORKNUM
,
n_fsm
blocks_now
,
smgrextend
(
rel
->
rd_smgr
,
FSM_FORKNUM
,
fsm_n
blocks_now
,
(
char
*
)
pg
,
rel
->
rd_istemp
);
(
char
*
)
pg
,
rel
->
rd_istemp
);
n_fsm
blocks_now
++
;
fsm_n
blocks_now
++
;
}
}
UnlockRelationForExtension
(
rel
,
ExclusiveLock
);
UnlockRelationForExtension
(
rel
,
ExclusiveLock
);
pfree
(
pg
);
pfree
(
pg
);
/* update the cache with the up-to-date size */
/* Update the relcache with the up-to-date size */
rel
->
rd_fsm_nblocks_cache
=
n_fsmblocks_now
;
if
(
!
InRecovery
)
CacheInvalidateRelcache
(
rel
);
rel
->
rd_fsm_nblocks
=
fsm_nblocks_now
;
}
}
/*
/*
...
...
src/backend/utils/cache/relcache.c
View file @
9858a8c8
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.27
6 2008/11/10 00:49:37 tgl
Exp $
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.27
7 2008/11/26 17:08:57 heikki
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -304,7 +304,7 @@ AllocateRelationDesc(Relation relation, Form_pg_class relp)
...
@@ -304,7 +304,7 @@ AllocateRelationDesc(Relation relation, Form_pg_class relp)
*/
*/
MemSet
(
relation
,
0
,
sizeof
(
RelationData
));
MemSet
(
relation
,
0
,
sizeof
(
RelationData
));
relation
->
rd_targblock
=
InvalidBlockNumber
;
relation
->
rd_targblock
=
InvalidBlockNumber
;
relation
->
rd_fsm_nblocks
_cache
=
InvalidBlockNumber
;
relation
->
rd_fsm_nblocks
=
InvalidBlockNumber
;
/* make sure relation is marked as having no open file yet */
/* make sure relation is marked as having no open file yet */
relation
->
rd_smgr
=
NULL
;
relation
->
rd_smgr
=
NULL
;
...
@@ -1376,7 +1376,7 @@ formrdesc(const char *relationName, Oid relationReltype,
...
@@ -1376,7 +1376,7 @@ formrdesc(const char *relationName, Oid relationReltype,
*/
*/
relation
=
(
Relation
)
palloc0
(
sizeof
(
RelationData
));
relation
=
(
Relation
)
palloc0
(
sizeof
(
RelationData
));
relation
->
rd_targblock
=
InvalidBlockNumber
;
relation
->
rd_targblock
=
InvalidBlockNumber
;
relation
->
rd_fsm_nblocks
_cache
=
InvalidBlockNumber
;
relation
->
rd_fsm_nblocks
=
InvalidBlockNumber
;
/* make sure relation is marked as having no open file yet */
/* make sure relation is marked as having no open file yet */
relation
->
rd_smgr
=
NULL
;
relation
->
rd_smgr
=
NULL
;
...
@@ -1665,9 +1665,9 @@ RelationReloadIndexInfo(Relation relation)
...
@@ -1665,9 +1665,9 @@ RelationReloadIndexInfo(Relation relation)
heap_freetuple
(
pg_class_tuple
);
heap_freetuple
(
pg_class_tuple
);
/* We must recalculate physical address in case it changed */
/* We must recalculate physical address in case it changed */
RelationInitPhysicalAddr
(
relation
);
RelationInitPhysicalAddr
(
relation
);
/* Must reset targblock and fsm_nblocks
_cache
in case rel was truncated */
/* Must reset targblock and fsm_nblocks in case rel was truncated */
relation
->
rd_targblock
=
InvalidBlockNumber
;
relation
->
rd_targblock
=
InvalidBlockNumber
;
relation
->
rd_fsm_nblocks
_cache
=
InvalidBlockNumber
;
relation
->
rd_fsm_nblocks
=
InvalidBlockNumber
;
/* Must free any AM cached data, too */
/* Must free any AM cached data, too */
if
(
relation
->
rd_amcache
)
if
(
relation
->
rd_amcache
)
pfree
(
relation
->
rd_amcache
);
pfree
(
relation
->
rd_amcache
);
...
@@ -1750,7 +1750,7 @@ RelationClearRelation(Relation relation, bool rebuild)
...
@@ -1750,7 +1750,7 @@ RelationClearRelation(Relation relation, bool rebuild)
if
(
relation
->
rd_isnailed
)
if
(
relation
->
rd_isnailed
)
{
{
relation
->
rd_targblock
=
InvalidBlockNumber
;
relation
->
rd_targblock
=
InvalidBlockNumber
;
relation
->
rd_fsm_nblocks
_cache
=
InvalidBlockNumber
;
relation
->
rd_fsm_nblocks
=
InvalidBlockNumber
;
if
(
relation
->
rd_rel
->
relkind
==
RELKIND_INDEX
)
if
(
relation
->
rd_rel
->
relkind
==
RELKIND_INDEX
)
{
{
relation
->
rd_isvalid
=
false
;
/* needs to be revalidated */
relation
->
rd_isvalid
=
false
;
/* needs to be revalidated */
...
@@ -2345,7 +2345,7 @@ RelationBuildLocalRelation(const char *relname,
...
@@ -2345,7 +2345,7 @@ RelationBuildLocalRelation(const char *relname,
rel
=
(
Relation
)
palloc0
(
sizeof
(
RelationData
));
rel
=
(
Relation
)
palloc0
(
sizeof
(
RelationData
));
rel
->
rd_targblock
=
InvalidBlockNumber
;
rel
->
rd_targblock
=
InvalidBlockNumber
;
rel
->
rd_fsm_nblocks
_cache
=
InvalidBlockNumber
;
rel
->
rd_fsm_nblocks
=
InvalidBlockNumber
;
/* make sure relation is marked as having no open file yet */
/* make sure relation is marked as having no open file yet */
rel
->
rd_smgr
=
NULL
;
rel
->
rd_smgr
=
NULL
;
...
@@ -3602,7 +3602,7 @@ load_relcache_init_file(void)
...
@@ -3602,7 +3602,7 @@ load_relcache_init_file(void)
*/
*/
rel
->
rd_smgr
=
NULL
;
rel
->
rd_smgr
=
NULL
;
rel
->
rd_targblock
=
InvalidBlockNumber
;
rel
->
rd_targblock
=
InvalidBlockNumber
;
rel
->
rd_fsm_nblocks
_cache
=
InvalidBlockNumber
;
rel
->
rd_fsm_nblocks
=
InvalidBlockNumber
;
if
(
rel
->
rd_isnailed
)
if
(
rel
->
rd_isnailed
)
rel
->
rd_refcnt
=
1
;
rel
->
rd_refcnt
=
1
;
else
else
...
...
src/include/utils/rel.h
View file @
9858a8c8
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.10
8 2008/09/30 10:52:14
heikki Exp $
* $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.10
9 2008/11/26 17:08:58
heikki Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -195,8 +195,8 @@ typedef struct RelationData
...
@@ -195,8 +195,8 @@ typedef struct RelationData
List
*
rd_indpred
;
/* index predicate tree, if any */
List
*
rd_indpred
;
/* index predicate tree, if any */
void
*
rd_amcache
;
/* available for use by index AM */
void
*
rd_amcache
;
/* available for use by index AM */
/*
Cached last-seen size of the FSM
*/
/*
size of the FSM, or InvalidBlockNumber if not known yet
*/
BlockNumber
rd_fsm_nblocks
_cache
;
BlockNumber
rd_fsm_nblocks
;
/* use "struct" here to avoid needing to include pgstat.h: */
/* use "struct" here to avoid needing to include pgstat.h: */
struct
PgStat_TableStatus
*
pgstat_info
;
/* statistics collection area */
struct
PgStat_TableStatus
*
pgstat_info
;
/* statistics collection area */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment