MCPcopy Create free account
hub / github.com/apache/cloudberry / generateGPSegConfigKey

Function generateGPSegConfigKey

src/common/etcdutils.c:88–134  ·  view source on GitHub ↗

* generateGPSegConfigKey: function used to generate ETCD configuration key and endpoint information. * parameter fts_dump_file_key OUT * parameter gp_etcd_namespace IN * parameter gp_etcd_account_id IN * parameter gp_etcd_cluster_id IN * parameter gp_etcd_endpoints OUT * parameter etcd_endpoints OUT * parameter etcd_endpoints_num OUT * return ture if configuration parse succeeded, otherwis

Source from the content-addressed store, hash-verified

86 * return ture if configuration parse succeeded, otherwise retrun false.
87 */
88bool
89generateGPSegConfigKey(char *fts_dump_file_key, const char *gp_etcd_namespace, const char *gp_etcd_account_id,
90 const char *gp_etcd_cluster_id, char *gp_etcd_endpoints, etcdlib_endpoint_t *etcd_endpoints,
91 int *etcd_endpoints_num)
92{
93 char *endpoints_list[GP_ETCD_ENDPOINTS_NUM] = {0};
94 etcdlib_endpoint_t *petcd_endpoints = etcd_endpoints;
95 bool ret = true;
96 int fts_dump_file_key_length = 0;
97 int etcd_port = 0;
98 char etcd_host[GP_ETCD_HOSTNAME_LEN];
99 memset(etcd_host, 0, GP_ETCD_HOSTNAME_LEN);
100
101 Assert(fts_dump_file_key != NULL);
102 Assert(gp_etcd_namespace != NULL && (strcmp(gp_etcd_namespace, "") != 0));
103 Assert(gp_etcd_account_id != NULL && (strcmp(gp_etcd_account_id, "") != 0));
104 Assert(gp_etcd_cluster_id != NULL && (strcmp(gp_etcd_cluster_id, "") != 0));
105 Assert(gp_etcd_endpoints != NULL && (strcmp(gp_etcd_endpoints, "") != 0));
106
107 fts_dump_file_key_length = snprintf(fts_dump_file_key, GP_ETCD_KEY_LEN, "%s/%s/%s/%s/%s", \
108 FTS_METADATA_DIR_PREFIX, gp_etcd_namespace, gp_etcd_account_id, gp_etcd_cluster_id, FTS_DUMP_FILE_KEY);
109
110 if (fts_dump_file_key_length == 0 || fts_dump_file_key_length > GP_ETCD_KEY_LEN)
111 return false;
112
113 if (fts_dump_file_key == NULL || fts_dump_file_key[0] == '\0')
114 return false;
115
116 ret = split(gp_etcd_endpoints, GP_ETCD_SEPERATOR, endpoints_list, etcd_endpoints_num);
117 if (!ret)
118 return false;
119
120 if (etcd_endpoints_num == 0 || *etcd_endpoints_num > GP_ETCD_ENDPOINTS_NUM)
121 return false;
122
123 for (int i = 0; i < (*etcd_endpoints_num); i++, petcd_endpoints++)
124 {
125 ret = parseEtcdHostConfiguration(endpoints_list[i], etcd_host, &etcd_port);
126 if (!ret || etcd_host[0] == '\0' || etcd_port == 0 )
127 return false;
128 petcd_endpoints->etcd_host = pstrdup(etcd_host);
129 petcd_endpoints->etcd_port = etcd_port;
130 etcd_port = 0;
131 }
132
133 return true;
134}
135
136/*
137 * generateGPFtsPromoteReadyKey: function used to generate FTS promote ready key.

Callers 2

etcdlib_init_configFunction · 0.85
initETCDFunction · 0.85

Calls 3

splitFunction · 0.85
pstrdupFunction · 0.70

Tested by

no test coverage detected