提交 dca6a9d2 编写于 作者: wmmhello's avatar wmmhello

[TD-5992] add set config interface for connector

上级 36c70110
......@@ -41,6 +41,14 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_initImp
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions
(JNIEnv *, jclass, jint, jstring);
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
* Method: setConfig
* Signature: (ILjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setConfig
(JNIEnv *, jclass, jstring);
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
* Method: getTsCharset
......
......@@ -170,6 +170,20 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_initImp(JNIEnv *e
jniDebug("jni initialized successfully, config directory: %s", configDir);
}
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setConfig(JNIEnv *env, jclass jobj, jstring config){
if (config == NULL) {
jniDebug("config value is null");
return -1;
}
const char *cfg = (*env)->GetStringUTFChars(env, config, NULL);
if (!cfg) {
return -1;
}
return taos_set_config(cfg);
}
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions(JNIEnv *env, jobject jobj, jint optionIndex,
jstring optionValue) {
if (optionValue == NULL) {
......@@ -213,7 +227,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions(JNIEnv
return res;
}
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_connectImp(JNIEnv *env, jobject jobj, jstring jhost,
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_connectImp(JNIEnv *env, jobject j obj, jstring jhost,
jint jport, jstring jdbName, jstring juser,
jstring jpass) {
jlong ret = 0;
......
......@@ -120,42 +120,6 @@ int32_t tscAcquireRpc(const char *key, const char *user, const char *secretEncry
return 0;
}
#include "cJSON.h"
static pthread_mutex_t setConfMutex = PTHREAD_MUTEX_INITIALIZER;
static bool setConfFlag = false;
int taos_set_config(const char *config){
if(taos_init()){
tscError("failed to call taos_init");
return -1;
}
pthread_mutex_lock(&setConfMutex);
if (setConfFlag) {
tscError("already set config");
return 0;
}
cJSON *root = cJSON_Parse(config);
if (root == NULL) {
tscError("failed to set config, invalid json format: %s", config);
return -1;
}
int size = cJSON_GetArraySize(root);
for(int i = 0; i < size; i++){
cJSON *item = cJSON_GetArrayItem(root, i);
if (!item) {
tscError("failed to read index:%d", i);
continue;
}
taosReadConfigOption(item->string, item->valuestring, NULL, NULL);
}
taosPrintGlobalCfg();
setConfFlag = true;
pthread_mutex_unlock(&setConfMutex);
return 0;
}
void taos_init_imp(void) {
char temp[128] = {0};
......@@ -473,3 +437,48 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
atomic_store_32(&lock, 0);
return ret;
}
#include "cJSON.h"
static int taos_set_config_imp(const char *config){
static bool setConfFlag = false;
if (setConfFlag) {
tscError("already set config");
return -1;
}
cJSON *root = cJSON_Parse(config);
if (root == NULL) {
tscError("failed to set config, invalid json format: %s", config);
return -1;
}
int size = cJSON_GetArraySize(root);
for(int i = 0; i < size; i++){
cJSON *item = cJSON_GetArrayItem(root, i);
if (!item) {
tscError("failed to read index:%d", i);
continue;
}
taosReadConfigOption(item->string, item->valuestring, NULL, NULL);
}
taosPrintGlobalCfg();
setConfFlag = true;
}
int taos_set_config(const char *config){
if(taos_init()){
tscError("failed to call taos_init");
return -1;
}
static int32_t lock = 0;
for (int i = 1; atomic_val_compare_exchange_32(&lock, 0, 1) != 0; ++i) {
if (i % 1000 == 0) {
tscInfo("haven't acquire lock after spin %d times.", i);
sched_yield();
}
}
int ret = taos_set_config_imp(config);
atomic_store_32(&lock, 0);
return ret;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册