LCOV - code coverage report
Current view: top level - libs/postgres_ffi/src - pg_constants.rs (source / functions) Coverage Total Hit
Test: 3eba1babe267649f8cebefc91c236589db030548.info Lines: 33.3 % 9 3
Test Date: 2024-11-22 12:36:12 Functions: 33.3 % 3 1

            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::PageHeaderData;
      13              : use crate::BLCKSZ;
      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 = 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           12 : pub const fn HEAPBLK_TO_MAPBLOCK(x: u32) -> u32 {
      62           12 :     x / HEAPBLOCKS_PER_PAGE
      63           12 : }
      64            0 : pub const fn HEAPBLK_TO_MAPBYTE(x: u32) -> u32 {
      65            0 :     (x % HEAPBLOCKS_PER_PAGE) / HEAPBLOCKS_PER_BYTE as u32
      66            0 : }
      67            0 : pub const fn HEAPBLK_TO_OFFSET(x: u32) -> u32 {
      68            0 :     (x % HEAPBLOCKS_PER_BYTE as u32) * BITS_PER_HEAPBLOCK as u32
      69            0 : }
      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 standbydefs.h
      84              : pub const XLOG_RUNNING_XACTS: u8 = 0x10;
      85              : 
      86              : // From srlu.h
      87              : pub const SLRU_PAGES_PER_SEGMENT: u32 = 32;
      88              : pub const SLRU_SEG_SIZE: usize = BLCKSZ as usize * SLRU_PAGES_PER_SEGMENT as usize;
      89              : 
      90              : /* mask for filtering opcodes out of xl_info */
      91              : pub const XLOG_XACT_OPMASK: u8 = 0x70;
      92              : pub const XLOG_HEAP_OPMASK: u8 = 0x70;
      93              : /* does this record have a 'xinfo' field or not */
      94              : pub const XLOG_XACT_HAS_INFO: u8 = 0x80;
      95              : 
      96              : /*
      97              :  * The following flags, stored in xinfo, determine which information is
      98              :  * contained in commit/abort records.
      99              :  */
     100              : pub const XACT_XINFO_HAS_DBINFO: u32 = 1u32 << 0;
     101              : pub const XACT_XINFO_HAS_SUBXACTS: u32 = 1u32 << 1;
     102              : pub const XACT_XINFO_HAS_RELFILENODES: u32 = 1u32 << 2;
     103              : pub const XACT_XINFO_HAS_INVALS: u32 = 1u32 << 3;
     104              : pub const XACT_XINFO_HAS_TWOPHASE: u32 = 1u32 << 4;
     105              : pub const XACT_XINFO_HAS_ORIGIN: u32 = 1u32 << 5;
     106              : // pub const XACT_XINFO_HAS_AE_LOCKS: u32 = 1u32 << 6;
     107              : // pub const XACT_XINFO_HAS_GID: u32 = 1u32 << 7;
     108              : 
     109              : // From pg_control.h and rmgrlist.h
     110              : pub const XLOG_NEXTOID: u8 = 0x30;
     111              : pub const XLOG_SWITCH: u8 = 0x40;
     112              : pub const XLOG_FPI_FOR_HINT: u8 = 0xA0;
     113              : pub const XLOG_FPI: u8 = 0xB0;
     114              : 
     115              : // From multixact.h
     116              : pub const FIRST_MULTIXACT_ID: u32 = 1;
     117              : pub const MAX_MULTIXACT_ID: u32 = 0xFFFFFFFF;
     118              : pub const MAX_MULTIXACT_OFFSET: u32 = 0xFFFFFFFF;
     119              : 
     120              : pub const XLOG_MULTIXACT_ZERO_OFF_PAGE: u8 = 0x00;
     121              : pub const XLOG_MULTIXACT_ZERO_MEM_PAGE: u8 = 0x10;
     122              : pub const XLOG_MULTIXACT_CREATE_ID: u8 = 0x20;
     123              : pub const XLOG_MULTIXACT_TRUNCATE_ID: u8 = 0x30;
     124              : 
     125              : pub const MULTIXACT_OFFSETS_PER_PAGE: u16 = BLCKSZ / 4;
     126              : pub const MXACT_MEMBER_BITS_PER_XACT: u16 = 8;
     127              : pub const MXACT_MEMBER_FLAGS_PER_BYTE: u16 = 1;
     128              : pub const MULTIXACT_FLAGBYTES_PER_GROUP: u16 = 4;
     129              : pub const MULTIXACT_MEMBERS_PER_MEMBERGROUP: u16 =
     130              :     MULTIXACT_FLAGBYTES_PER_GROUP * MXACT_MEMBER_FLAGS_PER_BYTE;
     131              : /* size in bytes of a complete group */
     132              : pub const MULTIXACT_MEMBERGROUP_SIZE: u16 =
     133              :     4 * MULTIXACT_MEMBERS_PER_MEMBERGROUP + MULTIXACT_FLAGBYTES_PER_GROUP;
     134              : pub const MULTIXACT_MEMBERGROUPS_PER_PAGE: u16 = BLCKSZ / MULTIXACT_MEMBERGROUP_SIZE;
     135              : pub const MULTIXACT_MEMBERS_PER_PAGE: u16 =
     136              :     MULTIXACT_MEMBERGROUPS_PER_PAGE * MULTIXACT_MEMBERS_PER_MEMBERGROUP;
     137              : 
     138              : // From heapam_xlog.h
     139              : pub const XLOG_HEAP_INSERT: u8 = 0x00;
     140              : pub const XLOG_HEAP_DELETE: u8 = 0x10;
     141              : pub const XLOG_HEAP_UPDATE: u8 = 0x20;
     142              : pub const XLOG_HEAP_HOT_UPDATE: u8 = 0x40;
     143              : pub const XLOG_HEAP_LOCK: u8 = 0x60;
     144              : pub const XLOG_HEAP_INIT_PAGE: u8 = 0x80;
     145              : pub const XLOG_HEAP2_VISIBLE: u8 = 0x40;
     146              : pub const XLOG_HEAP2_MULTI_INSERT: u8 = 0x50;
     147              : pub const XLOG_HEAP2_LOCK_UPDATED: u8 = 0x60;
     148              : pub const XLH_LOCK_ALL_FROZEN_CLEARED: u8 = 0x01;
     149              : pub const XLH_INSERT_ALL_FROZEN_SET: u8 = (1 << 5) as u8;
     150              : pub const XLH_INSERT_ALL_VISIBLE_CLEARED: u8 = (1 << 0) as u8;
     151              : pub const XLH_UPDATE_OLD_ALL_VISIBLE_CLEARED: u8 = (1 << 0) as u8;
     152              : pub const XLH_UPDATE_NEW_ALL_VISIBLE_CLEARED: u8 = (1 << 1) as u8;
     153              : pub const XLH_DELETE_ALL_VISIBLE_CLEARED: u8 = (1 << 0) as u8;
     154              : 
     155              : // From heapam_xlog.h
     156              : pub const XLOG_HEAP2_REWRITE: u8 = 0x00;
     157              : 
     158              : // From replication/message.h
     159              : pub const XLOG_LOGICAL_MESSAGE: u8 = 0x00;
     160              : 
     161              : // From rmgrlist.h
     162              : pub const RM_XLOG_ID: u8 = 0;
     163              : pub const RM_XACT_ID: u8 = 1;
     164              : pub const RM_SMGR_ID: u8 = 2;
     165              : pub const RM_CLOG_ID: u8 = 3;
     166              : pub const RM_DBASE_ID: u8 = 4;
     167              : pub const RM_TBLSPC_ID: u8 = 5;
     168              : pub const RM_MULTIXACT_ID: u8 = 6;
     169              : pub const RM_RELMAP_ID: u8 = 7;
     170              : pub const RM_STANDBY_ID: u8 = 8;
     171              : pub const RM_HEAP2_ID: u8 = 9;
     172              : pub const RM_HEAP_ID: u8 = 10;
     173              : pub const RM_REPLORIGIN_ID: u8 = 19;
     174              : pub const RM_LOGICALMSG_ID: u8 = 21;
     175              : 
     176              : // from neon_rmgr.h
     177              : pub const RM_NEON_ID: u8 = 134;
     178              : 
     179              : pub const XLOG_NEON_HEAP_INIT_PAGE: u8 = 0x80;
     180              : 
     181              : pub const XLOG_NEON_HEAP_INSERT: u8 = 0x00;
     182              : pub const XLOG_NEON_HEAP_DELETE: u8 = 0x10;
     183              : pub const XLOG_NEON_HEAP_UPDATE: u8 = 0x20;
     184              : pub const XLOG_NEON_HEAP_HOT_UPDATE: u8 = 0x30;
     185              : pub const XLOG_NEON_HEAP_LOCK: u8 = 0x40;
     186              : pub const XLOG_NEON_HEAP_MULTI_INSERT: u8 = 0x50;
     187              : 
     188              : pub const XLOG_NEON_HEAP_VISIBLE: u8 = 0x40;
     189              : 
     190              : // from xlogreader.h
     191              : pub const XLR_INFO_MASK: u8 = 0x0F;
     192              : pub const XLR_RMGR_INFO_MASK: u8 = 0xF0;
     193              : 
     194              : pub const XLOG_TBLSPC_CREATE: u8 = 0x00;
     195              : pub const XLOG_TBLSPC_DROP: u8 = 0x10;
     196              : 
     197              : //
     198              : // from xlogrecord.h
     199              : //
     200              : pub const XLR_MAX_BLOCK_ID: u8 = 32;
     201              : 
     202              : pub const XLR_BLOCK_ID_DATA_SHORT: u8 = 255;
     203              : pub const XLR_BLOCK_ID_DATA_LONG: u8 = 254;
     204              : pub const XLR_BLOCK_ID_ORIGIN: u8 = 253;
     205              : pub const XLR_BLOCK_ID_TOPLEVEL_XID: u8 = 252;
     206              : 
     207              : pub const BKPBLOCK_FORK_MASK: u8 = 0x0F;
     208              : pub const _BKPBLOCK_FLAG_MASK: u8 = 0xF0;
     209              : pub const BKPBLOCK_HAS_IMAGE: u8 = 0x10; /* block data is an XLogRecordBlockImage */
     210              : pub const BKPBLOCK_HAS_DATA: u8 = 0x20;
     211              : pub const BKPBLOCK_WILL_INIT: u8 = 0x40; /* redo will re-init the page */
     212              : pub const BKPBLOCK_SAME_REL: u8 = 0x80; /* RelFileNode omitted, same as previous */
     213              : 
     214              : /* Information stored in bimg_info */
     215              : pub const BKPIMAGE_HAS_HOLE: u8 = 0x01; /* page image has "hole" */
     216              : 
     217              : /* From transam.h */
     218              : pub const FIRST_NORMAL_TRANSACTION_ID: u32 = 3;
     219              : pub const INVALID_TRANSACTION_ID: u32 = 0;
     220              : 
     221              : /* pg_control.h */
     222              : pub const XLOG_CHECKPOINT_SHUTDOWN: u8 = 0x00;
     223              : pub const XLOG_CHECKPOINT_ONLINE: u8 = 0x10;
     224              : pub const XLOG_PARAMETER_CHANGE: u8 = 0x60;
     225              : pub const XLOG_END_OF_RECOVERY: u8 = 0x90;
     226              : 
     227              : /* From xlog.h */
     228              : pub const XLOG_REPLORIGIN_SET: u8 = 0x00;
     229              : pub const XLOG_REPLORIGIN_DROP: u8 = 0x10;
     230              : 
     231              : /* xlog_internal.h */
     232              : pub const XLP_FIRST_IS_CONTRECORD: u16 = 0x0001;
     233              : pub const XLP_LONG_HEADER: u16 = 0x0002;
     234              : 
     235              : /* From replication/slot.h */
     236              : pub const REPL_SLOT_ON_DISK_OFFSETOF_RESTART_LSN: usize = 4*4  /* offset of `slotdata` in ReplicationSlotOnDisk  */
     237              :    + 64 /* NameData */  + 4*4;
     238              : 
     239              : /* From fsm_internals.h */
     240              : const FSM_NODES_PER_PAGE: usize = BLCKSZ as usize - SIZEOF_PAGE_HEADER_DATA - 4;
     241              : const FSM_NON_LEAF_NODES_PER_PAGE: usize = BLCKSZ as usize / 2 - 1;
     242              : const FSM_LEAF_NODES_PER_PAGE: usize = FSM_NODES_PER_PAGE - FSM_NON_LEAF_NODES_PER_PAGE;
     243              : pub const SLOTS_PER_FSM_PAGE: u32 = FSM_LEAF_NODES_PER_PAGE as u32;
     244              : 
     245              : /* From visibilitymap.c */
     246              : 
     247              : pub const VM_MAPSIZE: usize = BLCKSZ as usize - MAXALIGN_SIZE_OF_PAGE_HEADER_DATA;
     248              : pub const VM_BITS_PER_HEAPBLOCK: usize = 2;
     249              : pub const VM_HEAPBLOCKS_PER_BYTE: usize = 8 / VM_BITS_PER_HEAPBLOCK;
     250              : pub const VM_HEAPBLOCKS_PER_PAGE: usize = VM_MAPSIZE * VM_HEAPBLOCKS_PER_BYTE;
     251              : 
     252              : /* From origin.c */
     253              : pub const REPLICATION_STATE_MAGIC: u32 = 0x1257DADE;
     254              : 
     255              : // Don't include postgresql.conf as it is inconvenient on node start:
     256              : // we need postgresql.conf before basebackup to synchronize safekeepers
     257              : // so no point in overwriting it during backup restore. Rest of the files
     258              : // here are not needed before backup so it is okay to edit them after.
     259              : pub const PGDATA_SPECIAL_FILES: [&str; 3] =
     260              :     ["pg_hba.conf", "pg_ident.conf", "postgresql.auto.conf"];
     261              : 
     262              : pub static PG_HBA: &str = include_str!("../samples/pg_hba.conf");
        

Generated by: LCOV version 2.1-beta