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.
2 files changed
tree: bbf8e374bdc52200f373a7dc6395cb70285d9040
  1. .github/
  2. ci/
  3. cluster/
  4. conv/
  5. dbconn/
  6. gperror/
  7. gplog/
  8. iohelper/
  9. operating/
  10. structmatcher/
  11. testhelper/
  12. .asf.yaml
  13. .gitignore
  14. .golangci.yml
  15. CODE_OF_CONDUCT.md
  16. CONTRIBUTING.md
  17. go.mod
  18. go.sum
  19. LICENSE
  20. Makefile
  21. NOTICE
  22. README.md
  23. SECURITY.md
  24. show_coverage.sh
README.md

go-libs for Apache Cloudberry (Incubating)

Slack Twitter Follow Website


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.

License

Licensed under Apache License Version 2.0. For more details, please refer to the LICENSE.

Acknowledgment

Thanks to all the gp-common-go-libs contributors, more details in its GitHub page.