@@ -856,8 +856,10 @@ SyncRepGetSyncStandbys(bool *am_sync)
856
856
static int
857
857
SyncRepGetStandbyPriority (void )
858
858
{
859
- const char * standby_name ;
860
- int priority ;
859
+ char * rawstring ;
860
+ List * elemlist ;
861
+ ListCell * l ;
862
+ int priority = 0 ;
861
863
bool found = false;
862
864
863
865
/*
@@ -867,29 +869,37 @@ SyncRepGetStandbyPriority(void)
867
869
if (am_cascading_walsender )
868
870
return 0 ;
869
871
870
- if (!SyncStandbysDefined () || SyncRepConfig == NULL )
872
+ /* Need a modifiable copy of string */
873
+ rawstring = pstrdup (SyncRepStandbyNames );
874
+
875
+ /* Parse string into list of identifiers */
876
+ if (!SplitIdentifierString (rawstring , ',' , & elemlist ))
877
+ {
878
+ /* syntax error in list */
879
+ pfree (rawstring );
880
+ list_free (elemlist );
881
+ /* GUC machinery will have already complained - no need to do again */
871
882
return 0 ;
883
+ }
872
884
873
- standby_name = SyncRepConfig -> member_names ;
874
- for (priority = 1 ; priority <= SyncRepConfig -> nmembers ; priority ++ )
885
+ foreach (l , elemlist )
875
886
{
887
+ char * standby_name = (char * ) lfirst (l );
888
+
889
+ priority ++ ;
890
+
876
891
if (pg_strcasecmp (standby_name , application_name ) == 0 ||
877
- strcmp (standby_name , "*" ) == 0 )
892
+ pg_strcasecmp (standby_name , "*" ) == 0 )
878
893
{
879
894
found = true;
880
895
break ;
881
896
}
882
- standby_name += strlen (standby_name ) + 1 ;
883
897
}
884
898
885
- if (! found )
886
- return 0 ;
899
+ pfree ( rawstring );
900
+ list_free ( elemlist ) ;
887
901
888
- /*
889
- * In quorum-based sync replication, all the standbys in the list have the
890
- * same priority, one.
891
- */
892
- return (SyncRepConfig -> syncrep_method == SYNC_REP_PRIORITY ) ? priority : 1 ;
902
+ return (found ? priority : 0 );
893
903
}
894
904
895
905
/*
0 commit comments