@@ -77,6 +77,66 @@ func parseWsrepLatency(value sql.RawBytes) (interface{}, error) {
7777 return result , nil
7878}
7979
80+ // ParseWsrepProviderOptions parses the given sql.RawBytes value into a map
81+ // containing all wsrep Provider options settings.
82+ func parseWsrepProviderOptions (value sql.RawBytes ) (interface {}, error ) {
83+ parts := strings .Split (strings .TrimSpace (string (value )), ";" )
84+ result := make (map [string ]interface {})
85+ for _ , setting := range parts {
86+ key , data , found := strings .Cut (setting , "=" )
87+
88+ // empty string at the end of the field, skip
89+ if len (setting ) != 0 && ! found {
90+ return nil , fmt .Errorf ("invalid key-value pair for %q" , setting )
91+ }
92+
93+ key = strings .TrimSpace (key )
94+ data = strings .TrimSpace (data )
95+ if len (data ) == 0 {
96+ continue // empty value, no point in continuing
97+ }
98+
99+ // Only process gcache.size for now
100+ if key != "gcache.size" {
101+ continue
102+ }
103+ key = strings .Replace (key , "." , "_" , - 1 )
104+
105+ // Extract the size suffix for values like 128M
106+ suffix := data [len (data )- 1 :]
107+ value := data [:len (data )- 1 ]
108+
109+ // Determine the scaling factor from the suffix
110+ var factor uint64
111+ switch strings .ToUpper (suffix ) {
112+ case "K" :
113+ factor = 1024
114+ case "M" :
115+ factor = 1024 * 1024
116+ case "G" :
117+ factor = 1024 * 1024 * 1024
118+ case "T" :
119+ factor = 1024 * 1024 * 1024 * 1024
120+ case "P" :
121+ factor = 1024 * 1024 * 1024 * 1024 * 1024
122+ case "E" :
123+ factor = 1024 * 1024 * 1024 * 1024 * 1024 * 1024
124+ default :
125+ // We got no known unit so parse the whole data as value
126+ value = data
127+ factor = 1
128+ }
129+
130+ // Compute the actual value
131+ v , err := strconv .ParseUint (value , 10 , 64 )
132+ if err != nil {
133+ return nil , fmt .Errorf ("failed to parse value %q: %w" , data , err )
134+ }
135+ result [key ] = v * factor
136+ }
137+ return result , nil
138+ }
139+
80140// ParseGTIDMode parses the given sql.RawBytes value into an int64
81141// representing the GTID mode. It returns an error if the value is unrecognized.
82142func ParseGTIDMode (value sql.RawBytes ) (interface {}, error ) {
@@ -172,6 +232,9 @@ var globalVariableConversions = map[string]conversionFunc{
172232 // https://dev.mysql.com/doc/refman/5.7/en/replication-options-gtids.html
173233 // https://dev.mysql.com/doc/refman/8.0/en/replication-options-gtids.html
174234 "gtid_mode" : ParseGTIDMode ,
235+
236+ // https://galeracluster.com/documentation/html_docs_proto-12/documentation/mysql-wsrep-options.html#wsrep-provider-options
237+ "wsrep_provider_options" : parseWsrepProviderOptions ,
175238}
176239
177240// ConvertGlobalStatus converts the given key and sql.RawBytes value into an appropriate type based on globalStatusConversions.
0 commit comments