@@ -1537,9 +1537,18 @@ pgstat_read_statsfile(void)
1537
1537
/*
1538
1538
* Verify it's of the expected format.
1539
1539
*/
1540
- if (!read_chunk_s (fpin , & format_id ) ||
1541
- format_id != PGSTAT_FILE_FORMAT_ID )
1540
+ if (!read_chunk_s (fpin , & format_id ))
1541
+ {
1542
+ elog (WARNING , "could not read format ID" );
1543
+ goto error ;
1544
+ }
1545
+
1546
+ if (format_id != PGSTAT_FILE_FORMAT_ID )
1547
+ {
1548
+ elog (WARNING , "found incorrect format ID %d (expected %d)" ,
1549
+ format_id , PGSTAT_FILE_FORMAT_ID );
1542
1550
goto error ;
1551
+ }
1543
1552
1544
1553
/*
1545
1554
* We found an existing statistics file. Read it and put all the stats
@@ -1559,22 +1568,37 @@ pgstat_read_statsfile(void)
1559
1568
1560
1569
/* entry for fixed-numbered stats */
1561
1570
if (!read_chunk_s (fpin , & kind ))
1571
+ {
1572
+ elog (WARNING , "could not read stats kind for entry of type %c" , t );
1562
1573
goto error ;
1574
+ }
1563
1575
1564
1576
if (!pgstat_is_kind_valid (kind ))
1577
+ {
1578
+ elog (WARNING , "invalid stats kind %d for entry of type %c" ,
1579
+ kind , t );
1565
1580
goto error ;
1581
+ }
1566
1582
1567
1583
info = pgstat_get_kind_info (kind );
1568
1584
1569
1585
if (!info -> fixed_amount )
1586
+ {
1587
+ elog (WARNING , "invalid fixed_amount in stats kind %d for entry of type %c" ,
1588
+ kind , t );
1570
1589
goto error ;
1590
+ }
1571
1591
1572
1592
/* Load back stats into shared memory */
1573
1593
ptr = ((char * ) shmem ) + info -> shared_ctl_off +
1574
1594
info -> shared_data_off ;
1575
1595
1576
1596
if (!read_chunk (fpin , ptr , info -> shared_data_len ))
1597
+ {
1598
+ elog (WARNING , "could not read data of stats kind %d for entry of type %c with size %u" ,
1599
+ kind , t , info -> shared_data_len );
1577
1600
goto error ;
1601
+ }
1578
1602
1579
1603
break ;
1580
1604
}
@@ -1591,10 +1615,17 @@ pgstat_read_statsfile(void)
1591
1615
{
1592
1616
/* normal stats entry, identified by PgStat_HashKey */
1593
1617
if (!read_chunk_s (fpin , & key ))
1618
+ {
1619
+ elog (WARNING , "could not read key for entry of type %c" , t );
1594
1620
goto error ;
1621
+ }
1595
1622
1596
1623
if (!pgstat_is_kind_valid (key .kind ))
1624
+ {
1625
+ elog (WARNING , "invalid stats kind for entry %d/%u/%u of type %c" ,
1626
+ key .kind , key .dboid , key .objoid , t );
1597
1627
goto error ;
1628
+ }
1598
1629
}
1599
1630
else
1600
1631
{
@@ -1604,22 +1635,41 @@ pgstat_read_statsfile(void)
1604
1635
NameData name ;
1605
1636
1606
1637
if (!read_chunk_s (fpin , & kind ))
1638
+ {
1639
+ elog (WARNING , "could not read stats kind for entry of type %c" , t );
1607
1640
goto error ;
1641
+ }
1608
1642
if (!read_chunk_s (fpin , & name ))
1643
+ {
1644
+ elog (WARNING , "could not read name of stats kind %d for entry of type %c" ,
1645
+ kind , t );
1609
1646
goto error ;
1647
+ }
1610
1648
if (!pgstat_is_kind_valid (kind ))
1649
+ {
1650
+ elog (WARNING , "invalid stats kind %d for entry of type %c" ,
1651
+ kind , t );
1611
1652
goto error ;
1653
+ }
1612
1654
1613
1655
kind_info = pgstat_get_kind_info (kind );
1614
1656
1615
1657
if (!kind_info -> from_serialized_name )
1658
+ {
1659
+ elog (WARNING , "invalid from_serialized_name in stats kind %d for entry of type %c" ,
1660
+ kind , t );
1616
1661
goto error ;
1662
+ }
1617
1663
1618
1664
if (!kind_info -> from_serialized_name (& name , & key ))
1619
1665
{
1620
1666
/* skip over data for entry we don't care about */
1621
1667
if (fseek (fpin , pgstat_get_entry_len (kind ), SEEK_CUR ) != 0 )
1668
+ {
1669
+ elog (WARNING , "could not seek \"%s\" of stats kind %d for entry of type %c" ,
1670
+ NameStr (name ), kind , t );
1622
1671
goto error ;
1672
+ }
1623
1673
1624
1674
continue ;
1625
1675
}
@@ -1638,8 +1688,8 @@ pgstat_read_statsfile(void)
1638
1688
if (found )
1639
1689
{
1640
1690
dshash_release_lock (pgStatLocal .shared_hash , p );
1641
- elog (WARNING , "found duplicate stats entry %d/%u/%u" ,
1642
- key .kind , key .dboid , key .objoid );
1691
+ elog (WARNING , "found duplicate stats entry %d/%u/%u of type %c " ,
1692
+ key .kind , key .dboid , key .objoid , t );
1643
1693
goto error ;
1644
1694
}
1645
1695
@@ -1649,7 +1699,11 @@ pgstat_read_statsfile(void)
1649
1699
if (!read_chunk (fpin ,
1650
1700
pgstat_get_entry_data (key .kind , header ),
1651
1701
pgstat_get_entry_len (key .kind )))
1702
+ {
1703
+ elog (WARNING , "could not read data for entry %d/%u/%u of type %c" ,
1704
+ key .kind , key .dboid , key .objoid , t );
1652
1705
goto error ;
1706
+ }
1653
1707
1654
1708
break ;
1655
1709
}
@@ -1660,11 +1714,15 @@ pgstat_read_statsfile(void)
1660
1714
* file
1661
1715
*/
1662
1716
if (fgetc (fpin ) != EOF )
1717
+ {
1718
+ elog (WARNING , "could not read end-of-file" );
1663
1719
goto error ;
1720
+ }
1664
1721
1665
1722
goto done ;
1666
1723
1667
1724
default :
1725
+ elog (WARNING , "could not read entry of type %c" , t );
1668
1726
goto error ;
1669
1727
}
1670
1728
}
0 commit comments