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

feat: add audit db for DDL storage

上级 d2367337
......@@ -148,6 +148,7 @@ extern int32_t tsHttpKeepAlive;
extern int8_t tsEnableMonitorModule;
extern int8_t tsMonitorReplica;
extern char tsMonitorDbName[];
extern char tsAuditDbName[];
extern char tsInternalPass[];
extern int32_t tsMonitorInterval;
......
......@@ -197,6 +197,7 @@ int32_t tsHttpKeepAlive = 30000;
int8_t tsEnableMonitorModule = 1;
int8_t tsMonitorReplica = 1;
char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log";
char tsAuditDbName[TSDB_DB_NAME_LEN] = "audit";
char tsInternalPass[] = "secretkey";
int32_t tsMonitorInterval = 30; // seconds
......
......@@ -41,6 +41,7 @@
#define DNODE_INFO_LEN 128
#define QUERY_ID_LEN 24
#define CHECK_INTERVAL 1000
#define AUDIT_MAX_RETRIES 10
#define SQL_STR_FMT "\"%s\""
......@@ -175,16 +176,24 @@ static void monSaveDisksInfo();
static void monSaveGrantsInfo();
static void monSaveHttpReqInfo();
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 monInitHttpStatusHashTable();
static void monCleanupHttpStatusHashTable();
static void monInitHttpStatusHashTable();
static void monCleanupHttpStatusHashTable();
extern int32_t (*monStartSystemFp)();
extern void (*monStopSystemFp)();
extern void (*monExecuteSQLFp)(char *sql);
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() {
if (tsMonitor.ep[0] == 0) {
strcpy(tsMonitor.ep, tsLocalEp);
......@@ -203,12 +212,20 @@ int32_t monInitSystem() {
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
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;
}
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);
monDebug("monitor thread is launched");
monStartSystemFp = monStartSystem;
monStopSystemFp = monStopSystem;
......@@ -250,6 +267,50 @@ SMonHttpStatus *monGetHttpStatusHashTableEntry(int32_t code) {
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) {
monDebug("starting to initialize monitor module ...");
setThreadName("monitor");
......@@ -335,12 +396,6 @@ static void *monThreadFunc(void *param) {
static void monBuildMonitorSql(char *sql, int32_t cmd) {
memset(sql, 0, SQL_LENGTH);
#ifdef _STORAGE
char *keepValue = "30,30,30";
#else
char *keepValue = "30";
#endif
if (cmd == MON_CMD_CREATE_DB) {
snprintf(sql, SQL_LENGTH,
"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.
先完成此消息的编辑!
想要评论请 注册