使用 GBase CAPI 負載均衡創建到 8a 集群的連接時,客戶端最少應該把 8a集群一個安全組的節點 ip 地址傳給 GBase CAPI。如host="192.168.1.1;192.168.1.2"。如果 8a 集群一個安全組只有一個節點,那么客戶端應該這樣傳給 GBase CAPI 集群的節點:host="192.168.1.1;"。字串中 ip 地址后的分號是必須的。使用 GBase CAPI 負載均衡創建到 8a 集群的連接時,如果沒有設定 "GBASE_OPT_USE_SERVER_BALANCE"選項的值(該值默認為 0),那么 GBase CAPI將在客戶端傳入的 ip 地址間進行負載均衡。如果設定"GBASE_OPT_USE_SERVER_BALANCE"選項的值為 1,那么 GBase CAPI 將在 8a 集群所有節點之間進行負載均衡。如下是使用 GBase CAPI 負載均衡的代碼樣例。
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "gbase.h"
int test_banalce()
{
GBASE* gbase = NULL;
char* host = "192.168.1.1;";
char* user = "gbase";
char* pwd = "111111";
char* db = "test";
int port = 5258;
int rc = 0;
int use_server_balance = 1;
gbase = gbase_init(NULL);
gbase_options(gbase, GBASE_OPT_USE_SERVER_BALANCE,
(void*)&use_server_balance);
if(!gbase_real_connect(gbase, host, user, pwd, db, port, NULL,
0))
{
fprintf(stderr, "%d\n%s\n",gbase_errno(gbase),
gbase_error(gbase));
rc = 1;
}
else
{
printf("%s\n", gbase_get_host_info(gbase));
}
gbase_close(gbase);
return rc;
}
int main()
{
int i = 0;
for(;i < 20; i++)
{
test_banalce();
usleep(2*1000);
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/263941.html
標籤:其他技術討論專區
