Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
09261647
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看板
提交
09261647
编写于
10月 27, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add audit db for DDL storage
上级
4b2acc80
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
34 deletion
+52
-34
src/inc/monitor.h
src/inc/monitor.h
+24
-0
src/mnode/src/mnodeDb.c
src/mnode/src/mnodeDb.c
+1
-0
src/plugins/monitor/src/monMain.c
src/plugins/monitor/src/monMain.c
+27
-34
未找到文件。
src/inc/monitor.h
浏览文件 @
09261647
...
...
@@ -27,6 +27,29 @@ extern "C" {
monSaveDnodeLog(level, __VA_ARGS__); \
}
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
{
const
char
*
name
;
int32_t
code
;
...
...
@@ -62,6 +85,7 @@ int32_t monInitSystem();
int32_t
monStartSystem
();
void
monStopSystem
();
void
monCleanupSystem
();
void
monSaveAuditLog
(
int8_t
type
,
const
char
*
user
,
const
char
*
obj
,
bool
result
);
void
monSaveAcctLog
(
SAcctMonitorObj
*
pMonObj
);
void
monSaveLog
(
int32_t
level
,
const
char
*
const
format
,
...);
void
monSaveDnodeLog
(
int32_t
level
,
const
char
*
const
format
,
...);
...
...
src/mnode/src/mnodeDb.c
浏览文件 @
09261647
...
...
@@ -409,6 +409,7 @@ static int32_t mnodeCreateDbCb(SMnodeMsg *pMsg, int32_t code) {
}
else
{
mError
(
"db:%s, failed to create by %s, reason:%s"
,
pDb
->
name
,
mnodeGetUserFromMsg
(
pMsg
),
tstrerror
(
code
));
}
monSaveAuditLog
(
MON_DDL_CMD_CREATE_DATABASE
,
mnodeGetUserFromMsg
(
pMsg
),
pDb
->
name
,
!
code
);
return
code
;
}
...
...
src/plugins/monitor/src/monMain.c
浏览文件 @
09261647
...
...
@@ -42,6 +42,8 @@
#define QUERY_ID_LEN 24
#define CHECK_INTERVAL 1000
#define AUDIT_MAX_RETRIES 10
#define MAX_DDL_TYPE_LEN 20
#define MAX_DDL_OBJ_LEN 512
#define SQL_STR_FMT "\"%s\""
...
...
@@ -139,29 +141,6 @@ 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
;
...
...
@@ -185,6 +164,7 @@ typedef struct {
}
SMonStat
;
static
void
*
monHttpStatusHashTable
;
static
void
*
auditConn
;
static
SMonConn
tsMonitor
=
{
0
};
static
SMonStat
tsMonStat
=
{{
0
}};
...
...
@@ -295,12 +275,10 @@ static void *monAuditFunc(void *param) {
setThreadName
(
"audit"
);
taosMsleep
(
1000
);
void
*
conn
=
NULL
;
int32_t
try
=
0
;
for
(;
try
<
AUDIT_MAX_RETRIES
;
++
try
)
{
c
onn
=
taos_connect
(
NULL
,
"root"
,
"taosdata"
,
""
,
0
);
if
(
c
onn
==
NULL
)
{
auditC
onn
=
taos_connect
(
NULL
,
"root"
,
"taosdata"
,
""
,
0
);
if
(
auditC
onn
==
NULL
)
{
monDebug
(
"audit retry connect, tries: %d"
,
try
);
taosMsleep
(
1000
);
}
else
{
...
...
@@ -321,7 +299,7 @@ static void *monAuditFunc(void *param) {
"blocks %d precision 'us'"
,
tsAuditDbName
,
keepValue
,
TSDB_MIN_CACHE_BLOCK_SIZE
,
TSDB_MIN_TOTAL_BLOCKS
);
void
*
res
=
taos_query
(
c
onn
,
sql
);
void
*
res
=
taos_query
(
auditC
onn
,
sql
);
int32_t
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
...
...
@@ -334,11 +312,13 @@ static void *monAuditFunc(void *param) {
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
);
", user_name binary(%d), ip_addr binary(%d), type binary(%d)"
", object binary(%d), result binary(10)"
")"
,
tsAuditDbName
,
TSDB_USER_LEN
,
IP_LEN_STR
,
MAX_DDL_TYPE_LEN
,
MAX_DDL_OBJ_LEN
);
res
=
taos_query
(
c
onn
,
sql
);
res
=
taos_query
(
auditC
onn
,
sql
);
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
...
...
@@ -588,6 +568,11 @@ void monCleanupSystem() {
pthread_join
(
tsMonitor
.
thread
,
NULL
);
}
if
(
auditConn
!=
NULL
)
{
taos_close
(
tsMonitor
.
conn
);
auditConn
=
NULL
;
}
if
(
tsMonitor
.
conn
!=
NULL
)
{
taos_close
(
tsMonitor
.
conn
);
tsMonitor
.
conn
=
NULL
;
...
...
@@ -1511,12 +1496,20 @@ void monSaveAuditLog(int8_t type, const char *user, const char *obj, bool result
tsAuditDbName
,
(
user
!=
NULL
)
?
user
:
"NULL"
,
tsLocalEp
,
(
obj
!=
NULL
)
?
obj
:
"NULL"
,
typeStr
,
(
obj
!=
NULL
)
?
obj
:
"NULL"
,
result
?
"success"
:
"fail"
);
monDebug
(
"save ddl info, sql:%s"
,
sql
);
taos_query_a
(
tsMonitor
.
conn
,
sql
,
monExecSqlCb
,
"account info"
);
void
*
res
=
taos_query
(
auditConn
,
sql
);
int32_t
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
if
(
code
!=
0
)
{
monError
(
"failed to save audit info, reason:%s, sql:%s"
,
tstrerror
(
code
),
sql
);
}
else
{
monDebug
(
"successfully save audit info, sql:%s"
,
sql
);
}
}
void
monSaveAcctLog
(
SAcctMonitorObj
*
pMon
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录