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
8f28789b
Commit
8f28789b
authored
May 09, 2012
by
Simon Riggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename BgWriterShmem/Request to CheckpointerShmem/Request
parent
bbd3ec9d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
55 deletions
+56
-55
src/backend/postmaster/checkpointer.c
src/backend/postmaster/checkpointer.c
+51
-51
src/backend/storage/ipc/ipci.c
src/backend/storage/ipc/ipci.c
+2
-2
src/include/postmaster/bgwriter.h
src/include/postmaster/bgwriter.h
+3
-2
No files found.
src/backend/postmaster/checkpointer.c
View file @
8f28789b
...
...
@@ -110,7 +110,7 @@ typedef struct
ForkNumber
forknum
;
BlockNumber
segno
;
/* see md.c for special values */
/* might add a real request-type field later; not needed yet */
}
BgWri
terRequest
;
}
Checkpoin
terRequest
;
typedef
struct
{
...
...
@@ -129,10 +129,10 @@ typedef struct
int
num_requests
;
/* current # of requests */
int
max_requests
;
/* allocated array size */
BgWri
terRequest
requests
[
1
];
/* VARIABLE LENGTH ARRAY */
}
BgWri
terShmemStruct
;
Checkpoin
terRequest
requests
[
1
];
/* VARIABLE LENGTH ARRAY */
}
Checkpoin
terShmemStruct
;
static
BgWriterShmemStruct
*
BgWri
terShmem
;
static
CheckpointerShmemStruct
*
Checkpoin
terShmem
;
/* interval for calling AbsorbFsyncRequests in CheckpointWriteDelay */
#define WRITES_PER_ABSORB 1000
...
...
@@ -195,7 +195,7 @@ CheckpointerMain(void)
sigjmp_buf
local_sigjmp_buf
;
MemoryContext
checkpointer_context
;
BgWri
terShmem
->
checkpointer_pid
=
MyProcPid
;
Checkpoin
terShmem
->
checkpointer_pid
=
MyProcPid
;
am_checkpointer
=
true
;
/*
...
...
@@ -302,7 +302,7 @@ CheckpointerMain(void)
if
(
ckpt_active
)
{
/* use volatile pointer to prevent code rearrangement */
volatile
BgWriterShmemStruct
*
bgs
=
BgWri
terShmem
;
volatile
CheckpointerShmemStruct
*
bgs
=
Checkpoin
terShmem
;
SpinLockAcquire
(
&
bgs
->
ckpt_lck
);
bgs
->
ckpt_failed
++
;
...
...
@@ -455,7 +455,7 @@ CheckpointerMain(void)
bool
do_restartpoint
;
/* use volatile pointer to prevent code rearrangement */
volatile
BgWriterShmemStruct
*
bgs
=
BgWri
terShmem
;
volatile
CheckpointerShmemStruct
*
bgs
=
Checkpoin
terShmem
;
/*
* Check if we should perform a checkpoint or a restartpoint. As a
...
...
@@ -651,7 +651,7 @@ ImmediateCheckpointRequested(void)
{
if
(
checkpoint_requested
)
{
volatile
BgWriterShmemStruct
*
bgs
=
BgWri
terShmem
;
volatile
CheckpointerShmemStruct
*
bgs
=
Checkpoin
terShmem
;
/*
* We don't need to acquire the ckpt_lck in this case because we're
...
...
@@ -893,11 +893,11 @@ ReqShutdownHandler(SIGNAL_ARGS)
*/
/*
*
BgWri
terShmemSize
*
Checkpoin
terShmemSize
* Compute space needed for bgwriter-related shared memory
*/
Size
BgWri
terShmemSize
(
void
)
Checkpoin
terShmemSize
(
void
)
{
Size
size
;
...
...
@@ -905,32 +905,32 @@ BgWriterShmemSize(void)
* Currently, the size of the requests[] array is arbitrarily set equal to
* NBuffers. This may prove too large or small ...
*/
size
=
offsetof
(
BgWri
terShmemStruct
,
requests
);
size
=
add_size
(
size
,
mul_size
(
NBuffers
,
sizeof
(
BgWri
terRequest
)));
size
=
offsetof
(
Checkpoin
terShmemStruct
,
requests
);
size
=
add_size
(
size
,
mul_size
(
NBuffers
,
sizeof
(
Checkpoin
terRequest
)));
return
size
;
}
/*
*
BgWri
terShmemInit
*
Checkpoin
terShmemInit
* Allocate and initialize bgwriter-related shared memory
*/
void
BgWri
terShmemInit
(
void
)
Checkpoin
terShmemInit
(
void
)
{
bool
found
;
BgWriterShmem
=
(
BgWri
terShmemStruct
*
)
CheckpointerShmem
=
(
Checkpoin
terShmemStruct
*
)
ShmemInitStruct
(
"Background Writer Data"
,
BgWri
terShmemSize
(),
Checkpoin
terShmemSize
(),
&
found
);
if
(
!
found
)
{
/* First time through, so initialize */
MemSet
(
BgWriterShmem
,
0
,
sizeof
(
BgWri
terShmemStruct
));
SpinLockInit
(
&
BgWri
terShmem
->
ckpt_lck
);
BgWri
terShmem
->
max_requests
=
NBuffers
;
MemSet
(
CheckpointerShmem
,
0
,
sizeof
(
Checkpoin
terShmemStruct
));
SpinLockInit
(
&
Checkpoin
terShmem
->
ckpt_lck
);
Checkpoin
terShmem
->
max_requests
=
NBuffers
;
}
}
...
...
@@ -955,7 +955,7 @@ void
RequestCheckpoint
(
int
flags
)
{
/* use volatile pointer to prevent code rearrangement */
volatile
BgWriterShmemStruct
*
bgs
=
BgWri
terShmem
;
volatile
CheckpointerShmemStruct
*
bgs
=
Checkpoin
terShmem
;
int
ntries
;
int
old_failed
,
old_started
;
...
...
@@ -1006,7 +1006,7 @@ RequestCheckpoint(int flags)
*/
for
(
ntries
=
0
;;
ntries
++
)
{
if
(
BgWri
terShmem
->
checkpointer_pid
==
0
)
if
(
Checkpoin
terShmem
->
checkpointer_pid
==
0
)
{
if
(
ntries
>=
20
)
/* max wait 2.0 sec */
{
...
...
@@ -1015,7 +1015,7 @@ RequestCheckpoint(int flags)
break
;
}
}
else
if
(
kill
(
BgWri
terShmem
->
checkpointer_pid
,
SIGINT
)
!=
0
)
else
if
(
kill
(
Checkpoin
terShmem
->
checkpointer_pid
,
SIGINT
)
!=
0
)
{
if
(
ntries
>=
20
)
/* max wait 2.0 sec */
{
...
...
@@ -1109,7 +1109,7 @@ bool
ForwardFsyncRequest
(
RelFileNodeBackend
rnode
,
ForkNumber
forknum
,
BlockNumber
segno
)
{
BgWri
terRequest
*
request
;
Checkpoin
terRequest
*
request
;
bool
too_full
;
if
(
!
IsUnderPostmaster
)
...
...
@@ -1121,35 +1121,35 @@ ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,
LWLockAcquire
(
CheckpointerCommLock
,
LW_EXCLUSIVE
);
/* Count all backend writes regardless of if they fit in the queue */
BgWri
terShmem
->
num_backend_writes
++
;
Checkpoin
terShmem
->
num_backend_writes
++
;
/*
* If the checkpointer isn't running or the request queue is full,
* the backend will have to perform its own fsync request. But before
* forcing that to happen, we can try to compact the request queue.
*/
if
(
BgWri
terShmem
->
checkpointer_pid
==
0
||
(
BgWriterShmem
->
num_requests
>=
BgWri
terShmem
->
max_requests
&&
if
(
Checkpoin
terShmem
->
checkpointer_pid
==
0
||
(
CheckpointerShmem
->
num_requests
>=
Checkpoin
terShmem
->
max_requests
&&
!
CompactCheckpointerRequestQueue
()))
{
/*
* Count the subset of writes where backends have to do their own
* fsync
*/
BgWri
terShmem
->
num_backend_fsync
++
;
Checkpoin
terShmem
->
num_backend_fsync
++
;
LWLockRelease
(
CheckpointerCommLock
);
return
false
;
}
/* OK, insert request */
request
=
&
BgWriterShmem
->
requests
[
BgWri
terShmem
->
num_requests
++
];
request
=
&
CheckpointerShmem
->
requests
[
Checkpoin
terShmem
->
num_requests
++
];
request
->
rnode
=
rnode
;
request
->
forknum
=
forknum
;
request
->
segno
=
segno
;
/* If queue is more than half full, nudge the checkpointer to empty it */
too_full
=
(
BgWri
terShmem
->
num_requests
>=
BgWri
terShmem
->
max_requests
/
2
);
too_full
=
(
Checkpoin
terShmem
->
num_requests
>=
Checkpoin
terShmem
->
max_requests
/
2
);
LWLockRelease
(
CheckpointerCommLock
);
...
...
@@ -1180,7 +1180,7 @@ CompactCheckpointerRequestQueue(void)
{
struct
BgWriterSlotMapping
{
BgWri
terRequest
request
;
Checkpoin
terRequest
request
;
int
slot
;
};
...
...
@@ -1196,16 +1196,16 @@ CompactCheckpointerRequestQueue(void)
/* Initialize temporary hash table */
MemSet
(
&
ctl
,
0
,
sizeof
(
ctl
));
ctl
.
keysize
=
sizeof
(
BgWri
terRequest
);
ctl
.
keysize
=
sizeof
(
Checkpoin
terRequest
);
ctl
.
entrysize
=
sizeof
(
struct
BgWriterSlotMapping
);
ctl
.
hash
=
tag_hash
;
htab
=
hash_create
(
"CompactCheckpointerRequestQueue"
,
BgWri
terShmem
->
num_requests
,
Checkpoin
terShmem
->
num_requests
,
&
ctl
,
HASH_ELEM
|
HASH_FUNCTION
);
/* Initialize skip_slot array */
skip_slot
=
palloc0
(
sizeof
(
bool
)
*
BgWri
terShmem
->
num_requests
);
skip_slot
=
palloc0
(
sizeof
(
bool
)
*
Checkpoin
terShmem
->
num_requests
);
/*
* The basic idea here is that a request can be skipped if it's followed
...
...
@@ -1220,13 +1220,13 @@ CompactCheckpointerRequestQueue(void)
* anyhow), but it's not clear that the extra complexity would buy us
* anything.
*/
for
(
n
=
0
;
n
<
BgWri
terShmem
->
num_requests
;
++
n
)
for
(
n
=
0
;
n
<
Checkpoin
terShmem
->
num_requests
;
++
n
)
{
BgWri
terRequest
*
request
;
Checkpoin
terRequest
*
request
;
struct
BgWriterSlotMapping
*
slotmap
;
bool
found
;
request
=
&
BgWri
terShmem
->
requests
[
n
];
request
=
&
Checkpoin
terShmem
->
requests
[
n
];
slotmap
=
hash_search
(
htab
,
request
,
HASH_ENTER
,
&
found
);
if
(
found
)
{
...
...
@@ -1247,16 +1247,16 @@ CompactCheckpointerRequestQueue(void)
}
/* We found some duplicates; remove them. */
for
(
n
=
0
,
preserve_count
=
0
;
n
<
BgWri
terShmem
->
num_requests
;
++
n
)
for
(
n
=
0
,
preserve_count
=
0
;
n
<
Checkpoin
terShmem
->
num_requests
;
++
n
)
{
if
(
skip_slot
[
n
])
continue
;
BgWriterShmem
->
requests
[
preserve_count
++
]
=
BgWri
terShmem
->
requests
[
n
];
CheckpointerShmem
->
requests
[
preserve_count
++
]
=
Checkpoin
terShmem
->
requests
[
n
];
}
ereport
(
DEBUG1
,
(
errmsg
(
"compacted fsync request queue from %d entries to %d entries"
,
BgWri
terShmem
->
num_requests
,
preserve_count
)));
BgWri
terShmem
->
num_requests
=
preserve_count
;
Checkpoin
terShmem
->
num_requests
,
preserve_count
)));
Checkpoin
terShmem
->
num_requests
=
preserve_count
;
/* Cleanup. */
pfree
(
skip_slot
);
...
...
@@ -1275,8 +1275,8 @@ CompactCheckpointerRequestQueue(void)
void
AbsorbFsyncRequests
(
void
)
{
BgWri
terRequest
*
requests
=
NULL
;
BgWri
terRequest
*
request
;
Checkpoin
terRequest
*
requests
=
NULL
;
Checkpoin
terRequest
*
request
;
int
n
;
if
(
!
am_checkpointer
)
...
...
@@ -1298,19 +1298,19 @@ AbsorbFsyncRequests(void)
LWLockAcquire
(
CheckpointerCommLock
,
LW_EXCLUSIVE
);
/* Transfer stats counts into pending pgstats message */
BgWriterStats
.
m_buf_written_backend
+=
BgWri
terShmem
->
num_backend_writes
;
BgWriterStats
.
m_buf_fsync_backend
+=
BgWri
terShmem
->
num_backend_fsync
;
BgWriterStats
.
m_buf_written_backend
+=
Checkpoin
terShmem
->
num_backend_writes
;
BgWriterStats
.
m_buf_fsync_backend
+=
Checkpoin
terShmem
->
num_backend_fsync
;
BgWri
terShmem
->
num_backend_writes
=
0
;
BgWri
terShmem
->
num_backend_fsync
=
0
;
Checkpoin
terShmem
->
num_backend_writes
=
0
;
Checkpoin
terShmem
->
num_backend_fsync
=
0
;
n
=
BgWri
terShmem
->
num_requests
;
n
=
Checkpoin
terShmem
->
num_requests
;
if
(
n
>
0
)
{
requests
=
(
BgWriterRequest
*
)
palloc
(
n
*
sizeof
(
BgWri
terRequest
));
memcpy
(
requests
,
BgWriterShmem
->
requests
,
n
*
sizeof
(
BgWri
terRequest
));
requests
=
(
CheckpointerRequest
*
)
palloc
(
n
*
sizeof
(
Checkpoin
terRequest
));
memcpy
(
requests
,
CheckpointerShmem
->
requests
,
n
*
sizeof
(
Checkpoin
terRequest
));
}
BgWri
terShmem
->
num_requests
=
0
;
Checkpoin
terShmem
->
num_requests
=
0
;
LWLockRelease
(
CheckpointerCommLock
);
...
...
src/backend/storage/ipc/ipci.c
View file @
8f28789b
...
...
@@ -119,7 +119,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
size
=
add_size
(
size
,
SInvalShmemSize
());
size
=
add_size
(
size
,
PMSignalShmemSize
());
size
=
add_size
(
size
,
ProcSignalShmemSize
());
size
=
add_size
(
size
,
BgWri
terShmemSize
());
size
=
add_size
(
size
,
Checkpoin
terShmemSize
());
size
=
add_size
(
size
,
AutoVacuumShmemSize
());
size
=
add_size
(
size
,
WalSndShmemSize
());
size
=
add_size
(
size
,
WalRcvShmemSize
());
...
...
@@ -224,7 +224,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
*/
PMSignalShmemInit
();
ProcSignalShmemInit
();
BgWri
terShmemInit
();
Checkpoin
terShmemInit
();
AutoVacuumShmemInit
();
WalSndShmemInit
();
WalRcvShmemInit
();
...
...
src/include/postmaster/bgwriter.h
View file @
8f28789b
...
...
@@ -32,7 +32,8 @@ extern bool ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,
BlockNumber
segno
);
extern
void
AbsorbFsyncRequests
(
void
);
extern
Size
BgWriterShmemSize
(
void
);
extern
void
BgWriterShmemInit
(
void
);
/* These were previously called BgWriterShmem... */
extern
Size
CheckpointerShmemSize
(
void
);
extern
void
CheckpointerShmemInit
(
void
);
#endif
/* _BGWRITER_H */
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