提交 acaf116a 编写于 作者: G Ganlin Zhao

feat: add audit db for DDL storage

上级 d2367337
...@@ -148,6 +148,7 @@ extern int32_t tsHttpKeepAlive; ...@@ -148,6 +148,7 @@ extern int32_t tsHttpKeepAlive;
extern int8_t tsEnableMonitorModule; extern int8_t tsEnableMonitorModule;
extern int8_t tsMonitorReplica; extern int8_t tsMonitorReplica;
extern char tsMonitorDbName[]; extern char tsMonitorDbName[];
extern char tsAuditDbName[];
extern char tsInternalPass[]; extern char tsInternalPass[];
extern int32_t tsMonitorInterval; extern int32_t tsMonitorInterval;
......
...@@ -197,6 +197,7 @@ int32_t tsHttpKeepAlive = 30000; ...@@ -197,6 +197,7 @@ int32_t tsHttpKeepAlive = 30000;
int8_t tsEnableMonitorModule = 1; int8_t tsEnableMonitorModule = 1;
int8_t tsMonitorReplica = 1; int8_t tsMonitorReplica = 1;
char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log"; char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log";
char tsAuditDbName[TSDB_DB_NAME_LEN] = "audit";
char tsInternalPass[] = "secretkey"; char tsInternalPass[] = "secretkey";
int32_t tsMonitorInterval = 30; // seconds int32_t tsMonitorInterval = 30; // seconds
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#define DNODE_INFO_LEN 128 #define DNODE_INFO_LEN 128
#define QUERY_ID_LEN 24 #define QUERY_ID_LEN 24
#define CHECK_INTERVAL 1000 #define CHECK_INTERVAL 1000
#define AUDIT_MAX_RETRIES 10
#define SQL_STR_FMT "\"%s\"" #define SQL_STR_FMT "\"%s\""
...@@ -176,6 +177,7 @@ static void monSaveGrantsInfo(); ...@@ -176,6 +177,7 @@ static void monSaveGrantsInfo();
static void monSaveHttpReqInfo(); static void monSaveHttpReqInfo();
static void monGetSysStats(); static void monGetSysStats();
static void *monThreadFunc(void *param); static void *monThreadFunc(void *param);
static void *monAuditFunc(void *param);
static void monBuildMonitorSql(char *sql, int32_t cmd); static void monBuildMonitorSql(char *sql, int32_t cmd);
static void monInitHttpStatusHashTable(); static void monInitHttpStatusHashTable();
static void monCleanupHttpStatusHashTable(); static void monCleanupHttpStatusHashTable();
...@@ -185,6 +187,13 @@ extern void (*monStopSystemFp)(); ...@@ -185,6 +187,13 @@ extern void (*monStopSystemFp)();
extern void (*monExecuteSQLFp)(char *sql); extern void (*monExecuteSQLFp)(char *sql);
extern char * strptime(const char *buf, const char *fmt, struct tm *tm); //make the compilation pass extern char * strptime(const char *buf, const char *fmt, struct tm *tm); //make the compilation pass
#ifdef _STORAGE
char *keepValue = "30,30,30";
#else
char *keepValue = "30";
#endif
int32_t monInitSystem() { int32_t monInitSystem() {
if (tsMonitor.ep[0] == 0) { if (tsMonitor.ep[0] == 0) {
strcpy(tsMonitor.ep, tsLocalEp); strcpy(tsMonitor.ep, tsLocalEp);
...@@ -203,12 +212,20 @@ int32_t monInitSystem() { ...@@ -203,12 +212,20 @@ int32_t monInitSystem() {
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE); pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
if (pthread_create(&tsMonitor.thread, &thAttr, monThreadFunc, NULL)) { if (pthread_create(&tsMonitor.thread, &thAttr, monThreadFunc, NULL)) {
monError("failed to create thread to for monitor module, reason:%s", strerror(errno)); monError("failed to create thread for monitor module, reason:%s", strerror(errno));
return -1; return -1;
} }
monError("monitor thread is launched");
pthread_t auditThread;
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_DETACHED);
if (pthread_create(&auditThread, &thAttr, monAuditFunc, NULL)) {
monError("failed to create audit thread, reason:%s", strerror(errno));
return -1;
}
monError("audit thread is launched");
pthread_attr_destroy(&thAttr); pthread_attr_destroy(&thAttr);
monDebug("monitor thread is launched");
monStartSystemFp = monStartSystem; monStartSystemFp = monStartSystem;
monStopSystemFp = monStopSystem; monStopSystemFp = monStopSystem;
...@@ -250,6 +267,50 @@ SMonHttpStatus *monGetHttpStatusHashTableEntry(int32_t code) { ...@@ -250,6 +267,50 @@ SMonHttpStatus *monGetHttpStatusHashTableEntry(int32_t code) {
return (SMonHttpStatus*)taosHashGet(monHttpStatusHashTable, &code, sizeof(int32_t)); return (SMonHttpStatus*)taosHashGet(monHttpStatusHashTable, &code, sizeof(int32_t));
} }
static void *monAuditFunc(void *param) {
monDebug("starting to initialize audit database...");
setThreadName("audit");
//taosMsleep(30000);
void *conn = NULL;
int32_t try = 0;
for (; try < AUDIT_MAX_RETRIES; ++try) {
conn = taos_connect(NULL, "root", "taosdata", "", 0);
if (conn == NULL) {
monDebug("audit retry connect, tries: %d", try);
taosMsleep(1000);
} else {
monDebug("audit successfuly connect to database");
break;
}
}
if (try == AUDIT_MAX_RETRIES) {
monError("audit failed to connect to database, reason:%s", tstrerror(terrno));
return NULL;
}
char sql[512] = {0};
snprintf(sql, SQL_LENGTH,
"create database if not exists %s replica 1 days 10 keep %s cache %d "
"blocks %d precision 'us'",
tsAuditDbName, keepValue, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MIN_TOTAL_BLOCKS);
void *res = taos_query(conn, sql);
int32_t code = taos_errno(res);
taos_free_result(res);
if (code != 0) {
monError("failed to exec sql:%s, reason:%s", sql, tstrerror(code));
return NULL;
} else {
monDebug("successfully to exec sql:%s", sql);
}
return NULL;
}
static void *monThreadFunc(void *param) { static void *monThreadFunc(void *param) {
monDebug("starting to initialize monitor module ..."); monDebug("starting to initialize monitor module ...");
setThreadName("monitor"); setThreadName("monitor");
...@@ -335,12 +396,6 @@ static void *monThreadFunc(void *param) { ...@@ -335,12 +396,6 @@ static void *monThreadFunc(void *param) {
static void monBuildMonitorSql(char *sql, int32_t cmd) { static void monBuildMonitorSql(char *sql, int32_t cmd) {
memset(sql, 0, SQL_LENGTH); memset(sql, 0, SQL_LENGTH);
#ifdef _STORAGE
char *keepValue = "30,30,30";
#else
char *keepValue = "30";
#endif
if (cmd == MON_CMD_CREATE_DB) { if (cmd == MON_CMD_CREATE_DB) {
snprintf(sql, SQL_LENGTH, snprintf(sql, SQL_LENGTH,
"create database if not exists %s replica %d days 10 keep %s cache %d " "create database if not exists %s replica %d days 10 keep %s cache %d "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册