LCOV - differential code coverage report
Current view: top level - src/backend/replication - syncrep_gram.y (source / functions) Coverage Total Hit UBC CBC
Current: a2387c32f2f8a1643c7d71b951587e6bcb2d4744 vs 371a302eecdc82274b0ae2967d18fd726a0aa6a1 Lines: 96.0 % 25 24 1 24
Current Date: 2025-10-26 12:31:50 -0700 Functions: 100.0 % 1 1 1
Baseline: lcov-20251027-010456-baseline Branches: 83.3 % 12 10 2 10
Baseline Date: 2025-10-26 11:01:32 +1300 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 100.0 % 1 1 1
(360..) days: 95.8 % 24 23 1 23
Function coverage date bins:
(360..) days: 100.0 % 1 1 1
Branch coverage date bins:
(360..) days: 83.3 % 12 10 2 10

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : %{
                                  2                 :                : /*-------------------------------------------------------------------------
                                  3                 :                :  *
                                  4                 :                :  * syncrep_gram.y               - Parser for synchronous_standby_names
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
                                  7                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :                :  *
                                  9                 :                :  *
                                 10                 :                :  * IDENTIFICATION
                                 11                 :                :  *    src/backend/replication/syncrep_gram.y
                                 12                 :                :  *
                                 13                 :                :  *-------------------------------------------------------------------------
                                 14                 :                :  */
                                 15                 :                : #include "postgres.h"
                                 16                 :                : 
                                 17                 :                : #include "nodes/pg_list.h"
                                 18                 :                : #include "replication/syncrep.h"
                                 19                 :                : 
                                 20                 :                : #include "syncrep_gram.h"
                                 21                 :                : 
                                 22                 :                : static SyncRepConfigData *create_syncrep_config(const char *num_sync,
                                 23                 :                :                     List *members, uint8 syncrep_method);
                                 24                 :                : 
                                 25                 :                : /*
                                 26                 :                :  * Bison doesn't allocate anything that needs to live across parser calls,
                                 27                 :                :  * so we can easily have it use palloc instead of malloc.  This prevents
                                 28                 :                :  * memory leaks if we error out during parsing.
                                 29                 :                :  */
                                 30                 :                : #define YYMALLOC palloc
                                 31                 :                : #define YYFREE   pfree
                                 32                 :                : 
                                 33                 :                : %}
                                 34                 :                : 
                                 35                 :                : %parse-param {SyncRepConfigData **syncrep_parse_result_p}
                                 36                 :                : %parse-param {char **syncrep_parse_error_msg_p}
                                 37                 :                : %parse-param {yyscan_t yyscanner}
                                 38                 :                : %lex-param   {char **syncrep_parse_error_msg_p}
                                 39                 :                : %lex-param   {yyscan_t yyscanner}
                                 40                 :                : %pure-parser
                                 41                 :                : %expect 0
                                 42                 :                : %name-prefix="syncrep_yy"
                                 43                 :                : 
                                 44                 :                : %union
                                 45                 :                : {
                                 46                 :                :     char       *str;
                                 47                 :                :     List       *list;
                                 48                 :                :     SyncRepConfigData *config;
                                 49                 :                : }
                                 50                 :                : 
                                 51                 :                : %token <str> NAME NUM JUNK ANY FIRST
                                 52                 :                : 
                                 53                 :                : %type <config> result standby_config
                                 54                 :                : %type <list> standby_list
                                 55                 :                : %type <str> standby_name
                                 56                 :                : 
                                 57                 :                : %start result
                                 58                 :                : 
                                 59                 :                : %%
                                 60                 :                : result:
                                 61                 :                :         standby_config              {
  276 peter@eisentraut.org       62                 :CBC          74 :                                         *syncrep_parse_result_p = $1;
                                 63                 :                :                                         (void) yynerrs; /* suppress compiler warning */
                                 64                 :                :                                     }
                                 65                 :                :     ;
                                 66                 :                : 
                                 67                 :                : standby_config:
 3234 fujii@postgresql.org       68                 :             56 :         standby_list                { $$ = create_syncrep_config("1", $1, SYNC_REP_PRIORITY); }
                                 69                 :             12 :         | NUM '(' standby_list ')'      { $$ = create_syncrep_config($1, $3, SYNC_REP_PRIORITY); }
                                 70                 :              4 :         | ANY NUM '(' standby_list ')'      { $$ = create_syncrep_config($2, $4, SYNC_REP_QUORUM); }
                                 71                 :              2 :         | FIRST NUM '(' standby_list ')'        { $$ = create_syncrep_config($2, $4, SYNC_REP_PRIORITY); }
                                 72                 :                :     ;
                                 73                 :                : 
                                 74                 :                : standby_list:
 3470 tgl@sss.pgh.pa.us          75                 :             74 :         standby_name                        { $$ = list_make1($1); }
                                 76                 :             30 :         | standby_list ',' standby_name     { $$ = lappend($1, $3); }
                                 77                 :                :     ;
                                 78                 :                : 
                                 79                 :                : standby_name:
                                 80                 :            104 :         NAME                        { $$ = $1; }
 3470 tgl@sss.pgh.pa.us          81                 :UBC           0 :         | NUM                       { $$ = $1; }
                                 82                 :                :     ;
                                 83                 :                : %%
                                 84                 :                : 
                                 85                 :                : static SyncRepConfigData *
 3234 fujii@postgresql.org       86                 :CBC          74 : create_syncrep_config(const char *num_sync, List *members, uint8 syncrep_method)
                                 87                 :                : {
                                 88                 :                :     SyncRepConfigData *config;
                                 89                 :                :     int         size;
                                 90                 :                :     ListCell   *lc;
                                 91                 :                :     char       *ptr;
                                 92                 :                : 
                                 93                 :                :     /* Compute space needed for flat representation */
 3470 tgl@sss.pgh.pa.us          94                 :             74 :     size = offsetof(SyncRepConfigData, member_names);
                                 95   [ +  -  +  +  :            178 :     foreach(lc, members)
                                              +  + ]
                                 96                 :                :     {
                                 97                 :            104 :         char       *standby_name = (char *) lfirst(lc);
                                 98                 :                : 
                                 99                 :            104 :         size += strlen(standby_name) + 1;
                                100                 :                :     }
                                101                 :                : 
                                102                 :                :     /* And transform the data into flat representation */
                                103                 :             74 :     config = (SyncRepConfigData *) palloc(size);
                                104                 :                : 
                                105                 :             74 :     config->config_size = size;
 3491 fujii@postgresql.org      106                 :             74 :     config->num_sync = atoi(num_sync);
 3234                           107                 :             74 :     config->syncrep_method = syncrep_method;
 3470 tgl@sss.pgh.pa.us         108                 :             74 :     config->nmembers = list_length(members);
                                109                 :             74 :     ptr = config->member_names;
                                110   [ +  -  +  +  :            178 :     foreach(lc, members)
                                              +  + ]
                                111                 :                :     {
                                112                 :            104 :         char       *standby_name = (char *) lfirst(lc);
                                113                 :                : 
                                114                 :            104 :         strcpy(ptr, standby_name);
                                115                 :            104 :         ptr += strlen(standby_name) + 1;
                                116                 :                :     }
                                117                 :                : 
 3491 fujii@postgresql.org      118                 :             74 :     return config;
                                119                 :                : }
        

Generated by: LCOV version 2.4-beta