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

Commited823da

Browse files
committed
Rename routines for write/read of pgstats file
This commit renames write_chunk and read_chunk to respectivelypgstat_write_chunk() and pgstat_read_chunk(), along with the *_sconvenience macros.These are made available for plug-ins, so as any code that decides towrite and/or read stats data can rely on a single code path for thiswork.Extracted from a larger patch by the same author.Author: Sami Imseih <samimseih@gmail.com>Discussion:https://postgr.es/m/CAA5RZ0s9SDOu+Z6veoJCHWk+kDeTktAtC-KY9fQ9Z6BJdDUirQ@mail.gmail.com
1 parent81f7738 commited823da

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

‎src/backend/utils/activity/pgstat.c‎

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,20 +1551,18 @@ pgstat_assert_is_up(void)
15511551
* ------------------------------------------------------------
15521552
*/
15531553

1554-
/*helpers for pgstat_write_statsfile() */
1555-
staticvoid
1556-
write_chunk(FILE*fpout,void*ptr,size_tlen)
1554+
/*helper for pgstat_write_statsfile() */
1555+
void
1556+
pgstat_write_chunk(FILE*fpout,void*ptr,size_tlen)
15571557
{
15581558
intrc;
15591559

15601560
rc=fwrite(ptr,len,1,fpout);
15611561

1562-
/*we'll check for errors with ferror once attheend */
1562+
/*We check for errors with ferror() when done writingthestats. */
15631563
(void)rc;
15641564
}
15651565

1566-
#definewrite_chunk_s(fpout,ptr) write_chunk(fpout, ptr, sizeof(*ptr))
1567-
15681566
/*
15691567
* This function is called in the last process that is accessing the shared
15701568
* stats so locking is not required.
@@ -1606,7 +1604,7 @@ pgstat_write_statsfile(void)
16061604
* Write the file header --- currently just a format ID.
16071605
*/
16081606
format_id=PGSTAT_FILE_FORMAT_ID;
1609-
write_chunk_s(fpout,&format_id);
1607+
pgstat_write_chunk_s(fpout,&format_id);
16101608

16111609
/* Write various stats structs for fixed number of objects */
16121610
for (PgStat_Kindkind=PGSTAT_KIND_MIN;kind <=PGSTAT_KIND_MAX;kind++)
@@ -1631,8 +1629,8 @@ pgstat_write_statsfile(void)
16311629
ptr=pgStatLocal.snapshot.custom_data[kind-PGSTAT_KIND_CUSTOM_MIN];
16321630

16331631
fputc(PGSTAT_FILE_ENTRY_FIXED,fpout);
1634-
write_chunk_s(fpout,&kind);
1635-
write_chunk(fpout,ptr,info->shared_data_len);
1632+
pgstat_write_chunk_s(fpout,&kind);
1633+
pgstat_write_chunk(fpout,ptr,info->shared_data_len);
16361634
}
16371635

16381636
/*
@@ -1686,7 +1684,7 @@ pgstat_write_statsfile(void)
16861684
{
16871685
/* normal stats entry, identified by PgStat_HashKey */
16881686
fputc(PGSTAT_FILE_ENTRY_HASH,fpout);
1689-
write_chunk_s(fpout,&ps->key);
1687+
pgstat_write_chunk_s(fpout,&ps->key);
16901688
}
16911689
else
16921690
{
@@ -1696,21 +1694,21 @@ pgstat_write_statsfile(void)
16961694
kind_info->to_serialized_name(&ps->key,shstats,&name);
16971695

16981696
fputc(PGSTAT_FILE_ENTRY_NAME,fpout);
1699-
write_chunk_s(fpout,&ps->key.kind);
1700-
write_chunk_s(fpout,&name);
1697+
pgstat_write_chunk_s(fpout,&ps->key.kind);
1698+
pgstat_write_chunk_s(fpout,&name);
17011699
}
17021700

17031701
/* Write except the header part of the entry */
1704-
write_chunk(fpout,
1705-
pgstat_get_entry_data(ps->key.kind,shstats),
1706-
pgstat_get_entry_len(ps->key.kind));
1702+
pgstat_write_chunk(fpout,
1703+
pgstat_get_entry_data(ps->key.kind,shstats),
1704+
pgstat_get_entry_len(ps->key.kind));
17071705
}
17081706
dshash_seq_term(&hstat);
17091707

17101708
/*
17111709
* No more output to be done. Close the temp file and replace the old
17121710
* pgstat.stat with it. The ferror() check replaces testing for error
1713-
* after each individual fputc or fwrite (inwrite_chunk()) above.
1711+
* after each individual fputc or fwrite (inpgstat_write_chunk()) above.
17141712
*/
17151713
fputc(PGSTAT_FILE_ENTRY_END,fpout);
17161714

@@ -1738,15 +1736,13 @@ pgstat_write_statsfile(void)
17381736
}
17391737
}
17401738

1741-
/*helpers for pgstat_read_statsfile() */
1742-
staticbool
1743-
read_chunk(FILE*fpin,void*ptr,size_tlen)
1739+
/*helper for pgstat_read_statsfile() */
1740+
bool
1741+
pgstat_read_chunk(FILE*fpin,void*ptr,size_tlen)
17441742
{
17451743
returnfread(ptr,1,len,fpin)==len;
17461744
}
17471745

1748-
#defineread_chunk_s(fpin,ptr) read_chunk(fpin, ptr, sizeof(*ptr))
1749-
17501746
/*
17511747
* Reads in existing statistics file into memory.
17521748
*
@@ -1790,7 +1786,7 @@ pgstat_read_statsfile(void)
17901786
/*
17911787
* Verify it's of the expected format.
17921788
*/
1793-
if (!read_chunk_s(fpin,&format_id))
1789+
if (!pgstat_read_chunk_s(fpin,&format_id))
17941790
{
17951791
elog(WARNING,"could not read format ID");
17961792
gotoerror;
@@ -1820,7 +1816,7 @@ pgstat_read_statsfile(void)
18201816
char*ptr;
18211817

18221818
/* entry for fixed-numbered stats */
1823-
if (!read_chunk_s(fpin,&kind))
1819+
if (!pgstat_read_chunk_s(fpin,&kind))
18241820
{
18251821
elog(WARNING,"could not read stats kind for entry of type %c",t);
18261822
gotoerror;
@@ -1860,7 +1856,7 @@ pgstat_read_statsfile(void)
18601856
info->shared_data_off;
18611857
}
18621858

1863-
if (!read_chunk(fpin,ptr,info->shared_data_len))
1859+
if (!pgstat_read_chunk(fpin,ptr,info->shared_data_len))
18641860
{
18651861
elog(WARNING,"could not read data of stats kind %u for entry of type %c with size %u",
18661862
kind,t,info->shared_data_len);
@@ -1881,7 +1877,7 @@ pgstat_read_statsfile(void)
18811877
if (t==PGSTAT_FILE_ENTRY_HASH)
18821878
{
18831879
/* normal stats entry, identified by PgStat_HashKey */
1884-
if (!read_chunk_s(fpin,&key))
1880+
if (!pgstat_read_chunk_s(fpin,&key))
18851881
{
18861882
elog(WARNING,"could not read key for entry of type %c",t);
18871883
gotoerror;
@@ -1910,12 +1906,12 @@ pgstat_read_statsfile(void)
19101906
PgStat_Kindkind;
19111907
NameDataname;
19121908

1913-
if (!read_chunk_s(fpin,&kind))
1909+
if (!pgstat_read_chunk_s(fpin,&kind))
19141910
{
19151911
elog(WARNING,"could not read stats kind for entry of type %c",t);
19161912
gotoerror;
19171913
}
1918-
if (!read_chunk_s(fpin,&name))
1914+
if (!pgstat_read_chunk_s(fpin,&name))
19191915
{
19201916
elog(WARNING,"could not read name of stats kind %u for entry of type %c",
19211917
kind,t);
@@ -1990,9 +1986,9 @@ pgstat_read_statsfile(void)
19901986
key.objid,t);
19911987
}
19921988

1993-
if (!read_chunk(fpin,
1994-
pgstat_get_entry_data(key.kind,header),
1995-
pgstat_get_entry_len(key.kind)))
1989+
if (!pgstat_read_chunk(fpin,
1990+
pgstat_get_entry_data(key.kind,header),
1991+
pgstat_get_entry_len(key.kind)))
19961992
{
19971993
elog(WARNING,"could not read data for entry %u/%u/%"PRIu64" of type %c",
19981994
key.kind,key.dboid,

‎src/include/utils/pgstat_internal.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,12 @@ extern PGDLLIMPORT bool pgstat_report_fixed;
818818
/* Backend-local stats state */
819819
externPGDLLIMPORTPgStat_LocalStatepgStatLocal;
820820

821+
/* Helper functions for reading and writing of on-disk stats file */
822+
externvoidpgstat_write_chunk(FILE*fpout,void*ptr,size_tlen);
823+
externboolpgstat_read_chunk(FILE*fpin,void*ptr,size_tlen);
824+
#definepgstat_read_chunk_s(fpin,ptr) pgstat_read_chunk(fpin, ptr, sizeof(*ptr))
825+
#definepgstat_write_chunk_s(fpout,ptr) pgstat_write_chunk(fpout, ptr, sizeof(*ptr))
826+
821827
/*
822828
* Implementation of inline functions declared above.
823829
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp