dbconfig.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _H_DTC_DB_CONFIG_H_
  17. #define _H_DTC_DB_CONFIG_H_
  18. #include "../table/table_def.h"
  19. #include "config.h"
  20. #include <stdint.h>
  21. #include <vector>
  22. #include <map>
  23. #define MAXDB_ON_MACHINE 1000
  24. #define GROUPS_PER_MACHINE 4
  25. #define GROUPS_PER_ROLE 3
  26. #define ROLES_PER_MACHINE 2
  27. #define MACHINEROLESTRING "ms?????"
  28. #define DB_FIELD_FLAGS_READONLY 1
  29. #define DB_FIELD_FLAGS_UNIQ 2
  30. #define DB_FIELD_FLAGS_DESC_ORDER 4
  31. #define DB_FIELD_FLAGS_VOLATILE 8
  32. #define DB_FIELD_FLAGS_DISCARD 0x10
  33. /* 默认key-hash so文件名及路径 */
  34. #define DEFAULT_KEY_HASH_SO_NAME "../lib/key-hash.so"
  35. #define DEFAULT_KEY_HASH_FUNCTION "StringHash(1,128)"
  36. /* key-hash接口函数 */
  37. typedef uint64_t (*key_hash_interface)(const char *key, int len, int left,
  38. int right);
  39. enum { INSERT_ORDER_LAST = 0, INSERT_ORDER_FIRST = 1, INSERT_ORDER_PURGE = 2 };
  40. enum { BY_MASTER, BY_SLAVE, BY_DB, BY_TABLE, BY_KEY, BY_FIFO };
  41. typedef enum {
  42. DUMMY_HELPER = 0,
  43. DTC_HELPER,
  44. MYSQL_HELPER,
  45. TDB_HELPER,
  46. CUSTOM_HELPER,
  47. } HELPERTYPE;
  48. struct MachineConfig {
  49. struct {
  50. const char *addr;
  51. const char *user;
  52. const char *pass;
  53. const char *optfile;
  54. //DataMerge Addr
  55. const char *dm;
  56. char path[32];
  57. } role[GROUPS_PER_MACHINE]; // GROUPS_PER_ROLE should be ROLES_PER_MACHINE
  58. HELPERTYPE helperType;
  59. int mode;
  60. uint16_t dbCnt;
  61. uint16_t procs;
  62. uint16_t dbIdx[MAXDB_ON_MACHINE];
  63. uint16_t gprocs[GROUPS_PER_MACHINE];
  64. uint32_t gqueues[GROUPS_PER_MACHINE];
  65. bool is_same(MachineConfig *mach);
  66. };
  67. struct FieldConfig {
  68. const char *name;
  69. char type;
  70. int size;
  71. DTCValue dval;
  72. int flags;
  73. bool is_same(FieldConfig *field);
  74. };
  75. struct KeyHash {
  76. int keyHashEnable;
  77. int keyHashLeftBegin; /* buff 的左起始位置 */
  78. int keyHashRightBegin; /* buff 的右起始位置 */
  79. key_hash_interface keyHashFunction;
  80. };
  81. enum Layered {
  82. HOT = 0,
  83. FULL
  84. };
  85. enum Depoly{
  86. SINGLE = 0,
  87. SHARDING_DB_ONE_TAB = 1,
  88. SINGLE_DB_SHARDING_TAB = 2,
  89. SHARDING_DB_SHARDING_TAB = 3
  90. };
  91. class DbConfig {
  92. public:
  93. DTCConfig *cfgObj;
  94. char *dbName;
  95. char *dbFormat;
  96. char *tblName;
  97. char *tblFormat;
  98. int dstype; /* data-source type: default is mysql 0: mysql 1: gaussdb 2: rocksdb */
  99. int checkTable;
  100. unsigned int dbDiv;
  101. unsigned int dbMod;
  102. unsigned int tblMod;
  103. unsigned int tblDiv;
  104. int fieldCnt;
  105. int keyFieldCnt;
  106. int idxFieldCnt;
  107. int machineCnt;
  108. int procs; //all machine procs total
  109. int database_max_count; //max db index
  110. enum Depoly depoly;
  111. struct KeyHash keyHashConfig;
  112. int slaveGuard;
  113. int autoinc;
  114. int lastacc;
  115. int lastmod;
  116. int lastcmod;
  117. int expireTime;
  118. int compressflag;
  119. int ordIns;
  120. char *ordSql;
  121. struct FieldConfig *field;
  122. struct MachineConfig *mach;
  123. static struct DbConfig *load_buffered(char *buf);
  124. static struct DbConfig *Load(const char *file);
  125. static struct DbConfig *Load(DTCConfig * , int i_server_type = 0);
  126. static bool build_path(char *path, int n, int pid, int group, int role,
  127. int type);
  128. void destory(void);
  129. void dump_db_config(const struct DbConfig *cf);
  130. void set_helper_path(int);
  131. DTCTableDefinition *build_table_definition(void);
  132. int load_key_hash(DTCConfig *);
  133. bool compare_mach(DbConfig *config);
  134. bool Compare(DbConfig *config, bool compareMach = false);
  135. int find_new_mach(DbConfig *config, std::vector<int> &newMach,
  136. std::map<int, int> &machMap);
  137. static int get_dtc_mode(YAML::Node dtc_config);
  138. static std::string get_shm_size(YAML::Node dtc_config);
  139. static int get_shm_id(YAML::Node dtc_config);
  140. static std::string get_bind_addr(YAML::Node dtc_config);
  141. private:
  142. int get_dtc_config(YAML::Node dtc_config, DTCConfig* raw,int i_server_type);
  143. int convert_case_sensitivity(std::string& s_val);
  144. };
  145. #endif