Skip to content

Commit abe6d79

Browse files
committed
refactor(utils): Simplify GetSegmentsHost to fetch all segments
Removes the specialized logic for fetching segments based on the current warehouse in Cloudberry Enterprise DB. The function now consistently retrieves all primary segments from gp_segment_configuration, regardless of the database type. This simplifies the implementation and ensures uniform behavior.
1 parent ee0f61f commit abe6d79

1 file changed

Lines changed: 1 addition & 25 deletions

File tree

utils/wrappers.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,13 @@ type SegmentIpInfo struct {
2222
// For Cloudberry Enterprise DB, it attempts to get segments for the warehouse identified by 'SHOW warehouse'.
2323
// For other databases (GPDB, CBDB), it gets all primary segments.
2424
func GetSegmentsHost(conn *dbconn.DBConn) []SegmentHostInfo {
25-
var query string
26-
27-
if conn.Version.IsCBEDB() {
28-
var warehouseName string
29-
errShowWarehouse := conn.Get(&warehouseName, "SHOW warehouse")
30-
gplog.FatalOnError(errShowWarehouse, "Failed to get warehouse name")
31-
32-
query = fmt.Sprintf(`
33-
WITH targetWarehouseID AS (
34-
SELECT gw.oid AS wh_id
35-
FROM gp_warehouse gw
36-
WHERE gw.warehouse_name = '%s'
37-
)
38-
SELECT gsc.content, gsc.hostname
39-
FROM gp_segment_configuration gsc
40-
WHERE gsc.role = 'p'
41-
AND gsc.content >= 0
42-
AND gsc.status = 'u'
43-
AND gsc.warehouseid = (SELECT wh_id FROM targetWarehouseID)
44-
ORDER BY gsc.content;
45-
`, warehouseName)
46-
} else {
47-
// For GPDB/CBDB: Get all primary segments
48-
query = `
25+
query := `
4926
SELECT content, hostname
5027
FROM gp_segment_configuration
5128
WHERE role = 'p'
5229
AND content >= 0
5330
ORDER BY content
5431
`
55-
}
5632

5733
hosts := make([]SegmentHostInfo, 0)
5834
gplog.Debug("GetSegmentsHost, query is %v", query)

0 commit comments

Comments
 (0)