Browse Source

Fix online bugs 2 (#232)

* update conf files.

* add multi connector conf.

* fixing.

* Add conf priorities.

* update doc.
Yang Shuang 1 year ago
parent
commit
5362a9110b

+ 1 - 1
.github/workflows/release.yml

@@ -6,7 +6,7 @@ on:
 env:
   CC: gcc-4.9
   CXX: g++-4.9    
-  ver: dtc-v2.1.3-rc3
+  ver: dtc-v2.1.3
 
 jobs:
   build:

+ 1 - 0
README.md

@@ -31,6 +31,7 @@ The DTC system consists of the following components:
 ## Performance
 * DTC can process 90,000 QPS of query requests at single-core cpu & single dtc instance.
 * DTC can provide above 3,000,000 QPS query capability with above 99.9% hit rate and less than 200 μs response time in actual distributed scenarios.
+* Layered Storage is able to provide about 1,000 QPS write capability with above 99.9% per single instance.
 ## How to Build
 DTC provides docker images for quick start:
 * Start server docker:<br/>

+ 4 - 2
conf/dtc.yaml

@@ -4,13 +4,15 @@
 props:
   log.level: debug
   listener.port.dtc: 20015
-  listener.port.extension: 2002
   shm.mem.size: 100 #MB
+  hash.custom: Yes
+  hash.custom.module: ../lib/key-hash.so
+  hash.custom.functon: "StringHash(1,128)"  
+  connector.procs: 10
 
 data_lifecycle:
   single.query.count: 10
   lifecycle.tablename: 'data_lifecycle_table'
-  rule.sql: 'uid = 0'
   rule.cron: '0 */1 * * * ?'
 
 connection: &connection

+ 1 - 0
dockerfiles/devel/dtc.dbaddition.ext.yaml

@@ -9,6 +9,7 @@ props:
   log.level: debug
   listener.port.dtc: 20015
   shm.mem.size: 100 #MB
+  connector.procs: 1
 
 connection: &connection
   addr: 127.0.0.1:3307

+ 1 - 0
dockerfiles/devel/dtc.dbaddition.s1.yaml

@@ -7,6 +7,7 @@ props:
   log.level: debug
   listener.port.dtc: 20015
   shm.mem.size: 100 #MB
+  connector.procs: 1
 
 connection: &connection
   addr: 127.0.0.1:3307

+ 1 - 0
dockerfiles/devel/dtc.dbaddition.s2.yaml

@@ -9,6 +9,7 @@ props:
   log.level: debug
   listener.port.dtc: 20015
   shm.mem.size: 100 #MB
+  connector.procs: 1
 
 connection: &connection
   addr: 127.0.0.1:3307

+ 1 - 0
dockerfiles/devel/dtc.dbaddition.s3.yaml

@@ -7,6 +7,7 @@ props:
   log.level: debug
   listener.port.dtc: 20015
   shm.mem.size: 100 #MB
+  connector.procs: 1
 
 connection: &connection
   addr: 127.0.0.1:3307

+ 1 - 0
dockerfiles/devel/dtc.layered.yaml

@@ -7,6 +7,7 @@ props:
   log.level: debug
   listener.port.dtc: 20015
   shm.mem.size: 100 #MB
+  connector.procs: 1
 
 connection: &connection
   addr: mysql:3306

+ 3 - 3
src/libs/common/config/dbconfig.cc

@@ -652,13 +652,13 @@ int DbConfig::get_dtc_config(YAML::Node dtc_config, DTCConfig* raw, int i_server
             }
         }
         /* Helper number alter */
-        m->gprocs[0] = raw->get_int_val(NULL, "Procs", 1);
+        m->gprocs[0] = dtc_config["props"]["connector.procs"].as<int>();
         if (m->gprocs[0] < 1)
             m->gprocs[0] = 0;
-        m->gprocs[1] = raw->get_int_val(NULL, "WriteProcs", 1);
+        m->gprocs[1] = dtc_config["props"]["connector.procs"].as<int>();
         if (m->gprocs[1] < 1)
             m->gprocs[1] = 0;
-        m->gprocs[2] = raw->get_int_val(NULL, "CommitProcs", 1);
+        m->gprocs[2] = dtc_config["props"]["connector.procs"].as<int>();
         if (m->gprocs[2] < 1)
             m->gprocs[2] = 0;
         /* Helper Queue Size */

+ 5 - 0
src/rule/re_comm.h

@@ -9,4 +9,9 @@ typedef struct _expr_properity{
     int condition_num;
 }expr_properity;
 
+#define YAML_DTC_BUFFER "YAML_DTC_BUFFER"
+#define YAML_DTC_RULES "YAML_DTC_RULES"
+#define YAML_DTC_KEY_TYPE "YAML_DTC_KEY_TYPE"
+#define YAML_DTC_KEY_STRING "YAML_DTC_KEY_STRING"
+
 #endif

+ 12 - 6
src/rule/re_load.cc

@@ -8,14 +8,19 @@
 
 using namespace hsql;
 
-std::map<std::string, std::string> g_map_dtc_yaml;
+std::vector<std::string> dtc_node;
+
+std::map<std::string, std::map<std::string, std::string>> g_map_dtc_yaml;
 
 // load rule from dtc.yaml
-std::string do_get_rule(std::string buf)
+std::string do_get_rule(std::map<std::string, std::string>* buffer)
 {
+    if(buffer->find(YAML_DTC_RULES) != buffer->end())
+        return (*buffer)[YAML_DTC_RULES];
+
     YAML::Node config;
     try {
-        config = YAML::Load(buf);
+        config = YAML::Load((*buffer)[YAML_DTC_BUFFER]);
 	} catch (const YAML::Exception &e) {
 		log4cplus_error("config file error:%s\n", e.what());
 		return "";
@@ -24,7 +29,8 @@ std::string do_get_rule(std::string buf)
     YAML::Node node = config["primary"]["layered.rule"];
     if(node)
     {
-        std::string rules = node.as<string>();
+        (*buffer)[YAML_DTC_RULES] = node.as<string>();
+        std::string rules = (*buffer)[YAML_DTC_RULES];
         return rules;
     }
 
@@ -163,14 +169,14 @@ std::string load_dtc_yaml_buffer(int mid)
     return res;
 }
 
-int re_load_rule(std::string buf, hsql::SQLParserResult* rule_ast, vector<vector<hsql::Expr*> >* expr_rules)
+int re_load_rule(std::map<std::string, std::string>* node, hsql::SQLParserResult* rule_ast, vector<vector<hsql::Expr*> >* expr_rules)
 {
     log4cplus_debug("load rule start...");
 
     if(rule_ast->isValid() && rule_ast->size() > 0)
         return 0;
 
-    std::string rules = do_get_rule(buf);
+    std::string rules = do_get_rule(node);
     if(rules.length() <= 0)
         return -1;
 

+ 2 - 1
src/rule/re_load.h

@@ -2,9 +2,10 @@
 #include "../libs/hsql/include/util/sqlhelper.h"
 #include <string>
 #include <vector>
+#include <map>
 
 using namespace std;
 
 int get_rule_condition_num(hsql::Expr* rule);
-int re_load_rule(std::string buf, hsql::SQLParserResult* rule_ast, vector<vector<hsql::Expr*> >* expr_rules);
+int re_load_rule(std::map<std::string, std::string>* node, hsql::SQLParserResult* rule_ast, vector<vector<hsql::Expr*> >* expr_rules);
 std::string load_dtc_yaml_buffer(int mid);

+ 47 - 45
src/rule/rule.cc

@@ -21,13 +21,16 @@
 using namespace std;
 using namespace hsql;
 
-extern std::map<std::string, std::string> g_map_dtc_yaml;
+extern std::map<std::string, std::map<std::string, std::string>> g_map_dtc_yaml;
 
-std::string get_key_info(std::string buf)
+std::string get_key_info(std::map<std::string, std::string>* buf)
 {
+    if(buf->find(YAML_DTC_KEY_STRING) != buf->end())
+        return (*buf)[YAML_DTC_KEY_STRING];
+
     YAML::Node config;
     try {
-        config = YAML::Load(buf);
+        config = YAML::Load((*buf)[YAML_DTC_BUFFER]);
 	} catch (const YAML::Exception &e) {
 		log4cplus_error("config file error:%s\n", e.what());
 		return "";
@@ -38,26 +41,13 @@ std::string get_key_info(std::string buf)
     {
         std::string keystr = node.as<string>();
         transform(keystr.begin(),keystr.end(),keystr.begin(),::toupper);
+        (*buf)[YAML_DTC_KEY_STRING] = keystr;
         return keystr;
     }
     
     return "";
 }
 
-extern "C" int rule_get_key(const char* conf, char* out)
-{
-    std::string strkey = get_key_info(conf);
-    printf("conf file: %s\n", conf);
-    printf("key len: %d, key: %s\n", strkey.length(), strkey.c_str());
-    if(strkey.length() > 0)
-    {
-        strcpy(out, strkey.c_str());
-        return strkey.length();
-    }
-
-    return 0;
-}
-
 extern "C" int get_statement_value(char* str, int len, const char* strkey, int* start_offset, int* end_offset)
 {
     hsql::SQLParserResult sql_ast;
@@ -214,36 +204,47 @@ std::string get_table_with_db(const char* sessiondb, const char* sql)
     return strres;
 }
 
-int rule_get_key_type(std::string buf)
+int rule_get_key_type(std::map<std::string, std::string>* buf)
 {
     YAML::Node config;
-    if(buf.length() == 0)
-        return -1;
+    std::string str = "";
 
-    try {
-        config = YAML::Load(buf);
-	} catch (const YAML::Exception &e) {
-		log4cplus_error("config buf load error:%s\n", e.what());
-		return -1;
-	}
+    if(buf->find(YAML_DTC_KEY_TYPE) != buf->end())
+        str = (*buf)[YAML_DTC_KEY_TYPE];
 
-    YAML::Node node = config["primary"]["cache"]["field"][0]["type"];
-    if(node)
+    if(str.length() == 0)
     {
-        std::string str = node.as<string>();
-        if(str == "signed")
-            return 1;
-        else if(str == "unsigned")
-            return 2;
-        else if(str == "float")
-            return 3;
-        else if(str == "string")
-            return 4;
-        else if(str == "binary")
-            return 5;
-        else   
+        if((*buf)[YAML_DTC_BUFFER].length() == 0)
+            return -1;
+
+        try {
+            config = YAML::Load((*buf)[YAML_DTC_BUFFER]);
+        } catch (const YAML::Exception &e) {
+            log4cplus_error("config buf load error:%s\n", e.what());
             return -1;
+        }
+
+        YAML::Node node = config["primary"]["cache"]["field"][0]["type"];
+        if(node)
+        {
+            str = node.as<string>();
+            (*buf)[YAML_DTC_KEY_TYPE] = str;
+        }
     }
+
+    if(str == "signed")
+        return 1;
+    else if(str == "unsigned")
+        return 2;
+    else if(str == "float")
+        return 3;
+    else if(str == "string")
+        return 4;
+    else if(str == "binary")
+        return 5;
+    else   
+        return -1;
+
     return -1;
 }
 
@@ -459,7 +460,8 @@ extern "C" int re_load_all_rules()
             log4cplus_debug("push %s into map.", Name);
             std::string strname = Name;
             transform(strname.begin(),strname.end(),strname.begin(),::toupper);
-            g_map_dtc_yaml[strname] = buf;
+            (g_map_dtc_yaml[strname])[YAML_DTC_BUFFER] = buf;
+            log4cplus_debug("name: %s, buf len: %d", strname.c_str(), (g_map_dtc_yaml[strname])[YAML_DTC_BUFFER].length());
         }
         else
         {
@@ -482,21 +484,21 @@ extern "C" int rule_sql_match(const char* szsql, const char* osql, const char* d
     std::string dtc_key = "";
     std::string sql = szsql;
 
-    init_log4cplus();
+    //init_log4cplus();
 
     log4cplus_debug("input sql: %s", osql);
 
     std::string db_dot_name = get_table_with_db(dbsession, szsql);
     if(db_dot_name.length() > 0 && g_map_dtc_yaml.count(db_dot_name) > 0)
     {
-        dtc_key = get_key_info(g_map_dtc_yaml[db_dot_name]);
+        dtc_key = get_key_info(&(g_map_dtc_yaml[db_dot_name]));
         if(dtc_key.length() == 0)
         {
             log4cplus_error("get dtc_key from yaml:%s failed.", db_dot_name.c_str());
             return -1;
         }
         strcpy(out_dtckey, dtc_key.c_str());
-        *out_keytype = rule_get_key_type(g_map_dtc_yaml[db_dot_name]);
+        *out_keytype = rule_get_key_type(&(g_map_dtc_yaml[db_dot_name]));
     }
     log4cplus_debug("dtc key len: %d, key: %s, dbname len: %d, dbname: %s", dtc_key.length(), dtc_key.c_str(), strlen(dbsession), std::string(dbsession).c_str());
 
@@ -564,7 +566,7 @@ extern "C" int rule_sql_match(const char* szsql, const char* osql, const char* d
     vector<vector<hsql::Expr*> > expr_rules;
     expr_rules.clear();
     hsql::SQLParserResult rule_ast;
-    int ret = re_load_rule(g_map_dtc_yaml[db_dot_name], &rule_ast, &expr_rules);
+    int ret = re_load_rule(&(g_map_dtc_yaml[db_dot_name]), &rule_ast, &expr_rules);
     if(ret != 0)
     {
         log4cplus_error("load rule error:%d", ret);

+ 0 - 1
src/rule/rule.h

@@ -5,7 +5,6 @@ extern "C"{
 
     int rule_sql_match(const char* szsql, const char* osql, const char* dbsession, char* out_dtckey, int* out_keytype);
     int sql_parse_table(const char* szsql, char* out);
-    int rule_get_key(const char* conf, char* out);
     int get_table_with_db(const char* sessiondb, const char* sql, char* result);    
     int re_load_all_rules();
 #ifdef __cplusplus