diff --git a/minidevops/README.MD b/minidevops/README.MD new file mode 100644 index 0000000000000000000000000000000000000000..f9ec4a8f190071d98d4b17de5b0bf3671bd38d6a --- /dev/null +++ b/minidevops/README.MD @@ -0,0 +1,219 @@ +# 一分钟快速搭建一个DevOps监控系统 +为了让更多的Devops领域的开发者快速体验TDengine的优秀特性,本文介绍了一种快速搭建Devops领域性能监控的demo,方便大家更方便的了解TDengine,并基于此文拓展Devops领域的应用。 +为了快速上手,本文用到的软件全部采用Docker容器方式部署,大家只需要安装Docker软件,就可以直接通过脚本运行所有软件,无需安装。这个Demo用到了以下Docker容器,都可以从Dockerhub上拉取相关镜像 +- tdengine/tdengine:1.6.4.5 TDengine开源版1.6.4.5.的镜像 +- tdengine/blm_telegraf:latest 用于telegraf写入TDengine的API,可以schemaless的将telegraf的数据写入TDengine +- tdengine/blm_prometheus:latest 用于Prometheus写入TDengine的API,可以schemaless的将Prometheus的数据写入TDengine +- grafana/grafana Grafana的镜像,一个广泛应用的开源可视化监控软件 +- telegraf:latest 一个广泛应用的开源数据采集程序 +- prom/prometheus:latest 一个广泛应用的k8s领域的开源数据采集程序 +## 说明 +本文中的图片链接在Github上显示不出来,建议将MD文件下载后用vscode或其他md文件浏览工具进行查看 +## 前提条件 +1. 一台linux服务器或运行linux操作系统的虚拟机或者运行MacOS的计算机 +2. 安装了Docker软件。Docker软件的安装方法请参考linux下安装Docker +3. sudo权限 +4. 下载本文用到的配置文件和脚本压缩包:[下载地址](http://www.taosdata.com/download/minidevops.tar.gz) + +压缩包下载下来后解压生成一个minidevops的文件夹,其结构如下 +```sh +minidevops$ tree +. +├── demodashboard.json +├── grafana +│   └── tdengine +│   ├── README.md +│   ├── css +│   │   └── query-editor.css +│   ├── datasource.js +│   ├── img +│   │   └── taosdata_logo.png +│   ├── module.js +│   ├── partials +│   │   ├── config.html +│   │   └── query.editor.html +│   ├── plugin.json +│   └── query_ctrl.js +├── prometheus +│   └── prometheus.yml +├── run.sh +└── telegraf + └── telegraf.conf +``` +`grafana`子文件夹里是TDengine的插件,用于在grafana中导入TDengine的数据源。 +`prometheus`子文件夹里是prometheus需要的配置文件。 +`run.sh`是运行脚本。 +`telegraf`子文件夹里是telegraf的配置文件。 +## 启动Docker镜像 +启动前,请确保系统里没有运行TDengine和Grafana,以及Telegraf和Prometheus,因为这些程序会占用docker所需的端口,造成脚本运行失败,建议先关闭这些程序。 +然后,只用在minidevops路径下执行 +```sh +sudo run.sh +``` +我们来看看`run.sh`里干了些什么: +```sh +#!/bin/bash + +LP=`pwd` + +#为了让脚本能够顺利执行,避免重复执行时出现错误, 首先将系统里所有docker容器停止了。请注意,如果该linux上已经运行了其他docker容器,也会被停止掉。 +docker rm -f `docker ps -a -q` + +#专门创建一个叫minidevops的虚拟网络,并指定了172.15.1.1~255这个地址段。 +docker network create --ip-range 172.15.1.255/24 --subnet 172.15.1.1/16 minidevops + +#启动grafana程序,并将tdengine插件文件所在路径绑定到容器中 +docker run -d --net minidevops --ip 172.15.1.11 -v $LP/grafana:/var/lib/grafana/plugins -p 3000:3000 grafana/grafana + +#启动tdengine的docker容器,并指定IP地址为172.15.1.6,绑定需要的端口 +docker run -d --net minidevops --ip 172.15.1.6 -p 6030:6030 -p 6020:6020 -p 6031:6031 -p 6032:6032 -p 6033:6033 -p 6034:6034 -p 6035:6035 -p 6036:6036 -p 6037:6037 -p 6038:6038 -p 6039:6039 tdengine/tdengine:1.6.4.5 + +#启动prometheus的写入代理程序,这个程序可以将prometheus发来的数据直接写入TDengine中,无需提前建立相关超级表和表,实现schemaless写入功能 +docker run -d --net minidevops --ip 172.15.1.7 -p 10203:10203 tdengine/blm_prometheus 172.15.1.6 + +#启动telegraf的写入代理程序,这个程序可以将telegraf发来的数据直接写入TDengine中,无需提前建立相关超级表和表,实现schemaless写入功能 +docker run -d --net minidevops --ip 172.15.1.8 -p 10202:10202 tdengine/blm_telegraf 172.15.1.6 + +#启动prometheus程序,并将配置文件所在路径绑定到容器中 +docker run -d --net minidevops --ip 172.15.1.9 -v $LP/prometheus:/etc/prometheus -p 9090:9090 prom/prometheus + +#启动telegraf程序,并将配置文件所在路径绑定到容器中 +docker run -d --net minidevops --ip 172.15.1.10 -v $LP/telegraf:/etc/telegraf -p 8092:8092 -p 8094:8094 -p 8125:8125 telegraf + +#通过Grafana的API,将TDengine配置成Grafana的datasources +curl -X POST http://localhost:3000/api/datasources --header "Content-Type:application/json" -u admin:admin -d '{"Name": "TDengine","Type": "tdengine","TypeLogoUrl": "public/plugins/tdengine/img/taosdata_logo.png","Access": "proxy","Url": "http://172.15.1.6:6020","BasicAuth": false,"isDefault": true,"jsonData": {},"readOnly": false}' + +#通过Grafana的API,配置一个示范的监控面板 +curl -X POST http://localhost:3000/api/dashboards/db --header "Content-Type:application/json" -u admin:admin -d '{"dashboard":{"annotations":{"list":[{"builtIn":1,"datasource":"-- Grafana --","enable":true,"hide":true,"iconColor":"rgba(0, 211, 255, 1)","name":"Annotations & Alerts","type":"dashboard"}]},"editable":true,"gnetId":null,"graphTooltip":0,"id":1,"links":[],"panels":[{"datasource":null,"gridPos":{"h":8,"w":6,"x":0,"y":0},"id":6,"options":{"fieldOptions":{"calcs":["mean"],"defaults":{"color":{"mode":"thresholds"},"links":[{"title":"","url":""}],"mappings":[],"max":100,"min":0,"thresholds":{"mode":"absolute","steps":[{"color":"green","value":null},{"color":"red","value":80}]},"unit":"percent"},"overrides":[],"values":false},"orientation":"auto","showThresholdLabels":false,"showThresholdMarkers":true},"pluginVersion":"6.6.0","targets":[{"refId":"A","sql":"select last_row(value) from telegraf.mem where field=\"used_percent\""}],"timeFrom":null,"timeShift":null,"title":"Memory used percent","type":"gauge"},{"aliasColors":{},"bars":false,"dashLength":10,"dashes":false,"datasource":null,"fill":1,"fillGradient":0,"gridPos":{"h":8,"w":12,"x":6,"y":0},"hiddenSeries":false,"id":8,"legend":{"avg":false,"current":false,"max":false,"min":false,"show":true,"total":false,"values":false},"lines":true,"linewidth":1,"nullPointMode":"null","options":{"dataLinks":[]},"percentage":false,"pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"alias":"MEMUSED-PERCENT","refId":"A","sql":"select avg(value) from telegraf.mem where field=\"used_percent\" interval(1m)"}],"thresholds":[],"timeFrom":null,"timeRegions":[],"timeShift":null,"title":"Panel Title","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"format":"short","label":null,"logBase":1,"max":null,"min":null,"show":true},{"format":"short","label":null,"logBase":1,"max":null,"min":null,"show":true}],"yaxis":{"align":false,"alignLevel":null}},{"datasource":null,"gridPos":{"h":9,"w":6,"x":0,"y":8},"id":10,"options":{"fieldOptions":{"calcs":["mean"],"defaults":{"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"green","value":null}]},"unit":"percent"},"overrides":[],"values":false},"orientation":"auto","showThresholdLabels":false,"showThresholdMarkers":true},"pluginVersion":"6.6.0","targets":[{"alias":"CPU-SYS","refId":"A","sql":"select last_row(value) from telegraf.cpu where field=\"usage_system\""},{"alias":"CPU-IDLE","refId":"B","sql":"select last_row(value) from telegraf.cpu where field=\"usage_idle\""},{"alias":"CPU-USER","refId":"C","sql":"select last_row(value) from telegraf.cpu where field=\"usage_user\""}],"timeFrom":null,"timeShift":null,"title":"Panel Title","type":"gauge"},{"aliasColors":{},"bars":false,"dashLength":10,"dashes":false,"datasource":"TDengine","description":"General CPU monitor","fill":1,"fillGradient":0,"gridPos":{"h":9,"w":12,"x":6,"y":8},"hiddenSeries":false,"id":2,"legend":{"avg":false,"current":false,"max":false,"min":false,"show":true,"total":false,"values":false},"lines":true,"linewidth":1,"nullPointMode":"null","options":{"dataLinks":[]},"percentage":false,"pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"alias":"CPU-USER","refId":"A","sql":"select avg(value) from telegraf.cpu where field=\"usage_user\" and cpu=\"cpu-total\" interval(1m)"},{"alias":"CPU-SYS","refId":"B","sql":"select avg(value) from telegraf.cpu where field=\"usage_system\" and cpu=\"cpu-total\" interval(1m)"},{"alias":"CPU-IDLE","refId":"C","sql":"select avg(value) from telegraf.cpu where field=\"usage_idle\" and cpu=\"cpu-total\" interval(1m)"}],"thresholds":[],"timeFrom":null,"timeRegions":[],"timeShift":null,"title":"CPU","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"format":"short","label":null,"logBase":1,"max":null,"min":null,"show":true},{"format":"short","label":null,"logBase":1,"max":null,"min":null,"show":true}],"yaxis":{"align":false,"alignLevel":null}}],"refresh":"10s","schemaVersion":22,"style":"dark","tags":["demo"],"templating":{"list":[]},"time":{"from":"now-3h","to":"now"},"timepicker":{"refresh_intervals":["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"]},"timezone":"","title":"TDengineDashboardDemo","id":null,"uid":null,"version":0}}' +``` +执行以上脚本后,可以通过docker container ls命令来确认容器运行的状态: +```sh +$docker container ls +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +f875bd7d90d1 telegraf "/entrypoint.sh tele…" 6 hours ago Up 6 hours 0.0.0.0:8092->8092/tcp, 8092/udp, 0.0.0.0:8094->8094/tcp, 8125/udp, 0.0.0.0:8125->8125/tcp wonderful_antonelli +38ee2d5c3cb3 prom/prometheus "/bin/prometheus --c…" 6 hours ago Up 6 hours 0.0.0.0:9090->9090/tcp infallible_mestorf +1a1939386c07 tdengine/blm_telegraf "/root/blm_telegraf …" 6 hours ago Up 6 hours 0.0.0.0:10202->10202/tcp stupefied_hypatia +7063eb05caa4 tdengine/blm_prometheus "/root/blm_prometheu…" 6 hours ago Up 6 hours 0.0.0.0:10203->10203/tcp jovial_feynman +4a7b27931d21 tdengine/tdengine:1.6.4.5 "taosd" 6 hours ago Up 6 hours 0.0.0.0:6020->6020/tcp, 0.0.0.0:6030-6039->6030-6039/tcp, 6040-6050/tcp eager_kowalevski +ad2895760bc0 grafana/grafana "/run.sh" 6 hours ago Up 6 hours 0.0.0.0:3000->3000/tcp romantic_mccarthy +``` +当以上几个容器都已正常运行后,则我们的demo小系统已经开始工作了。 +## Grafana中进行配置 +打开浏览器,在地址栏输入服务器所在的IP地址 +`http://localhost:3000` +就可以访问到grafana的页面,如果不在本机打开浏览器,则将localhost改成server的ip地址即可。 +进入登录页面,用户名和密码都是缺省的admin,输入后,即可进入grafana的控制台输入用户名/密码后,会进入修改密码页面,选择skip,跳过这一步。进入Grafana后,可以在页面的左下角看到TDengineDashboardDemo已经创建好了,![](https://www.taosdata.com/blog/wp-content/uploads/2020/02/image2020-2-1_22-50-58-1024x465.png)对于有些浏览器打开时,可能会在home页面中没有TDengineDashboardDemo的选项,可以通过在Dashboard->Manage中选择![](https://www.taosdata.com/blog/wp-content/uploads/2020/02/2-1024x553.png)TDengineDashboardDemo。点击TDengineDashboardDemo进入示例监控面板。刚点进去页面时,监控曲线是空白的,因为监控数据还不够多,需要等待一段时间,让数据采集程序采集更多的数据。![](https://www.taosdata.com/blog/wp-content/uploads/2020/02/image-5-1024x853.png) + +如上两个监控面板分别监控了CPU和内存占用率。点击面板上的标题可以选择Edit进入编辑界面,新增监控数据。关于Grafana的监控面板设置,可以详细参考Grafana官网文档[Getting Started](https://grafana.com/docs/grafana/latest/guides/getting_started/)。 + +## 原理介绍 +按上面的操作,我们已经将监控系统搭建起来了,目前可以监控系统的CPU占有率了。下面介绍下这个Demo系统的工作原理。 +如下图所示,这个系统由数据采集功能(prometheus,telegraf),时序数据库功能(TDengine和适配程序),可视化功能(Grafana)组成。下面虚线框里的TDengine,blm_prometheus, blm_telegraf三个容器组成了一个schemaless写入的时序数据库,对于采用telegraf和prometheus作为采集程序的监控对象,可以直接将数据写入TDengine,并通过grafana进行可视化呈现。 +![architecture](https://www.taosdata.com/blog/wp-content/uploads/2020/02/image2020-1-29_21-22-6.png) +### 数据采集 +数据采集由Telegraf和Prometheus完成。Telegraf根据配置,从操作系统层面采集系统的相关统计值,并按配置上报给指定的URL,上报的数据json格式为 +```json +{ + "fields":{ + "usage_guest":0, + "usage_guest_nice":0, + "usage_idle":87.73726273726274, + "usage_iowait":0, + "usage_irq":0, + "usage_nice":0, + "usage_softirq":0, + "usage_steal":0, + "usage_system":2.6973026973026974, + "usage_user":9.565434565434565 + }, + "name":"cpu", + "tags":{ + "cpu":"cpu-total", + "host":"liutaodeMacBook-Pro.local" + }, + "timestamp":1571665100 +} +``` +其中name将被作为超级表的表名,tags作为普通表的tags,fields的名称也会作为一个tag用来描述普通表的标签。举个例子,一个普通表的结构如下,这是一个存储usage_softirq数据的普通表。 +![表结构](https://www.taosdata.com/blog/wp-content/uploads/2020/02/image2020-1-29_21-38-24.png) + +### Telegraf的配置 +对于使用telegraf作为数据采集程序的监控对象,可以在telegraf的配置文件telegraf.conf中将outputs.http部分的配置按以下配置修改,就可以直接将数据写入TDengine中了 +```toml +[[outputs.http]] +# ## URL is the address to send metrics to +url = "http://172.15.1.8:10202/telegraf" +# +# ## HTTP Basic Auth credentials +# # username = "username" +# # password = "pa$$word" +# + +data_format = "json" +json_timestamp_units = "1ms" +``` +可以打开HTTP basic Auth验证机制,本Demo为了简化没有打开验证功能。 +对于多个被监控对象,只需要在telegraf.conf文件中都写上以上的配置内容,就可以将数据写入TDengine中了。 + +### Telegraf数据在TDengine中的存储结构 +Telegraf的数据在TDengine中的存储,是以数据name为超级表名,以tags值加上监控对象的ip地址,以及field的属性名作为tag值,存入TDengine中的。 +以name为cpu的数据为例,telegraf产生的数据为: +```json +{ + "fields":{ + "usage_guest":0, + "usage_guest_nice":0, + "usage_idle":87.73726273726274, + "usage_iowait":0, + "usage_irq":0, + "usage_nice":0, + "usage_softirq":0, + "usage_steal":0, + "usage_system":2.6973026973026974, + "usage_user":9.565434565434565 + }, + "name":"cpu", + "tags":{ + "cpu":"cpu-total", + "host":"liutaodeMacBook-Pro.local" + }, + "timestamp":1571665100 +} +``` +则写入TDengine时会自动存入一个名为cpu的超级表中,这个表的结构如下 +![telegraf表结构](https://www.taosdata.com/blog/wp-content/uploads/2020/02/image2020-2-2_0-37-49.png) +这个超级表的tag字段有cpu,host,srcip,field;其中cpu,host是原始数据携带的tag,而srcip是监控对象的IP地址,field是监控对象cpu类型数据中的fields属性,取值空间为[usage_guest,usage_guest_nice,usage_idle,usage_iowait,usage_irq,usage_nice,usage_softirq,usage_steal,usage_system,usage_user],每个field值对应着一个具体含义的数据。 + +因此,在查询的时候,可以用这些tag来过滤数据,也可以用超级表来聚合数据。 +### Prometheus的配置 +对于使用Prometheus作为数据采集程序的监控对象,可以在Prometheus的配置文件prometheus.yaml文件中,将remote write部分的配置按以下配置修改,就可以直接将数据写入TDengine中了。 +```yaml +remote_write: + - url: "http://172.15.1.7:10203/receive" +``` +对于多个被监控对象,只需要在每个被监控对象的prometheus配置中增加以上配置内容,就可以将数据写入TDengine中了。 +### Prometheus数据在TDengine中的存储结构 +Prometheus的数据在TDengine中的存储,与telegraf类似,也是以数据的name字段为超级表名,以数据的label作为tag值,存入TDengine中 +以prometheus_engine_queries这个数据为例[prom表结构](https://www.taosdata.com/blog/wp-content/uploads/2020/02/image2020-2-2_0-51-4.png) +在TDengine中会自动创建一个prometheus_engine_queries的超级表,tag字段为t_instance,t_job,t_monitor。 +查询时,可以用这些tag来过滤数据,也可以用超级表来聚合数据。 + +## 数据查询 +我们可以登陆到TDengine的客户端命令,通过命令行看看TDengine里面都存储了些什么数据,顺便也能体验一下TDengine的高性能查询。如何才能登陆到TDengine的客户端,我们可以通过以下几步来完成。 +首先通过下面的命令查询一下tdengine的Docker ID +```sh +docker container ls +``` +然后再执行 +```sh +docker exec -it tdengine的containerID bash +``` +就可以进入TDengine容器的命令行,执行taos,就进入以下界面![](https://www.taosdata.com/blog/wp-content/uploads/2020/02/image2020-1-29_21-55-53.png) +Telegraf的数据写入时,自动创建了一个名为telegraf的database,可以通过 +``` +use telegraf; +``` +使用telegraf这个数据库。然后执行show tables,describe table等命令详细查询下telegraf这个库里保存了些什么数据。 +具体TDengine的查询语句可以参考[TDengine官方文档](https://www.taosdata.com/cn/documentation/taos-sql/) +## 接入多个监控对象 +就像前面原理介绍的,这个miniDevops的小系统,已经提供了一个时序数据库和可视化系统,对于多台机器的监控,只需要将每台机器的telegraf或prometheus配置按上面所述修改,就可以完成监控数据采集和可视化呈现了。 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 590dba01a3a40ac23ec38534425d90b47f197800..712ccbffbfba1a23b347a38008b1b381dc248698 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,7 @@ ADD_SUBDIRECTORY(rpc) ADD_SUBDIRECTORY(client) ADD_SUBDIRECTORY(kit) ADD_SUBDIRECTORY(modules) +ADD_SUBDIRECTORY(sdb) ADD_SUBDIRECTORY(mnode) ADD_SUBDIRECTORY(dnode) ADD_SUBDIRECTORY(vnode) diff --git a/src/dnode/CMakeLists.txt b/src/dnode/CMakeLists.txt index 32cf41b1a8597b1b2b9374bd279c9ad0b7881a7d..143c5397e8301da5bf411258ed721f8e63f84098 100644 --- a/src/dnode/CMakeLists.txt +++ b/src/dnode/CMakeLists.txt @@ -2,7 +2,10 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT(TDengine) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) + INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) + INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/dnode/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/detail/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/vnode/detail/inc) @@ -11,7 +14,6 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/modules/monitor/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/inc) INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/util/cluster/inc) - INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(src SRC) diff --git a/src/dnode/inc/dnodeMgmt.h b/src/dnode/inc/dnodeMgmt.h index 51e3e7c18e315c9f1c8dac48786d2416b962d396..194bde30546d6c60bd10ae2e90f437f9cc5d31e3 100644 --- a/src/dnode/inc/dnodeMgmt.h +++ b/src/dnode/inc/dnodeMgmt.h @@ -21,14 +21,7 @@ extern "C" { #endif #include "tsched.h" - -typedef struct { - char id[20]; - char sid; - void *thandle; - int mgmtIndex; - char status; // 0:offline, 1:online -} SMgmtObj; +#include "dnode.h" int vnodeProcessCreateMeterRequest(char *pMsg, int msgLen, SMgmtObj *pMgmtObj); int vnodeProcessRemoveMeterRequest(char *pMsg, int msgLen, SMgmtObj *pMgmtObj); @@ -37,24 +30,6 @@ void dnodeDistributeMsgFromMgmt(char *content, int msgLen, int msgType, SMgmtObj void mgmtProcessMsgFromDnodeSpec(SSchedMsg *sched); extern void *dmQhandle; -extern char *(*taosBuildRspMsgToMnodeWithSize)(SMgmtObj *pObj, char type, int size); -extern char *(*taosBuildReqMsgToMnodeWithSize)(SMgmtObj *pObj, char type, int size); -extern char *(*taosBuildRspMsgToMnode)(SMgmtObj *pObj, char type); -extern char *(*taosBuildReqMsgToMnode)(SMgmtObj *pObj, char type); -extern int (*taosSendMsgToMnode)(SMgmtObj *pObj, char *msg, int msgLen); -extern int (*taosSendSimpleRspToMnode)(SMgmtObj *pObj, char rsptype, char code); -extern void (*dnodeInitMgmtIp)(); -extern int (*dnodeInitMgmtConn)(); - -char *taosBuildRspMsgToMnodeWithSizeEdgeImp(SMgmtObj *pObj, char type, int size); -char *taosBuildReqMsgToMnodeWithSizeEdgeImp(SMgmtObj *pObj, char type, int size); -char *taosBuildRspMsgToMnodeEdgeImp(SMgmtObj *pObj, char type); -char *taosBuildReqMsgToMnodeEdgeImp(SMgmtObj *pObj, char type); -int taosSendMsgToMnodeEdgeImp(SMgmtObj *pObj, char *msg, int msgLen); -int taosSendSimpleRspToMnodeEdgeImp(SMgmtObj *pObj, char rsptype, char code); -void dnodeInitMgmtIpEdgeImp(); -void* dnodeProcessMsgFromMgmtEdgeImp(SSchedMsg *sched); -int dnodeInitMgmtConnEdgeImp(); #ifdef __cplusplus } diff --git a/src/dnode/inc/dnodeModule.h b/src/dnode/inc/dnodeModule.h index 76f3bd4ffa5b2bb87897cc141b4381c5a2eaee55..7967fa956e03d6c187ba5eecb17f496f92d5f6e4 100644 --- a/src/dnode/inc/dnodeModule.h +++ b/src/dnode/inc/dnodeModule.h @@ -33,6 +33,8 @@ enum _module { TSDB_MOD_MGMT, TSDB_MOD_HTTP, TSDB_MOD_MONITOR, + TSDB_MOD_DCLUSTER, + TSDB_MOD_MSTORAGE, TSDB_MOD_MAX }; @@ -54,9 +56,6 @@ void dnodeAllocModules(); int32_t dnodeInitModules(); void dnodeCleanUpModules(); -extern void (*dnodeStartModules)(); -void dnodeStartModulesEdgeImp(); - #ifdef __cplusplus } #endif diff --git a/src/dnode/inc/dnodeService.h b/src/dnode/inc/dnodeService.h deleted file mode 100644 index 953c01413fb75e6257c560117570112e3335fcda..0000000000000000000000000000000000000000 --- a/src/dnode/inc/dnodeService.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef TDENGINE_DNODE_SERVICE_H -#define TDENGINE_DNODE_SERVICE_H - -#ifdef __cplusplus -extern "C" { -#endif - -void (*dnodeParseParameterK)(); -void dnodeParseParameterKComImp(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/dnode/inc/dnodeSystem.h b/src/dnode/inc/dnodeSystem.h index e4245a1496cc21c7cf600be8df1d4d21460d9f5f..eb25357c59438a0cd3e3dd9d2bab7524ba769ee3 100644 --- a/src/dnode/inc/dnodeSystem.h +++ b/src/dnode/inc/dnodeSystem.h @@ -26,9 +26,6 @@ extern "C" { extern pthread_mutex_t dmutex; extern bool tsDnodeStopping; -extern int (*dnodeInitStorage)(); -extern void (*dnodeCleanupStorage)(); -extern int (*dnodeCheckSystem)(); int dnodeInitSystem(); void dnodeCleanUpSystem(); diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index 2a10e0a7469c385496a6c5c533c2a77b30679ce5..482e6ae477fea672719092c3a831026bb1c76e07 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -17,6 +17,7 @@ #include "os.h" +#include "dnode.h" #include "dnodeSystem.h" #include "dnodeMgmt.h" @@ -43,17 +44,7 @@ void vnodeUpdateHeadFile(int vnode, int oldTables, int newTables); void vnodeOpenVnode(int vnode); void vnodeCleanUpOneVnode(int vnode); - -char *(*taosBuildRspMsgToMnodeWithSize)(SMgmtObj *pObj, char type, int size) = NULL; -char *(*taosBuildReqMsgToMnodeWithSize)(SMgmtObj *pObj, char type, int size) = NULL; -char *(*taosBuildRspMsgToMnode)(SMgmtObj *pObj, char type) = NULL; -char *(*taosBuildReqMsgToMnode)(SMgmtObj *pObj, char type) = NULL; -int (*taosSendMsgToMnode)(SMgmtObj *pObj, char *msg, int msgLen) = NULL; -int (*taosSendSimpleRspToMnode)(SMgmtObj *pObj, char rsptype, char code) = NULL; -void (*dnodeInitMgmtIp)() = NULL; -int (*dnodeInitMgmtConn)() = NULL; - -char *taosBuildRspMsgToMnodeWithSizeEdgeImp(SMgmtObj *pObj, char type, int size) { +char *taosBuildRspMsgToMnodeWithSizeImp(SMgmtObj *pObj, char type, int size) { char *pStart = (char *)malloc(size); if (pStart == NULL) { return NULL; @@ -62,8 +53,9 @@ char *taosBuildRspMsgToMnodeWithSizeEdgeImp(SMgmtObj *pObj, char type, int size) *pStart = type; return pStart + 1; } +char *(*taosBuildRspMsgToMnodeWithSize)(SMgmtObj *pObj, char type, int size) = taosBuildRspMsgToMnodeWithSizeImp; -char *taosBuildReqMsgToMnodeWithSizeEdgeImp(SMgmtObj *pObj, char type, int size) { +char *taosBuildReqMsgToMnodeWithSizeImp(SMgmtObj *pObj, char type, int size) { char *pStart = (char *)malloc(size); if (pStart == NULL) { return NULL; @@ -72,16 +64,19 @@ char *taosBuildReqMsgToMnodeWithSizeEdgeImp(SMgmtObj *pObj, char type, int size) *pStart = type; return pStart + 1; } +char *(*taosBuildReqMsgToMnodeWithSize)(SMgmtObj *pObj, char type, int size) = taosBuildReqMsgToMnodeWithSizeImp; -char *taosBuildRspMsgToMnodeEdgeImp(SMgmtObj *pObj, char type) { - return taosBuildRspMsgToMnodeWithSize(pObj, type, 256); +char *taosBuildRspMsgToMnodeImp(SMgmtObj *pObj, char type) { + return taosBuildRspMsgToMnodeWithSizeImp(pObj, type, 256); } +char *(*taosBuildRspMsgToMnode)(SMgmtObj *pObj, char type) = taosBuildRspMsgToMnodeImp; -char *taosBuildReqMsgToMnodeEdgeImp(SMgmtObj *pObj, char type) { - return taosBuildReqMsgToMnodeWithSize(pObj, type, 256); +char *taosBuildReqMsgToMnodeImp(SMgmtObj *pObj, char type) { + return taosBuildReqMsgToMnodeWithSizeImp(pObj, type, 256); } +char *(*taosBuildReqMsgToMnode)(SMgmtObj *pObj, char type) = taosBuildReqMsgToMnodeImp; -int taosSendMsgToMnodeEdgeImp(SMgmtObj *pObj, char *msg, int msgLen) { +int taosSendMsgToMnodeImp(SMgmtObj *pObj, char *msg, int msgLen) { dTrace("msg:%s is sent to mnode", taosMsg[(uint8_t)(*(msg-1))]); /* @@ -96,8 +91,9 @@ int taosSendMsgToMnodeEdgeImp(SMgmtObj *pObj, char *msg, int msgLen) { return 0; } +int (*taosSendMsgToMnode)(SMgmtObj *pObj, char *msg, int msgLen) = taosSendMsgToMnodeImp; -int taosSendSimpleRspToMnodeEdgeImp(SMgmtObj *pObj, char rsptype, char code) { +int taosSendSimpleRspToMnodeImp(SMgmtObj *pObj, char rsptype, char code) { char *pStart = taosBuildRspMsgToMnode(0, rsptype); if (pStart == NULL) { return 0; @@ -108,8 +104,15 @@ int taosSendSimpleRspToMnodeEdgeImp(SMgmtObj *pObj, char rsptype, char code) { return 0; } +int (*taosSendSimpleRspToMnode)(SMgmtObj *pObj, char rsptype, char code) = taosSendSimpleRspToMnodeImp; + +int32_t dnodeInitMgmtImp() { return 0; } +int32_t (*dnodeInitMgmt)() = dnodeInitMgmtImp; -void* dnodeProcessMsgFromMgmtEdgeImp(SSchedMsg *sched) { +void dnodeInitMgmtIpImp() {} +void (*dnodeInitMgmtIp)() = dnodeInitMgmtIpImp; + +void* dnodeProcessMsgFromMgmtImp(SSchedMsg *sched) { char msgType = *sched->msg; char *content = sched->msg + 1; @@ -122,13 +125,6 @@ void* dnodeProcessMsgFromMgmtEdgeImp(SSchedMsg *sched) { return NULL; } -int dnodeInitMgmtConnEdgeImp() { - return 0; -} - -void dnodeInitMgmtIpEdgeImp() {} - - void dnodeDistributeMsgFromMgmt(char *content, int msgLen, int msgType, SMgmtObj *pObj) { if (msgType == TSDB_MSG_TYPE_CREATE) { vnodeProcessCreateMeterRequest(content, msgLen, pObj); diff --git a/src/dnode/src/dnodeModule.c b/src/dnode/src/dnodeModule.c index b06069927a74b4a4c6d53bb2500dc3b9774469da..5999ff3239461901e37619f05e0a9c5fa4219134 100644 --- a/src/dnode/src/dnodeModule.c +++ b/src/dnode/src/dnodeModule.c @@ -25,7 +25,6 @@ SModule tsModule[TSDB_MOD_MAX] = {0}; uint32_t tsModuleStatus = 0; -void (*dnodeStartModules)() = NULL; void dnodeAllocModules() { tsModule[TSDB_MOD_MGMT].name = "mgmt"; @@ -116,7 +115,7 @@ int32_t dnodeInitModules() { return 0; } -void dnodeStartModulesEdgeImp() { +void dnodeStartModulesImp() { for (int mod = 1; mod < TSDB_MOD_MAX; ++mod) { if (tsModule[mod].num != 0 && tsModule[mod].startFp) { if ((*tsModule[mod].startFp)() != 0) { @@ -129,3 +128,4 @@ void dnodeStartModulesEdgeImp() { (*tsModule[TSDB_MOD_MGMT].cleanUpFp)(); } } +void (*dnodeStartModules)() = dnodeStartModulesImp; diff --git a/src/dnode/src/dnodeService.c b/src/dnode/src/dnodeService.c index 085451862ccb7c148f8191dcec4292f942770e32..9558052458ca7cdf632b577acc431ff669dee3dc 100644 --- a/src/dnode/src/dnodeService.c +++ b/src/dnode/src/dnodeService.c @@ -14,16 +14,37 @@ */ #define _DEFAULT_SOURCE - #include "os.h" - -#include "dnodeSystem.h" #include "tglobalcfg.h" #include "tsdb.h" #include "vnode.h" +#include "dnodeSystem.h" + +#ifdef CLUSTER + #include "dnodeCluster.h" + #include "httpAdmin.h" + #include "mnodeAccount.h" + #include "mnodeBalance.h" + #include "mnodeCluster.h" + #include "mnodeReplica.h" + #include "multilevelStorage.h" + #include "vnodeCluster.h" + #include "vnodeReplica.h" + void init() { + dnodeClusterInit(); + httpAdminInit(); + mnodeAccountInit(); + mnodeBalanceInit(); + mnodeClusterInit(); + sdbReplicaInit(); + multilevelStorageInit(); + vnodeClusterInit(); + vnodeReplicaInit(); + } +#endif -void (*dnodeParseParameterK)() = NULL; -void dnodeParseParameterKComImp() {} +void dnodeParseParameterKImp() {} +void (*dnodeParseParameterK)() = dnodeParseParameterKImp; /* Termination handler */ void signal_handler(int signum, siginfo_t *sigInfo, void *context) { diff --git a/src/dnode/src/dnodeSystem.c b/src/dnode/src/dnodeSystem.c index 2511329c451a22b675458529f7cfa279cf14fec0..7b2a273a14fb7cd2e700a20c1b435227d66221dd 100644 --- a/src/dnode/src/dnodeSystem.c +++ b/src/dnode/src/dnodeSystem.c @@ -18,9 +18,9 @@ #include "tsdb.h" #include "tlog.h" #include "ttimer.h" +#include "dnode.h" #include "dnodeMgmt.h" #include "dnodeModule.h" -#include "dnodeService.h" #include "dnodeSystem.h" #include "monitorSystem.h" #include "httpSystem.h" @@ -42,14 +42,10 @@ void * queryQhandle; int tsVnodePeers = TSDB_VNODES_SUPPORT - 1; int tsMaxQueues; uint32_t tsRebootTime; -int (*dnodeInitStorage)() = NULL; -void (*dnodeCleanupStorage)() = NULL; -int (*dnodeCheckSystem)() = NULL; int32_t dnodeInitRpcQHandle(); int32_t dnodeInitQueryQHandle(); int32_t dnodeInitTmrCtl(); -void dnodeInitPlugin(); void dnodeCountRequestImp(SCountInfo *info); void dnodeCleanUpSystem() { @@ -88,8 +84,6 @@ int dnodeInitSystem() { char temp[128]; struct stat dirstat; - dnodeInitPlugin(); - taosResolveCRC(); tsRebootTime = taosGetTimestampSec(); @@ -169,7 +163,7 @@ int dnodeInitSystem() { return -1; } - if (dnodeInitMgmtConn() < 0) { + if (dnodeInitMgmt() < 0) { dError("failed to init communication to mgmt"); return -1; } @@ -207,7 +201,7 @@ void dnodeCountRequestImp(SCountInfo *info) { info->insertReqNum = atomic_exchange_32(&vnodeInsertReqNum, 0); } -int dnodeInitStorageComImp() { +int dnodeInitStorageImp() { struct stat dirstat; strcpy(tsDirectory, dataDir); if (stat(dataDir, &dirstat) < 0) { @@ -228,8 +222,10 @@ int dnodeInitStorageComImp() { return 0; } +int32_t (*dnodeInitStorage)() = dnodeInitStorageImp; -void dnodeCleanupStorageComImp() {} +void dnodeCleanupStorageImp() {} +void (*dnodeCleanupStorage)() = dnodeCleanupStorageImp; int32_t dnodeInitQueryQHandle() { int numOfThreads = tsRatioOfQueryThreads * tsNumOfCores * tsNumOfThreadsPerCore; @@ -270,26 +266,7 @@ int32_t dnodeInitRpcQHandle() { } -int dnodeCheckSystemComImp() { - return 0; -} - -void dnodeInitPlugin() { - dnodeInitMgmtConn = dnodeInitMgmtConnEdgeImp; - dnodeInitMgmtIp = dnodeInitMgmtIpEdgeImp; - - taosBuildRspMsgToMnodeWithSize = taosBuildRspMsgToMnodeWithSizeEdgeImp; - taosBuildReqMsgToMnodeWithSize = taosBuildReqMsgToMnodeWithSizeEdgeImp; - taosBuildRspMsgToMnode = taosBuildRspMsgToMnodeEdgeImp; - taosBuildReqMsgToMnode = taosBuildReqMsgToMnodeEdgeImp; - taosSendMsgToMnode = taosSendMsgToMnodeEdgeImp; - taosSendSimpleRspToMnode = taosSendSimpleRspToMnodeEdgeImp; - - dnodeParseParameterK = dnodeParseParameterKComImp; - dnodeCheckSystem = dnodeCheckSystemComImp; - dnodeInitStorage = dnodeInitStorageComImp; - dnodeCleanupStorage = dnodeCleanupStorageComImp; - dnodeStartModules = dnodeStartModulesEdgeImp; -} +int dnodeCheckSystemImp() { return 0; } +int (*dnodeCheckSystem)() = dnodeCheckSystemImp; diff --git a/src/inc/dnode.h b/src/inc/dnode.h new file mode 100644 index 0000000000000000000000000000000000000000..8da538d6e71e09b770282b192f03d7f40a810400 --- /dev/null +++ b/src/inc/dnode.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_DNODE_H +#define TDENGINE_DNODE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef struct { + char id[20]; + char sid; + void *thandle; + int mgmtIndex; + char status; // 0:offline, 1:online +} SMgmtObj; + +// global variables +extern pthread_mutex_t dmutex; + +// dnodeCluster +extern void (*dnodeStartModules)(); +extern void (*dnodeParseParameterK)(); +extern int32_t (*dnodeCheckSystem)(); +extern char *(*taosBuildRspMsgToMnodeWithSize)(SMgmtObj *pObj, char type, int size); +extern char *(*taosBuildReqMsgToMnodeWithSize)(SMgmtObj *pObj, char type, int size); +extern char *(*taosBuildRspMsgToMnode)(SMgmtObj *pObj, char type); +extern char *(*taosBuildReqMsgToMnode)(SMgmtObj *pObj, char type); +extern int (*taosSendMsgToMnode)(SMgmtObj *pObj, char *msg, int msgLen); +extern int (*taosSendSimpleRspToMnode)(SMgmtObj *pObj, char rsptype, char code); +extern void (*dnodeInitMgmtIp)(); +extern int (*dnodeInitMgmt)(); + + +// multilevelStorage +extern int32_t (*dnodeInitStorage)(); +extern void (*dnodeCleanupStorage)(); + +void dnodeCheckDbRunning(const char* dir); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h index 35cf6a42443ef40135c3937867339c6634c32140..243835bacd22c74ebffa88e49bfe0184806de8c1 100644 --- a/src/inc/tglobalcfg.h +++ b/src/inc/tglobalcfg.h @@ -262,6 +262,9 @@ SGlobalConfig *tsGetConfigOption(const char *option); #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) +extern char mgmtDirectory[]; + + #ifdef __cplusplus } #endif diff --git a/src/mnode/CMakeLists.txt b/src/mnode/CMakeLists.txt index df4123d3c70a76e4d9dc318bfd17ed8790b5121d..f94d1e8d1c67578a4d701eee017a4db87365446d 100644 --- a/src/mnode/CMakeLists.txt +++ b/src/mnode/CMakeLists.txt @@ -1,6 +1,23 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT(TDengine) -ADD_SUBDIRECTORY(sdb) -ADD_SUBDIRECTORY(detail) -ADD_SUBDIRECTORY(lite) \ No newline at end of file +IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/dnode/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/detail/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/vnode/detail/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) + INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) + INCLUDE_DIRECTORIES(inc) + AUX_SOURCE_DIRECTORY(src SRC) + ADD_LIBRARY(mnode ${SRC}) + TARGET_LINK_LIBRARIES(mnode trpc tutil sdb pthread) + + IF (TD_CLUSTER) + TARGET_LINK_LIBRARIES(mnode mcluster) + ELSEIF (TD_LITE) + TARGET_LINK_LIBRARIES(mnode mlite) + ENDIF () +ENDIF () + + diff --git a/src/mnode/detail/CMakeLists.txt b/src/mnode/detail/CMakeLists.txt deleted file mode 100644 index f94d1e8d1c67578a4d701eee017a4db87365446d..0000000000000000000000000000000000000000 --- a/src/mnode/detail/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) -PROJECT(TDengine) - -IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) - INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/dnode/inc) - INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/detail/inc) - INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/vnode/detail/inc) - INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) - INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) - INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) - INCLUDE_DIRECTORIES(inc) - AUX_SOURCE_DIRECTORY(src SRC) - ADD_LIBRARY(mnode ${SRC}) - TARGET_LINK_LIBRARIES(mnode trpc tutil sdb pthread) - - IF (TD_CLUSTER) - TARGET_LINK_LIBRARIES(mnode mcluster) - ELSEIF (TD_LITE) - TARGET_LINK_LIBRARIES(mnode mlite) - ENDIF () -ENDIF () - - diff --git a/src/mnode/detail/inc/mgmt.h b/src/mnode/inc/mgmt.h similarity index 100% rename from src/mnode/detail/inc/mgmt.h rename to src/mnode/inc/mgmt.h diff --git a/src/mnode/detail/inc/mgmtBalance.h b/src/mnode/inc/mgmtBalance.h similarity index 100% rename from src/mnode/detail/inc/mgmtBalance.h rename to src/mnode/inc/mgmtBalance.h diff --git a/src/mnode/detail/inc/mgmtProfile.h b/src/mnode/inc/mgmtProfile.h similarity index 100% rename from src/mnode/detail/inc/mgmtProfile.h rename to src/mnode/inc/mgmtProfile.h diff --git a/src/mnode/detail/inc/mgmtSystem.h b/src/mnode/inc/mgmtSystem.h similarity index 100% rename from src/mnode/detail/inc/mgmtSystem.h rename to src/mnode/inc/mgmtSystem.h diff --git a/src/mnode/detail/inc/mgmtUtil.h b/src/mnode/inc/mgmtUtil.h similarity index 100% rename from src/mnode/detail/inc/mgmtUtil.h rename to src/mnode/inc/mgmtUtil.h diff --git a/src/mnode/lite/src/mgmtAcct.spec.c b/src/mnode/lite/src/mgmtAcct.spec.c index 81f83df98858055cde7da09e07edb077ab8f0014..a1b7438f3569d1a319a4b09a9d3f4606aaa9edeb 100644 --- a/src/mnode/lite/src/mgmtAcct.spec.c +++ b/src/mnode/lite/src/mgmtAcct.spec.c @@ -16,56 +16,4 @@ #define _DEFAULT_SOURCE #include "mgmt.h" -extern void *userSdb; -extern void *dbSdb; -SAcctObj acctObj; -int mgmtInitAccts() { return 0; } - -void mgmtCreateRootAcct() {} - -SAcctObj *mgmtGetAcct(char *name) { return &acctObj; } - -int mgmtCheckUserLimit(SAcctObj *pAcct) { - int numOfUsers = sdbGetNumOfRows(userSdb); - if (numOfUsers >= tsMaxUsers) { - mWarn("numOfUsers:%d, exceed tsMaxUsers:%d", numOfUsers, tsMaxUsers); - return TSDB_CODE_TOO_MANY_USERS; - } - return 0; -} - -int mgmtCheckDbLimit(SAcctObj *pAcct) { - int numOfDbs = sdbGetNumOfRows(dbSdb); - if (numOfDbs >= tsMaxDbs) { - mWarn("numOfDbs:%d, exceed tsMaxDbs:%d", numOfDbs, tsMaxDbs); - return TSDB_CODE_TOO_MANY_DATABSES; - } - return 0; -} - -int mgmtCheckMeterLimit(SAcctObj *pAcct) { return 0; } - -int mgmtCheckUserGrant() { return 0; } - -int mgmtCheckDbGrant() { return 0; } - -int mgmtCheckMeterGrant() { return 0; } - -void grantAddTimeSeries(uint32_t timeSeriesNum) {} - -void mgmtCheckAcct() { - SAcctObj *pAcct = &acctObj; - pAcct->acctId = 0; - strcpy(pAcct->user, "root"); - - mgmtCreateUser(pAcct, "root", "taosdata"); - mgmtCreateUser(pAcct, "monitor", tsInternalPass); - mgmtCreateUser(pAcct, "_root", tsInternalPass); -} - -void mgmtCleanUpAccts() {} - -int mgmtGetAcctMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { return TSDB_CODE_OPS_NOT_SUPPORT; } - -int mgmtRetrieveAccts(SShowObj *pShow, char *data, int rows, SConnObj *pConn) { return 0; } diff --git a/src/mnode/lite/src/mgmtDnodeInt.spec.c b/src/mnode/lite/src/mgmtDnodeInt.spec.c index ab6b7fff3b6c690995b254b8373a79f46005e135..2de08c795a5e7471531b5740c0d80d5bcc42191e 100644 --- a/src/mnode/lite/src/mgmtDnodeInt.spec.c +++ b/src/mnode/lite/src/mgmtDnodeInt.spec.c @@ -28,7 +28,7 @@ extern void *dmQhandle; void * mgmtStatusTimer = NULL; void mgmtProcessMsgFromDnode(char *content, int msgLen, int msgType, SDnodeObj *pObj); -void* dnodeProcessMsgFromMgmtEdgeImp(SSchedMsg *sched); +void* dnodeProcessMsgFromMgmtImp(SSchedMsg *sched); char *taosBuildRspMsgToDnodeWithSize(SDnodeObj *pObj, char type, int size) { char *pStart = (char *)malloc(size); @@ -67,7 +67,7 @@ int taosSendMsgToDnode(SDnodeObj *pObj, char *msg, int msgLen) { * Lite version has no message header, so minus one */ SSchedMsg schedMsg; - schedMsg.fp = dnodeProcessMsgFromMgmtEdgeImp; + schedMsg.fp = dnodeProcessMsgFromMgmtImp; schedMsg.msg = msg - 1; schedMsg.ahandle = NULL; schedMsg.thandle = NULL; diff --git a/src/mnode/detail/src/mgmtAcct.c b/src/mnode/src/mgmtAcct.c similarity index 67% rename from src/mnode/detail/src/mgmtAcct.c rename to src/mnode/src/mgmtAcct.c index e5f52b17f963dfeaf915c21aeedf61e9655d8cd1..1605db3c2ad4abf2a7a290d2f0297eabc3e388c3 100644 --- a/src/mnode/detail/src/mgmtAcct.c +++ b/src/mnode/src/mgmtAcct.c @@ -19,6 +19,11 @@ #include "mgmt.h" #include "tschemautil.h" +extern void *userSdb; +extern void *dbSdb; +SAcctObj acctObj; + + int mgmtGetAcctsNum(); SShowObj *mgmtGetNextAcct(SShowObj *pShow, SAcctObj **pAcct); @@ -126,3 +131,58 @@ int mgmtRemoveConnFromAcct(SConnObj *pConn) { return 0; } + +/* + * Edge Version Implementation + */ + +int mgmtInitAcctsImp() { return 0; } +int (*mgmtInitAccts)() = mgmtInitAcctsImp; + +void mgmtCreateRootAcct() {} + +SAcctObj *mgmtGetAcct(char *name) { return &acctObj; } + +int mgmtCheckUserLimit(SAcctObj *pAcct) { + int numOfUsers = sdbGetNumOfRows(userSdb); + if (numOfUsers >= tsMaxUsers) { + mWarn("numOfUsers:%d, exceed tsMaxUsers:%d", numOfUsers, tsMaxUsers); + return TSDB_CODE_TOO_MANY_USERS; + } + return 0; +} + +int mgmtCheckDbLimit(SAcctObj *pAcct) { + int numOfDbs = sdbGetNumOfRows(dbSdb); + if (numOfDbs >= tsMaxDbs) { + mWarn("numOfDbs:%d, exceed tsMaxDbs:%d", numOfDbs, tsMaxDbs); + return TSDB_CODE_TOO_MANY_DATABSES; + } + return 0; +} + +int mgmtCheckMeterLimit(SAcctObj *pAcct) { return 0; } + +int mgmtCheckUserGrant() { return 0; } + +int mgmtCheckDbGrant() { return 0; } + +int mgmtCheckMeterGrant() { return 0; } + +void grantAddTimeSeries(uint32_t timeSeriesNum) {} + +void mgmtCheckAcct() { + SAcctObj *pAcct = &acctObj; + pAcct->acctId = 0; + strcpy(pAcct->user, "root"); + + mgmtCreateUser(pAcct, "root", "taosdata"); + mgmtCreateUser(pAcct, "monitor", tsInternalPass); + mgmtCreateUser(pAcct, "_root", tsInternalPass); +} + +void mgmtCleanUpAccts() {} + +int mgmtGetAcctMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { return TSDB_CODE_OPS_NOT_SUPPORT; } + +int mgmtRetrieveAccts(SShowObj *pShow, char *data, int rows, SConnObj *pConn) { return 0; } diff --git a/src/mnode/detail/src/mgmtConn.c b/src/mnode/src/mgmtConn.c similarity index 100% rename from src/mnode/detail/src/mgmtConn.c rename to src/mnode/src/mgmtConn.c diff --git a/src/mnode/detail/src/mgmtDb.c b/src/mnode/src/mgmtDb.c similarity index 100% rename from src/mnode/detail/src/mgmtDb.c rename to src/mnode/src/mgmtDb.c diff --git a/src/mnode/detail/src/mgmtDnode.c b/src/mnode/src/mgmtDnode.c similarity index 100% rename from src/mnode/detail/src/mgmtDnode.c rename to src/mnode/src/mgmtDnode.c diff --git a/src/mnode/detail/src/mgmtDnodeInt.c b/src/mnode/src/mgmtDnodeInt.c similarity index 100% rename from src/mnode/detail/src/mgmtDnodeInt.c rename to src/mnode/src/mgmtDnodeInt.c diff --git a/src/mnode/detail/src/mgmtMeter.c b/src/mnode/src/mgmtMeter.c similarity index 100% rename from src/mnode/detail/src/mgmtMeter.c rename to src/mnode/src/mgmtMeter.c diff --git a/src/mnode/detail/src/mgmtProfile.c b/src/mnode/src/mgmtProfile.c similarity index 100% rename from src/mnode/detail/src/mgmtProfile.c rename to src/mnode/src/mgmtProfile.c diff --git a/src/mnode/detail/src/mgmtShell.c b/src/mnode/src/mgmtShell.c similarity index 100% rename from src/mnode/detail/src/mgmtShell.c rename to src/mnode/src/mgmtShell.c diff --git a/src/mnode/detail/src/mgmtSupertableQuery.c b/src/mnode/src/mgmtSupertableQuery.c similarity index 100% rename from src/mnode/detail/src/mgmtSupertableQuery.c rename to src/mnode/src/mgmtSupertableQuery.c diff --git a/src/mnode/detail/src/mgmtSystem.c b/src/mnode/src/mgmtSystem.c similarity index 100% rename from src/mnode/detail/src/mgmtSystem.c rename to src/mnode/src/mgmtSystem.c diff --git a/src/mnode/detail/src/mgmtUser.c b/src/mnode/src/mgmtUser.c similarity index 100% rename from src/mnode/detail/src/mgmtUser.c rename to src/mnode/src/mgmtUser.c diff --git a/src/mnode/detail/src/mgmtUtil.c b/src/mnode/src/mgmtUtil.c similarity index 100% rename from src/mnode/detail/src/mgmtUtil.c rename to src/mnode/src/mgmtUtil.c diff --git a/src/mnode/detail/src/mgmtVgroup.c b/src/mnode/src/mgmtVgroup.c similarity index 100% rename from src/mnode/detail/src/mgmtVgroup.c rename to src/mnode/src/mgmtVgroup.c diff --git a/src/mnode/sdb/CMakeLists.txt b/src/sdb/CMakeLists.txt similarity index 100% rename from src/mnode/sdb/CMakeLists.txt rename to src/sdb/CMakeLists.txt diff --git a/src/mnode/sdb/inc/hashint.h b/src/sdb/inc/hashint.h similarity index 100% rename from src/mnode/sdb/inc/hashint.h rename to src/sdb/inc/hashint.h diff --git a/src/mnode/sdb/inc/hashstr.h b/src/sdb/inc/hashstr.h similarity index 100% rename from src/mnode/sdb/inc/hashstr.h rename to src/sdb/inc/hashstr.h diff --git a/src/mnode/sdb/inc/sdbint.h b/src/sdb/inc/sdbint.h similarity index 100% rename from src/mnode/sdb/inc/sdbint.h rename to src/sdb/inc/sdbint.h diff --git a/src/mnode/sdb/src/hashint.c b/src/sdb/src/hashint.c similarity index 100% rename from src/mnode/sdb/src/hashint.c rename to src/sdb/src/hashint.c diff --git a/src/mnode/sdb/src/hashstr.c b/src/sdb/src/hashstr.c similarity index 100% rename from src/mnode/sdb/src/hashstr.c rename to src/sdb/src/hashstr.c diff --git a/src/mnode/sdb/src/sdbEngine.c b/src/sdb/src/sdbEngine.c similarity index 100% rename from src/mnode/sdb/src/sdbEngine.c rename to src/sdb/src/sdbEngine.c diff --git a/src/mnode/sdb/src/sdbstr.c b/src/sdb/src/sdbstr.c similarity index 100% rename from src/mnode/sdb/src/sdbstr.c rename to src/sdb/src/sdbstr.c diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 3718d57cbad70fb9ac368194f4f69e6c57c5bf7b..89a8691c1f91441bacd99f0a051857c6e72bbf16 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -98,6 +98,7 @@ ELSEIF(TD_DARWIN_64) LIST(APPEND SRC ./src/ttypes.c) LIST(APPEND SRC ./src/tutil.c) LIST(APPEND SRC ./src/version.c) + LIST(APPEND SRC ./src/hash.c) ADD_LIBRARY(tutil ${SRC}) TARGET_LINK_LIBRARIES(tutil iconv pthread os) ENDIF()