Introducing API GetSegmentConfigurationFromFile() for configuration retrieval from file
This PR introduces an API GetSegmentConfigurationFromFile() to parse the gpsegconfig_dump file to retrieve segment configuration information.
The recommended use of the API is to get the contents of gp_segment_configuration when the database is down.
In the realm of gpdb, the gpsegconfig_dump file holds the crucial segment configuration information. this file is generated in the coordinator
data directory through the fts process. gpsegconfig_dump is always in sync with gp_segment_configuration as on each fts probe the file
gets updated if there is any change in the segment configuration. Various fts gucs govern the frequency of writing to this file.
Note: Since the gpsegconfig_dump file is updated by fts process the information returned by
this function can be a bit stale since the user can configure fts to run less frequently
The gpsegconfig_dump file follows a structured format, as illustrated in the example below:
1 -1 p p n u 6000 localhost localhost /data/temp1
2 0 p p n u 6002 localhost localhost /data/temp2
3 1 p p n u 6003 localhost localhost /data/temp3
4 2 p p n u 6004 localhost localhost /data/temp4
Example Usage:
segments, err := GetSegmentConfigurationFromFile("/path/to/coordinator/data/dir")
if err != nil {
//Handle error
return
}
*. if gpsegconfig_dump has the following content ( with data-dir).
1 -1 p p n u 6000 localhost localhost /data/qddir
2 0 p p n u 6002 localhost localhost /data/seg1
SegConfig will have the DataDir field populated
*. gpsegconfig_dump has the following content ( without data-dir)
1 -1 p p n u 6000 localhost localhost
2 0 p p n u 6002 localhost localhost
SegConfig will have the DataDir field empty
The structured data, captured in the gpsegconfig_dump file, is now accessible through the newly added API GetSegmentConfigurationFromFile().
This enhancement helps the other utilities to perform some operations even if the database is offline.
e.g.
In gpsupport utility if the database is down we can use this API to retrieve the data dirs to perform a log collection.
or
In gpdeletesystem if the database is down the API can be used to perform the database cleanup still.
The reason to add it in gp-common-go-libs is that this is the growing API library that is being used by almost all the newly created gp modern
utilities like project spine/ gpdr/ gpupgrade/ gpbackup/gprestore.
Added test cases to do the unit testing around the following scenario
when the file is valid it should provide valid results.
when the file is invalid it should fail in parsing or reading it.
added test cases to cover old and new field counts of gpsegconfig_dump.
when the user passes the wrong coordinatorDataDir argument.
This project is a fork of the Greenplum gp-common-go-libs, which is a dependency for the gpbackup utility in Cloudberry.
Please note that this repository is only maintained for Cloudberry 1.0 and its later versions.
Licensed under Apache License Version 2.0. For more details, please refer to the LICENSE.
Thanks to all the gp-common-go-libs contributors, more details in its GitHub page.