Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4b2acc80
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4b2acc80
编写于
10月 27, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add audit db for DDL storage
上级
62f55b1c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
149 addition
and
7 deletion
+149
-7
src/inc/taosdef.h
src/inc/taosdef.h
+4
-4
src/plugins/monitor/src/monMain.c
src/plugins/monitor/src/monMain.c
+145
-3
未找到文件。
src/inc/taosdef.h
浏览文件 @
4b2acc80
...
...
@@ -244,12 +244,12 @@ do { \
#define TSDB_VERSION_LEN 12
#define TSDB_LOCALE_LEN 64
#define TSDB_TIMEZONE_LEN 96
#define TSDB_LABEL_LEN 8
#define TSDB_LABEL_LEN 8
#define TSDB_CLUSTER_ID_LEN 40
#define TSDB_FQDN_LEN 128
#define TSDB_EP_LEN (TSDB_FQDN_LEN+6)
#define TSDB_IPv4ADDR_LEN
16
#define TSDB_IPv4ADDR_LEN
16
#define TSDB_FILENAME_LEN 128
#define TSDB_SHOW_SQL_LEN 512
#define TSDB_SHOW_SUBQUERY_LEN 1000
...
...
@@ -313,7 +313,7 @@ do { \
#define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default
#define TSDB_MIN_DAYS_PER_FILE 1
#define TSDB_MAX_DAYS_PER_FILE 3650
#define TSDB_MAX_DAYS_PER_FILE 3650
#define TSDB_DEFAULT_DAYS_PER_FILE 10
#define TSDB_MIN_KEEP 1 // data in db to be reserved.
...
...
@@ -412,7 +412,7 @@ do { \
#define TSDB_ORDER_ASC 1
#define TSDB_ORDER_DESC 2
#define TSDB_DEFAULT_CLUSTER_HASH_SIZE 1
#define TSDB_DEFAULT_MNODES_HASH_SIZE 5
#define TSDB_DEFAULT_DNODES_HASH_SIZE 10
...
...
src/plugins/monitor/src/monMain.c
浏览文件 @
4b2acc80
...
...
@@ -139,6 +139,29 @@ typedef enum {
MON_STATE_INITED
}
EMonState
;
typedef
enum
{
// create
MON_DDL_CMD_CREATE_DATABASE
,
MON_DDL_CMD_CREATE_TABLE
,
MON_DDL_CMD_CREATE_CHILD_TABLE
,
MON_DDL_CMD_CREATE_SUPER_TABLE
,
// drop
MON_DDL_CMD_DROP_DATABASE
,
MON_DDL_CMD_DROP_TABLE
,
MON_DDL_CMD_DROP_CHILD_TABLE
,
MON_DDL_CMD_DROP_SUPER_TABLE
,
// alter
MON_DDL_CMD_ALTER_DATABASE
,
MON_DDL_CMD_ADD_COLUMN
,
MON_DDL_CMD_DROP_COLUMN
,
MON_DDL_CMD_MODIFY_COLUMN
,
MON_DDL_CMD_ADD_TAG
,
MON_DDL_CMD_DROP_TAG
,
MON_DDL_CMD_CHANGE_TAG
,
MON_DDL_CMD_MODIFY_TAG
,
MON_DDL_CMD_SET_TAG
,
}
EMonDDLCmdType
;
typedef
struct
{
pthread_t
thread
;
void
*
conn
;
...
...
@@ -291,6 +314,7 @@ static void *monAuditFunc(void *param) {
return
NULL
;
}
// create database
char
sql
[
512
]
=
{
0
};
snprintf
(
sql
,
sizeof
(
sql
),
"create database if not exists %s replica 1 days 10 keep %s cache %d "
...
...
@@ -302,10 +326,25 @@ static void *monAuditFunc(void *param) {
taos_free_result
(
res
);
if
(
code
!=
0
)
{
monError
(
"failed to exec sql:%s, reason:%s"
,
sql
,
tstrerror
(
code
));
monError
(
"failed to create database: %s, sql:%s, reason:%s"
,
tsAuditDbName
,
sql
,
tstrerror
(
code
));
return
NULL
;
}
// create table
memset
(
sql
,
0
,
sizeof
(
sql
));
snprintf
(
sql
,
sizeof
(
sql
),
"create table if not exists %s.ddl(ts timestamp"
", user_name binary(10), ip_addr binary(%d), type binary(10)"
", object binary(64), result bool"
")"
,
tsAuditDbName
,
IP_LEN_STR
);
res
=
taos_query
(
conn
,
sql
);
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
if
(
code
!=
0
)
{
monError
(
"failed to create table: ddl, exec sql:%s, reason:%s"
,
sql
,
tstrerror
(
code
));
return
NULL
;
}
else
{
monDebug
(
"successfully to exec sql:%s"
,
sql
);
}
return
NULL
;
...
...
@@ -1378,6 +1417,108 @@ static void monExecSqlCb(void *param, TAOS_RES *result, int32_t code) {
taos_free_result
(
result
);
}
static
bool
monConvDDLType2Str
(
int8_t
type
,
char
*
buf
,
int32_t
len
)
{
if
(
buf
==
NULL
)
{
return
false
;
}
switch
(
type
)
{
case
MON_DDL_CMD_CREATE_DATABASE
:
{
strncpy
(
buf
,
"CREATE DATABASE"
,
len
);
break
;
}
case
MON_DDL_CMD_CREATE_TABLE
:
{
strncpy
(
buf
,
"CREATE TABLE"
,
len
);
break
;
}
case
MON_DDL_CMD_CREATE_CHILD_TABLE
:
{
strncpy
(
buf
,
"CREATE CHILD TABLE"
,
len
);
break
;
}
case
MON_DDL_CMD_CREATE_SUPER_TABLE
:
{
strncpy
(
buf
,
"CREATE SUPER TABLE"
,
len
);
break
;
}
case
MON_DDL_CMD_DROP_DATABASE
:
{
strncpy
(
buf
,
"DROP DATABASE"
,
len
);
break
;
}
case
MON_DDL_CMD_DROP_TABLE
:
{
strncpy
(
buf
,
"DROP TABLE"
,
len
);
break
;
}
case
MON_DDL_CMD_DROP_CHILD_TABLE
:
{
strncpy
(
buf
,
"DROP CHILD TABLE"
,
len
);
break
;
}
case
MON_DDL_CMD_DROP_SUPER_TABLE
:
{
strncpy
(
buf
,
"DROP SUPER TABLE"
,
len
);
break
;
}
case
MON_DDL_CMD_DROP_COLUMN
:
{
strncpy
(
buf
,
"DROP COLUMN"
,
len
);
break
;
}
case
MON_DDL_CMD_DROP_TAG
:
{
strncpy
(
buf
,
"DROP TAG"
,
len
);
break
;
}
case
MON_DDL_CMD_ALTER_DATABASE
:
{
strncpy
(
buf
,
"ALTER DATABASE"
,
len
);
break
;
}
case
MON_DDL_CMD_ADD_COLUMN
:
{
strncpy
(
buf
,
"ADD COLUMN"
,
len
);
break
;
}
case
MON_DDL_CMD_ADD_TAG
:
{
strncpy
(
buf
,
"ADD TAG"
,
len
);
break
;
}
case
MON_DDL_CMD_MODIFY_COLUMN
:
{
strncpy
(
buf
,
"MODIFY COLUMN"
,
len
);
break
;
}
case
MON_DDL_CMD_MODIFY_TAG
:
{
strncpy
(
buf
,
"MODIFY TAG"
,
len
);
break
;
}
case
MON_DDL_CMD_CHANGE_TAG
:
{
strncpy
(
buf
,
"CHANGE TAG"
,
len
);
break
;
}
default:
{
return
false
;
}
}
return
true
;
}
void
monSaveAuditLog
(
int8_t
type
,
const
char
*
user
,
const
char
*
obj
,
bool
result
)
{
char
sql
[
1024
]
=
{
0
};
char
typeStr
[
64
]
=
{
0
};
if
(
!
monConvDDLType2Str
(
type
,
typeStr
,
(
int32_t
)
sizeof
(
typeStr
)))
{
monError
(
"unknown DDL type: %d "
,
type
);
return
;
}
snprintf
(
sql
,
1023
,
"insert into %s.ddl values(now, "
SQL_STR_FMT
", "
SQL_STR_FMT
", "
SQL_STR_FMT
", "
SQL_STR_FMT
", "
SQL_STR_FMT
")"
,
tsAuditDbName
,
(
user
!=
NULL
)
?
user
:
"NULL"
,
tsLocalEp
,
(
obj
!=
NULL
)
?
obj
:
"NULL"
,
typeStr
,
result
?
"success"
:
"fail"
);
monDebug
(
"save ddl info, sql:%s"
,
sql
);
taos_query_a
(
tsMonitor
.
conn
,
sql
,
monExecSqlCb
,
"account info"
);
}
void
monSaveAcctLog
(
SAcctMonitorObj
*
pMon
)
{
if
(
tsMonitor
.
state
!=
MON_STATE_INITED
)
return
;
...
...
@@ -1454,6 +1595,7 @@ void monSaveDnodeLog(int32_t level, const char *const format, ...) {
taos_query_a
(
tsMonitor
.
conn
,
sql
,
monExecSqlCb
,
"log"
);
}
void
monExecuteSQL
(
char
*
sql
)
{
if
(
tsMonitor
.
state
!=
MON_STATE_INITED
)
return
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录