* Copyright (c) 2020 Huawei Technologies Co.,Ltd.
*
* openGauss is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* ---------------------------------------------------------------------------------------
*
* etcdapi.h
*
*
*
* IDENTIFICATION
* src/include/cm/etcdapi.h
*
* ---------------------------------------------------------------------------------------
*/
#ifndef _ETCD_API_H_
#define _ETCD_API_H_
typedef int EtcdSession;
typedef enum {
ETCD_OK = 0,
ETCD_WTF = -1,
EcodeKeyNotFound = 100,
EcodeTestFailed = 101,
EcodeNotFile = 102,
ecodeNoMorePeer = 103,
EcodeNotDir = 104,
EcodeNodeExist = 105,
ecodeKeyIsPreserved = 106,
EcodeRootROnly = 107,
EcodeDirNotEmpty = 108,
ecodeExistingPeerAddr = 109,
EcodeUnauthorized = 110,
ecodeValueRequired = 200,
EcodePrevValueRequired = 201,
EcodeTTLNaN = 202,
EcodeIndexNaN = 203,
ecodeValueOrTTLRequired = 204,
ecodeTimeoutNaN = 205,
ecodeNameRequired = 206,
ecodeIndexOrValueRequired = 207,
ecodeIndexValueMutex = 208,
EcodeInvalidField = 209,
EcodeInvalidForm = 210,
EcodeRefreshValue = 211,
EcodeRefreshTTLRequired = 212,
EcodeRaftInternal = 300,
EcodeLeaderElect = 301,
EcodeWatcherCleared = 400,
EcodeEventIndexCleared = 401,
ecodeStandbyInternal = 402,
ecodeInvalidActiveSize = 403,
ecodeInvalidRemoveDelay = 404,
ecodeClientInternal = 500
} EtcdResult;
typedef struct {
char* prevValue;
uint64_t prevIndex;
int64_t ttl;
char prevExist[5];
bool refresh;
bool dir;
bool noValueOnSuccess;
} SetEtcdOption;
typedef struct {
bool recursive;
bool sort;
bool quorum;
} GetEtcdOption;
typedef struct {
char* prevValue;
uint64_t prevIndex;
bool recursive;
bool dir;
} DeleteEtcdOption;
typedef struct {
char* host;
unsigned short port;
} EtcdServerSocket;
const int ETCD_MAX_PATH_LEN = 1024;
typedef struct {
char etcd_ca_path[ETCD_MAX_PATH_LEN];
char client_crt_path[ETCD_MAX_PATH_LEN];
char client_key_path[ETCD_MAX_PATH_LEN];
} EtcdTlsAuthPath;
#define ETCD_VALUE_LEN 128
#define ERR_LEN 1024
#define ETCD_STATE_LEN 16
const int ETCD_DEFAULT_TIMEOUT = 2000;
* etcd_open
*
* Establish a session to an etcd cluster.On success, 0 is returned;
* on failure, an error code is returned
*
* session
* The index of the session being created
*
* server_list
* Array of etcd_server structures, with the last having host=NULL. The
* caller is responsible for ensuring that this remains valid as long as
* the session exists.
*
* tls_path
* Certificate information required for HTTPS connection
*
* time_out
* This parameter is used to set the session timeout period.
*/
int etcd_open(EtcdSession* session, EtcdServerSocket* server_list, EtcdTlsAuthPath* tls_path, int time_out);
* etcd_close
*
* Terminate a session, closing connections and freeing memory (or any other
* resources) associated with it.
*
* session
* The index of the session to be closed.
*/
int etcd_close(int session);
* etcd_open_str
*
* Create a session for the ETCD cluster with a string containing
* the list of services and certificates and timeout information.
*
* session
* The index of the session being created
*
* server_names
* String containing the service list. If the session information
* exists, The caller is responsible for ensuring that this remains
* valid as long as the session exists.
*
* tls_path
* Certificate information required for HTTPS connection
*
* timeout
* This parameter is used to set the session timeout period.
*/
int etcd_open_str(EtcdSession* session, char* server_names, EtcdTlsAuthPath* tls_path, int timeout);
* etcd_set
*
* Write a key, with optional previous value (as a precondition).
*
* session
* The index of the session
*
* key
* The etcd key (path) to set.
*
* value
* New value as a null-terminated string.
*
* option
* Indicates the operation information structure of the set operation.
* Currently, only prevValue is used. If prevValue = NULL, prevValue
* is not used. That is, the value of the current node is not considered.
*/
int etcd_set(EtcdSession session, char* key, char* value, SetEtcdOption* option);
* etcd_get
*
* Fetch a key from one of the servers in a session.On success, 0 is returned;
* on failure, an error code is returned
*
* session
* The index of the session
*
* key
* The etcd key (path) to fetch.
*
* value
* The value of the key, it is a newly allocated string, which must be
* freed by the caller.
*
* max_size
* defines the max buffer size of health_member
*
* option
* Operation information structure of the Get operation. Currently,
* only quorum is used to specify whether to obtain the latest committed
* value applied in the member arbitration to ensure external consistency
* (or linearization).
*/
int etcd_get(int session, char* key, char* value, int max_size, GetEtcdOption* option);
* etcd_delete
*
* Delete a key from one of the servers in a session.
*
* session
* The index of the session
*
* key
* The etcd key (path) to delete.
*
* option
* Indicates the operation information structure of the Delete operation.
* No information is used at present.
*/
int etcd_delete(int session, char* key, DeleteEtcdOption* option);
* etcd_cluster_health
*
* Get the health of the cluster.If member_name is not empty, check the health
* status of the corresponding etcd node and store the health status into
* health_member. If member_name is empty, check the health status of the entire
* etcd cluster and write health_member.
*
* session
* The index of the session
*
* member_name
* etcd member name,If this parameter is set to NULL or an empty string,
* the health status of the ETCD cluster is obtained. If the character
* string is a node name, it indicates the health status of a node.
*
* health_state
* Save the etcd cluster health information
*
* state_Size
* defines the max buffer size of health_member
*/
int etcd_cluster_health(int session, char* member_name, char* health_state, int state_Size);
* etcd_cluster_state
*
* Get the state of the cluster member.
*
* session
* The index of the session
*
* member_name
* etcd member name
*
* is_leader
* Whether this node is the leader node or not
*/
int etcd_cluster_state(int session, char* member_name, bool* is_leader);
* get_last_error
*
* Obtains the information that fails to be invoked and saves the information to the buffer. If the interface is
* successfully invoked, the buffer is empty.
*
*/
const char* get_last_error();
#endif