LCOV - differential code coverage report
Current view: top level - libs/postgres_ffi/src - pg_constants.rs (source / functions) Coverage Total Hit CBC
Current: f6946e90941b557c917ac98cd5a7e9506d180f3e.info Lines: 100.0 % 9 9 9
Current Date: 2023-10-19 02:04:12 Functions: 100.0 % 3 3 3
Baseline: c8637f37369098875162f194f92736355783b050.info
Baseline Date: 2023-10-18 20:25:20

           TLA  Line data    Source code
       1                 : //!
       2                 : //! Misc constants, copied from PostgreSQL headers.
       3                 : //!
       4                 : //! Only place version-independent constants here.
       5                 : //!
       6                 : //! TODO: These probably should be auto-generated using bindgen,
       7                 : //! rather than copied by hand. Although on the other hand, it's nice
       8                 : //! to have them all here in one place, and have the ability to add
       9                 : //! comments on them.
      10                 : //!
      11                 : 
      12                 : use crate::BLCKSZ;
      13                 : use crate::{PageHeaderData, XLogRecord};
      14                 : 
      15                 : //
      16                 : // From pg_tablespace_d.h
      17                 : //
      18                 : pub const DEFAULTTABLESPACE_OID: u32 = 1663;
      19                 : pub const GLOBALTABLESPACE_OID: u32 = 1664;
      20                 : 
      21                 : // From storage_xlog.h
      22                 : pub const XLOG_SMGR_CREATE: u8 = 0x10;
      23                 : pub const XLOG_SMGR_TRUNCATE: u8 = 0x20;
      24                 : 
      25                 : pub const SMGR_TRUNCATE_HEAP: u32 = 0x0001;
      26                 : pub const SMGR_TRUNCATE_VM: u32 = 0x0002;
      27                 : pub const SMGR_TRUNCATE_FSM: u32 = 0x0004;
      28                 : 
      29                 : //
      30                 : // From bufpage.h
      31                 : //
      32                 : 
      33                 : // Assumes 8 byte alignment
      34                 : const SIZEOF_PAGE_HEADER_DATA: usize = std::mem::size_of::<PageHeaderData>();
      35                 : pub const MAXALIGN_SIZE_OF_PAGE_HEADER_DATA: usize = (SIZEOF_PAGE_HEADER_DATA + 7) & !7;
      36                 : 
      37                 : //
      38                 : // constants from clog.h
      39                 : //
      40                 : pub const CLOG_XACTS_PER_BYTE: u32 = 4;
      41                 : pub const CLOG_XACTS_PER_PAGE: u32 = BLCKSZ as u32 * CLOG_XACTS_PER_BYTE;
      42                 : pub const CLOG_BITS_PER_XACT: u8 = 2;
      43                 : pub const CLOG_XACT_BITMASK: u8 = (1 << CLOG_BITS_PER_XACT) - 1;
      44                 : 
      45                 : pub const TRANSACTION_STATUS_COMMITTED: u8 = 0x01;
      46                 : pub const TRANSACTION_STATUS_ABORTED: u8 = 0x02;
      47                 : pub const TRANSACTION_STATUS_SUB_COMMITTED: u8 = 0x03;
      48                 : 
      49                 : pub const CLOG_ZEROPAGE: u8 = 0x00;
      50                 : pub const CLOG_TRUNCATE: u8 = 0x10;
      51                 : 
      52                 : //
      53                 : // Constants from visibilitymap.h, visibilitymapdefs.h and visibilitymap.c
      54                 : //
      55                 : pub const SIZE_OF_PAGE_HEADER: u16 = 24;
      56                 : pub const BITS_PER_BYTE: u16 = 8;
      57                 : pub const HEAPBLOCKS_PER_PAGE: u32 =
      58                 :     (BLCKSZ - SIZE_OF_PAGE_HEADER) as u32 * 8 / BITS_PER_HEAPBLOCK as u32;
      59                 : pub const HEAPBLOCKS_PER_BYTE: u16 = BITS_PER_BYTE / BITS_PER_HEAPBLOCK;
      60                 : 
      61 CBC      139271 : pub const fn HEAPBLK_TO_MAPBLOCK(x: u32) -> u32 {
      62          139271 :     x / HEAPBLOCKS_PER_PAGE
      63          139271 : }
      64           10641 : pub const fn HEAPBLK_TO_MAPBYTE(x: u32) -> u32 {
      65           10641 :     (x % HEAPBLOCKS_PER_PAGE) / HEAPBLOCKS_PER_BYTE as u32
      66           10641 : }
      67           10641 : pub const fn HEAPBLK_TO_OFFSET(x: u32) -> u32 {
      68           10641 :     (x % HEAPBLOCKS_PER_BYTE as u32) * BITS_PER_HEAPBLOCK as u32
      69           10641 : }
      70                 : 
      71                 : pub const BITS_PER_HEAPBLOCK: u16 = 2;
      72                 : pub const VISIBILITYMAP_ALL_VISIBLE: u8 = 0x01;
      73                 : pub const VISIBILITYMAP_ALL_FROZEN: u8 = 0x02;
      74                 : pub const VISIBILITYMAP_VALID_BITS: u8 = 0x03;
      75                 : 
      76                 : // From xact.h
      77                 : pub const XLOG_XACT_COMMIT: u8 = 0x00;
      78                 : pub const XLOG_XACT_PREPARE: u8 = 0x10;
      79                 : pub const XLOG_XACT_ABORT: u8 = 0x20;
      80                 : pub const XLOG_XACT_COMMIT_PREPARED: u8 = 0x30;
      81                 : pub const XLOG_XACT_ABORT_PREPARED: u8 = 0x40;
      82                 : 
      83                 : // From srlu.h
      84                 : pub const SLRU_PAGES_PER_SEGMENT: u32 = 32;
      85                 : pub const SLRU_SEG_SIZE: usize = BLCKSZ as usize * SLRU_PAGES_PER_SEGMENT as usize;
      86                 : 
      87                 : /* mask for filtering opcodes out of xl_info */
      88                 : pub const XLOG_XACT_OPMASK: u8 = 0x70;
      89                 : pub const XLOG_HEAP_OPMASK: u8 = 0x70;
      90                 : /* does this record have a 'xinfo' field or not */
      91                 : pub const XLOG_XACT_HAS_INFO: u8 = 0x80;
      92                 : 
      93                 : /*
      94                 :  * The following flags, stored in xinfo, determine which information is
      95                 :  * contained in commit/abort records.
      96                 :  */
      97                 : pub const XACT_XINFO_HAS_DBINFO: u32 = 1u32 << 0;
      98                 : pub const XACT_XINFO_HAS_SUBXACTS: u32 = 1u32 << 1;
      99                 : pub const XACT_XINFO_HAS_RELFILENODES: u32 = 1u32 << 2;
     100                 : pub const XACT_XINFO_HAS_INVALS: u32 = 1u32 << 3;
     101                 : pub const XACT_XINFO_HAS_TWOPHASE: u32 = 1u32 << 4;
     102                 : // pub const XACT_XINFO_HAS_ORIGIN: u32 = 1u32 << 5;
     103                 : // pub const XACT_XINFO_HAS_AE_LOCKS: u32 = 1u32 << 6;
     104                 : // pub const XACT_XINFO_HAS_GID: u32 = 1u32 << 7;
     105                 : 
     106                 : // From pg_control.h and rmgrlist.h
     107                 : pub const XLOG_NEXTOID: u8 = 0x30;
     108                 : pub const XLOG_SWITCH: u8 = 0x40;
     109                 : pub const XLOG_FPI_FOR_HINT: u8 = 0xA0;
     110                 : pub const XLOG_FPI: u8 = 0xB0;
     111                 : 
     112                 : // From multixact.h
     113                 : pub const FIRST_MULTIXACT_ID: u32 = 1;
     114                 : pub const MAX_MULTIXACT_ID: u32 = 0xFFFFFFFF;
     115                 : pub const MAX_MULTIXACT_OFFSET: u32 = 0xFFFFFFFF;
     116                 : 
     117                 : pub const XLOG_MULTIXACT_ZERO_OFF_PAGE: u8 = 0x00;
     118                 : pub const XLOG_MULTIXACT_ZERO_MEM_PAGE: u8 = 0x10;
     119                 : pub const XLOG_MULTIXACT_CREATE_ID: u8 = 0x20;
     120                 : pub const XLOG_MULTIXACT_TRUNCATE_ID: u8 = 0x30;
     121                 : 
     122                 : pub const MULTIXACT_OFFSETS_PER_PAGE: u16 = BLCKSZ / 4;
     123                 : pub const MXACT_MEMBER_BITS_PER_XACT: u16 = 8;
     124                 : pub const MXACT_MEMBER_FLAGS_PER_BYTE: u16 = 1;
     125                 : pub const MULTIXACT_FLAGBYTES_PER_GROUP: u16 = 4;
     126                 : pub const MULTIXACT_MEMBERS_PER_MEMBERGROUP: u16 =
     127                 :     MULTIXACT_FLAGBYTES_PER_GROUP * MXACT_MEMBER_FLAGS_PER_BYTE;
     128                 : /* size in bytes of a complete group */
     129                 : pub const MULTIXACT_MEMBERGROUP_SIZE: u16 =
     130                 :     4 * MULTIXACT_MEMBERS_PER_MEMBERGROUP + MULTIXACT_FLAGBYTES_PER_GROUP;
     131                 : pub const MULTIXACT_MEMBERGROUPS_PER_PAGE: u16 = BLCKSZ / MULTIXACT_MEMBERGROUP_SIZE;
     132                 : pub const MULTIXACT_MEMBERS_PER_PAGE: u16 =
     133                 :     MULTIXACT_MEMBERGROUPS_PER_PAGE * MULTIXACT_MEMBERS_PER_MEMBERGROUP;
     134                 : 
     135                 : // From heapam_xlog.h
     136                 : pub const XLOG_HEAP_INSERT: u8 = 0x00;
     137                 : pub const XLOG_HEAP_DELETE: u8 = 0x10;
     138                 : pub const XLOG_HEAP_UPDATE: u8 = 0x20;
     139                 : pub const XLOG_HEAP_HOT_UPDATE: u8 = 0x40;
     140                 : pub const XLOG_HEAP_LOCK: u8 = 0x60;
     141                 : pub const XLOG_HEAP_INIT_PAGE: u8 = 0x80;
     142                 : pub const XLOG_HEAP2_VISIBLE: u8 = 0x40;
     143                 : pub const XLOG_HEAP2_MULTI_INSERT: u8 = 0x50;
     144                 : pub const XLOG_HEAP2_LOCK_UPDATED: u8 = 0x60;
     145                 : pub const XLH_LOCK_ALL_FROZEN_CLEARED: u8 = 0x01;
     146                 : pub const XLH_INSERT_ALL_FROZEN_SET: u8 = (1 << 5) as u8;
     147                 : pub const XLH_INSERT_ALL_VISIBLE_CLEARED: u8 = (1 << 0) as u8;
     148                 : pub const XLH_UPDATE_OLD_ALL_VISIBLE_CLEARED: u8 = (1 << 0) as u8;
     149                 : pub const XLH_UPDATE_NEW_ALL_VISIBLE_CLEARED: u8 = (1 << 1) as u8;
     150                 : pub const XLH_DELETE_ALL_VISIBLE_CLEARED: u8 = (1 << 0) as u8;
     151                 : 
     152                 : // From replication/message.h
     153                 : pub const XLOG_LOGICAL_MESSAGE: u8 = 0x00;
     154                 : 
     155                 : // From rmgrlist.h
     156                 : pub const RM_XLOG_ID: u8 = 0;
     157                 : pub const RM_XACT_ID: u8 = 1;
     158                 : pub const RM_SMGR_ID: u8 = 2;
     159                 : pub const RM_CLOG_ID: u8 = 3;
     160                 : pub const RM_DBASE_ID: u8 = 4;
     161                 : pub const RM_TBLSPC_ID: u8 = 5;
     162                 : pub const RM_MULTIXACT_ID: u8 = 6;
     163                 : pub const RM_RELMAP_ID: u8 = 7;
     164                 : pub const RM_STANDBY_ID: u8 = 8;
     165                 : pub const RM_HEAP2_ID: u8 = 9;
     166                 : pub const RM_HEAP_ID: u8 = 10;
     167                 : pub const RM_LOGICALMSG_ID: u8 = 21;
     168                 : 
     169                 : // from neon_rmgr.h
     170                 : pub const RM_NEON_ID: u8 = 134;
     171                 : 
     172                 : pub const XLOG_NEON_HEAP_INIT_PAGE: u8 = 0x80;
     173                 : 
     174                 : pub const XLOG_NEON_HEAP_INSERT: u8 = 0x00;
     175                 : pub const XLOG_NEON_HEAP_DELETE: u8 = 0x10;
     176                 : pub const XLOG_NEON_HEAP_UPDATE: u8 = 0x20;
     177                 : pub const XLOG_NEON_HEAP_HOT_UPDATE: u8 = 0x30;
     178                 : pub const XLOG_NEON_HEAP_LOCK: u8 = 0x40;
     179                 : pub const XLOG_NEON_HEAP_MULTI_INSERT: u8 = 0x50;
     180                 : 
     181                 : pub const XLOG_NEON_HEAP_VISIBLE: u8 = 0x40;
     182                 : 
     183                 : // from xlogreader.h
     184                 : pub const XLR_INFO_MASK: u8 = 0x0F;
     185                 : pub const XLR_RMGR_INFO_MASK: u8 = 0xF0;
     186                 : 
     187                 : pub const XLOG_TBLSPC_CREATE: u8 = 0x00;
     188                 : pub const XLOG_TBLSPC_DROP: u8 = 0x10;
     189                 : 
     190                 : pub const SIZEOF_XLOGRECORD: u32 = std::mem::size_of::<XLogRecord>() as u32;
     191                 : 
     192                 : //
     193                 : // from xlogrecord.h
     194                 : //
     195                 : pub const XLR_MAX_BLOCK_ID: u8 = 32;
     196                 : 
     197                 : pub const XLR_BLOCK_ID_DATA_SHORT: u8 = 255;
     198                 : pub const XLR_BLOCK_ID_DATA_LONG: u8 = 254;
     199                 : pub const XLR_BLOCK_ID_ORIGIN: u8 = 253;
     200                 : pub const XLR_BLOCK_ID_TOPLEVEL_XID: u8 = 252;
     201                 : 
     202                 : pub const BKPBLOCK_FORK_MASK: u8 = 0x0F;
     203                 : pub const _BKPBLOCK_FLAG_MASK: u8 = 0xF0;
     204                 : pub const BKPBLOCK_HAS_IMAGE: u8 = 0x10; /* block data is an XLogRecordBlockImage */
     205                 : pub const BKPBLOCK_HAS_DATA: u8 = 0x20;
     206                 : pub const BKPBLOCK_WILL_INIT: u8 = 0x40; /* redo will re-init the page */
     207                 : pub const BKPBLOCK_SAME_REL: u8 = 0x80; /* RelFileNode omitted, same as previous */
     208                 : 
     209                 : /* Information stored in bimg_info */
     210                 : pub const BKPIMAGE_HAS_HOLE: u8 = 0x01; /* page image has "hole" */
     211                 : 
     212                 : /* From transam.h */
     213                 : pub const FIRST_NORMAL_TRANSACTION_ID: u32 = 3;
     214                 : pub const INVALID_TRANSACTION_ID: u32 = 0;
     215                 : pub const FIRST_BOOTSTRAP_OBJECT_ID: u32 = 12000;
     216                 : pub const FIRST_NORMAL_OBJECT_ID: u32 = 16384;
     217                 : 
     218                 : pub const XLOG_CHECKPOINT_SHUTDOWN: u8 = 0x00;
     219                 : pub const XLOG_CHECKPOINT_ONLINE: u8 = 0x10;
     220                 : pub const XLP_FIRST_IS_CONTRECORD: u16 = 0x0001;
     221                 : pub const XLP_LONG_HEADER: u16 = 0x0002;
     222                 : 
     223                 : /* From replication/slot.h */
     224                 : pub const REPL_SLOT_ON_DISK_OFFSETOF_RESTART_LSN: usize = 4*4  /* offset of `slotdata` in ReplicationSlotOnDisk  */
     225                 :    + 64 /* NameData */  + 4*4;
     226                 : 
     227                 : /* From fsm_internals.h */
     228                 : const FSM_NODES_PER_PAGE: usize = BLCKSZ as usize - SIZEOF_PAGE_HEADER_DATA - 4;
     229                 : const FSM_NON_LEAF_NODES_PER_PAGE: usize = BLCKSZ as usize / 2 - 1;
     230                 : const FSM_LEAF_NODES_PER_PAGE: usize = FSM_NODES_PER_PAGE - FSM_NON_LEAF_NODES_PER_PAGE;
     231                 : pub const SLOTS_PER_FSM_PAGE: u32 = FSM_LEAF_NODES_PER_PAGE as u32;
     232                 : 
     233                 : /* From visibilitymap.c */
     234                 : pub const VM_HEAPBLOCKS_PER_PAGE: u32 =
     235                 :     (BLCKSZ as usize - SIZEOF_PAGE_HEADER_DATA) as u32 * (8 / 2); // MAPSIZE * (BITS_PER_BYTE / BITS_PER_HEAPBLOCK)
     236                 : 
     237                 : // List of subdirectories inside pgdata.
     238                 : // Copied from src/bin/initdb/initdb.c
     239                 : pub const PGDATA_SUBDIRS: [&str; 22] = [
     240                 :     "global",
     241                 :     "pg_wal/archive_status",
     242                 :     "pg_commit_ts",
     243                 :     "pg_dynshmem",
     244                 :     "pg_notify",
     245                 :     "pg_serial",
     246                 :     "pg_snapshots",
     247                 :     "pg_subtrans",
     248                 :     "pg_twophase",
     249                 :     "pg_multixact",
     250                 :     "pg_multixact/members",
     251                 :     "pg_multixact/offsets",
     252                 :     "base",
     253                 :     "base/1",
     254                 :     "pg_replslot",
     255                 :     "pg_tblspc",
     256                 :     "pg_stat",
     257                 :     "pg_stat_tmp",
     258                 :     "pg_xact",
     259                 :     "pg_logical",
     260                 :     "pg_logical/snapshots",
     261                 :     "pg_logical/mappings",
     262                 : ];
     263                 : 
     264                 : // Don't include postgresql.conf as it is inconvenient on node start:
     265                 : // we need postgresql.conf before basebackup to synchronize safekeepers
     266                 : // so no point in overwriting it during backup restore. Rest of the files
     267                 : // here are not needed before backup so it is okay to edit them after.
     268                 : pub const PGDATA_SPECIAL_FILES: [&str; 3] =
     269                 :     ["pg_hba.conf", "pg_ident.conf", "postgresql.auto.conf"];
     270                 : 
     271                 : pub static PG_HBA: &str = include_str!("../samples/pg_hba.conf");
        

Generated by: LCOV version 2.1-beta