Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit507ba16

Browse files
committed
Convert macros to static inline functions (xlog_internal.h)
Reviewed-by: Amul Sul <sulamul@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com
1 parent3e9ca52 commit507ba16

File tree

1 file changed

+96
-58
lines changed

1 file changed

+96
-58
lines changed

‎src/include/access/xlog_internal.h

Lines changed: 96 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -159,74 +159,112 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
159159
#defineXLOG_FNAME_LEN 24
160160

161161
/*
162-
* Generate a WAL segment file name. Do not use thismacro in a helper
162+
* Generate a WAL segment file name. Do not use thisfunction in a helper
163163
* function allocating the result generated.
164164
*/
165-
#defineXLogFileName(fname,tli,logSegNo,wal_segsz_bytes)\
166-
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,\
167-
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
168-
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))
165+
staticinlinevoid
166+
XLogFileName(char*fname,TimeLineIDtli,XLogSegNologSegNo,intwal_segsz_bytes)
167+
{
168+
snprintf(fname,MAXFNAMELEN,"%08X%08X%08X",tli,
169+
(uint32) (logSegNo /XLogSegmentsPerXLogId(wal_segsz_bytes)),
170+
(uint32) (logSegNo %XLogSegmentsPerXLogId(wal_segsz_bytes)));
171+
}
169172

170-
#defineXLogFileNameById(fname,tli,log,seg)\
171-
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
173+
staticinlinevoid
174+
XLogFileNameById(char*fname,TimeLineIDtli,uint32log,uint32seg)
175+
{
176+
snprintf(fname,MAXFNAMELEN,"%08X%08X%08X",tli,log,seg);
177+
}
172178

173-
#defineIsXLogFileName(fname) \
174-
(strlen(fname) == XLOG_FNAME_LEN && \
175-
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN)
179+
staticinlinebool
180+
IsXLogFileName(constchar*fname)
181+
{
182+
return (strlen(fname)==XLOG_FNAME_LEN&& \
183+
strspn(fname,"0123456789ABCDEF")==XLOG_FNAME_LEN);
184+
}
176185

177186
/*
178187
* XLOG segment with .partial suffix. Used by pg_receivewal and at end of
179188
* archive recovery, when we want to archive a WAL segment but it might not
180189
* be complete yet.
181190
*/
182-
#defineIsPartialXLogFileName(fname)\
183-
(strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") &&\
184-
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&\
185-
strcmp((fname) + XLOG_FNAME_LEN, ".partial") == 0)
186-
187-
#defineXLogFromFileName(fname,tli,logSegNo,wal_segsz_bytes)\
188-
do {\
189-
uint32 log;\
190-
uint32 seg;\
191-
sscanf(fname, "%08X%08X%08X", tli, &log, &seg); \
192-
*logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg; \
193-
} while (0)
194-
195-
#defineXLogFilePath(path,tli,logSegNo,wal_segsz_bytes)\
196-
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,\
197-
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
198-
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))
199-
200-
#defineTLHistoryFileName(fname,tli)\
201-
snprintf(fname, MAXFNAMELEN, "%08X.history", tli)
202-
203-
#defineIsTLHistoryFileName(fname)\
204-
(strlen(fname) == 8 + strlen(".history") &&\
205-
strspn(fname, "0123456789ABCDEF") == 8 &&\
206-
strcmp((fname) + 8, ".history") == 0)
207-
208-
#defineTLHistoryFilePath(path,tli)\
209-
snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli)
210-
211-
#defineStatusFilePath(path,xlog,suffix)\
212-
snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix)
213-
214-
#defineBackupHistoryFileName(fname,tli,logSegNo,startpoint,wal_segsz_bytes) \
215-
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli, \
216-
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
217-
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)), \
218-
(uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)))
219-
220-
#defineIsBackupHistoryFileName(fname) \
221-
(strlen(fname) > XLOG_FNAME_LEN && \
222-
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
223-
strcmp((fname) + strlen(fname) - strlen(".backup"), ".backup") == 0)
224-
225-
#defineBackupHistoryFilePath(path,tli,logSegNo,startpoint,wal_segsz_bytes)\
226-
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli, \
227-
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
228-
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)), \
229-
(uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)))
191+
staticinlinebool
192+
IsPartialXLogFileName(constchar*fname)
193+
{
194+
return (strlen(fname)==XLOG_FNAME_LEN+strlen(".partial")&&
195+
strspn(fname,"0123456789ABCDEF")==XLOG_FNAME_LEN&&
196+
strcmp(fname+XLOG_FNAME_LEN,".partial")==0);
197+
}
198+
199+
staticinlinevoid
200+
XLogFromFileName(constchar*fname,TimeLineID*tli,XLogSegNo*logSegNo,intwal_segsz_bytes)
201+
{
202+
uint32log;
203+
uint32seg;
204+
205+
sscanf(fname,"%08X%08X%08X",tli,&log,&seg);
206+
*logSegNo= (uint64)log*XLogSegmentsPerXLogId(wal_segsz_bytes)+seg;
207+
}
208+
209+
staticinlinevoid
210+
XLogFilePath(char*path,TimeLineIDtli,XLogSegNologSegNo,intwal_segsz_bytes)
211+
{
212+
snprintf(path,MAXPGPATH,XLOGDIR"/%08X%08X%08X",tli,
213+
(uint32) (logSegNo /XLogSegmentsPerXLogId(wal_segsz_bytes)),
214+
(uint32) (logSegNo %XLogSegmentsPerXLogId(wal_segsz_bytes)));
215+
}
216+
217+
staticinlinevoid
218+
TLHistoryFileName(char*fname,TimeLineIDtli)
219+
{
220+
snprintf(fname,MAXFNAMELEN,"%08X.history",tli);
221+
}
222+
223+
staticinlinebool
224+
IsTLHistoryFileName(constchar*fname)
225+
{
226+
return (strlen(fname)==8+strlen(".history")&&
227+
strspn(fname,"0123456789ABCDEF")==8&&
228+
strcmp(fname+8,".history")==0);
229+
}
230+
231+
staticinlinevoid
232+
TLHistoryFilePath(char*path,TimeLineIDtli)
233+
{
234+
snprintf(path,MAXPGPATH,XLOGDIR"/%08X.history",tli);
235+
}
236+
237+
staticinlinevoid
238+
StatusFilePath(char*path,constchar*xlog,constchar*suffix)
239+
{
240+
snprintf(path,MAXPGPATH,XLOGDIR"/archive_status/%s%s",xlog,suffix);
241+
}
242+
243+
staticinlinevoid
244+
BackupHistoryFileName(char*fname,TimeLineIDtli,XLogSegNologSegNo,XLogRecPtrstartpoint,intwal_segsz_bytes)
245+
{
246+
snprintf(fname,MAXFNAMELEN,"%08X%08X%08X.%08X.backup",tli,
247+
(uint32) (logSegNo /XLogSegmentsPerXLogId(wal_segsz_bytes)),
248+
(uint32) (logSegNo %XLogSegmentsPerXLogId(wal_segsz_bytes)),
249+
(uint32) (XLogSegmentOffset(startpoint,wal_segsz_bytes)));
250+
}
251+
252+
staticinlinebool
253+
IsBackupHistoryFileName(constchar*fname)
254+
{
255+
return (strlen(fname)>XLOG_FNAME_LEN&&
256+
strspn(fname,"0123456789ABCDEF")==XLOG_FNAME_LEN&&
257+
strcmp(fname+strlen(fname)-strlen(".backup"),".backup")==0);
258+
}
259+
260+
staticinlinevoid
261+
BackupHistoryFilePath(char*path,TimeLineIDtli,XLogSegNologSegNo,XLogRecPtrstartpoint,intwal_segsz_bytes)
262+
{
263+
snprintf(path,MAXPGPATH,XLOGDIR"/%08X%08X%08X.%08X.backup",tli,
264+
(uint32) (logSegNo /XLogSegmentsPerXLogId(wal_segsz_bytes)),
265+
(uint32) (logSegNo %XLogSegmentsPerXLogId(wal_segsz_bytes)),
266+
(uint32) (XLogSegmentOffset((startpoint),wal_segsz_bytes)));
267+
}
230268

231269
/*
232270
* Information logged when we detect a change in one of the parameters

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp