|
132 | 132 | * ---------
|
133 | 133 | */
|
134 | 134 | #define PGSTAT_FILE_ENTRY_END 'E' /* end of file */
|
| 135 | +#define PGSTAT_FILE_ENTRY_FIXED 'F' /* fixed-numbered stats entry */ |
135 | 136 | #define PGSTAT_FILE_ENTRY_NAME 'N' /* stats entry identified by name */
|
136 | 137 | #define PGSTAT_FILE_ENTRY_HASH 'S' /* stats entry identified by
|
137 | 138 | * PgStat_HashKey */
|
@@ -1396,6 +1397,9 @@ pgstat_write_statsfile(void)
|
1396 | 1397 |
|
1397 | 1398 | pgstat_build_snapshot_fixed(kind);
|
1398 | 1399 | ptr = ((char *) &pgStatLocal.snapshot) + info->snapshot_ctl_off;
|
| 1400 | + |
| 1401 | + fputc(PGSTAT_FILE_ENTRY_FIXED, fpout); |
| 1402 | + write_chunk_s(fpout, &kind); |
1399 | 1403 | write_chunk(fpout, ptr, info->shared_data_len);
|
1400 | 1404 | }
|
1401 | 1405 |
|
@@ -1537,32 +1541,43 @@ pgstat_read_statsfile(void)
|
1537 | 1541 | format_id != PGSTAT_FILE_FORMAT_ID)
|
1538 | 1542 | goto error;
|
1539 | 1543 |
|
1540 |
| - /* Read various stats structs with fixed number of objects */ |
1541 |
| - for (int kind = PGSTAT_KIND_FIRST_VALID; kind <= PGSTAT_KIND_LAST; kind++) |
1542 |
| - { |
1543 |
| - char *ptr; |
1544 |
| - const PgStat_KindInfo *info = pgstat_get_kind_info(kind); |
1545 |
| - |
1546 |
| - if (!info->fixed_amount) |
1547 |
| - continue; |
1548 |
| - |
1549 |
| - Assert(info->shared_ctl_off != 0); |
1550 |
| - |
1551 |
| - ptr = ((char *) shmem) + info->shared_ctl_off + info->shared_data_off; |
1552 |
| - if (!read_chunk(fpin, ptr, info->shared_data_len)) |
1553 |
| - goto error; |
1554 |
| - } |
1555 |
| - |
1556 | 1544 | /*
|
1557 |
| - * We found an existing statistics file. Read it and put all the hash |
1558 |
| - * table entries into place. |
| 1545 | + * We found an existing statistics file. Read it and put all the stats |
| 1546 | + * data into place. |
1559 | 1547 | */
|
1560 | 1548 | for (;;)
|
1561 | 1549 | {
|
1562 | 1550 | int t = fgetc(fpin);
|
1563 | 1551 |
|
1564 | 1552 | switch (t)
|
1565 | 1553 | {
|
| 1554 | + case PGSTAT_FILE_ENTRY_FIXED: |
| 1555 | + { |
| 1556 | + PgStat_Kind kind; |
| 1557 | + const PgStat_KindInfo *info; |
| 1558 | + char *ptr; |
| 1559 | + |
| 1560 | + /* entry for fixed-numbered stats */ |
| 1561 | + if (!read_chunk_s(fpin, &kind)) |
| 1562 | + goto error; |
| 1563 | + |
| 1564 | + if (!pgstat_is_kind_valid(kind)) |
| 1565 | + goto error; |
| 1566 | + |
| 1567 | + info = pgstat_get_kind_info(kind); |
| 1568 | + |
| 1569 | + if (!info->fixed_amount) |
| 1570 | + goto error; |
| 1571 | + |
| 1572 | + /* Load back stats into shared memory */ |
| 1573 | + ptr = ((char *) shmem) + info->shared_ctl_off + |
| 1574 | + info->shared_data_off; |
| 1575 | + |
| 1576 | + if (!read_chunk(fpin, ptr, info->shared_data_len)) |
| 1577 | + goto error; |
| 1578 | + |
| 1579 | + break; |
| 1580 | + } |
1566 | 1581 | case PGSTAT_FILE_ENTRY_HASH:
|
1567 | 1582 | case PGSTAT_FILE_ENTRY_NAME:
|
1568 | 1583 | {
|
|
0 commit comments