Merge from origin/develop
This commit is contained in:
commit
00813785ab
|
@ -87,6 +87,7 @@ TDengine系统后台服务由taosd提供,可以在配置文件taos.cfg里修
|
||||||
- httpPort: RESTful服务使用的端口号,所有的HTTP请求(TCP)都需要向该接口发起查询/写入请求。
|
- httpPort: RESTful服务使用的端口号,所有的HTTP请求(TCP)都需要向该接口发起查询/写入请求。
|
||||||
- dataDir: 数据文件目录,所有的数据文件都将写入该目录。默认值:/var/lib/taos。
|
- dataDir: 数据文件目录,所有的数据文件都将写入该目录。默认值:/var/lib/taos。
|
||||||
- logDir:日志文件目录,客户端和服务器的运行日志文件将写入该目录。默认值:/var/log/taos。
|
- logDir:日志文件目录,客户端和服务器的运行日志文件将写入该目录。默认值:/var/log/taos。
|
||||||
|
- tempDir:临时文件目录,客户端和服务器的临时文件(主要是查询时用于保存中间结果的问题)将写入该目录。 默认值:Linux下为 /tmp/,Windows下为环境变量 tmp 或 temp 指向的目录。
|
||||||
- arbitrator:系统中裁决器的end point, 缺省值为空。
|
- arbitrator:系统中裁决器的end point, 缺省值为空。
|
||||||
- role:dnode的可选角色。0-any; 既可作为mnode,也可分配vnode;1-mgmt;只能作为mnode,不能分配vnode;2-dnode;不能作为mnode,只能分配vnode
|
- role:dnode的可选角色。0-any; 既可作为mnode,也可分配vnode;1-mgmt;只能作为mnode,不能分配vnode;2-dnode;不能作为mnode,只能分配vnode
|
||||||
- debugFlag:运行日志开关。131(输出错误和警告日志),135( 输出错误、警告和调试日志),143( 输出错误、警告、调试和跟踪日志)。默认值:131或135(不同模块有不同的默认值)。
|
- debugFlag:运行日志开关。131(输出错误和警告日志),135( 输出错误、警告和调试日志),143( 输出错误、警告、调试和跟踪日志)。默认值:131或135(不同模块有不同的默认值)。
|
||||||
|
|
|
@ -616,6 +616,43 @@ HTTP请求URL采用`sqlutc`时,返回结果集的时间戳将采用UTC时间
|
||||||
- httpEnableCompress: 是否支持压缩,默认不支持,目前TDengine仅支持gzip压缩格式
|
- httpEnableCompress: 是否支持压缩,默认不支持,目前TDengine仅支持gzip压缩格式
|
||||||
- httpDebugFlag: 日志开关,131:仅错误和报警信息,135:调试信息,143:非常详细的调试信息,默认131
|
- httpDebugFlag: 日志开关,131:仅错误和报警信息,135:调试信息,143:非常详细的调试信息,默认131
|
||||||
|
|
||||||
|
## CSharp Connector
|
||||||
|
|
||||||
|
在Windows系统上,C#应用程序可以使用TDengine的原生C接口来执行所有数据库操作,后续版本将提供ORM(dapper)框架驱动。
|
||||||
|
|
||||||
|
#### 安装TDengine客户端
|
||||||
|
|
||||||
|
C#连接器需要使用`libtaos.so`和`taos.h`。因此,在使用C#连接器之前,需在程序运行的Windows环境安装TDengine的Windows客户端,以便获得相关驱动文件。
|
||||||
|
|
||||||
|
安装完成后,在文件夹`C:/TDengine/examples/C#`中,将会看到两个文件
|
||||||
|
|
||||||
|
- TDengineDriver.cs 调用taos.dll文件的Native C方法
|
||||||
|
- TDengineTest.cs 参考程序示例
|
||||||
|
|
||||||
|
在文件夹`C:\Windows\System32`,将会看到`taos.dll`文件
|
||||||
|
|
||||||
|
#### 使用方法
|
||||||
|
|
||||||
|
- 将C#接口文件TDengineDriver.cs加入到应用程序所在.NET项目中
|
||||||
|
- 参考TDengineTest.cs来定义数据库连接参数,及执行数据插入、查询等操作的方法
|
||||||
|
- 因为C#接口需要用到`taos.dll`文件,用户可以将`taos.dll`文件加入.NET解决方案中
|
||||||
|
|
||||||
|
#### 注意事项
|
||||||
|
|
||||||
|
- `taos.dll`文件使用x64平台编译,所以.NET项目在生成.exe文件时,“解决方案”/“项目”的“平台”请均选择“x64”。
|
||||||
|
- 此.NET接口目前已经在Visual Studio 2013/2015/2017中验证过,其它VS版本尚待验证。
|
||||||
|
|
||||||
|
#### 第三方驱动
|
||||||
|
|
||||||
|
Maikebing.Data.Taos是一个TDengine的ADO.Net提供器,支持linux,windows。该开发包由热心贡献者`麦壳饼@@maikebing`提供,具体请参考
|
||||||
|
|
||||||
|
```
|
||||||
|
//接口下载
|
||||||
|
https://github.com/maikebing/Maikebing.EntityFrameworkCore.Taos
|
||||||
|
//用法说明
|
||||||
|
https://www.taosdata.com/blog/2020/11/02/1901.html
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Go Connector
|
## Go Connector
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
# data file's directory
|
# data file's directory
|
||||||
# dataDir /var/lib/taos
|
# dataDir /var/lib/taos
|
||||||
|
|
||||||
|
# temporary file's directory
|
||||||
|
# tempDir /tmp/
|
||||||
|
|
||||||
# the arbitrator's fully qualified domain name (FQDN) for TDengine system, for cluster only
|
# the arbitrator's fully qualified domain name (FQDN) for TDengine system, for cluster only
|
||||||
# arbitrator arbitrator_hostname:6042
|
# arbitrator arbitrator_hostname:6042
|
||||||
|
|
||||||
|
@ -256,3 +259,5 @@
|
||||||
# maximum display width of binary and nchar fields in the shell. The parts exceeding this limit will be hidden
|
# maximum display width of binary and nchar fields in the shell. The parts exceeding this limit will be hidden
|
||||||
# maxBinaryDisplayWidth 30
|
# maxBinaryDisplayWidth 30
|
||||||
|
|
||||||
|
# enable/disable telemetry reporting
|
||||||
|
# telemetryReporting 1
|
|
@ -2,7 +2,7 @@
|
||||||
%define cfg_install_dir /etc/taos
|
%define cfg_install_dir /etc/taos
|
||||||
%define __strip /bin/true
|
%define __strip /bin/true
|
||||||
|
|
||||||
Name: TDengine
|
Name: tdengine
|
||||||
Version: %{_version}
|
Version: %{_version}
|
||||||
Release: 3%{?dist}
|
Release: 3%{?dist}
|
||||||
Summary: tdengine from taosdata
|
Summary: tdengine from taosdata
|
||||||
|
|
|
@ -490,7 +490,7 @@ static bool balanceMontiorDropping() {
|
||||||
|
|
||||||
if (pDnode->status == TAOS_DN_STATUS_OFFLINE) {
|
if (pDnode->status == TAOS_DN_STATUS_OFFLINE) {
|
||||||
if (pDnode->lastAccess + tsOfflineThreshold > tsAccessSquence) continue;
|
if (pDnode->lastAccess + tsOfflineThreshold > tsAccessSquence) continue;
|
||||||
if (strcmp(pDnode->dnodeEp, dnodeGetMnodeMasterEp()) == 0) continue;
|
if (dnodeIsMasterEp(pDnode->dnodeEp)) continue;
|
||||||
if (mnodeGetDnodesNum() <= 1) continue;
|
if (mnodeGetDnodesNum() <= 1) continue;
|
||||||
|
|
||||||
mLInfo("dnode:%d, set to removing state for it offline:%d seconds", pDnode->dnodeId,
|
mLInfo("dnode:%d, set to removing state for it offline:%d seconds", pDnode->dnodeId,
|
||||||
|
|
|
@ -87,8 +87,8 @@ typedef struct SJoinSupporter {
|
||||||
} SJoinSupporter;
|
} SJoinSupporter;
|
||||||
|
|
||||||
typedef struct SVgroupTableInfo {
|
typedef struct SVgroupTableInfo {
|
||||||
SCMVgroupInfo vgInfo;
|
SVgroupInfo vgInfo;
|
||||||
SArray* itemList; //SArray<STableIdInfo>
|
SArray* itemList; //SArray<STableIdInfo>
|
||||||
} SVgroupTableInfo;
|
} SVgroupTableInfo;
|
||||||
|
|
||||||
static FORCE_INLINE SQueryInfo* tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex) {
|
static FORCE_INLINE SQueryInfo* tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex) {
|
||||||
|
@ -238,7 +238,7 @@ void tscDoQuery(SSqlObj* pSql);
|
||||||
|
|
||||||
SVgroupsInfo* tscVgroupInfoClone(SVgroupsInfo *pInfo);
|
SVgroupsInfo* tscVgroupInfoClone(SVgroupsInfo *pInfo);
|
||||||
void* tscVgroupInfoClear(SVgroupsInfo *pInfo);
|
void* tscVgroupInfoClear(SVgroupsInfo *pInfo);
|
||||||
void tscSCMVgroupInfoCopy(SCMVgroupInfo* dst, const SCMVgroupInfo* src);
|
void tscSVgroupInfoCopy(SVgroupInfo* dst, const SVgroupInfo* src);
|
||||||
/**
|
/**
|
||||||
* The create object function must be successful expect for the out of memory issue.
|
* The create object function must be successful expect for the out of memory issue.
|
||||||
*
|
*
|
||||||
|
|
|
@ -90,12 +90,12 @@ typedef struct STableComInfo {
|
||||||
int32_t rowSize;
|
int32_t rowSize;
|
||||||
} STableComInfo;
|
} STableComInfo;
|
||||||
|
|
||||||
typedef struct SCMCorVgroupInfo {
|
typedef struct SCorVgroupInfo {
|
||||||
int32_t version;
|
int32_t version;
|
||||||
int8_t inUse;
|
int8_t inUse;
|
||||||
int8_t numOfEps;
|
int8_t numOfEps;
|
||||||
SEpAddr1 epAddr[TSDB_MAX_REPLICA];
|
SEpAddr1 epAddr[TSDB_MAX_REPLICA];
|
||||||
} SCMCorVgroupInfo;
|
} SCorVgroupInfo;
|
||||||
|
|
||||||
typedef struct STableMeta {
|
typedef struct STableMeta {
|
||||||
STableComInfo tableInfo;
|
STableComInfo tableInfo;
|
||||||
|
@ -103,8 +103,8 @@ typedef struct STableMeta {
|
||||||
int16_t sversion;
|
int16_t sversion;
|
||||||
int16_t tversion;
|
int16_t tversion;
|
||||||
char sTableId[TSDB_TABLE_FNAME_LEN];
|
char sTableId[TSDB_TABLE_FNAME_LEN];
|
||||||
SCMVgroupInfo vgroupInfo;
|
SVgroupInfo vgroupInfo;
|
||||||
SCMCorVgroupInfo corVgroupInfo;
|
SCorVgroupInfo corVgroupInfo;
|
||||||
STableId id;
|
STableId id;
|
||||||
SSchema schema[]; // if the table is TSDB_CHILD_TABLE, schema is acquired by super table meta info
|
SSchema schema[]; // if the table is TSDB_CHILD_TABLE, schema is acquired by super table meta info
|
||||||
} STableMeta;
|
} STableMeta;
|
||||||
|
|
|
@ -702,7 +702,7 @@ static int32_t doParseInsertStatement(SSqlObj *pSql, void *pTableList, char **st
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_TSC_INVALID_SQL;
|
int32_t code = TSDB_CODE_TSC_INVALID_SQL;
|
||||||
char * tmpTokenBuf = calloc(1, 4096); // used for deleting Escape character: \\, \', \"
|
char * tmpTokenBuf = calloc(1, 16*1024); // used for deleting Escape character: \\, \', \"
|
||||||
if (NULL == tmpTokenBuf) {
|
if (NULL == tmpTokenBuf) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ void tscKillStream(STscObj *pObj, uint32_t killId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
|
int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
|
||||||
SCMHeartBeatMsg *pHeartbeat = pMsg;
|
SHeartBeatMsg *pHeartbeat = pMsg;
|
||||||
int allocedQueriesNum = pHeartbeat->numOfQueries;
|
int allocedQueriesNum = pHeartbeat->numOfQueries;
|
||||||
int allocedStreamsNum = pHeartbeat->numOfStreams;
|
int allocedStreamsNum = pHeartbeat->numOfStreams;
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t msgLen = pHeartbeat->numOfQueries * sizeof(SQueryDesc) + pHeartbeat->numOfStreams * sizeof(SStreamDesc) +
|
int32_t msgLen = pHeartbeat->numOfQueries * sizeof(SQueryDesc) + pHeartbeat->numOfStreams * sizeof(SStreamDesc) +
|
||||||
sizeof(SCMHeartBeatMsg);
|
sizeof(SHeartBeatMsg);
|
||||||
pHeartbeat->connId = htonl(pObj->connId);
|
pHeartbeat->connId = htonl(pObj->connId);
|
||||||
pHeartbeat->numOfQueries = htonl(pHeartbeat->numOfQueries);
|
pHeartbeat->numOfQueries = htonl(pHeartbeat->numOfQueries);
|
||||||
pHeartbeat->numOfStreams = htonl(pHeartbeat->numOfStreams);
|
pHeartbeat->numOfStreams = htonl(pHeartbeat->numOfStreams);
|
||||||
|
|
|
@ -114,7 +114,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString);
|
||||||
static int32_t getTableIndexImpl(SStrToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex);
|
static int32_t getTableIndexImpl(SStrToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex);
|
||||||
static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
|
static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
|
||||||
static int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
|
static int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
|
||||||
static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate);
|
static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate);
|
||||||
|
|
||||||
static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex);
|
static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex);
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
|
|
||||||
char* pMsg = pCmd->payload;
|
char* pMsg = pCmd->payload;
|
||||||
|
|
||||||
SCMCfgDnodeMsg* pCfg = (SCMCfgDnodeMsg*)pMsg;
|
SCfgDnodeMsg* pCfg = (SCfgDnodeMsg*)pMsg;
|
||||||
pDCL->a[0].n = strdequote(pDCL->a[0].z);
|
pDCL->a[0].n = strdequote(pDCL->a[0].z);
|
||||||
|
|
||||||
strncpy(pCfg->ep, pDCL->a[0].z, pDCL->a[0].n);
|
strncpy(pCfg->ep, pDCL->a[0].z, pDCL->a[0].n);
|
||||||
|
@ -619,11 +619,15 @@ static bool isTopBottomQuery(SQueryInfo* pQueryInfo) {
|
||||||
int32_t parseIntervalClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
|
int32_t parseIntervalClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
|
||||||
const char* msg1 = "invalid query expression";
|
const char* msg1 = "invalid query expression";
|
||||||
const char* msg2 = "interval cannot be less than 10 ms";
|
const char* msg2 = "interval cannot be less than 10 ms";
|
||||||
|
const char* msg3 = "sliding cannot be used without interval";
|
||||||
|
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
if (pQuerySql->interval.type == 0 || pQuerySql->interval.n == 0) {
|
if (pQuerySql->interval.type == 0 || pQuerySql->interval.n == 0) {
|
||||||
|
if (pQuerySql->sliding.n > 0) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5185,7 +5189,7 @@ int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIn
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setKeepOption(SSqlCmd* pCmd, SCMCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
|
static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
|
||||||
const char* msg = "invalid number of options";
|
const char* msg = "invalid number of options";
|
||||||
|
|
||||||
pMsg->daysToKeep = htonl(-1);
|
pMsg->daysToKeep = htonl(-1);
|
||||||
|
@ -5216,7 +5220,7 @@ static int32_t setKeepOption(SSqlCmd* pCmd, SCMCreateDbMsg* pMsg, SCreateDBInfo*
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setTimePrecision(SSqlCmd* pCmd, SCMCreateDbMsg* pMsg, SCreateDBInfo* pCreateDbInfo) {
|
static int32_t setTimePrecision(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDbInfo) {
|
||||||
const char* msg = "invalid time precision";
|
const char* msg = "invalid time precision";
|
||||||
|
|
||||||
pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default
|
pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default
|
||||||
|
@ -5240,7 +5244,7 @@ static int32_t setTimePrecision(SSqlCmd* pCmd, SCMCreateDbMsg* pMsg, SCreateDBIn
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setCreateDBOption(SCMCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
|
static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
|
||||||
pMsg->maxTables = htonl(-1); // max tables can not be set anymore
|
pMsg->maxTables = htonl(-1); // max tables can not be set anymore
|
||||||
pMsg->cacheBlockSize = htonl(pCreateDb->cacheBlockSize);
|
pMsg->cacheBlockSize = htonl(pCreateDb->cacheBlockSize);
|
||||||
pMsg->totalBlocks = htonl(pCreateDb->numOfBlocks);
|
pMsg->totalBlocks = htonl(pCreateDb->numOfBlocks);
|
||||||
|
@ -5258,7 +5262,7 @@ static void setCreateDBOption(SCMCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) {
|
int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) {
|
||||||
SCMCreateDbMsg* pMsg = (SCMCreateDbMsg*)(pCmd->payload);
|
SCreateDbMsg* pMsg = (SCreateDbMsg *)(pCmd->payload);
|
||||||
setCreateDBOption(pMsg, pCreateDbSql);
|
setCreateDBOption(pMsg, pCreateDbSql);
|
||||||
|
|
||||||
if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) {
|
if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -5776,7 +5780,7 @@ int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
|
||||||
}
|
}
|
||||||
|
|
||||||
// can only perform the parameters based on the macro definitation
|
// can only perform the parameters based on the macro definitation
|
||||||
int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate) {
|
int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate) {
|
||||||
char msg[512] = {0};
|
char msg[512] = {0};
|
||||||
|
|
||||||
if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) {
|
if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) {
|
||||||
|
|
|
@ -140,7 +140,7 @@ struct SSchema tscGetTbnameColumnSchema() {
|
||||||
strcpy(s.name, TSQL_TBNAME_L);
|
strcpy(s.name, TSQL_TBNAME_L);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
static void tscInitCorVgroupInfo(SCMCorVgroupInfo *corVgroupInfo, SCMVgroupInfo *vgroupInfo) {
|
static void tscInitCorVgroupInfo(SCorVgroupInfo *corVgroupInfo, SVgroupInfo *vgroupInfo) {
|
||||||
corVgroupInfo->version = 0;
|
corVgroupInfo->version = 0;
|
||||||
corVgroupInfo->inUse = 0;
|
corVgroupInfo->inUse = 0;
|
||||||
corVgroupInfo->numOfEps = vgroupInfo->numOfEps;
|
corVgroupInfo->numOfEps = vgroupInfo->numOfEps;
|
||||||
|
@ -166,7 +166,7 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size
|
||||||
pTableMeta->id.tid = pTableMetaMsg->tid;
|
pTableMeta->id.tid = pTableMetaMsg->tid;
|
||||||
pTableMeta->id.uid = pTableMetaMsg->uid;
|
pTableMeta->id.uid = pTableMetaMsg->uid;
|
||||||
|
|
||||||
SCMVgroupInfo* pVgroupInfo = &pTableMeta->vgroupInfo;
|
SVgroupInfo* pVgroupInfo = &pTableMeta->vgroupInfo;
|
||||||
pVgroupInfo->numOfEps = pTableMetaMsg->vgroup.numOfEps;
|
pVgroupInfo->numOfEps = pTableMetaMsg->vgroup.numOfEps;
|
||||||
pVgroupInfo->vgId = pTableMetaMsg->vgroup.vgId;
|
pVgroupInfo->vgId = pTableMetaMsg->vgroup.vgId;
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ static int32_t getWaitingTimeInterval(int32_t count) {
|
||||||
return initial * (2<<(count - 2));
|
return initial * (2<<(count - 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tscSetDnodeEpSet(SSqlObj* pSql, SCMVgroupInfo* pVgroupInfo) {
|
static void tscSetDnodeEpSet(SSqlObj* pSql, SVgroupInfo* pVgroupInfo) {
|
||||||
assert(pSql != NULL && pVgroupInfo != NULL && pVgroupInfo->numOfEps > 0);
|
assert(pSql != NULL && pVgroupInfo != NULL && pVgroupInfo->numOfEps > 0);
|
||||||
|
|
||||||
SRpcEpSet* pEpSet = &pSql->epSet;
|
SRpcEpSet* pEpSet = &pSql->epSet;
|
||||||
|
@ -100,7 +100,7 @@ void tscUpdateMgmtEpSet(SRpcEpSet *pEpSet) {
|
||||||
tscMgmtEpSet.epSet = *pEpSet;
|
tscMgmtEpSet.epSet = *pEpSet;
|
||||||
taosCorEndWrite(&tscMgmtEpSet.version);
|
taosCorEndWrite(&tscMgmtEpSet.version);
|
||||||
}
|
}
|
||||||
static void tscDumpEpSetFromVgroupInfo(SCMCorVgroupInfo *pVgroupInfo, SRpcEpSet *pEpSet) {
|
static void tscDumpEpSetFromVgroupInfo(SCorVgroupInfo *pVgroupInfo, SRpcEpSet *pEpSet) {
|
||||||
if (pVgroupInfo == NULL) { return;}
|
if (pVgroupInfo == NULL) { return;}
|
||||||
taosCorBeginRead(&pVgroupInfo->version);
|
taosCorBeginRead(&pVgroupInfo->version);
|
||||||
int8_t inUse = pVgroupInfo->inUse;
|
int8_t inUse = pVgroupInfo->inUse;
|
||||||
|
@ -117,7 +117,7 @@ static void tscUpdateVgroupInfo(SSqlObj *pObj, SRpcEpSet *pEpSet) {
|
||||||
SSqlCmd *pCmd = &pObj->cmd;
|
SSqlCmd *pCmd = &pObj->cmd;
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
if (pTableMetaInfo == NULL || pTableMetaInfo->pTableMeta == NULL) { return;}
|
if (pTableMetaInfo == NULL || pTableMetaInfo->pTableMeta == NULL) { return;}
|
||||||
SCMCorVgroupInfo *pVgroupInfo = &pTableMetaInfo->pTableMeta->corVgroupInfo;
|
SCorVgroupInfo *pVgroupInfo = &pTableMetaInfo->pTableMeta->corVgroupInfo;
|
||||||
|
|
||||||
taosCorBeginWrite(&pVgroupInfo->version);
|
taosCorBeginWrite(&pVgroupInfo->version);
|
||||||
tscDebug("before: Endpoint in use: %d", pVgroupInfo->inUse);
|
tscDebug("before: Endpoint in use: %d", pVgroupInfo->inUse);
|
||||||
|
@ -158,8 +158,8 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) {
|
||||||
SSqlRes *pRes = &pSql->res;
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
SCMHeartBeatRsp *pRsp = (SCMHeartBeatRsp *)pRes->pRsp;
|
SHeartBeatRsp *pRsp = (SHeartBeatRsp *)pRes->pRsp;
|
||||||
SRpcEpSet * epSet = &pRsp->epSet;
|
SRpcEpSet * epSet = &pRsp->epSet;
|
||||||
if (epSet->numOfEps > 0) {
|
if (epSet->numOfEps > 0) {
|
||||||
tscEpSetHtons(epSet);
|
tscEpSetHtons(epSet);
|
||||||
tscUpdateMgmtEpSet(epSet);
|
tscUpdateMgmtEpSet(epSet);
|
||||||
|
@ -584,7 +584,7 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char
|
||||||
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
|
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
|
||||||
if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo) || pTableMetaInfo->pVgroupTables == NULL) {
|
if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo) || pTableMetaInfo->pVgroupTables == NULL) {
|
||||||
|
|
||||||
SCMVgroupInfo* pVgroupInfo = NULL;
|
SVgroupInfo* pVgroupInfo = NULL;
|
||||||
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||||
int32_t index = pTableMetaInfo->vgroupIndex;
|
int32_t index = pTableMetaInfo->vgroupIndex;
|
||||||
assert(index >= 0);
|
assert(index >= 0);
|
||||||
|
@ -925,10 +925,10 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMCreateDbMsg);
|
pCmd->payloadLen = sizeof(SCreateDbMsg);
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_DB;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_DB;
|
||||||
|
|
||||||
SCMCreateDbMsg *pCreateDbMsg = (SCMCreateDbMsg*)pCmd->payload;
|
SCreateDbMsg *pCreateDbMsg = (SCreateDbMsg *)pCmd->payload;
|
||||||
|
|
||||||
assert(pCmd->numOfClause == 1);
|
assert(pCmd->numOfClause == 1);
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
|
@ -939,13 +939,13 @@ int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMCreateDnodeMsg);
|
pCmd->payloadLen = sizeof(SCreateDnodeMsg);
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||||
tscError("%p failed to malloc for query msg", pSql);
|
tscError("%p failed to malloc for query msg", pSql);
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMCreateDnodeMsg *pCreate = (SCMCreateDnodeMsg *)pCmd->payload;
|
SCreateDnodeMsg *pCreate = (SCreateDnodeMsg *)pCmd->payload;
|
||||||
strncpy(pCreate->ep, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n);
|
strncpy(pCreate->ep, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n);
|
||||||
|
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_DNODE;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_DNODE;
|
||||||
|
@ -955,13 +955,13 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMCreateAcctMsg);
|
pCmd->payloadLen = sizeof(SCreateAcctMsg);
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||||
tscError("%p failed to malloc for query msg", pSql);
|
tscError("%p failed to malloc for query msg", pSql);
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMCreateAcctMsg *pAlterMsg = (SCMCreateAcctMsg *)pCmd->payload;
|
SCreateAcctMsg *pAlterMsg = (SCreateAcctMsg *)pCmd->payload;
|
||||||
|
|
||||||
SStrToken *pName = &pInfo->pDCLInfo->user.user;
|
SStrToken *pName = &pInfo->pDCLInfo->user.user;
|
||||||
SStrToken *pPwd = &pInfo->pDCLInfo->user.passwd;
|
SStrToken *pPwd = &pInfo->pDCLInfo->user.passwd;
|
||||||
|
@ -1000,14 +1000,14 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMCreateUserMsg);
|
pCmd->payloadLen = sizeof(SCreateUserMsg);
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||||
tscError("%p failed to malloc for query msg", pSql);
|
tscError("%p failed to malloc for query msg", pSql);
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMCreateUserMsg *pAlterMsg = (SCMCreateUserMsg*)pCmd->payload;
|
SCreateUserMsg *pAlterMsg = (SCreateUserMsg *)pCmd->payload;
|
||||||
|
|
||||||
SUserInfo *pUser = &pInfo->pDCLInfo->user;
|
SUserInfo *pUser = &pInfo->pDCLInfo->user;
|
||||||
strncpy(pAlterMsg->user, pUser->user.z, pUser->user.n);
|
strncpy(pAlterMsg->user, pUser->user.z, pUser->user.n);
|
||||||
|
@ -1032,21 +1032,21 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int32_t tscBuildCfgDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildCfgDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMCfgDnodeMsg);
|
pCmd->payloadLen = sizeof(SCfgDnodeMsg);
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_CONFIG_DNODE;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_CONFIG_DNODE;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMDropDbMsg);
|
pCmd->payloadLen = sizeof(SDropDbMsg);
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||||
tscError("%p failed to malloc for query msg", pSql);
|
tscError("%p failed to malloc for query msg", pSql);
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMDropDbMsg *pDropDbMsg = (SCMDropDbMsg*)pCmd->payload;
|
SDropDbMsg *pDropDbMsg = (SDropDbMsg*)pCmd->payload;
|
||||||
|
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
tstrncpy(pDropDbMsg->db, pTableMetaInfo->name, sizeof(pDropDbMsg->db));
|
tstrncpy(pDropDbMsg->db, pTableMetaInfo->name, sizeof(pDropDbMsg->db));
|
||||||
|
@ -1076,13 +1076,13 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMDropDnodeMsg);
|
pCmd->payloadLen = sizeof(SDropDnodeMsg);
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||||
tscError("%p failed to malloc for query msg", pSql);
|
tscError("%p failed to malloc for query msg", pSql);
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMDropDnodeMsg *pDrop = (SCMDropDnodeMsg *)pCmd->payload;
|
SDropDnodeMsg * pDrop = (SDropDnodeMsg *)pCmd->payload;
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
tstrncpy(pDrop->ep, pTableMetaInfo->name, sizeof(pDrop->ep));
|
tstrncpy(pDrop->ep, pTableMetaInfo->name, sizeof(pDrop->ep));
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_DNODE;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_DNODE;
|
||||||
|
@ -1092,7 +1092,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int32_t tscBuildDropUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildDropUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMDropUserMsg);
|
pCmd->payloadLen = sizeof(SDropUserMsg);
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_USER;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_USER;
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||||
|
@ -1100,7 +1100,7 @@ int32_t tscBuildDropUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload;
|
SDropUserMsg * pDropMsg = (SDropUserMsg *)pCmd->payload;
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
tstrncpy(pDropMsg->user, pTableMetaInfo->name, sizeof(pDropMsg->user));
|
tstrncpy(pDropMsg->user, pTableMetaInfo->name, sizeof(pDropMsg->user));
|
||||||
|
|
||||||
|
@ -1109,7 +1109,7 @@ int32_t tscBuildDropUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMDropUserMsg);
|
pCmd->payloadLen = sizeof(SDropUserMsg);
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_ACCT;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_ACCT;
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||||
|
@ -1117,7 +1117,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload;
|
SDropUserMsg * pDropMsg = (SDropUserMsg *)pCmd->payload;
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
tstrncpy(pDropMsg->user, pTableMetaInfo->name, sizeof(pDropMsg->user));
|
tstrncpy(pDropMsg->user, pTableMetaInfo->name, sizeof(pDropMsg->user));
|
||||||
|
|
||||||
|
@ -1126,14 +1126,14 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMUseDbMsg);
|
pCmd->payloadLen = sizeof(SUseDbMsg);
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||||
tscError("%p failed to malloc for query msg", pSql);
|
tscError("%p failed to malloc for query msg", pSql);
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMUseDbMsg *pUseDbMsg = (SCMUseDbMsg*)pCmd->payload;
|
SUseDbMsg *pUseDbMsg = (SUseDbMsg *)pCmd->payload;
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
strcpy(pUseDbMsg->db, pTableMetaInfo->name);
|
strcpy(pUseDbMsg->db, pTableMetaInfo->name);
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_USE_DB;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_USE_DB;
|
||||||
|
@ -1145,14 +1145,14 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
STscObj *pObj = pSql->pTscObj;
|
STscObj *pObj = pSql->pTscObj;
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_SHOW;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_SHOW;
|
||||||
pCmd->payloadLen = sizeof(SCMShowMsg) + 100;
|
pCmd->payloadLen = sizeof(SShowMsg) + 100;
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||||
tscError("%p failed to malloc for query msg", pSql);
|
tscError("%p failed to malloc for query msg", pSql);
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMShowMsg *pShowMsg = (SCMShowMsg*)pCmd->payload;
|
SShowMsg *pShowMsg = (SShowMsg *)pCmd->payload;
|
||||||
|
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
size_t nameLen = strlen(pTableMetaInfo->name);
|
size_t nameLen = strlen(pTableMetaInfo->name);
|
||||||
|
@ -1179,13 +1179,13 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
pShowMsg->payloadLen = htons(pEpAddr->n);
|
pShowMsg->payloadLen = htons(pEpAddr->n);
|
||||||
}
|
}
|
||||||
|
|
||||||
pCmd->payloadLen = sizeof(SCMShowMsg) + pShowMsg->payloadLen;
|
pCmd->payloadLen = sizeof(SShowMsg) + pShowMsg->payloadLen;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMKillQueryMsg);
|
pCmd->payloadLen = sizeof(SKillQueryMsg);
|
||||||
|
|
||||||
switch (pCmd->command) {
|
switch (pCmd->command) {
|
||||||
case TSDB_SQL_KILL_QUERY:
|
case TSDB_SQL_KILL_QUERY:
|
||||||
|
@ -1297,8 +1297,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int tscEstimateAlterTableMsgLength(SSqlCmd *pCmd) {
|
int tscEstimateAlterTableMsgLength(SSqlCmd *pCmd) {
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||||
return minMsgSize() + sizeof(SCMAlterTableMsg) + sizeof(SSchema) * tscNumOfFields(pQueryInfo) +
|
return minMsgSize() + sizeof(SAlterTableMsg) + sizeof(SSchema) * tscNumOfFields(pQueryInfo) + TSDB_EXTRA_PAYLOAD_SIZE;
|
||||||
TSDB_EXTRA_PAYLOAD_SIZE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
@ -1317,7 +1316,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMAlterTableMsg *pAlterTableMsg = (SCMAlterTableMsg *)pCmd->payload;
|
SAlterTableMsg *pAlterTableMsg = (SAlterTableMsg *)pCmd->payload;
|
||||||
tscGetDBInfoFromTableFullName(pTableMetaInfo->name, pAlterTableMsg->db);
|
tscGetDBInfoFromTableFullName(pTableMetaInfo->name, pAlterTableMsg->db);
|
||||||
|
|
||||||
strcpy(pAlterTableMsg->tableId, pTableMetaInfo->name);
|
strcpy(pAlterTableMsg->tableId, pTableMetaInfo->name);
|
||||||
|
@ -1366,10 +1365,10 @@ int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SCMAlterDbMsg);
|
pCmd->payloadLen = sizeof(SAlterDbMsg);
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_ALTER_DB;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_ALTER_DB;
|
||||||
|
|
||||||
SCMAlterDbMsg *pAlterDbMsg = (SCMAlterDbMsg*)pCmd->payload;
|
SAlterDbMsg *pAlterDbMsg = (SAlterDbMsg* )pCmd->payload;
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
tstrncpy(pAlterDbMsg->db, pTableMetaInfo->name, sizeof(pAlterDbMsg->db));
|
tstrncpy(pAlterDbMsg->db, pTableMetaInfo->name, sizeof(pAlterDbMsg->db));
|
||||||
|
|
||||||
|
@ -1494,14 +1493,14 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
STscObj *pObj = pSql->pTscObj;
|
STscObj *pObj = pSql->pTscObj;
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_CONNECT;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_CONNECT;
|
||||||
pCmd->payloadLen = sizeof(SCMConnectMsg);
|
pCmd->payloadLen = sizeof(SConnectMsg);
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||||
tscError("%p failed to malloc for query msg", pSql);
|
tscError("%p failed to malloc for query msg", pSql);
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMConnectMsg *pConnect = (SCMConnectMsg*)pCmd->payload;
|
SConnectMsg *pConnect = (SConnectMsg*)pCmd->payload;
|
||||||
|
|
||||||
// TODO refactor full_name
|
// TODO refactor full_name
|
||||||
char *db; // ugly code to move the space
|
char *db; // ugly code to move the space
|
||||||
|
@ -1523,11 +1522,11 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
|
||||||
SCMTableInfoMsg* pInfoMsg = (SCMTableInfoMsg *)pCmd->payload;
|
STableInfoMsg *pInfoMsg = (STableInfoMsg *)pCmd->payload;
|
||||||
strcpy(pInfoMsg->tableId, pTableMetaInfo->name);
|
strcpy(pInfoMsg->tableId, pTableMetaInfo->name);
|
||||||
pInfoMsg->createFlag = htons(pSql->cmd.autoCreated ? 1 : 0);
|
pInfoMsg->createFlag = htons(pSql->cmd.autoCreated ? 1 : 0);
|
||||||
|
|
||||||
char* pMsg = (char*)pInfoMsg + sizeof(SCMTableInfoMsg);
|
char *pMsg = (char *)pInfoMsg + sizeof(STableInfoMsg);
|
||||||
|
|
||||||
size_t len = htonl(pCmd->tagData.dataLen);
|
size_t len = htonl(pCmd->tagData.dataLen);
|
||||||
if (pSql->cmd.autoCreated) {
|
if (pSql->cmd.autoCreated) {
|
||||||
|
@ -1546,7 +1545,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* multi table meta req pkg format:
|
* multi table meta req pkg format:
|
||||||
* | SMgmtHead | SCMMultiTableInfoMsg | tableId0 | tableId1 | tableId2 | ......
|
* | SMgmtHead | SMultiTableInfoMsg | tableId0 | tableId1 | tableId2 | ......
|
||||||
* no used 4B
|
* no used 4B
|
||||||
**/
|
**/
|
||||||
int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
@ -1564,7 +1563,7 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SMgmtHead *pMgmt = (SMgmtHead *)(pCmd->payload + tsRpcHeadSize);
|
SMgmtHead *pMgmt = (SMgmtHead *)(pCmd->payload + tsRpcHeadSize);
|
||||||
memset(pMgmt->db, 0, TSDB_TABLE_FNAME_LEN); // server don't need the db
|
memset(pMgmt->db, 0, TSDB_TABLE_FNAME_LEN); // server don't need the db
|
||||||
|
|
||||||
SCMMultiTableInfoMsg *pInfoMsg = (SCMMultiTableInfoMsg *)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead));
|
SMultiTableInfoMsg *pInfoMsg = (SMultiTableInfoMsg *)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead));
|
||||||
pInfoMsg->numOfTables = htonl((int32_t)pCmd->count);
|
pInfoMsg->numOfTables = htonl((int32_t)pCmd->count);
|
||||||
|
|
||||||
if (pCmd->payloadLen > 0) {
|
if (pCmd->payloadLen > 0) {
|
||||||
|
@ -1573,7 +1572,7 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
taosTFree(tmpData);
|
taosTFree(tmpData);
|
||||||
|
|
||||||
pCmd->payloadLen += sizeof(SMgmtHead) + sizeof(SCMMultiTableInfoMsg);
|
pCmd->payloadLen += sizeof(SMgmtHead) + sizeof(SMultiTableInfoMsg);
|
||||||
pCmd->msgType = TSDB_MSG_TYPE_CM_TABLES_META;
|
pCmd->msgType = TSDB_MSG_TYPE_CM_TABLES_META;
|
||||||
|
|
||||||
assert(pCmd->payloadLen + minMsgSize() <= pCmd->allocSize);
|
assert(pCmd->payloadLen + minMsgSize() <= pCmd->allocSize);
|
||||||
|
@ -1619,11 +1618,11 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
char* pMsg = pCmd->payload;
|
char* pMsg = pCmd->payload;
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||||
|
|
||||||
SCMSTableVgroupMsg *pStableVgroupMsg = (SCMSTableVgroupMsg *) pMsg;
|
SSTableVgroupMsg *pStableVgroupMsg = (SSTableVgroupMsg *)pMsg;
|
||||||
pStableVgroupMsg->numOfTables = htonl(pQueryInfo->numOfTables);
|
pStableVgroupMsg->numOfTables = htonl(pQueryInfo->numOfTables);
|
||||||
pMsg += sizeof(SCMSTableVgroupMsg);
|
pMsg += sizeof(SSTableVgroupMsg);
|
||||||
|
|
||||||
for(int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, i);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, i);
|
||||||
size_t size = sizeof(pTableMetaInfo->name);
|
size_t size = sizeof(pTableMetaInfo->name);
|
||||||
tstrncpy(pMsg, pTableMetaInfo->name, size);
|
tstrncpy(pMsg, pTableMetaInfo->name, size);
|
||||||
|
@ -1656,7 +1655,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
numOfStreams++;
|
numOfStreams++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = numOfQueries * sizeof(SQueryDesc) + numOfStreams * sizeof(SStreamDesc) + sizeof(SCMHeartBeatMsg) + 100;
|
int size = numOfQueries * sizeof(SQueryDesc) + numOfStreams * sizeof(SStreamDesc) + sizeof(SHeartBeatMsg) + 100;
|
||||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
|
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
|
||||||
pthread_mutex_unlock(&pObj->mutex);
|
pthread_mutex_unlock(&pObj->mutex);
|
||||||
tscError("%p failed to create heartbeat msg", pSql);
|
tscError("%p failed to create heartbeat msg", pSql);
|
||||||
|
@ -1664,7 +1663,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO the expired hb and client can not be identified by server till now.
|
// TODO the expired hb and client can not be identified by server till now.
|
||||||
SCMHeartBeatMsg *pHeartbeat = (SCMHeartBeatMsg *)pCmd->payload;
|
SHeartBeatMsg *pHeartbeat = (SHeartBeatMsg *)pCmd->payload;
|
||||||
tstrncpy(pHeartbeat->clientVer, version, tListLen(pHeartbeat->clientVer));
|
tstrncpy(pHeartbeat->clientVer, version, tListLen(pHeartbeat->clientVer));
|
||||||
|
|
||||||
pHeartbeat->numOfQueries = numOfQueries;
|
pHeartbeat->numOfQueries = numOfQueries;
|
||||||
|
@ -1755,7 +1754,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* multi table meta rsp pkg format:
|
* multi table meta rsp pkg format:
|
||||||
* | STaosRsp | ieType | SCMMultiTableInfoMsg | SMeterMeta0 | SSchema0 | SMeterMeta1 | SSchema1 | SMeterMeta2 | SSchema2
|
* | STaosRsp | ieType | SMultiTableInfoMsg | SMeterMeta0 | SSchema0 | SMeterMeta1 | SSchema1 | SMeterMeta2 | SSchema2
|
||||||
* |...... 1B 1B 4B
|
* |...... 1B 1B 4B
|
||||||
**/
|
**/
|
||||||
int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) {
|
int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) {
|
||||||
|
@ -1772,9 +1771,9 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) {
|
||||||
|
|
||||||
rsp++;
|
rsp++;
|
||||||
|
|
||||||
SCMMultiTableInfoMsg *pInfo = (SCMMultiTableInfoMsg *)rsp;
|
SMultiTableInfoMsg *pInfo = (SMultiTableInfoMsg *)rsp;
|
||||||
totalNum = htonl(pInfo->numOfTables);
|
totalNum = htonl(pInfo->numOfTables);
|
||||||
rsp += sizeof(SCMMultiTableInfoMsg);
|
rsp += sizeof(SMultiTableInfoMsg);
|
||||||
|
|
||||||
for (i = 0; i < totalNum; i++) {
|
for (i = 0; i < totalNum; i++) {
|
||||||
SMultiTableMeta *pMultiMeta = (SMultiTableMeta *)rsp;
|
SMultiTableMeta *pMultiMeta = (SMultiTableMeta *)rsp;
|
||||||
|
@ -1866,9 +1865,9 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) {
|
||||||
SSqlRes* pRes = &pSql->res;
|
SSqlRes* pRes = &pSql->res;
|
||||||
|
|
||||||
// NOTE: the order of several table must be preserved.
|
// NOTE: the order of several table must be preserved.
|
||||||
SCMSTableVgroupRspMsg *pStableVgroup = (SCMSTableVgroupRspMsg *)pRes->pRsp;
|
SSTableVgroupRspMsg *pStableVgroup = (SSTableVgroupRspMsg *)pRes->pRsp;
|
||||||
pStableVgroup->numOfTables = htonl(pStableVgroup->numOfTables);
|
pStableVgroup->numOfTables = htonl(pStableVgroup->numOfTables);
|
||||||
char* pMsg = pRes->pRsp + sizeof(SCMSTableVgroupRspMsg);
|
char *pMsg = pRes->pRsp + sizeof(SSTableVgroupRspMsg);
|
||||||
|
|
||||||
// master sqlObj locates in param
|
// master sqlObj locates in param
|
||||||
SSqlObj* parent = pSql->param;
|
SSqlObj* parent = pSql->param;
|
||||||
|
@ -1881,18 +1880,18 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) {
|
||||||
SVgroupsMsg * pVgroupMsg = (SVgroupsMsg *) pMsg;
|
SVgroupsMsg * pVgroupMsg = (SVgroupsMsg *) pMsg;
|
||||||
pVgroupMsg->numOfVgroups = htonl(pVgroupMsg->numOfVgroups);
|
pVgroupMsg->numOfVgroups = htonl(pVgroupMsg->numOfVgroups);
|
||||||
|
|
||||||
size_t size = sizeof(SCMVgroupMsg) * pVgroupMsg->numOfVgroups + sizeof(SVgroupsMsg);
|
size_t size = sizeof(SVgroupMsg) * pVgroupMsg->numOfVgroups + sizeof(SVgroupsMsg);
|
||||||
|
|
||||||
size_t vgroupsz = sizeof(SCMVgroupInfo) * pVgroupMsg->numOfVgroups + sizeof(SVgroupsInfo);
|
size_t vgroupsz = sizeof(SVgroupInfo) * pVgroupMsg->numOfVgroups + sizeof(SVgroupsInfo);
|
||||||
pInfo->vgroupList = calloc(1, vgroupsz);
|
pInfo->vgroupList = calloc(1, vgroupsz);
|
||||||
assert(pInfo->vgroupList != NULL);
|
assert(pInfo->vgroupList != NULL);
|
||||||
|
|
||||||
pInfo->vgroupList->numOfVgroups = pVgroupMsg->numOfVgroups;
|
pInfo->vgroupList->numOfVgroups = pVgroupMsg->numOfVgroups;
|
||||||
for (int32_t j = 0; j < pInfo->vgroupList->numOfVgroups; ++j) {
|
for (int32_t j = 0; j < pInfo->vgroupList->numOfVgroups; ++j) {
|
||||||
//just init, no need to lock
|
//just init, no need to lock
|
||||||
SCMVgroupInfo *pVgroups = &pInfo->vgroupList->vgroups[j];
|
SVgroupInfo *pVgroups = &pInfo->vgroupList->vgroups[j];
|
||||||
|
|
||||||
SCMVgroupMsg *vmsg = &pVgroupMsg->vgroups[j];
|
SVgroupMsg *vmsg = &pVgroupMsg->vgroups[j];
|
||||||
pVgroups->vgId = htonl(vmsg->vgId);
|
pVgroups->vgId = htonl(vmsg->vgId);
|
||||||
pVgroups->numOfEps = vmsg->numOfEps;
|
pVgroups->numOfEps = vmsg->numOfEps;
|
||||||
|
|
||||||
|
@ -1914,10 +1913,10 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) {
|
||||||
* current process do not use the cache at all
|
* current process do not use the cache at all
|
||||||
*/
|
*/
|
||||||
int tscProcessShowRsp(SSqlObj *pSql) {
|
int tscProcessShowRsp(SSqlObj *pSql) {
|
||||||
STableMetaMsg * pMetaMsg;
|
STableMetaMsg *pMetaMsg;
|
||||||
SCMShowRsp *pShow;
|
SShowRsp * pShow;
|
||||||
SSchema * pSchema;
|
SSchema * pSchema;
|
||||||
char key[20];
|
char key[20];
|
||||||
|
|
||||||
SSqlRes *pRes = &pSql->res;
|
SSqlRes *pRes = &pSql->res;
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
|
@ -1926,7 +1925,7 @@ int tscProcessShowRsp(SSqlObj *pSql) {
|
||||||
|
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
|
||||||
pShow = (SCMShowRsp *)pRes->pRsp;
|
pShow = (SShowRsp *)pRes->pRsp;
|
||||||
pShow->qhandle = htobe64(pShow->qhandle);
|
pShow->qhandle = htobe64(pShow->qhandle);
|
||||||
pRes->qhandle = pShow->qhandle;
|
pRes->qhandle = pShow->qhandle;
|
||||||
|
|
||||||
|
@ -2024,7 +2023,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
|
||||||
|
|
||||||
char temp[TSDB_TABLE_FNAME_LEN * 2] = {0};
|
char temp[TSDB_TABLE_FNAME_LEN * 2] = {0};
|
||||||
|
|
||||||
SCMConnectRsp *pConnect = (SCMConnectRsp *)pRes->pRsp;
|
SConnectRsp *pConnect = (SConnectRsp *)pRes->pRsp;
|
||||||
tstrncpy(pObj->acctId, pConnect->acctId, sizeof(pObj->acctId)); // copy acctId from response
|
tstrncpy(pObj->acctId, pConnect->acctId, sizeof(pObj->acctId)); // copy acctId from response
|
||||||
int32_t len = sprintf(temp, "%s%s%s", pObj->acctId, TS_PATH_DELIMITER, pObj->db);
|
int32_t len = sprintf(temp, "%s%s%s", pObj->acctId, TS_PATH_DELIMITER, pObj->db);
|
||||||
|
|
||||||
|
|
|
@ -509,7 +509,7 @@ void tscBuildVgroupTableInfo(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, SArr
|
||||||
SVgroupTableInfo info = {{0}};
|
SVgroupTableInfo info = {{0}};
|
||||||
for (int32_t m = 0; m < pvg->numOfVgroups; ++m) {
|
for (int32_t m = 0; m < pvg->numOfVgroups; ++m) {
|
||||||
if (tt->vgId == pvg->vgroups[m].vgId) {
|
if (tt->vgId == pvg->vgroups[m].vgId) {
|
||||||
tscSCMVgroupInfoCopy(&info.vgInfo, &pvg->vgroups[m]);
|
tscSVgroupInfoCopy(&info.vgInfo, &pvg->vgroups[m]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1449,6 +1449,7 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) {
|
||||||
|
|
||||||
tscDebug("%p start subquery, total:%d", pSql, pQueryInfo->numOfTables);
|
tscDebug("%p start subquery, total:%d", pSql, pQueryInfo->numOfTables);
|
||||||
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
||||||
|
|
||||||
SJoinSupporter *pSupporter = tscCreateJoinSupporter(pSql, i);
|
SJoinSupporter *pSupporter = tscCreateJoinSupporter(pSql, i);
|
||||||
|
|
||||||
if (pSupporter == NULL) { // failed to create support struct, abort current query
|
if (pSupporter == NULL) { // failed to create support struct, abort current query
|
||||||
|
@ -1670,8 +1671,8 @@ static int32_t tscReissueSubquery(SRetrieveSupport *trsupport, SSqlObj *pSql, in
|
||||||
SSqlObj *pParentSql = trsupport->pParentSql;
|
SSqlObj *pParentSql = trsupport->pParentSql;
|
||||||
int32_t subqueryIndex = trsupport->subqueryIndex;
|
int32_t subqueryIndex = trsupport->subqueryIndex;
|
||||||
|
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
||||||
SCMVgroupInfo* pVgroup = &pTableMetaInfo->vgroupList->vgroups[0];
|
SVgroupInfo* pVgroup = &pTableMetaInfo->vgroupList->vgroups[0];
|
||||||
|
|
||||||
tExtMemBufferClear(trsupport->pExtMemBuffer[subqueryIndex]);
|
tExtMemBufferClear(trsupport->pExtMemBuffer[subqueryIndex]);
|
||||||
|
|
||||||
|
@ -1873,7 +1874,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
|
||||||
assert(pState->numOfRemain <= pState->numOfSub && pState->numOfRemain >= 0);
|
assert(pState->numOfRemain <= pState->numOfSub && pState->numOfRemain >= 0);
|
||||||
|
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
||||||
SCMVgroupInfo *pVgroup = &pTableMetaInfo->vgroupList->vgroups[0];
|
SVgroupInfo *pVgroup = &pTableMetaInfo->vgroupList->vgroups[0];
|
||||||
|
|
||||||
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
|
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
|
||||||
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY;
|
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY;
|
||||||
|
@ -1984,7 +1985,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
|
||||||
assert(pSql->cmd.numOfClause == 1 && pQueryInfo->numOfTables == 1);
|
assert(pSql->cmd.numOfClause == 1 && pQueryInfo->numOfTables == 1);
|
||||||
|
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
||||||
SCMVgroupInfo* pVgroup = &pTableMetaInfo->vgroupList->vgroups[trsupport->subqueryIndex];
|
SVgroupInfo* pVgroup = &pTableMetaInfo->vgroupList->vgroups[trsupport->subqueryIndex];
|
||||||
|
|
||||||
// stable query killed or other subquery failed, all query stopped
|
// stable query killed or other subquery failed, all query stopped
|
||||||
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
|
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
|
||||||
|
|
|
@ -104,7 +104,6 @@ void taos_init_imp(void) {
|
||||||
|
|
||||||
taosReadGlobalCfg();
|
taosReadGlobalCfg();
|
||||||
taosCheckGlobalCfg();
|
taosCheckGlobalCfg();
|
||||||
taosPrintGlobalCfg();
|
|
||||||
|
|
||||||
tscDebug("starting to initialize TAOS client ...");
|
tscDebug("starting to initialize TAOS client ...");
|
||||||
tscDebug("Local End Point is:%s", tsLocalEp);
|
tscDebug("Local End Point is:%s", tsLocalEp);
|
||||||
|
|
|
@ -2158,7 +2158,7 @@ int16_t tscGetJoinTagColIdByUid(STagCond* pTagCond, uint64_t uid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t tscGetTagColIndexById(STableMeta* pTableMeta, int16_t colId) {
|
int16_t tscGetTagColIndexById(STableMeta* pTableMeta, int16_t colId) {
|
||||||
int32_t numOfTags = tscGetNumOfColumns(pTableMeta);
|
int32_t numOfTags = tscGetNumOfTags(pTableMeta);
|
||||||
|
|
||||||
SSchema* pSchema = tscGetTableTagSchema(pTableMeta);
|
SSchema* pSchema = tscGetTableTagSchema(pTableMeta);
|
||||||
for(int32_t i = 0; i < numOfTags; ++i) {
|
for(int32_t i = 0; i < numOfTags; ++i) {
|
||||||
|
@ -2167,7 +2167,9 @@ int16_t tscGetTagColIndexById(STableMeta* pTableMeta, int16_t colId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
// can not reach here
|
||||||
|
assert(0);
|
||||||
|
return INT16_MIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tscIsUpdateQuery(SSqlObj* pSql) {
|
bool tscIsUpdateQuery(SSqlObj* pSql) {
|
||||||
|
@ -2439,7 +2441,7 @@ SVgroupsInfo* tscVgroupInfoClone(SVgroupsInfo *vgroupList) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size = sizeof(SVgroupsInfo) + sizeof(SCMVgroupInfo) * vgroupList->numOfVgroups;
|
size_t size = sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * vgroupList->numOfVgroups;
|
||||||
SVgroupsInfo* pNew = calloc(1, size);
|
SVgroupsInfo* pNew = calloc(1, size);
|
||||||
if (pNew == NULL) {
|
if (pNew == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2448,9 +2450,9 @@ SVgroupsInfo* tscVgroupInfoClone(SVgroupsInfo *vgroupList) {
|
||||||
pNew->numOfVgroups = vgroupList->numOfVgroups;
|
pNew->numOfVgroups = vgroupList->numOfVgroups;
|
||||||
|
|
||||||
for(int32_t i = 0; i < vgroupList->numOfVgroups; ++i) {
|
for(int32_t i = 0; i < vgroupList->numOfVgroups; ++i) {
|
||||||
SCMVgroupInfo* pNewVInfo = &pNew->vgroups[i];
|
SVgroupInfo* pNewVInfo = &pNew->vgroups[i];
|
||||||
|
|
||||||
SCMVgroupInfo* pvInfo = &vgroupList->vgroups[i];
|
SVgroupInfo* pvInfo = &vgroupList->vgroups[i];
|
||||||
pNewVInfo->vgId = pvInfo->vgId;
|
pNewVInfo->vgId = pvInfo->vgId;
|
||||||
pNewVInfo->numOfEps = pvInfo->numOfEps;
|
pNewVInfo->numOfEps = pvInfo->numOfEps;
|
||||||
|
|
||||||
|
@ -2469,7 +2471,7 @@ void* tscVgroupInfoClear(SVgroupsInfo *vgroupList) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int32_t i = 0; i < vgroupList->numOfVgroups; ++i) {
|
for(int32_t i = 0; i < vgroupList->numOfVgroups; ++i) {
|
||||||
SCMVgroupInfo* pVgroupInfo = &vgroupList->vgroups[i];
|
SVgroupInfo* pVgroupInfo = &vgroupList->vgroups[i];
|
||||||
|
|
||||||
for(int32_t j = 0; j < pVgroupInfo->numOfEps; ++j) {
|
for(int32_t j = 0; j < pVgroupInfo->numOfEps; ++j) {
|
||||||
taosTFree(pVgroupInfo->epAddr[j].fqdn);
|
taosTFree(pVgroupInfo->epAddr[j].fqdn);
|
||||||
|
@ -2480,7 +2482,7 @@ void* tscVgroupInfoClear(SVgroupsInfo *vgroupList) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscSCMVgroupInfoCopy(SCMVgroupInfo* dst, const SCMVgroupInfo* src) {
|
void tscSVgroupInfoCopy(SVgroupInfo* dst, const SVgroupInfo* src) {
|
||||||
dst->vgId = src->vgId;
|
dst->vgId = src->vgId;
|
||||||
dst->numOfEps = src->numOfEps;
|
dst->numOfEps = src->numOfEps;
|
||||||
for(int32_t i = 0; i < dst->numOfEps; ++i) {
|
for(int32_t i = 0; i < dst->numOfEps; ++i) {
|
||||||
|
|
|
@ -51,6 +51,7 @@ extern char tsLocale[];
|
||||||
extern char tsCharset[]; // default encode string
|
extern char tsCharset[]; // default encode string
|
||||||
extern int32_t tsEnableCoreFile;
|
extern int32_t tsEnableCoreFile;
|
||||||
extern int32_t tsCompressMsgSize;
|
extern int32_t tsCompressMsgSize;
|
||||||
|
extern char tsTempDir[];
|
||||||
|
|
||||||
//query buffer management
|
//query buffer management
|
||||||
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer for each data node during query processing
|
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer for each data node during query processing
|
||||||
|
@ -184,12 +185,12 @@ extern int32_t debugFlag;
|
||||||
|
|
||||||
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
||||||
|
|
||||||
void taosInitGlobalCfg();
|
void taosInitGlobalCfg();
|
||||||
bool taosCheckGlobalCfg();
|
int32_t taosCheckGlobalCfg();
|
||||||
void taosSetAllDebugFlag();
|
void taosSetAllDebugFlag();
|
||||||
bool taosCfgDynamicOptions(char *msg);
|
bool taosCfgDynamicOptions(char *msg);
|
||||||
int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port);
|
int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port);
|
||||||
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId);
|
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ char tsLocale[TSDB_LOCALE_LEN] = {0};
|
||||||
char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string
|
char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string
|
||||||
int32_t tsEnableCoreFile = 0;
|
int32_t tsEnableCoreFile = 0;
|
||||||
int32_t tsMaxBinaryDisplayWidth = 30;
|
int32_t tsMaxBinaryDisplayWidth = 30;
|
||||||
|
char tsTempDir[TSDB_FILENAME_LEN] = "/tmp/";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* denote if the server needs to compress response message at the application layer to client, including query rsp,
|
* denote if the server needs to compress response message at the application layer to client, including query rsp,
|
||||||
|
@ -1321,13 +1322,23 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.ptrLength = 0;
|
cfg.ptrLength = 0;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
|
cfg.option = "tempDir";
|
||||||
|
cfg.ptr = tsTempDir;
|
||||||
|
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||||
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
|
cfg.minValue = 0;
|
||||||
|
cfg.maxValue = 0;
|
||||||
|
cfg.ptrLength = tListLen(tsTempDir);
|
||||||
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
|
taosInitConfigOption(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosInitGlobalCfg() {
|
void taosInitGlobalCfg() {
|
||||||
pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig);
|
pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool taosCheckGlobalCfg() {
|
int32_t taosCheckGlobalCfg() {
|
||||||
char fqdn[TSDB_FQDN_LEN];
|
char fqdn[TSDB_FQDN_LEN];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
|
||||||
|
@ -1386,7 +1397,9 @@ bool taosCheckGlobalCfg() {
|
||||||
tsSyncPort = tsServerPort + TSDB_PORT_SYNC;
|
tsSyncPort = tsServerPort + TSDB_PORT_SYNC;
|
||||||
tsHttpPort = tsServerPort + TSDB_PORT_HTTP;
|
tsHttpPort = tsServerPort + TSDB_PORT_HTTP;
|
||||||
|
|
||||||
return true;
|
taosPrintGlobalCfg();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port) {
|
int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8d7bf743852897110cbdcc7c4322cd7a74d4167b
|
Subproject commit 8c58c512b6acda8bcdfa48fdc7140227b5221766
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TDENGINE_DNODE_CFG_H
|
||||||
|
#define TDENGINE_DNODE_CFG_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int32_t dnodeInitCfg();
|
||||||
|
void dnodeCleanupCfg();
|
||||||
|
void dnodeUpdateCfg(SDnodeCfg *cfg);
|
||||||
|
int32_t dnodeGetDnodeId();
|
||||||
|
void dnodeGetCfg(int32_t *dnodeId, char *clusterId);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TDENGINE_DNODE_EP_H
|
||||||
|
#define TDENGINE_DNODE_EP_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "taosmsg.h"
|
||||||
|
|
||||||
|
int32_t dnodeInitEps();
|
||||||
|
void dnodeCleanupEps();
|
||||||
|
void dnodeUpdateEps(SDnodeEps *eps);
|
||||||
|
void dnodeUpdateEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port);
|
||||||
|
bool dnodeCheckEpChanged(int32_t dnodeId, char *epstr);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TDENGINE_DNODE_MINFOS_H
|
||||||
|
#define TDENGINE_DNODE_MINFOS_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "taosmsg.h"
|
||||||
|
|
||||||
|
int32_t dnodeInitMInfos();
|
||||||
|
void dnodeCleanupMInfos();
|
||||||
|
void dnodeUpdateMInfos(SMnodeInfos *minfos);
|
||||||
|
void dnodeUpdateEpSetForPeer(SRpcEpSet *epSet);
|
||||||
|
void dnodeGetMInfos(SMnodeInfos *minfos);
|
||||||
|
bool dnodeIsMasterEp(char *ep);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -20,6 +20,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "trpc.h"
|
||||||
|
|
||||||
int32_t dnodeInitMgmt();
|
int32_t dnodeInitMgmt();
|
||||||
void dnodeCleanupMgmt();
|
void dnodeCleanupMgmt();
|
||||||
int32_t dnodeInitMgmtTimer();
|
int32_t dnodeInitMgmtTimer();
|
||||||
|
@ -35,8 +37,8 @@ void* dnodeGetVnodeTsdb(void *pVnode);
|
||||||
void dnodeReleaseVnode(void *pVnode);
|
void dnodeReleaseVnode(void *pVnode);
|
||||||
|
|
||||||
void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell);
|
void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell);
|
||||||
void dnodeGetMnodeEpSetForPeer(void *epSet);
|
void dnodeGetEpSetForPeer(SRpcEpSet *epSet);
|
||||||
void dnodeGetMnodeEpSetForShell(void *epSet);
|
void dnodeGetEpSetForShell(SRpcEpSet *epSet);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,163 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "cJSON.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
#include "dnode.h"
|
||||||
|
#include "dnodeInt.h"
|
||||||
|
#include "dnodeCfg.h"
|
||||||
|
|
||||||
|
static SDnodeCfg tsCfg = {0};
|
||||||
|
static pthread_mutex_t tsCfgMutex;
|
||||||
|
|
||||||
|
static int32_t dnodeReadCfg();
|
||||||
|
static int32_t dnodeWriteCfg();
|
||||||
|
static void dnodeResetCfg(SDnodeCfg *cfg);
|
||||||
|
static void dnodePrintCfg(SDnodeCfg *cfg);
|
||||||
|
|
||||||
|
int32_t dnodeInitCfg() {
|
||||||
|
pthread_mutex_init(&tsCfgMutex, NULL);
|
||||||
|
dnodeResetCfg(NULL);
|
||||||
|
int32_t ret = dnodeReadCfg();
|
||||||
|
if (ret == 0) {
|
||||||
|
dInfo("dnode cfg is initialized");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeCleanupCfg() { pthread_mutex_destroy(&tsCfgMutex); }
|
||||||
|
|
||||||
|
void dnodeUpdateCfg(SDnodeCfg *cfg) {
|
||||||
|
if (tsCfg.dnodeId != 0) return;
|
||||||
|
dnodeResetCfg(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t dnodeGetDnodeId() {
|
||||||
|
int32_t dnodeId = 0;
|
||||||
|
pthread_mutex_lock(&tsCfgMutex);
|
||||||
|
dnodeId = tsCfg.dnodeId;
|
||||||
|
pthread_mutex_unlock(&tsCfgMutex);
|
||||||
|
return dnodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeGetCfg(int32_t *dnodeId, char *clusterId) {
|
||||||
|
pthread_mutex_lock(&tsCfgMutex);
|
||||||
|
*dnodeId = tsCfg.dnodeId;
|
||||||
|
tstrncpy(clusterId, tsCfg.clusterId, TSDB_CLUSTER_ID_LEN);
|
||||||
|
pthread_mutex_unlock(&tsCfgMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dnodeResetCfg(SDnodeCfg *cfg) {
|
||||||
|
if (cfg == NULL) return;
|
||||||
|
if (cfg->dnodeId == 0) return;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&tsCfgMutex);
|
||||||
|
tsCfg.dnodeId = cfg->dnodeId;
|
||||||
|
tstrncpy(tsCfg.clusterId, cfg->clusterId, TSDB_CLUSTER_ID_LEN);
|
||||||
|
dnodePrintCfg(cfg);
|
||||||
|
dnodeWriteCfg();
|
||||||
|
pthread_mutex_unlock(&tsCfgMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dnodePrintCfg(SDnodeCfg *cfg) {
|
||||||
|
dInfo("dnodeId is set to %d, clusterId is set to %s", cfg->dnodeId, cfg->clusterId);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dnodeReadCfg() {
|
||||||
|
int32_t len = 0;
|
||||||
|
int32_t maxLen = 200;
|
||||||
|
char * content = calloc(1, maxLen + 1);
|
||||||
|
cJSON * root = NULL;
|
||||||
|
FILE * fp = NULL;
|
||||||
|
SDnodeCfg cfg = {0};
|
||||||
|
|
||||||
|
char file[TSDB_FILENAME_LEN + 20] = {0};
|
||||||
|
sprintf(file, "%s/dnodeCfg.json", tsDnodeDir);
|
||||||
|
|
||||||
|
fp = fopen(file, "r");
|
||||||
|
if (!fp) {
|
||||||
|
dDebug("failed to read %s, file not exist", file);
|
||||||
|
goto PARSE_CFG_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = fread(content, 1, maxLen, fp);
|
||||||
|
if (len <= 0) {
|
||||||
|
dError("failed to read %s, content is null", file);
|
||||||
|
goto PARSE_CFG_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
content[len] = 0;
|
||||||
|
root = cJSON_Parse(content);
|
||||||
|
if (root == NULL) {
|
||||||
|
dError("failed to read %s, invalid json format", file);
|
||||||
|
goto PARSE_CFG_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId");
|
||||||
|
if (!dnodeId || dnodeId->type != cJSON_Number) {
|
||||||
|
dError("failed to read %s, dnodeId not found", file);
|
||||||
|
goto PARSE_CFG_OVER;
|
||||||
|
}
|
||||||
|
cfg.dnodeId = dnodeId->valueint;
|
||||||
|
|
||||||
|
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||||
|
if (!clusterId || clusterId->type != cJSON_String) {
|
||||||
|
dError("failed to read %s, clusterId not found", file);
|
||||||
|
goto PARSE_CFG_OVER;
|
||||||
|
}
|
||||||
|
tstrncpy(cfg.clusterId, clusterId->valuestring, TSDB_CLUSTER_ID_LEN);
|
||||||
|
|
||||||
|
dInfo("read file %s successed", file);
|
||||||
|
|
||||||
|
PARSE_CFG_OVER:
|
||||||
|
if (content != NULL) free(content);
|
||||||
|
if (root != NULL) cJSON_Delete(root);
|
||||||
|
if (fp != NULL) fclose(fp);
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
|
dnodeResetCfg(&cfg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dnodeWriteCfg() {
|
||||||
|
char file[TSDB_FILENAME_LEN + 20] = {0};
|
||||||
|
sprintf(file, "%s/dnodeCfg.json", tsDnodeDir);
|
||||||
|
|
||||||
|
FILE *fp = fopen(file, "w");
|
||||||
|
if (!fp) {
|
||||||
|
dError("failed to write %s, reason:%s", file, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t len = 0;
|
||||||
|
int32_t maxLen = 200;
|
||||||
|
char * content = calloc(1, maxLen + 1);
|
||||||
|
|
||||||
|
len += snprintf(content + len, maxLen - len, "{\n");
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", tsCfg.dnodeId);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%s\"\n", tsCfg.clusterId);
|
||||||
|
len += snprintf(content + len, maxLen - len, "}\n");
|
||||||
|
|
||||||
|
fwrite(content, 1, len, fp);
|
||||||
|
fflush(fp);
|
||||||
|
fclose(fp);
|
||||||
|
free(content);
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
|
dInfo("successed to write %s", file);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -15,9 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosdef.h"
|
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "mnode.h"
|
|
||||||
#include "dnodeInt.h"
|
#include "dnodeInt.h"
|
||||||
#include "dnodeCheck.h"
|
#include "dnodeCheck.h"
|
||||||
|
|
||||||
|
@ -30,8 +28,8 @@ typedef struct {
|
||||||
void (*stopFp)();
|
void (*stopFp)();
|
||||||
} SCheckItem;
|
} SCheckItem;
|
||||||
|
|
||||||
static SCheckItem tsCheckItem[TSDB_CHECK_ITEM_MAX] = {{0}};
|
static SCheckItem tsCheckItem[TSDB_CHECK_ITEM_MAX] = {{0}};
|
||||||
int64_t tsMinFreeMemSizeForStart = 0;
|
int64_t tsMinFreeMemSizeForStart = 0;
|
||||||
|
|
||||||
static int bindTcpPort(int port) {
|
static int bindTcpPort(int port) {
|
||||||
int serverSocket;
|
int serverSocket;
|
||||||
|
@ -264,8 +262,6 @@ int32_t dnodeInitCheck() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dInfo("dnode check is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,283 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "cJSON.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
#include "hash.h"
|
||||||
|
#include "dnode.h"
|
||||||
|
#include "dnodeInt.h"
|
||||||
|
#include "dnodeEps.h"
|
||||||
|
|
||||||
|
static SDnodeEps *tsEps = NULL;
|
||||||
|
static SHashObj * tsEpsHash = NULL;
|
||||||
|
static pthread_mutex_t tsEpsMutex;
|
||||||
|
|
||||||
|
static int32_t dnodeReadEps();
|
||||||
|
static int32_t dnodeWriteEps();
|
||||||
|
static void dnodeResetEps(SDnodeEps *eps);
|
||||||
|
static void dnodePrintEps(SDnodeEps *eps);
|
||||||
|
|
||||||
|
int32_t dnodeInitEps() {
|
||||||
|
pthread_mutex_init(&tsEpsMutex, NULL);
|
||||||
|
tsEpsHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, true);
|
||||||
|
dnodeResetEps(NULL);
|
||||||
|
int32_t ret = dnodeReadEps();
|
||||||
|
if (ret == 0) {
|
||||||
|
dInfo("dnode eps is initialized");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeCleanupEps() {
|
||||||
|
pthread_mutex_lock(&tsEpsMutex);
|
||||||
|
if (tsEps) {
|
||||||
|
free(tsEps);
|
||||||
|
tsEps = NULL;
|
||||||
|
}
|
||||||
|
if (tsEpsHash) {
|
||||||
|
taosHashCleanup(tsEpsHash);
|
||||||
|
tsEpsHash = NULL;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&tsEpsMutex);
|
||||||
|
pthread_mutex_destroy(&tsEpsMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeUpdateEps(SDnodeEps *eps) {
|
||||||
|
if (eps == NULL) return;
|
||||||
|
|
||||||
|
eps->dnodeNum = htonl(eps->dnodeNum);
|
||||||
|
for (int32_t i = 0; i < eps->dnodeNum; ++i) {
|
||||||
|
eps->dnodeEps[i].dnodeId = htonl(eps->dnodeEps[i].dnodeId);
|
||||||
|
eps->dnodeEps[i].dnodePort = htons(eps->dnodeEps[i].dnodePort);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&tsEpsMutex);
|
||||||
|
if (eps->dnodeNum != tsEps->dnodeNum) {
|
||||||
|
dnodeResetEps(eps);
|
||||||
|
dnodeWriteEps();
|
||||||
|
} else {
|
||||||
|
int32_t size = sizeof(SDnodeEps) + eps->dnodeNum * sizeof(SDnodeEp);
|
||||||
|
if (memcmp(eps, tsEps, size) != 0) {
|
||||||
|
dnodeResetEps(eps);
|
||||||
|
dnodeWriteEps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&tsEpsMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dnodeCheckEpChanged(int32_t dnodeId, char *epstr) {
|
||||||
|
bool changed = false;
|
||||||
|
pthread_mutex_lock(&tsEpsMutex);
|
||||||
|
SDnodeEp *ep = taosHashGet(tsEpsHash, &dnodeId, sizeof(int32_t));
|
||||||
|
if (ep != NULL) {
|
||||||
|
char epSaved[TSDB_EP_LEN + 1];
|
||||||
|
snprintf(epSaved, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort);
|
||||||
|
changed = strcmp(epstr, epSaved) != 0;
|
||||||
|
tstrncpy(epstr, epSaved, TSDB_EP_LEN);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&tsEpsMutex);
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeUpdateEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port) {
|
||||||
|
pthread_mutex_lock(&tsEpsMutex);
|
||||||
|
SDnodeEp *ep = taosHashGet(tsEpsHash, &dnodeId, sizeof(int32_t));
|
||||||
|
if (ep != NULL) {
|
||||||
|
if (port) *port = ep->dnodePort;
|
||||||
|
if (fqdn) tstrncpy(fqdn, ep->dnodeFqdn, TSDB_FQDN_LEN);
|
||||||
|
if (epstr) snprintf(epstr, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&tsEpsMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dnodeResetEps(SDnodeEps *eps) {
|
||||||
|
if (eps == NULL) {
|
||||||
|
int32_t size = sizeof(SDnodeEps) + sizeof(SDnodeEp);
|
||||||
|
if (tsEps == NULL) {
|
||||||
|
tsEps = calloc(1, size);
|
||||||
|
} else {
|
||||||
|
tsEps->dnodeNum = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
assert(tsEps);
|
||||||
|
|
||||||
|
int32_t size = sizeof(SDnodeEps) + sizeof(SDnodeEp) * eps->dnodeNum;
|
||||||
|
if (eps->dnodeNum > tsEps->dnodeNum) {
|
||||||
|
tsEps = realloc(tsEps, size);
|
||||||
|
}
|
||||||
|
memcpy(tsEps, eps, size);
|
||||||
|
dnodePrintEps(eps);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < tsEps->dnodeNum; ++i) {
|
||||||
|
SDnodeEp *ep = &tsEps->dnodeEps[i];
|
||||||
|
taosHashPut(tsEpsHash, &ep->dnodeId, sizeof(int32_t), ep, sizeof(SDnodeEp));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dnodePrintEps(SDnodeEps *eps) {
|
||||||
|
dDebug("print dnodeEp, dnodeNum:%d", eps->dnodeNum);
|
||||||
|
for (int32_t i = 0; i < eps->dnodeNum; i++) {
|
||||||
|
SDnodeEp *ep = &eps->dnodeEps[i];
|
||||||
|
dDebug("dnodeId:%d, dnodeFqdn:%s dnodePort:%u", ep->dnodeId, ep->dnodeFqdn, ep->dnodePort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dnodeReadEps() {
|
||||||
|
int32_t ret = -1;
|
||||||
|
int32_t len = 0;
|
||||||
|
int32_t maxLen = 30000;
|
||||||
|
char * content = calloc(1, maxLen + 1);
|
||||||
|
cJSON * root = NULL;
|
||||||
|
FILE * fp = NULL;
|
||||||
|
SDnodeEps *eps = NULL;
|
||||||
|
|
||||||
|
char file[TSDB_FILENAME_LEN + 20] = {0};
|
||||||
|
sprintf(file, "%s/dnodeEps.json", tsDnodeDir);
|
||||||
|
|
||||||
|
fp = fopen(file, "r");
|
||||||
|
if (!fp) {
|
||||||
|
dDebug("failed to read %s, file not exist", file);
|
||||||
|
goto PRASE_EPS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = fread(content, 1, maxLen, fp);
|
||||||
|
if (len <= 0) {
|
||||||
|
dError("failed to read %s, content is null", file);
|
||||||
|
goto PRASE_EPS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
content[len] = 0;
|
||||||
|
root = cJSON_Parse(content);
|
||||||
|
if (root == NULL) {
|
||||||
|
dError("failed to read %s, invalid json format", file);
|
||||||
|
goto PRASE_EPS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *dnodeNum = cJSON_GetObjectItem(root, "dnodeNum");
|
||||||
|
if (!dnodeNum || dnodeNum->type != cJSON_Number) {
|
||||||
|
dError("failed to read %s, dnodeNum not found", file);
|
||||||
|
goto PRASE_EPS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *dnodeInfos = cJSON_GetObjectItem(root, "dnodeInfos");
|
||||||
|
if (!dnodeInfos || dnodeInfos->type != cJSON_Array) {
|
||||||
|
dError("failed to read %s, dnodeInfos not found", file);
|
||||||
|
goto PRASE_EPS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t dnodeInfosSize = cJSON_GetArraySize(dnodeInfos);
|
||||||
|
if (dnodeInfosSize != dnodeNum->valueint) {
|
||||||
|
dError("failed to read %s, dnodeInfos size:%d not matched dnodeNum:%d", file, dnodeInfosSize,
|
||||||
|
(int32_t)dnodeNum->valueint);
|
||||||
|
goto PRASE_EPS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t epsSize = sizeof(SDnodeEps) + dnodeInfosSize * sizeof(SDnodeEp);
|
||||||
|
eps = calloc(1, epsSize);
|
||||||
|
eps->dnodeNum = dnodeInfosSize;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < dnodeInfosSize; ++i) {
|
||||||
|
cJSON *dnodeInfo = cJSON_GetArrayItem(dnodeInfos, i);
|
||||||
|
if (dnodeInfo == NULL) break;
|
||||||
|
|
||||||
|
SDnodeEp *ep = &eps->dnodeEps[i];
|
||||||
|
|
||||||
|
cJSON *dnodeId = cJSON_GetObjectItem(dnodeInfo, "dnodeId");
|
||||||
|
if (!dnodeId || dnodeId->type != cJSON_Number) {
|
||||||
|
dError("failed to read %s, dnodeId not found", file);
|
||||||
|
goto PRASE_EPS_OVER;
|
||||||
|
}
|
||||||
|
ep->dnodeId = dnodeId->valueint;
|
||||||
|
|
||||||
|
cJSON *dnodeFqdn = cJSON_GetObjectItem(dnodeInfo, "dnodeFqdn");
|
||||||
|
if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) {
|
||||||
|
dError("failed to read %s, dnodeFqdn not found", file);
|
||||||
|
goto PRASE_EPS_OVER;
|
||||||
|
}
|
||||||
|
strncpy(ep->dnodeFqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN);
|
||||||
|
|
||||||
|
cJSON *dnodePort = cJSON_GetObjectItem(dnodeInfo, "dnodePort");
|
||||||
|
if (!dnodePort || dnodePort->type != cJSON_Number) {
|
||||||
|
dError("failed to read %s, dnodePort not found", file);
|
||||||
|
goto PRASE_EPS_OVER;
|
||||||
|
}
|
||||||
|
ep->dnodePort = (uint16_t)dnodePort->valueint;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
dInfo("read file %s successed", file);
|
||||||
|
dnodePrintEps(eps);
|
||||||
|
|
||||||
|
PRASE_EPS_OVER:
|
||||||
|
if (content != NULL) free(content);
|
||||||
|
if (root != NULL) cJSON_Delete(root);
|
||||||
|
if (fp != NULL) fclose(fp);
|
||||||
|
if (ret != 0) {
|
||||||
|
if (eps) free(eps);
|
||||||
|
eps = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dnodeResetEps(eps);
|
||||||
|
if (eps) free(eps);
|
||||||
|
|
||||||
|
dnodeUpdateEp(dnodeGetDnodeId(), tsLocalEp, tsLocalFqdn, &tsServerPort);
|
||||||
|
|
||||||
|
terrno = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dnodeWriteEps() {
|
||||||
|
char file[TSDB_FILENAME_LEN + 20] = {0};
|
||||||
|
sprintf(file, "%s/dnodeEps.json", tsDnodeDir);
|
||||||
|
|
||||||
|
FILE *fp = fopen(file, "w");
|
||||||
|
if (!fp) {
|
||||||
|
dError("failed to write %s, reason:%s", file, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t len = 0;
|
||||||
|
int32_t maxLen = 30000;
|
||||||
|
char * content = calloc(1, maxLen + 1);
|
||||||
|
|
||||||
|
len += snprintf(content + len, maxLen - len, "{\n");
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"dnodeNum\": %d,\n", tsEps->dnodeNum);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"dnodeInfos\": [{\n");
|
||||||
|
for (int32_t i = 0; i < tsEps->dnodeNum; ++i) {
|
||||||
|
SDnodeEp *ep = &tsEps->dnodeEps[i];
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", ep->dnodeId);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"dnodeFqdn\": \"%s\",\n", ep->dnodeFqdn);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"dnodePort\": %u\n", ep->dnodePort);
|
||||||
|
if (i < tsEps->dnodeNum - 1) {
|
||||||
|
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||||
|
} else {
|
||||||
|
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len += snprintf(content + len, maxLen - len, "}\n");
|
||||||
|
|
||||||
|
fwrite(content, 1, len, fp);
|
||||||
|
fflush(fp);
|
||||||
|
fclose(fp);
|
||||||
|
free(content);
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
|
dInfo("successed to write %s", file);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,288 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "cJSON.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
#include "mnode.h"
|
||||||
|
#include "dnode.h"
|
||||||
|
#include "dnodeInt.h"
|
||||||
|
#include "dnodeMInfos.h"
|
||||||
|
|
||||||
|
static SMnodeInfos tsMInfos;
|
||||||
|
static SRpcEpSet tsMEpSet;
|
||||||
|
static pthread_mutex_t tsMInfosMutex;
|
||||||
|
|
||||||
|
static void dnodeResetMInfos(SMnodeInfos *minfos);
|
||||||
|
static void dnodePrintMInfos(SMnodeInfos *minfos);
|
||||||
|
static int32_t dnodeReadMInfos();
|
||||||
|
static int32_t dnodeWriteMInfos();
|
||||||
|
|
||||||
|
int32_t dnodeInitMInfos() {
|
||||||
|
pthread_mutex_init(&tsMInfosMutex, NULL);
|
||||||
|
dnodeResetMInfos(NULL);
|
||||||
|
int32_t ret = dnodeReadMInfos();
|
||||||
|
if (ret == 0) {
|
||||||
|
dInfo("dnode minfos is initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeCleanupMInfos() { pthread_mutex_destroy(&tsMInfosMutex); }
|
||||||
|
|
||||||
|
void dnodeUpdateMInfos(SMnodeInfos *minfos) {
|
||||||
|
if (minfos->mnodeNum <= 0 || minfos->mnodeNum > 3) {
|
||||||
|
dError("invalid mnode infos, mnodeNum:%d", minfos->mnodeNum);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < minfos->mnodeNum; ++i) {
|
||||||
|
SMnodeInfo *minfo = &minfos->mnodeInfos[i];
|
||||||
|
minfo->mnodeId = htonl(minfo->mnodeId);
|
||||||
|
if (minfo->mnodeId <= 0 || strlen(minfo->mnodeEp) <= 5) {
|
||||||
|
dError("invalid mnode info:%d, mnodeId:%d mnodeEp:%s", i, minfo->mnodeId, minfo->mnodeEp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&tsMInfosMutex);
|
||||||
|
if (minfos->mnodeNum != tsMInfos.mnodeNum) {
|
||||||
|
dnodeResetMInfos(minfos);
|
||||||
|
dnodeWriteMInfos();
|
||||||
|
sdbUpdateAsync();
|
||||||
|
} else {
|
||||||
|
int32_t size = sizeof(SMnodeInfos);
|
||||||
|
if (memcmp(minfos, &tsMInfos, size) != 0) {
|
||||||
|
dnodeResetMInfos(minfos);
|
||||||
|
dnodeWriteMInfos();
|
||||||
|
sdbUpdateAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&tsMInfosMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeUpdateEpSetForPeer(SRpcEpSet *ep) {
|
||||||
|
if (ep->numOfEps <= 0) {
|
||||||
|
dError("mnode EP list for peer is changed, but content is invalid, discard it");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&tsMInfosMutex);
|
||||||
|
dInfo("mnode EP list for peer is changed, numOfEps:%d inUse:%d", ep->numOfEps, ep->inUse);
|
||||||
|
for (int i = 0; i < ep->numOfEps; ++i) {
|
||||||
|
ep->port[i] -= TSDB_PORT_DNODEDNODE;
|
||||||
|
dInfo("mnode index:%d %s:%u", i, ep->fqdn[i], ep->port[i]);
|
||||||
|
}
|
||||||
|
tsMEpSet = *ep;
|
||||||
|
pthread_mutex_unlock(&tsMInfosMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dnodeIsMasterEp(char *ep) {
|
||||||
|
pthread_mutex_lock(&tsMInfosMutex);
|
||||||
|
bool isMaster = strcmp(ep, tsMInfos.mnodeInfos[tsMEpSet.inUse].mnodeEp) == 0;
|
||||||
|
pthread_mutex_unlock(&tsMInfosMutex);
|
||||||
|
|
||||||
|
return isMaster;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeGetMInfos(SMnodeInfos *minfos) {
|
||||||
|
pthread_mutex_lock(&tsMInfosMutex);
|
||||||
|
memcpy(minfos, &tsMInfos, sizeof(SMnodeInfos));
|
||||||
|
for (int32_t i = 0; i < tsMInfos.mnodeNum; ++i) {
|
||||||
|
minfos->mnodeInfos[i].mnodeId = htonl(tsMInfos.mnodeInfos[i].mnodeId);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&tsMInfosMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeGetEpSetForPeer(SRpcEpSet *epSet) {
|
||||||
|
pthread_mutex_lock(&tsMInfosMutex);
|
||||||
|
*epSet = tsMEpSet;
|
||||||
|
for (int i = 0; i < epSet->numOfEps; ++i) {
|
||||||
|
epSet->port[i] += TSDB_PORT_DNODEDNODE;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&tsMInfosMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeGetEpSetForShell(SRpcEpSet *epSet) {
|
||||||
|
pthread_mutex_lock(&tsMInfosMutex);
|
||||||
|
*epSet = tsMEpSet;
|
||||||
|
pthread_mutex_unlock(&tsMInfosMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dnodePrintMInfos(SMnodeInfos *minfos) {
|
||||||
|
dInfo("print mnode infos, mnodeNum:%d inUse:%d", minfos->mnodeNum, minfos->inUse);
|
||||||
|
for (int32_t i = 0; i < minfos->mnodeNum; i++) {
|
||||||
|
dInfo("mnode index:%d, %s", minfos->mnodeInfos[i].mnodeId, minfos->mnodeInfos[i].mnodeEp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dnodeResetMInfos(SMnodeInfos *minfos) {
|
||||||
|
if (minfos == NULL) {
|
||||||
|
tsMEpSet.numOfEps = 1;
|
||||||
|
taosGetFqdnPortFromEp(tsFirst, tsMEpSet.fqdn[0], &tsMEpSet.port[0]);
|
||||||
|
|
||||||
|
if (strcmp(tsSecond, tsFirst) != 0) {
|
||||||
|
tsMEpSet.numOfEps = 2;
|
||||||
|
taosGetFqdnPortFromEp(tsSecond, tsMEpSet.fqdn[1], &tsMEpSet.port[1]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minfos->mnodeNum == 0) return;
|
||||||
|
|
||||||
|
int32_t size = sizeof(SMnodeInfos);
|
||||||
|
memcpy(&tsMInfos, minfos, size);
|
||||||
|
|
||||||
|
tsMEpSet.inUse = tsMInfos.inUse;
|
||||||
|
tsMEpSet.numOfEps = tsMInfos.mnodeNum;
|
||||||
|
for (int32_t i = 0; i < tsMInfos.mnodeNum; i++) {
|
||||||
|
taosGetFqdnPortFromEp(tsMInfos.mnodeInfos[i].mnodeEp, tsMEpSet.fqdn[i], &tsMEpSet.port[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
dnodePrintMInfos(minfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dnodeReadMInfos() {
|
||||||
|
int32_t len = 0;
|
||||||
|
int32_t maxLen = 2000;
|
||||||
|
char * content = calloc(1, maxLen + 1);
|
||||||
|
cJSON * root = NULL;
|
||||||
|
FILE * fp = NULL;
|
||||||
|
SMnodeInfos minfos = {0};
|
||||||
|
|
||||||
|
char file[TSDB_FILENAME_LEN + 20] = {0};
|
||||||
|
sprintf(file, "%s/mnodeEpSet.json", tsDnodeDir);
|
||||||
|
|
||||||
|
fp = fopen(file, "r");
|
||||||
|
if (!fp) {
|
||||||
|
dDebug("failed to read %s, file not exist", file);
|
||||||
|
goto PARSE_MINFOS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = fread(content, 1, maxLen, fp);
|
||||||
|
if (len <= 0) {
|
||||||
|
dError("failed to read %s, content is null", file);
|
||||||
|
goto PARSE_MINFOS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
content[len] = 0;
|
||||||
|
root = cJSON_Parse(content);
|
||||||
|
if (root == NULL) {
|
||||||
|
dError("failed to read %s, invalid json format", file);
|
||||||
|
goto PARSE_MINFOS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *inUse = cJSON_GetObjectItem(root, "inUse");
|
||||||
|
if (!inUse || inUse->type != cJSON_Number) {
|
||||||
|
dError("failed to read mnodeEpSet.json, inUse not found");
|
||||||
|
goto PARSE_MINFOS_OVER;
|
||||||
|
}
|
||||||
|
tsMInfos.inUse = inUse->valueint;
|
||||||
|
|
||||||
|
cJSON *nodeNum = cJSON_GetObjectItem(root, "nodeNum");
|
||||||
|
if (!nodeNum || nodeNum->type != cJSON_Number) {
|
||||||
|
dError("failed to read mnodeEpSet.json, nodeNum not found");
|
||||||
|
goto PARSE_MINFOS_OVER;
|
||||||
|
}
|
||||||
|
minfos.mnodeNum = nodeNum->valueint;
|
||||||
|
|
||||||
|
cJSON *nodeInfos = cJSON_GetObjectItem(root, "nodeInfos");
|
||||||
|
if (!nodeInfos || nodeInfos->type != cJSON_Array) {
|
||||||
|
dError("failed to read mnodeEpSet.json, nodeInfos not found");
|
||||||
|
goto PARSE_MINFOS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
int size = cJSON_GetArraySize(nodeInfos);
|
||||||
|
if (size != minfos.mnodeNum) {
|
||||||
|
dError("failed to read mnodeEpSet.json, nodeInfos size not matched");
|
||||||
|
goto PARSE_MINFOS_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
cJSON *nodeInfo = cJSON_GetArrayItem(nodeInfos, i);
|
||||||
|
if (nodeInfo == NULL) continue;
|
||||||
|
|
||||||
|
cJSON *nodeId = cJSON_GetObjectItem(nodeInfo, "nodeId");
|
||||||
|
if (!nodeId || nodeId->type != cJSON_Number) {
|
||||||
|
dError("failed to read mnodeEpSet.json, nodeId not found");
|
||||||
|
goto PARSE_MINFOS_OVER;
|
||||||
|
}
|
||||||
|
minfos.mnodeInfos[i].mnodeId = nodeId->valueint;
|
||||||
|
|
||||||
|
cJSON *nodeEp = cJSON_GetObjectItem(nodeInfo, "nodeEp");
|
||||||
|
if (!nodeEp || nodeEp->type != cJSON_String || nodeEp->valuestring == NULL) {
|
||||||
|
dError("failed to read mnodeEpSet.json, nodeName not found");
|
||||||
|
goto PARSE_MINFOS_OVER;
|
||||||
|
}
|
||||||
|
strncpy(minfos.mnodeInfos[i].mnodeEp, nodeEp->valuestring, TSDB_EP_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
dInfo("read file %s successed", file);
|
||||||
|
dnodePrintMInfos(&minfos);
|
||||||
|
|
||||||
|
PARSE_MINFOS_OVER:
|
||||||
|
if (content != NULL) free(content);
|
||||||
|
if (root != NULL) cJSON_Delete(root);
|
||||||
|
if (fp != NULL) fclose(fp);
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < minfos.mnodeNum; ++i) {
|
||||||
|
SMnodeInfo *mInfo = &minfos.mnodeInfos[i];
|
||||||
|
dnodeUpdateEp(mInfo->mnodeId, mInfo->mnodeEp, NULL, NULL);
|
||||||
|
}
|
||||||
|
dnodeResetMInfos(&minfos);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dnodeWriteMInfos() {
|
||||||
|
char file[TSDB_FILENAME_LEN + 20] = {0};
|
||||||
|
sprintf(file, "%s/mnodeEpSet.json", tsDnodeDir);
|
||||||
|
|
||||||
|
FILE *fp = fopen(file, "w");
|
||||||
|
if (!fp) {
|
||||||
|
dError("failed to write %s, reason:%s", file, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t len = 0;
|
||||||
|
int32_t maxLen = 2000;
|
||||||
|
char * content = calloc(1, maxLen + 1);
|
||||||
|
|
||||||
|
len += snprintf(content + len, maxLen - len, "{\n");
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"inUse\": %d,\n", tsMInfos.inUse);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"nodeNum\": %d,\n", tsMInfos.mnodeNum);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"nodeInfos\": [{\n");
|
||||||
|
for (int32_t i = 0; i < tsMInfos.mnodeNum; i++) {
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"nodeId\": %d,\n", tsMInfos.mnodeInfos[i].mnodeId);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"nodeEp\": \"%s\"\n", tsMInfos.mnodeInfos[i].mnodeEp);
|
||||||
|
if (i < tsMInfos.mnodeNum - 1) {
|
||||||
|
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||||
|
} else {
|
||||||
|
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len += snprintf(content + len, maxLen - len, "}\n");
|
||||||
|
|
||||||
|
fwrite(content, 1, len, fp);
|
||||||
|
fflush(fp);
|
||||||
|
fclose(fp);
|
||||||
|
free(content);
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
|
dInfo("successed to write %s", file);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -58,7 +58,7 @@ int32_t dnodeInitMnodePeer() {
|
||||||
dDebug("dnode mpeer worker:%d is created", i);
|
dDebug("dnode mpeer worker:%d is created", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnode mpeer is opened, workers:%d qset:%p", tsMPeerPool.maxNum, tsMPeerQset);
|
dDebug("dnode mpeer is initialized, workers:%d qset:%p", tsMPeerPool.maxNum, tsMPeerQset);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ int32_t dnodeInitMnodeRead() {
|
||||||
dDebug("dnode mread worker:%d is created", i);
|
dDebug("dnode mread worker:%d is created", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnode mread is opened, workers:%d qset:%p", tsMReadPool.maxNum, tsMReadQset);
|
dDebug("dnode mread is initialized, workers:%d qset:%p", tsMReadPool.maxNum, tsMReadQset);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ int32_t dnodeInitMnodeWrite() {
|
||||||
dDebug("dnode mwrite worker:%d is created", i);
|
dDebug("dnode mwrite worker:%d is created", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnode mwrite is opened, workers:%d qset:%p", tsMWritePool.maxNum, tsMWriteQset);
|
dDebug("dnode mwrite is initialized, workers:%d qset:%p", tsMWritePool.maxNum, tsMWriteQset);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,15 @@
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "tconfig.h"
|
#include "tconfig.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
|
#include "twal.h"
|
||||||
#include "dnode.h"
|
#include "dnode.h"
|
||||||
#include "dnodeInt.h"
|
#include "dnodeInt.h"
|
||||||
#include "dnodeMgmt.h"
|
#include "dnodeMgmt.h"
|
||||||
#include "dnodePeer.h"
|
#include "dnodePeer.h"
|
||||||
#include "dnodeModule.h"
|
#include "dnodeModule.h"
|
||||||
|
#include "dnodeEps.h"
|
||||||
|
#include "dnodeMInfos.h"
|
||||||
|
#include "dnodeCfg.h"
|
||||||
#include "dnodeCheck.h"
|
#include "dnodeCheck.h"
|
||||||
#include "dnodeVRead.h"
|
#include "dnodeVRead.h"
|
||||||
#include "dnodeVWrite.h"
|
#include "dnodeVWrite.h"
|
||||||
|
@ -33,23 +37,29 @@
|
||||||
#include "dnodeShell.h"
|
#include "dnodeShell.h"
|
||||||
#include "dnodeTelemetry.h"
|
#include "dnodeTelemetry.h"
|
||||||
|
|
||||||
static int32_t dnodeInitStorage();
|
|
||||||
static void dnodeCleanupStorage();
|
|
||||||
static void dnodeSetRunStatus(SDnodeRunStatus status);
|
|
||||||
static void dnodeCheckDataDirOpenned(char *dir);
|
|
||||||
static SDnodeRunStatus tsDnodeRunStatus = TSDB_DNODE_RUN_STATUS_STOPPED;
|
static SDnodeRunStatus tsDnodeRunStatus = TSDB_DNODE_RUN_STATUS_STOPPED;
|
||||||
|
|
||||||
|
static int32_t dnodeInitStorage();
|
||||||
|
static void dnodeCleanupStorage();
|
||||||
|
static void dnodeSetRunStatus(SDnodeRunStatus status);
|
||||||
|
static void dnodeCheckDataDirOpenned(char *dir);
|
||||||
static int32_t dnodeInitComponents();
|
static int32_t dnodeInitComponents();
|
||||||
static void dnodeCleanupComponents(int32_t stepId);
|
static void dnodeCleanupComponents(int32_t stepId);
|
||||||
static int dnodeCreateDir(const char *dir);
|
static int dnodeCreateDir(const char *dir);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *const name;
|
const char *const name;
|
||||||
int (*init)();
|
int32_t (*init)();
|
||||||
void (*cleanup)();
|
void (*cleanup)();
|
||||||
} SDnodeComponent;
|
} SDnodeComponent;
|
||||||
|
|
||||||
static const SDnodeComponent tsDnodeComponents[] = {
|
static const SDnodeComponent tsDnodeComponents[] = {
|
||||||
{"storage", dnodeInitStorage, dnodeCleanupStorage},
|
{"storage", dnodeInitStorage, dnodeCleanupStorage},
|
||||||
|
{"dnodecfg", dnodeInitCfg, dnodeCleanupCfg},
|
||||||
|
{"dnodeeps", dnodeInitEps, dnodeCleanupEps},
|
||||||
|
{"globalcfg" ,taosCheckGlobalCfg, NULL},
|
||||||
|
{"mnodeinfos",dnodeInitMInfos, dnodeCleanupMInfos},
|
||||||
|
{"wal", walInit, walCleanUp},
|
||||||
{"check", dnodeInitCheck, dnodeCleanupCheck}, // NOTES: dnodeInitCheck must be behind the dnodeinitStorage component !!!
|
{"check", dnodeInitCheck, dnodeCleanupCheck}, // NOTES: dnodeInitCheck must be behind the dnodeinitStorage component !!!
|
||||||
{"vread", dnodeInitVnodeRead, dnodeCleanupVnodeRead},
|
{"vread", dnodeInitVnodeRead, dnodeCleanupVnodeRead},
|
||||||
{"vwrite", dnodeInitVnodeWrite, dnodeCleanupVnodeWrite},
|
{"vwrite", dnodeInitVnodeWrite, dnodeCleanupVnodeWrite},
|
||||||
|
@ -75,7 +85,9 @@ static int dnodeCreateDir(const char *dir) {
|
||||||
|
|
||||||
static void dnodeCleanupComponents(int32_t stepId) {
|
static void dnodeCleanupComponents(int32_t stepId) {
|
||||||
for (int32_t i = stepId; i >= 0; i--) {
|
for (int32_t i = stepId; i >= 0; i--) {
|
||||||
tsDnodeComponents[i].cleanup();
|
if (tsDnodeComponents[i].cleanup) {
|
||||||
|
(*tsDnodeComponents[i].cleanup)();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,14 +124,13 @@ int32_t dnodeInitSystem() {
|
||||||
printf("failed to init log file\n");
|
printf("failed to init log file\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!taosReadGlobalCfg() || !taosCheckGlobalCfg()) {
|
if (!taosReadGlobalCfg()) {
|
||||||
taosPrintGlobalCfg();
|
taosPrintGlobalCfg();
|
||||||
dError("TDengine read global config failed");
|
dError("TDengine read global config failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
taosPrintGlobalCfg();
|
|
||||||
|
|
||||||
dInfo("start to initialize TDengine on %s", tsLocalEp);
|
dInfo("start to initialize TDengine");
|
||||||
|
|
||||||
if (dnodeInitComponents() != 0) {
|
if (dnodeInitComponents() != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -198,7 +209,7 @@ static int32_t dnodeInitStorage() {
|
||||||
|
|
||||||
dnodeCheckDataDirOpenned(tsDnodeDir);
|
dnodeCheckDataDirOpenned(tsDnodeDir);
|
||||||
|
|
||||||
dInfo("storage directory is initialized");
|
dInfo("dnode storage is initialized at %s", tsDnodeDir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,12 +31,13 @@
|
||||||
#include "mnode.h"
|
#include "mnode.h"
|
||||||
#include "dnodeInt.h"
|
#include "dnodeInt.h"
|
||||||
#include "dnodeMgmt.h"
|
#include "dnodeMgmt.h"
|
||||||
|
#include "dnodeEps.h"
|
||||||
|
#include "dnodeCfg.h"
|
||||||
|
#include "dnodeMInfos.h"
|
||||||
#include "dnodeVRead.h"
|
#include "dnodeVRead.h"
|
||||||
#include "dnodeVWrite.h"
|
#include "dnodeVWrite.h"
|
||||||
#include "dnodeModule.h"
|
#include "dnodeModule.h"
|
||||||
|
|
||||||
#define MPEER_CONTENT_LEN 2000
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
int32_t threadIndex;
|
int32_t threadIndex;
|
||||||
|
@ -46,23 +47,13 @@ typedef struct {
|
||||||
int32_t * vnodeList;
|
int32_t * vnodeList;
|
||||||
} SOpenVnodeThread;
|
} SOpenVnodeThread;
|
||||||
|
|
||||||
void * tsDnodeTmr = NULL;
|
void * tsDnodeTmr = NULL;
|
||||||
static void * tsStatusTimer = NULL;
|
static void * tsStatusTimer = NULL;
|
||||||
static uint32_t tsRebootTime;
|
static uint32_t tsRebootTime;
|
||||||
|
static taos_qset tsMgmtQset = NULL;
|
||||||
|
static taos_queue tsMgmtQueue = NULL;
|
||||||
|
static pthread_t tsQthread;
|
||||||
|
|
||||||
static SRpcEpSet tsDMnodeEpSet = {0};
|
|
||||||
static SDMMnodeInfos tsDMnodeInfos = {0};
|
|
||||||
static SDMDnodeCfg tsDnodeCfg = {0};
|
|
||||||
static taos_qset tsMgmtQset = NULL;
|
|
||||||
static taos_queue tsMgmtQueue = NULL;
|
|
||||||
static pthread_t tsQthread;
|
|
||||||
|
|
||||||
static void dnodeUpdateMnodeInfos(SDMMnodeInfos *pMnodes);
|
|
||||||
static bool dnodeReadMnodeInfos();
|
|
||||||
static void dnodeSaveMnodeInfos();
|
|
||||||
static void dnodeUpdateDnodeCfg(SDMDnodeCfg *pCfg);
|
|
||||||
static bool dnodeReadDnodeCfg();
|
|
||||||
static void dnodeSaveDnodeCfg();
|
|
||||||
static void dnodeProcessStatusRsp(SRpcMsg *pMsg);
|
static void dnodeProcessStatusRsp(SRpcMsg *pMsg);
|
||||||
static void dnodeSendStatusMsg(void *handle, void *tmrId);
|
static void dnodeSendStatusMsg(void *handle, void *tmrId);
|
||||||
static void *dnodeProcessMgmtQueue(void *param);
|
static void *dnodeProcessMgmtQueue(void *param);
|
||||||
|
@ -74,7 +65,7 @@ static int32_t dnodeProcessAlterVnodeMsg(SRpcMsg *pMsg);
|
||||||
static int32_t dnodeProcessDropVnodeMsg(SRpcMsg *pMsg);
|
static int32_t dnodeProcessDropVnodeMsg(SRpcMsg *pMsg);
|
||||||
static int32_t dnodeProcessAlterStreamMsg(SRpcMsg *pMsg);
|
static int32_t dnodeProcessAlterStreamMsg(SRpcMsg *pMsg);
|
||||||
static int32_t dnodeProcessConfigDnodeMsg(SRpcMsg *pMsg);
|
static int32_t dnodeProcessConfigDnodeMsg(SRpcMsg *pMsg);
|
||||||
static int32_t dnodeProcessCreateMnodeMsg(SRpcMsg *pMsg);
|
static int32_t dnodeProcessCreateMnodeMsg(SRpcMsg *pMsg);
|
||||||
static int32_t (*dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *pMsg);
|
static int32_t (*dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *pMsg);
|
||||||
|
|
||||||
int32_t dnodeInitMgmt() {
|
int32_t dnodeInitMgmt() {
|
||||||
|
@ -86,28 +77,8 @@ int32_t dnodeInitMgmt() {
|
||||||
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_CREATE_MNODE] = dnodeProcessCreateMnodeMsg;
|
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_CREATE_MNODE] = dnodeProcessCreateMnodeMsg;
|
||||||
|
|
||||||
dnodeAddClientRspHandle(TSDB_MSG_TYPE_DM_STATUS_RSP, dnodeProcessStatusRsp);
|
dnodeAddClientRspHandle(TSDB_MSG_TYPE_DM_STATUS_RSP, dnodeProcessStatusRsp);
|
||||||
dnodeReadDnodeCfg();
|
|
||||||
tsRebootTime = taosGetTimestampSec();
|
tsRebootTime = taosGetTimestampSec();
|
||||||
|
|
||||||
if (!dnodeReadMnodeInfos()) {
|
|
||||||
memset(&tsDMnodeEpSet, 0, sizeof(SRpcEpSet));
|
|
||||||
memset(&tsDMnodeInfos, 0, sizeof(SDMMnodeInfos));
|
|
||||||
|
|
||||||
tsDMnodeEpSet.numOfEps = 1;
|
|
||||||
taosGetFqdnPortFromEp(tsFirst, tsDMnodeEpSet.fqdn[0], &tsDMnodeEpSet.port[0]);
|
|
||||||
|
|
||||||
if (strcmp(tsSecond, tsFirst) != 0) {
|
|
||||||
tsDMnodeEpSet.numOfEps = 2;
|
|
||||||
taosGetFqdnPortFromEp(tsSecond, tsDMnodeEpSet.fqdn[1], &tsDMnodeEpSet.port[1]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tsDMnodeEpSet.inUse = tsDMnodeInfos.inUse;
|
|
||||||
tsDMnodeEpSet.numOfEps = tsDMnodeInfos.nodeNum;
|
|
||||||
for (int32_t i = 0; i < tsDMnodeInfos.nodeNum; i++) {
|
|
||||||
taosGetFqdnPortFromEp(tsDMnodeInfos.nodeInfos[i].nodeEp, tsDMnodeEpSet.fqdn[i], &tsDMnodeEpSet.port[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t code = vnodeInitResources();
|
int32_t code = vnodeInitResources();
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
dnodeCleanupMgmt();
|
dnodeCleanupMgmt();
|
||||||
|
@ -381,7 +352,7 @@ static void dnodeCloseVnodes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* dnodeParseVnodeMsg(SRpcMsg *rpcMsg) {
|
static void* dnodeParseVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
SMDCreateVnodeMsg *pCreate = rpcMsg->pCont;
|
SCreateVnodeMsg *pCreate = rpcMsg->pCont;
|
||||||
pCreate->cfg.vgId = htonl(pCreate->cfg.vgId);
|
pCreate->cfg.vgId = htonl(pCreate->cfg.vgId);
|
||||||
pCreate->cfg.cfgVersion = htonl(pCreate->cfg.cfgVersion);
|
pCreate->cfg.cfgVersion = htonl(pCreate->cfg.cfgVersion);
|
||||||
pCreate->cfg.maxTables = htonl(pCreate->cfg.maxTables);
|
pCreate->cfg.maxTables = htonl(pCreate->cfg.maxTables);
|
||||||
|
@ -404,7 +375,7 @@ static void* dnodeParseVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) {
|
static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
SMDCreateVnodeMsg *pCreate = dnodeParseVnodeMsg(rpcMsg);
|
SCreateVnodeMsg *pCreate = dnodeParseVnodeMsg(rpcMsg);
|
||||||
|
|
||||||
void *pVnode = vnodeAcquire(pCreate->cfg.vgId);
|
void *pVnode = vnodeAcquire(pCreate->cfg.vgId);
|
||||||
if (pVnode != NULL) {
|
if (pVnode != NULL) {
|
||||||
|
@ -418,7 +389,7 @@ static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dnodeProcessAlterVnodeMsg(SRpcMsg *rpcMsg) {
|
static int32_t dnodeProcessAlterVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
SMDAlterVnodeMsg *pAlter = dnodeParseVnodeMsg(rpcMsg);
|
SAlterVnodeMsg *pAlter = dnodeParseVnodeMsg(rpcMsg);
|
||||||
|
|
||||||
void *pVnode = vnodeAcquire(pAlter->cfg.vgId);
|
void *pVnode = vnodeAcquire(pAlter->cfg.vgId);
|
||||||
if (pVnode != NULL) {
|
if (pVnode != NULL) {
|
||||||
|
@ -433,14 +404,14 @@ static int32_t dnodeProcessAlterVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dnodeProcessDropVnodeMsg(SRpcMsg *rpcMsg) {
|
static int32_t dnodeProcessDropVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
SMDDropVnodeMsg *pDrop = rpcMsg->pCont;
|
SDropVnodeMsg *pDrop = rpcMsg->pCont;
|
||||||
pDrop->vgId = htonl(pDrop->vgId);
|
pDrop->vgId = htonl(pDrop->vgId);
|
||||||
|
|
||||||
return vnodeDrop(pDrop->vgId);
|
return vnodeDrop(pDrop->vgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dnodeProcessAlterStreamMsg(SRpcMsg *pMsg) {
|
static int32_t dnodeProcessAlterStreamMsg(SRpcMsg *pMsg) {
|
||||||
// SMDAlterStreamMsg *pStream = pCont;
|
// SAlterStreamMsg *pStream = pCont;
|
||||||
// pStream->uid = htobe64(pStream->uid);
|
// pStream->uid = htobe64(pStream->uid);
|
||||||
// pStream->stime = htobe64(pStream->stime);
|
// pStream->stime = htobe64(pStream->stime);
|
||||||
// pStream->vnode = htonl(pStream->vnode);
|
// pStream->vnode = htonl(pStream->vnode);
|
||||||
|
@ -453,12 +424,12 @@ static int32_t dnodeProcessAlterStreamMsg(SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dnodeProcessConfigDnodeMsg(SRpcMsg *pMsg) {
|
static int32_t dnodeProcessConfigDnodeMsg(SRpcMsg *pMsg) {
|
||||||
SMDCfgDnodeMsg *pCfg = pMsg->pCont;
|
SCfgDnodeMsg *pCfg = pMsg->pCont;
|
||||||
return taosCfgDynamicOptions(pCfg->config);
|
return taosCfgDynamicOptions(pCfg->config);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dnodeProcessCreateMnodeMsg(SRpcMsg *pMsg) {
|
static int32_t dnodeProcessCreateMnodeMsg(SRpcMsg *pMsg) {
|
||||||
SMDCreateMnodeMsg *pCfg = pMsg->pCont;
|
SCreateMnodeMsg *pCfg = pMsg->pCont;
|
||||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||||
if (pCfg->dnodeId != dnodeGetDnodeId()) {
|
if (pCfg->dnodeId != dnodeGetDnodeId()) {
|
||||||
dError("dnodeId:%d, in create mnode msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId());
|
dError("dnodeId:%d, in create mnode msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId());
|
||||||
|
@ -470,10 +441,10 @@ static int32_t dnodeProcessCreateMnodeMsg(SRpcMsg *pMsg) {
|
||||||
return TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED;
|
return TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnodeId:%d, create mnode msg is received from mnodes, numOfMnodes:%d", pCfg->dnodeId, pCfg->mnodes.nodeNum);
|
dDebug("dnodeId:%d, create mnode msg is received from mnodes, numOfMnodes:%d", pCfg->dnodeId, pCfg->mnodes.mnodeNum);
|
||||||
for (int i = 0; i < pCfg->mnodes.nodeNum; ++i) {
|
for (int i = 0; i < pCfg->mnodes.mnodeNum; ++i) {
|
||||||
pCfg->mnodes.nodeInfos[i].nodeId = htonl(pCfg->mnodes.nodeInfos[i].nodeId);
|
pCfg->mnodes.mnodeInfos[i].mnodeId = htonl(pCfg->mnodes.mnodeInfos[i].mnodeId);
|
||||||
dDebug("mnode index:%d, mnode:%d:%s", i, pCfg->mnodes.nodeInfos[i].nodeId, pCfg->mnodes.nodeInfos[i].nodeEp);
|
dDebug("mnode index:%d, mnode:%d:%s", i, pCfg->mnodes.mnodeInfos[i].mnodeId, pCfg->mnodes.mnodeInfos[i].mnodeEp);
|
||||||
}
|
}
|
||||||
|
|
||||||
dnodeStartMnode(&pCfg->mnodes);
|
dnodeStartMnode(&pCfg->mnodes);
|
||||||
|
@ -481,34 +452,6 @@ static int32_t dnodeProcessCreateMnodeMsg(SRpcMsg *pMsg) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeUpdateMnodeEpSetForPeer(SRpcEpSet *pEpSet) {
|
|
||||||
if (pEpSet->numOfEps <= 0) {
|
|
||||||
dError("mnode EP list for peer is changed, but content is invalid, discard it");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dInfo("mnode EP list for peer is changed, numOfEps:%d inUse:%d", pEpSet->numOfEps, pEpSet->inUse);
|
|
||||||
for (int i = 0; i < pEpSet->numOfEps; ++i) {
|
|
||||||
pEpSet->port[i] -= TSDB_PORT_DNODEDNODE;
|
|
||||||
dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
tsDMnodeEpSet = *pEpSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dnodeGetMnodeEpSetForPeer(void *epSetRaw) {
|
|
||||||
SRpcEpSet *epSet = epSetRaw;
|
|
||||||
*epSet = tsDMnodeEpSet;
|
|
||||||
|
|
||||||
for (int i=0; i<epSet->numOfEps; ++i)
|
|
||||||
epSet->port[i] += TSDB_PORT_DNODEDNODE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dnodeGetMnodeEpSetForShell(void *epSetRaw) {
|
|
||||||
SRpcEpSet *epSet = epSetRaw;
|
|
||||||
*epSet = tsDMnodeEpSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
|
static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
|
||||||
if (pMsg->code != TSDB_CODE_SUCCESS) {
|
if (pMsg->code != TSDB_CODE_SUCCESS) {
|
||||||
dError("status rsp is received, error:%s", tstrerror(pMsg->code));
|
dError("status rsp is received, error:%s", tstrerror(pMsg->code));
|
||||||
|
@ -516,202 +459,24 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDMStatusRsp *pStatusRsp = pMsg->pCont;
|
SStatusRsp *pStatusRsp = pMsg->pCont;
|
||||||
SDMMnodeInfos *pMnodes = &pStatusRsp->mnodes;
|
SMnodeInfos *minfos = &pStatusRsp->mnodes;
|
||||||
if (pMnodes->nodeNum <= 0) {
|
dnodeUpdateMInfos(minfos);
|
||||||
dError("status msg is invalid, num of ips is %d", pMnodes->nodeNum);
|
|
||||||
taosTmrReset(dnodeSendStatusMsg, tsStatusInterval * 1000, NULL, tsDnodeTmr, &tsStatusTimer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDMDnodeCfg *pCfg = &pStatusRsp->dnodeCfg;
|
SDnodeCfg *pCfg = &pStatusRsp->dnodeCfg;
|
||||||
pCfg->numOfVnodes = htonl(pCfg->numOfVnodes);
|
pCfg->numOfVnodes = htonl(pCfg->numOfVnodes);
|
||||||
pCfg->moduleStatus = htonl(pCfg->moduleStatus);
|
pCfg->moduleStatus = htonl(pCfg->moduleStatus);
|
||||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||||
|
dnodeUpdateCfg(pCfg);
|
||||||
for (int32_t i = 0; i < pMnodes->nodeNum; ++i) {
|
|
||||||
SDMMnodeInfo *pMnodeInfo = &pMnodes->nodeInfos[i];
|
|
||||||
pMnodeInfo->nodeId = htonl(pMnodeInfo->nodeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
vnodeSetAccess(pStatusRsp->vgAccess, pCfg->numOfVnodes);
|
vnodeSetAccess(pStatusRsp->vgAccess, pCfg->numOfVnodes);
|
||||||
|
|
||||||
// will not set mnode in status msg
|
SDnodeEps *pEps = (SDnodeEps *)((char *)pStatusRsp->vgAccess + pCfg->numOfVnodes * sizeof(SVgroupAccess));
|
||||||
// dnodeProcessModuleStatus(pCfg->moduleStatus);
|
dnodeUpdateEps(pEps);
|
||||||
dnodeUpdateDnodeCfg(pCfg);
|
|
||||||
|
|
||||||
dnodeUpdateMnodeInfos(pMnodes);
|
|
||||||
taosTmrReset(dnodeSendStatusMsg, tsStatusInterval * 1000, NULL, tsDnodeTmr, &tsStatusTimer);
|
taosTmrReset(dnodeSendStatusMsg, tsStatusInterval * 1000, NULL, tsDnodeTmr, &tsStatusTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool dnodeCheckMnodeInfos(SDMMnodeInfos *pMnodes) {
|
|
||||||
if (pMnodes->nodeNum <= 0 || pMnodes->nodeNum > 3) {
|
|
||||||
dError("invalid mnode infos, num:%d", pMnodes->nodeNum);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pMnodes->nodeNum; ++i) {
|
|
||||||
SDMMnodeInfo *pMnodeInfo = &pMnodes->nodeInfos[i];
|
|
||||||
if (pMnodeInfo->nodeId <= 0 || strlen(pMnodeInfo->nodeEp) <= 5) {
|
|
||||||
dError("invalid mnode info:%d, nodeId:%d nodeEp:%s", i, pMnodeInfo->nodeId, pMnodeInfo->nodeEp);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dnodeUpdateMnodeInfos(SDMMnodeInfos *pMnodes) {
|
|
||||||
bool mnodesChanged = (memcmp(&tsDMnodeInfos, pMnodes, sizeof(SDMMnodeInfos)) != 0);
|
|
||||||
bool mnodesNotInit = (tsDMnodeInfos.nodeNum == 0);
|
|
||||||
if (!(mnodesChanged || mnodesNotInit)) return;
|
|
||||||
|
|
||||||
if (!dnodeCheckMnodeInfos(pMnodes)) return;
|
|
||||||
|
|
||||||
memcpy(&tsDMnodeInfos, pMnodes, sizeof(SDMMnodeInfos));
|
|
||||||
dInfo("mnode infos is changed, nodeNum:%d inUse:%d", tsDMnodeInfos.nodeNum, tsDMnodeInfos.inUse);
|
|
||||||
for (int32_t i = 0; i < tsDMnodeInfos.nodeNum; i++) {
|
|
||||||
dInfo("mnode index:%d, %s", tsDMnodeInfos.nodeInfos[i].nodeId, tsDMnodeInfos.nodeInfos[i].nodeEp);
|
|
||||||
}
|
|
||||||
|
|
||||||
tsDMnodeEpSet.inUse = tsDMnodeInfos.inUse;
|
|
||||||
tsDMnodeEpSet.numOfEps = tsDMnodeInfos.nodeNum;
|
|
||||||
for (int32_t i = 0; i < tsDMnodeInfos.nodeNum; i++) {
|
|
||||||
taosGetFqdnPortFromEp(tsDMnodeInfos.nodeInfos[i].nodeEp, tsDMnodeEpSet.fqdn[i], &tsDMnodeEpSet.port[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
dnodeSaveMnodeInfos();
|
|
||||||
sdbUpdateAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool dnodeReadMnodeInfos() {
|
|
||||||
char ipFile[TSDB_FILENAME_LEN*2] = {0};
|
|
||||||
|
|
||||||
sprintf(ipFile, "%s/mnodeEpSet.json", tsDnodeDir);
|
|
||||||
FILE *fp = fopen(ipFile, "r");
|
|
||||||
if (!fp) {
|
|
||||||
dDebug("failed to read mnodeEpSet.json, file not exist");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ret = false;
|
|
||||||
int maxLen = 2000;
|
|
||||||
char *content = calloc(1, maxLen + 1);
|
|
||||||
int len = fread(content, 1, maxLen, fp);
|
|
||||||
if (len <= 0) {
|
|
||||||
free(content);
|
|
||||||
fclose(fp);
|
|
||||||
dError("failed to read mnodeEpSet.json, content is null");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
content[len] = 0;
|
|
||||||
cJSON* root = cJSON_Parse(content);
|
|
||||||
if (root == NULL) {
|
|
||||||
dError("failed to read mnodeEpSet.json, invalid json format");
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* inUse = cJSON_GetObjectItem(root, "inUse");
|
|
||||||
if (!inUse || inUse->type != cJSON_Number) {
|
|
||||||
dError("failed to read mnodeEpSet.json, inUse not found");
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
tsDMnodeInfos.inUse = inUse->valueint;
|
|
||||||
|
|
||||||
cJSON* nodeNum = cJSON_GetObjectItem(root, "nodeNum");
|
|
||||||
if (!nodeNum || nodeNum->type != cJSON_Number) {
|
|
||||||
dError("failed to read mnodeEpSet.json, nodeNum not found");
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
tsDMnodeInfos.nodeNum = nodeNum->valueint;
|
|
||||||
|
|
||||||
cJSON* nodeInfos = cJSON_GetObjectItem(root, "nodeInfos");
|
|
||||||
if (!nodeInfos || nodeInfos->type != cJSON_Array) {
|
|
||||||
dError("failed to read mnodeEpSet.json, nodeInfos not found");
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
int size = cJSON_GetArraySize(nodeInfos);
|
|
||||||
if (size != tsDMnodeInfos.nodeNum) {
|
|
||||||
dError("failed to read mnodeEpSet.json, nodeInfos size not matched");
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i) {
|
|
||||||
cJSON *nodeInfo = cJSON_GetArrayItem(nodeInfos, i);
|
|
||||||
if (nodeInfo == NULL) continue;
|
|
||||||
|
|
||||||
cJSON *nodeId = cJSON_GetObjectItem(nodeInfo, "nodeId");
|
|
||||||
if (!nodeId || nodeId->type != cJSON_Number) {
|
|
||||||
dError("failed to read mnodeEpSet.json, nodeId not found");
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
tsDMnodeInfos.nodeInfos[i].nodeId = nodeId->valueint;
|
|
||||||
|
|
||||||
cJSON *nodeEp = cJSON_GetObjectItem(nodeInfo, "nodeEp");
|
|
||||||
if (!nodeEp || nodeEp->type != cJSON_String || nodeEp->valuestring == NULL) {
|
|
||||||
dError("failed to read mnodeEpSet.json, nodeName not found");
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
strncpy(tsDMnodeInfos.nodeInfos[i].nodeEp, nodeEp->valuestring, TSDB_EP_LEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = true;
|
|
||||||
|
|
||||||
dInfo("read mnode epSet successed, numOfEps:%d inUse:%d", tsDMnodeInfos.nodeNum, tsDMnodeInfos.inUse);
|
|
||||||
for (int32_t i = 0; i < tsDMnodeInfos.nodeNum; i++) {
|
|
||||||
dInfo("mnode:%d, %s", tsDMnodeInfos.nodeInfos[i].nodeId, tsDMnodeInfos.nodeInfos[i].nodeEp);
|
|
||||||
}
|
|
||||||
|
|
||||||
PARSE_OVER:
|
|
||||||
free(content);
|
|
||||||
cJSON_Delete(root);
|
|
||||||
fclose(fp);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dnodeSaveMnodeInfos() {
|
|
||||||
char ipFile[TSDB_FILENAME_LEN] = {0};
|
|
||||||
sprintf(ipFile, "%s/mnodeEpSet.json", tsDnodeDir);
|
|
||||||
FILE *fp = fopen(ipFile, "w");
|
|
||||||
if (!fp) return;
|
|
||||||
|
|
||||||
int32_t len = 0;
|
|
||||||
int32_t maxLen = 2000;
|
|
||||||
char * content = calloc(1, maxLen + 1);
|
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"inUse\": %d,\n", tsDMnodeInfos.inUse);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"nodeNum\": %d,\n", tsDMnodeInfos.nodeNum);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"nodeInfos\": [{\n");
|
|
||||||
for (int32_t i = 0; i < tsDMnodeInfos.nodeNum; i++) {
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"nodeId\": %d,\n", tsDMnodeInfos.nodeInfos[i].nodeId);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"nodeEp\": \"%s\"\n", tsDMnodeInfos.nodeInfos[i].nodeEp);
|
|
||||||
if (i < tsDMnodeInfos.nodeNum -1) {
|
|
||||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
|
||||||
} else {
|
|
||||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
|
||||||
|
|
||||||
fwrite(content, 1, len, fp);
|
|
||||||
fflush(fp);
|
|
||||||
fclose(fp);
|
|
||||||
free(content);
|
|
||||||
|
|
||||||
dInfo("save mnode epSet successed");
|
|
||||||
}
|
|
||||||
|
|
||||||
char *dnodeGetMnodeMasterEp() {
|
|
||||||
return tsDMnodeInfos.nodeInfos[tsDMnodeEpSet.inUse].nodeEp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* dnodeGetMnodeInfos() {
|
|
||||||
return &tsDMnodeInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dnodeSendStatusMsg(void *handle, void *tmrId) {
|
static void dnodeSendStatusMsg(void *handle, void *tmrId) {
|
||||||
if (tsDnodeTmr == NULL) {
|
if (tsDnodeTmr == NULL) {
|
||||||
dError("dnode timer is already released");
|
dError("dnode timer is already released");
|
||||||
|
@ -724,22 +489,21 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t contLen = sizeof(SDMStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
||||||
SDMStatusMsg *pStatus = rpcMallocCont(contLen);
|
SStatusMsg *pStatus = rpcMallocCont(contLen);
|
||||||
if (pStatus == NULL) {
|
if (pStatus == NULL) {
|
||||||
taosTmrReset(dnodeSendStatusMsg, tsStatusInterval * 1000, NULL, tsDnodeTmr, &tsStatusTimer);
|
taosTmrReset(dnodeSendStatusMsg, tsStatusInterval * 1000, NULL, tsDnodeTmr, &tsStatusTimer);
|
||||||
dError("failed to malloc status message");
|
dError("failed to malloc status message");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//strcpy(pStatus->dnodeName, tsDnodeName);
|
dnodeGetCfg(&pStatus->dnodeId, pStatus->clusterId);
|
||||||
|
pStatus->dnodeId = htonl(dnodeGetDnodeId());
|
||||||
pStatus->version = htonl(tsVersion);
|
pStatus->version = htonl(tsVersion);
|
||||||
pStatus->dnodeId = htonl(tsDnodeCfg.dnodeId);
|
|
||||||
pStatus->lastReboot = htonl(tsRebootTime);
|
pStatus->lastReboot = htonl(tsRebootTime);
|
||||||
pStatus->numOfCores = htons((uint16_t) tsNumOfCores);
|
pStatus->numOfCores = htons((uint16_t) tsNumOfCores);
|
||||||
pStatus->diskAvailable = tsAvailDataDirGB;
|
pStatus->diskAvailable = tsAvailDataDirGB;
|
||||||
pStatus->alternativeRole = (uint8_t) tsAlternativeRole;
|
pStatus->alternativeRole = (uint8_t) tsAlternativeRole;
|
||||||
tstrncpy(pStatus->clusterId, tsDnodeCfg.clusterId, TSDB_CLUSTER_ID_LEN);
|
|
||||||
tstrncpy(pStatus->dnodeEp, tsLocalEp, TSDB_EP_LEN);
|
tstrncpy(pStatus->dnodeEp, tsLocalEp, TSDB_EP_LEN);
|
||||||
|
|
||||||
// fill cluster cfg parameters
|
// fill cluster cfg parameters
|
||||||
|
@ -759,7 +523,7 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) {
|
||||||
tstrncpy(pStatus->clusterCfg.charset, tsCharset, TSDB_LOCALE_LEN);
|
tstrncpy(pStatus->clusterCfg.charset, tsCharset, TSDB_LOCALE_LEN);
|
||||||
|
|
||||||
vnodeBuildStatusMsg(pStatus);
|
vnodeBuildStatusMsg(pStatus);
|
||||||
contLen = sizeof(SDMStatusMsg) + pStatus->openVnodes * sizeof(SVnodeLoad);
|
contLen = sizeof(SStatusMsg) + pStatus->openVnodes * sizeof(SVnodeLoad);
|
||||||
pStatus->openVnodes = htons(pStatus->openVnodes);
|
pStatus->openVnodes = htons(pStatus->openVnodes);
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {
|
SRpcMsg rpcMsg = {
|
||||||
|
@ -769,110 +533,19 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) {
|
||||||
};
|
};
|
||||||
|
|
||||||
SRpcEpSet epSet;
|
SRpcEpSet epSet;
|
||||||
dnodeGetMnodeEpSetForPeer(&epSet);
|
dnodeGetEpSetForPeer(&epSet);
|
||||||
dnodeSendMsgToDnode(&epSet, &rpcMsg);
|
dnodeSendMsgToDnode(&epSet, &rpcMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool dnodeReadDnodeCfg() {
|
|
||||||
char dnodeCfgFile[TSDB_FILENAME_LEN*2] = {0};
|
|
||||||
|
|
||||||
sprintf(dnodeCfgFile, "%s/dnodeCfg.json", tsDnodeDir);
|
|
||||||
|
|
||||||
FILE *fp = fopen(dnodeCfgFile, "r");
|
|
||||||
if (!fp) {
|
|
||||||
dDebug("failed to read dnodeCfg.json, file not exist");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ret = false;
|
|
||||||
int maxLen = 100;
|
|
||||||
char *content = calloc(1, maxLen + 1);
|
|
||||||
int len = fread(content, 1, maxLen, fp);
|
|
||||||
if (len <= 0) {
|
|
||||||
free(content);
|
|
||||||
fclose(fp);
|
|
||||||
dError("failed to read dnodeCfg.json, content is null");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
content[len] = 0;
|
|
||||||
cJSON* root = cJSON_Parse(content);
|
|
||||||
if (root == NULL) {
|
|
||||||
dError("failed to read dnodeCfg.json, invalid json format");
|
|
||||||
goto PARSE_CFG_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* dnodeId = cJSON_GetObjectItem(root, "dnodeId");
|
|
||||||
if (!dnodeId || dnodeId->type != cJSON_Number) {
|
|
||||||
dError("failed to read dnodeCfg.json, dnodeId not found");
|
|
||||||
goto PARSE_CFG_OVER;
|
|
||||||
}
|
|
||||||
tsDnodeCfg.dnodeId = dnodeId->valueint;
|
|
||||||
|
|
||||||
cJSON* clusterId = cJSON_GetObjectItem(root, "clusterId");
|
|
||||||
if (!clusterId || clusterId->type != cJSON_String) {
|
|
||||||
dError("failed to read dnodeCfg.json, clusterId not found");
|
|
||||||
goto PARSE_CFG_OVER;
|
|
||||||
}
|
|
||||||
tstrncpy(tsDnodeCfg.clusterId, clusterId->valuestring, TSDB_CLUSTER_ID_LEN);
|
|
||||||
|
|
||||||
ret = true;
|
|
||||||
|
|
||||||
dInfo("read numOfVnodes successed, dnodeId:%d", tsDnodeCfg.dnodeId);
|
|
||||||
|
|
||||||
PARSE_CFG_OVER:
|
|
||||||
free(content);
|
|
||||||
cJSON_Delete(root);
|
|
||||||
fclose(fp);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dnodeSaveDnodeCfg() {
|
|
||||||
char dnodeCfgFile[TSDB_FILENAME_LEN] = {0};
|
|
||||||
sprintf(dnodeCfgFile, "%s/dnodeCfg.json", tsDnodeDir);
|
|
||||||
|
|
||||||
FILE *fp = fopen(dnodeCfgFile, "w");
|
|
||||||
if (!fp) return;
|
|
||||||
|
|
||||||
int32_t len = 0;
|
|
||||||
int32_t maxLen = 200;
|
|
||||||
char * content = calloc(1, maxLen + 1);
|
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", tsDnodeCfg.dnodeId);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%s\"\n", tsDnodeCfg.clusterId);
|
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
|
||||||
|
|
||||||
fwrite(content, 1, len, fp);
|
|
||||||
fflush(fp);
|
|
||||||
fclose(fp);
|
|
||||||
free(content);
|
|
||||||
|
|
||||||
dInfo("save dnodeId successed");
|
|
||||||
}
|
|
||||||
|
|
||||||
void dnodeUpdateDnodeCfg(SDMDnodeCfg *pCfg) {
|
|
||||||
if (tsDnodeCfg.dnodeId == 0) {
|
|
||||||
dInfo("dnodeId is set to %d, clusterId is set to %s", pCfg->dnodeId, pCfg->clusterId);
|
|
||||||
tsDnodeCfg.dnodeId = pCfg->dnodeId;
|
|
||||||
tstrncpy(tsDnodeCfg.clusterId, pCfg->clusterId, TSDB_CLUSTER_ID_LEN);
|
|
||||||
dnodeSaveDnodeCfg();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t dnodeGetDnodeId() {
|
|
||||||
return tsDnodeCfg.dnodeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell) {
|
void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell) {
|
||||||
SRpcConnInfo connInfo = {0};
|
SRpcConnInfo connInfo = {0};
|
||||||
rpcGetConnInfo(rpcMsg->handle, &connInfo);
|
rpcGetConnInfo(rpcMsg->handle, &connInfo);
|
||||||
|
|
||||||
SRpcEpSet epSet = {0};
|
SRpcEpSet epSet = {0};
|
||||||
if (forShell) {
|
if (forShell) {
|
||||||
dnodeGetMnodeEpSetForShell(&epSet);
|
dnodeGetEpSetForShell(&epSet);
|
||||||
} else {
|
} else {
|
||||||
dnodeGetMnodeEpSetForPeer(&epSet);
|
dnodeGetEpSetForPeer(&epSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("msg:%s will be redirected, dnodeIp:%s user:%s, numOfEps:%d inUse:%d", taosMsg[rpcMsg->msgType],
|
dDebug("msg:%s will be redirected, dnodeIp:%s user:%s, numOfEps:%d inUse:%d", taosMsg[rpcMsg->msgType],
|
||||||
|
|
|
@ -114,6 +114,7 @@ int32_t dnodeInitModules() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dInfo("dnode modules is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,8 +147,8 @@ void dnodeProcessModuleStatus(uint32_t moduleStatus) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dnodeStartMnode(void *pMnodes) {
|
bool dnodeStartMnode(SMnodeInfos *minfos) {
|
||||||
SDMMnodeInfos *mnodes = pMnodes;
|
SMnodeInfos *mnodes = minfos;
|
||||||
|
|
||||||
if (tsModuleStatus & (1 << TSDB_MOD_MNODE)) {
|
if (tsModuleStatus & (1 << TSDB_MOD_MNODE)) {
|
||||||
dDebug("mnode module is already started, module status:%d", tsModuleStatus);
|
dDebug("mnode module is already started, module status:%d", tsModuleStatus);
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
#include "dnodeMgmt.h"
|
#include "dnodeMgmt.h"
|
||||||
#include "dnodeVWrite.h"
|
#include "dnodeVWrite.h"
|
||||||
#include "dnodeMPeer.h"
|
#include "dnodeMPeer.h"
|
||||||
|
#include "dnodeMInfos.h"
|
||||||
|
|
||||||
extern void dnodeUpdateMnodeEpSetForPeer(SRpcEpSet *pEpSet);
|
|
||||||
static void (*dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
|
static void (*dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
|
||||||
static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcEpSet *);
|
static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcEpSet *);
|
||||||
static void (*dnodeProcessRspMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *rpcMsg);
|
static void (*dnodeProcessRspMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *rpcMsg);
|
||||||
|
@ -72,7 +72,7 @@ int32_t dnodeInitServer() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("inter-dnodes RPC server is opened");
|
dInfo("dnode inter-dnodes RPC server is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ int32_t dnodeInitClient() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("inter-dnodes rpc client is opened");
|
dInfo("dnode inter-dnodes rpc client is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,13 +145,13 @@ void dnodeCleanupClient() {
|
||||||
if (tsDnodeClientRpc) {
|
if (tsDnodeClientRpc) {
|
||||||
rpcClose(tsDnodeClientRpc);
|
rpcClose(tsDnodeClientRpc);
|
||||||
tsDnodeClientRpc = NULL;
|
tsDnodeClientRpc = NULL;
|
||||||
dInfo("inter-dnodes rpc client is closed");
|
dInfo("dnode inter-dnodes rpc client is closed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dnodeProcessRspFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
static void dnodeProcessRspFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
||||||
if (pMsg->msgType == TSDB_MSG_TYPE_DM_STATUS_RSP && pEpSet) {
|
if (pMsg->msgType == TSDB_MSG_TYPE_DM_STATUS_RSP && pEpSet) {
|
||||||
dnodeUpdateMnodeEpSetForPeer(pEpSet);
|
dnodeUpdateEpSetForPeer(pEpSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dnodeProcessRspMsgFp[pMsg->msgType]) {
|
if (dnodeProcessRspMsgFp[pMsg->msgType]) {
|
||||||
|
@ -173,7 +173,7 @@ void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg) {
|
||||||
|
|
||||||
void dnodeSendMsgToMnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp) {
|
void dnodeSendMsgToMnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp) {
|
||||||
SRpcEpSet epSet = {0};
|
SRpcEpSet epSet = {0};
|
||||||
dnodeGetMnodeEpSetForPeer(&epSet);
|
dnodeGetEpSetForPeer(&epSet);
|
||||||
rpcSendRecv(tsDnodeClientRpc, &epSet, rpcMsg, rpcRsp);
|
rpcSendRecv(tsDnodeClientRpc, &epSet, rpcMsg, rpcRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ int32_t dnodeInitShell() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("shell rpc server is opened");
|
dInfo("dnode shell rpc server is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,12 +146,12 @@ static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char
|
||||||
int code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey);
|
int code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey);
|
||||||
if (code != TSDB_CODE_APP_NOT_READY) return code;
|
if (code != TSDB_CODE_APP_NOT_READY) return code;
|
||||||
|
|
||||||
SDMAuthMsg *pMsg = rpcMallocCont(sizeof(SDMAuthMsg));
|
SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg));
|
||||||
tstrncpy(pMsg->user, user, sizeof(pMsg->user));
|
tstrncpy(pMsg->user, user, sizeof(pMsg->user));
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {0};
|
||||||
rpcMsg.pCont = pMsg;
|
rpcMsg.pCont = pMsg;
|
||||||
rpcMsg.contLen = sizeof(SDMAuthMsg);
|
rpcMsg.contLen = sizeof(SAuthMsg);
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_DM_AUTH;
|
rpcMsg.msgType = TSDB_MSG_TYPE_DM_AUTH;
|
||||||
|
|
||||||
dDebug("user:%s, send auth msg to mnodes", user);
|
dDebug("user:%s, send auth msg to mnodes", user);
|
||||||
|
@ -161,7 +161,7 @@ static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char
|
||||||
if (rpcRsp.code != 0) {
|
if (rpcRsp.code != 0) {
|
||||||
dError("user:%s, auth msg received from mnodes, error:%s", user, tstrerror(rpcRsp.code));
|
dError("user:%s, auth msg received from mnodes, error:%s", user, tstrerror(rpcRsp.code));
|
||||||
} else {
|
} else {
|
||||||
SDMAuthRsp *pRsp = rpcRsp.pCont;
|
SAuthRsp *pRsp = rpcRsp.pCont;
|
||||||
dDebug("user:%s, auth msg received from mnodes", user);
|
dDebug("user:%s, auth msg received from mnodes", user);
|
||||||
memcpy(secret, pRsp->secret, TSDB_KEY_LEN);
|
memcpy(secret, pRsp->secret, TSDB_KEY_LEN);
|
||||||
memcpy(ckey, pRsp->ckey, TSDB_KEY_LEN);
|
memcpy(ckey, pRsp->ckey, TSDB_KEY_LEN);
|
||||||
|
@ -176,8 +176,8 @@ static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char
|
||||||
void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t tid) {
|
void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t tid) {
|
||||||
dDebug("vgId:%d, tid:%d send config table msg to mnode", vgId, tid);
|
dDebug("vgId:%d, tid:%d send config table msg to mnode", vgId, tid);
|
||||||
|
|
||||||
int32_t contLen = sizeof(SDMConfigTableMsg);
|
int32_t contLen = sizeof(SConfigTableMsg);
|
||||||
SDMConfigTableMsg *pMsg = rpcMallocCont(contLen);
|
SConfigTableMsg *pMsg = rpcMallocCont(contLen);
|
||||||
|
|
||||||
pMsg->dnodeId = htonl(dnodeGetDnodeId());
|
pMsg->dnodeId = htonl(dnodeGetDnodeId());
|
||||||
pMsg->vgId = htonl(vgId);
|
pMsg->vgId = htonl(vgId);
|
||||||
|
|
|
@ -299,6 +299,7 @@ int32_t dnodeInitTelemetry() {
|
||||||
dTrace("failed to create telemetry thread, reason:%s", strerror(errno));
|
dTrace("failed to create telemetry thread, reason:%s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dInfo("dnode telemetry is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ int32_t dnodeInitVnodeRead() {
|
||||||
pWorker->workerId = i;
|
pWorker->workerId = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("dnode read is opened, min worker:%d max worker:%d", readPool.min, readPool.max);
|
dInfo("dnode read is initialized, min worker:%d max worker:%d", readPool.min, readPool.max);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ int32_t dnodeInitVnodeWrite() {
|
||||||
wWorkerPool.writeWorker[i].workerId = i;
|
wWorkerPool.writeWorker[i].workerId = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("dnode write is opened, max worker %d", wWorkerPool.max);
|
dInfo("dnode write is initialized, max worker %d", wWorkerPool.max);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
|
#include "taosmsg.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t queryReqNum;
|
int32_t queryReqNum;
|
||||||
|
@ -38,12 +39,13 @@ SDnodeRunStatus dnodeGetRunStatus();
|
||||||
SDnodeStatisInfo dnodeGetStatisInfo();
|
SDnodeStatisInfo dnodeGetStatisInfo();
|
||||||
|
|
||||||
bool dnodeIsFirstDeploy();
|
bool dnodeIsFirstDeploy();
|
||||||
char * dnodeGetMnodeMasterEp();
|
bool dnodeIsMasterEp(char *ep);
|
||||||
void dnodeGetMnodeEpSetForPeer(void *epSet);
|
void dnodeGetEpSetForPeer(SRpcEpSet *epSet);
|
||||||
void dnodeGetMnodeEpSetForShell(void *epSet);
|
void dnodeGetEpSetForShell(SRpcEpSet *epSet);
|
||||||
void * dnodeGetMnodeInfos();
|
|
||||||
int32_t dnodeGetDnodeId();
|
int32_t dnodeGetDnodeId();
|
||||||
bool dnodeStartMnode(void *pModes);
|
void dnodeUpdateEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port);
|
||||||
|
bool dnodeCheckEpChanged(int32_t dnodeId, char *epstr);
|
||||||
|
bool dnodeStartMnode(SMnodeInfos *minfos);
|
||||||
|
|
||||||
void dnodeAddClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg));
|
void dnodeAddClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg));
|
||||||
void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg);
|
void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg);
|
||||||
|
|
|
@ -295,7 +295,7 @@ typedef struct {
|
||||||
SSchema schema[];
|
SSchema schema[];
|
||||||
// tagVal is padded after schema
|
// tagVal is padded after schema
|
||||||
// char tagVal[];
|
// char tagVal[];
|
||||||
} SCMAlterTableMsg;
|
} SAlterTableMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SMsgHead head;
|
SMsgHead head;
|
||||||
|
@ -312,12 +312,12 @@ typedef struct {
|
||||||
} SUpdateTableTagValMsg;
|
} SUpdateTableTagValMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char clientVersion[TSDB_VERSION_LEN];
|
char clientVersion[TSDB_VERSION_LEN];
|
||||||
char msgVersion[TSDB_VERSION_LEN];
|
char msgVersion[TSDB_VERSION_LEN];
|
||||||
char db[TSDB_TABLE_FNAME_LEN];
|
char db[TSDB_TABLE_FNAME_LEN];
|
||||||
char appName[TSDB_APPNAME_LEN];
|
char appName[TSDB_APPNAME_LEN];
|
||||||
int32_t pid;
|
int32_t pid;
|
||||||
} SCMConnectMsg;
|
} SConnectMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char acctId[TSDB_ACCT_LEN];
|
char acctId[TSDB_ACCT_LEN];
|
||||||
|
@ -328,7 +328,7 @@ typedef struct {
|
||||||
int8_t reserved2;
|
int8_t reserved2;
|
||||||
int32_t connId;
|
int32_t connId;
|
||||||
SRpcEpSet epSet;
|
SRpcEpSet epSet;
|
||||||
} SCMConnectRsp;
|
} SConnectRsp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t maxUsers;
|
int32_t maxUsers;
|
||||||
|
@ -348,18 +348,18 @@ typedef struct {
|
||||||
char user[TSDB_USER_LEN];
|
char user[TSDB_USER_LEN];
|
||||||
char pass[TSDB_KEY_LEN];
|
char pass[TSDB_KEY_LEN];
|
||||||
SAcctCfg cfg;
|
SAcctCfg cfg;
|
||||||
} SCMCreateAcctMsg, SCMAlterAcctMsg;
|
} SCreateAcctMsg, SAlterAcctMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char user[TSDB_USER_LEN];
|
char user[TSDB_USER_LEN];
|
||||||
} SCMDropUserMsg, SCMDropAcctMsg;
|
} SDropUserMsg, SDropAcctMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char user[TSDB_USER_LEN];
|
char user[TSDB_USER_LEN];
|
||||||
char pass[TSDB_KEY_LEN];
|
char pass[TSDB_KEY_LEN];
|
||||||
int8_t privilege;
|
int8_t privilege;
|
||||||
int8_t flag;
|
int8_t flag;
|
||||||
} SCMCreateUserMsg, SCMAlterUserMsg;
|
} SCreateUserMsg, SAlterUserMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t contLen;
|
int32_t contLen;
|
||||||
|
@ -374,11 +374,11 @@ typedef struct {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
char tableId[TSDB_TABLE_FNAME_LEN];
|
char tableId[TSDB_TABLE_FNAME_LEN];
|
||||||
} SMDDropSTableMsg;
|
} SDropSTableMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
} SMDDropVnodeMsg;
|
} SDropVnodeMsg;
|
||||||
|
|
||||||
typedef struct SColIndex {
|
typedef struct SColIndex {
|
||||||
int16_t colId; // column id
|
int16_t colId; // column id
|
||||||
|
@ -546,12 +546,12 @@ typedef struct {
|
||||||
int8_t ignoreExist;
|
int8_t ignoreExist;
|
||||||
int8_t update;
|
int8_t update;
|
||||||
int8_t reserve[9];
|
int8_t reserve[9];
|
||||||
} SCMCreateDbMsg, SCMAlterDbMsg;
|
} SCreateDbMsg, SAlterDbMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char db[TSDB_TABLE_FNAME_LEN];
|
char db[TSDB_TABLE_FNAME_LEN];
|
||||||
uint8_t ignoreNotExists;
|
uint8_t ignoreNotExists;
|
||||||
} SCMDropDbMsg, SCMUseDbMsg;
|
} SDropDbMsg, SUseDbMsg;
|
||||||
|
|
||||||
// IMPORTANT: sizeof(SVnodeStatisticInfo) should not exceed
|
// IMPORTANT: sizeof(SVnodeStatisticInfo) should not exceed
|
||||||
// TSDB_FILE_HEADER_LEN/4 - TSDB_FILE_HEADER_VERSION_SIZE
|
// TSDB_FILE_HEADER_LEN/4 - TSDB_FILE_HEADER_VERSION_SIZE
|
||||||
|
@ -566,7 +566,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
int8_t accessState;
|
int8_t accessState;
|
||||||
} SDMVgroupAccess;
|
} SVgroupAccess;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
|
@ -574,18 +574,29 @@ typedef struct {
|
||||||
uint32_t numOfVnodes;
|
uint32_t numOfVnodes;
|
||||||
char clusterId[TSDB_CLUSTER_ID_LEN];
|
char clusterId[TSDB_CLUSTER_ID_LEN];
|
||||||
char reserved[16];
|
char reserved[16];
|
||||||
} SDMDnodeCfg;
|
} SDnodeCfg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t nodeId;
|
int32_t dnodeId;
|
||||||
char nodeEp[TSDB_EP_LEN];
|
uint16_t dnodePort;
|
||||||
} SDMMnodeInfo;
|
char dnodeFqdn[TSDB_FQDN_LEN];
|
||||||
|
} SDnodeEp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t inUse;
|
int32_t dnodeNum;
|
||||||
int8_t nodeNum;
|
SDnodeEp dnodeEps[];
|
||||||
SDMMnodeInfo nodeInfos[TSDB_MAX_REPLICA];
|
} SDnodeEps;
|
||||||
} SDMMnodeInfos;
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t mnodeId;
|
||||||
|
char mnodeEp[TSDB_EP_LEN];
|
||||||
|
} SMnodeInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int8_t inUse;
|
||||||
|
int8_t mnodeNum;
|
||||||
|
SMnodeInfo mnodeInfos[TSDB_MAX_REPLICA];
|
||||||
|
} SMnodeInfos;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t numOfMnodes; // tsNumOfMnodes
|
int32_t numOfMnodes; // tsNumOfMnodes
|
||||||
|
@ -617,13 +628,13 @@ typedef struct {
|
||||||
uint8_t reserve2[15];
|
uint8_t reserve2[15];
|
||||||
SClusterCfg clusterCfg;
|
SClusterCfg clusterCfg;
|
||||||
SVnodeLoad load[];
|
SVnodeLoad load[];
|
||||||
} SDMStatusMsg;
|
} SStatusMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SDMMnodeInfos mnodes;
|
SMnodeInfos mnodes;
|
||||||
SDMDnodeCfg dnodeCfg;
|
SDnodeCfg dnodeCfg;
|
||||||
SDMVgroupAccess vgAccess[];
|
SVgroupAccess vgAccess[];
|
||||||
} SDMStatusRsp;
|
} SStatusRsp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t vgId;
|
uint32_t vgId;
|
||||||
|
@ -647,54 +658,54 @@ typedef struct {
|
||||||
int8_t quorum;
|
int8_t quorum;
|
||||||
int8_t update;
|
int8_t update;
|
||||||
int8_t reserved[15];
|
int8_t reserved[15];
|
||||||
} SMDVnodeCfg;
|
} SVnodeCfg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t nodeId;
|
int32_t nodeId;
|
||||||
char nodeEp[TSDB_EP_LEN];
|
char nodeEp[TSDB_EP_LEN];
|
||||||
} SMDVnodeDesc;
|
} SVnodeDesc;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||||
SMDVnodeCfg cfg;
|
SVnodeCfg cfg;
|
||||||
SMDVnodeDesc nodes[TSDB_MAX_REPLICA];
|
SVnodeDesc nodes[TSDB_MAX_REPLICA];
|
||||||
} SMDCreateVnodeMsg, SMDAlterVnodeMsg;
|
} SCreateVnodeMsg, SAlterVnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char tableId[TSDB_TABLE_FNAME_LEN];
|
char tableId[TSDB_TABLE_FNAME_LEN];
|
||||||
int16_t createFlag;
|
int16_t createFlag;
|
||||||
char tags[];
|
char tags[];
|
||||||
} SCMTableInfoMsg;
|
} STableInfoMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t numOfTables;
|
int32_t numOfTables;
|
||||||
char tableIds[];
|
char tableIds[];
|
||||||
} SCMMultiTableInfoMsg;
|
} SMultiTableInfoMsg;
|
||||||
|
|
||||||
typedef struct SCMSTableVgroupMsg {
|
typedef struct SSTableVgroupMsg {
|
||||||
int32_t numOfTables;
|
int32_t numOfTables;
|
||||||
} SCMSTableVgroupMsg, SCMSTableVgroupRspMsg;
|
} SSTableVgroupMsg, SSTableVgroupRspMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
int8_t numOfEps;
|
int8_t numOfEps;
|
||||||
SEpAddr1 epAddr[TSDB_MAX_REPLICA];
|
SEpAddr1 epAddr[TSDB_MAX_REPLICA];
|
||||||
} SCMVgroupInfo;
|
} SVgroupInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
int8_t numOfEps;
|
int8_t numOfEps;
|
||||||
SEpAddrMsg epAddr[TSDB_MAX_REPLICA];
|
SEpAddrMsg epAddr[TSDB_MAX_REPLICA];
|
||||||
} SCMVgroupMsg;
|
} SVgroupMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t numOfVgroups;
|
int32_t numOfVgroups;
|
||||||
SCMVgroupInfo vgroups[];
|
SVgroupInfo vgroups[];
|
||||||
} SVgroupsInfo;
|
} SVgroupsInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t numOfVgroups;
|
int32_t numOfVgroups;
|
||||||
SCMVgroupMsg vgroups[];
|
SVgroupMsg vgroups[];
|
||||||
} SVgroupsMsg;
|
} SVgroupsMsg;
|
||||||
|
|
||||||
typedef struct STableMetaMsg {
|
typedef struct STableMetaMsg {
|
||||||
|
@ -709,7 +720,7 @@ typedef struct STableMetaMsg {
|
||||||
int16_t tversion;
|
int16_t tversion;
|
||||||
int32_t tid;
|
int32_t tid;
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
SCMVgroupMsg vgroup;
|
SVgroupMsg vgroup;
|
||||||
SSchema schema[];
|
SSchema schema[];
|
||||||
} STableMetaMsg;
|
} STableMetaMsg;
|
||||||
|
|
||||||
|
@ -735,38 +746,38 @@ typedef struct {
|
||||||
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||||
uint16_t payloadLen;
|
uint16_t payloadLen;
|
||||||
char payload[];
|
char payload[];
|
||||||
} SCMShowMsg;
|
} SShowMsg;
|
||||||
|
|
||||||
typedef struct SCMShowRsp {
|
typedef struct SShowRsp {
|
||||||
uint64_t qhandle;
|
uint64_t qhandle;
|
||||||
STableMetaMsg tableMeta;
|
STableMetaMsg tableMeta;
|
||||||
} SCMShowRsp;
|
} SShowRsp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char ep[TSDB_EP_LEN]; // end point, hostname:port
|
char ep[TSDB_EP_LEN]; // end point, hostname:port
|
||||||
} SCMCreateDnodeMsg, SCMDropDnodeMsg;
|
} SCreateDnodeMsg, SDropDnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
char dnodeEp[TSDB_EP_LEN]; // end point, hostname:port
|
char dnodeEp[TSDB_EP_LEN]; // end point, hostname:port
|
||||||
SDMMnodeInfos mnodes;
|
SMnodeInfos mnodes;
|
||||||
} SMDCreateMnodeMsg;
|
} SCreateMnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
int32_t tid;
|
int32_t tid;
|
||||||
} SDMConfigTableMsg;
|
} SConfigTableMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t dnodeId;
|
uint32_t dnodeId;
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
} SDMConfigVnodeMsg;
|
} SConfigVnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char ep[TSDB_EP_LEN]; // end point, hostname:port
|
char ep[TSDB_EP_LEN]; // end point, hostname:port
|
||||||
char config[64];
|
char config[64];
|
||||||
} SMDCfgDnodeMsg, SCMCfgDnodeMsg;
|
} SCfgDnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char sql[TSDB_SHOW_SQL_LEN];
|
char sql[TSDB_SHOW_SQL_LEN];
|
||||||
|
@ -795,7 +806,7 @@ typedef struct {
|
||||||
int32_t numOfStreams;
|
int32_t numOfStreams;
|
||||||
char appName[TSDB_APPNAME_LEN];
|
char appName[TSDB_APPNAME_LEN];
|
||||||
char pData[];
|
char pData[];
|
||||||
} SCMHeartBeatMsg;
|
} SHeartBeatMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t queryId;
|
uint32_t queryId;
|
||||||
|
@ -805,11 +816,11 @@ typedef struct {
|
||||||
uint32_t connId;
|
uint32_t connId;
|
||||||
int8_t killConnection;
|
int8_t killConnection;
|
||||||
SRpcEpSet epSet;
|
SRpcEpSet epSet;
|
||||||
} SCMHeartBeatRsp;
|
} SHeartBeatRsp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char queryId[TSDB_KILL_MSG_LEN + 1];
|
char queryId[TSDB_KILL_MSG_LEN + 1];
|
||||||
} SCMKillQueryMsg, SCMKillStreamMsg, SCMKillConnMsg;
|
} SKillQueryMsg, SKillStreamMsg, SKillConnMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vnode;
|
int32_t vnode;
|
||||||
|
@ -818,7 +829,7 @@ typedef struct {
|
||||||
uint64_t stime; // stream starting time
|
uint64_t stime; // stream starting time
|
||||||
int32_t status;
|
int32_t status;
|
||||||
char tableId[TSDB_TABLE_FNAME_LEN];
|
char tableId[TSDB_TABLE_FNAME_LEN];
|
||||||
} SMDAlterStreamMsg;
|
} SAlterStreamMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char user[TSDB_USER_LEN];
|
char user[TSDB_USER_LEN];
|
||||||
|
@ -826,7 +837,7 @@ typedef struct {
|
||||||
char encrypt;
|
char encrypt;
|
||||||
char secret[TSDB_KEY_LEN];
|
char secret[TSDB_KEY_LEN];
|
||||||
char ckey[TSDB_KEY_LEN];
|
char ckey[TSDB_KEY_LEN];
|
||||||
} SDMAuthMsg, SDMAuthRsp;
|
} SAuthMsg, SAuthRsp;
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ typedef uint32_t (*FGetFileInfo)(void *ahandle, char *name, uint32_t *index, uin
|
||||||
|
|
||||||
// get the wal file from index or after
|
// get the wal file from index or after
|
||||||
// return value, -1: error, 1:more wal files, 0:last WAL. if name[0]==0, no WAL file
|
// return value, -1: error, 1:more wal files, 0:last WAL. if name[0]==0, no WAL file
|
||||||
typedef int (*FGetWalInfo)(void *ahandle, char *name, uint32_t *index);
|
typedef int32_t (*FGetWalInfo)(void *ahandle, char *fileName, int64_t *fileId);
|
||||||
|
|
||||||
// when a forward pkt is received, call this to handle data
|
// when a forward pkt is received, call this to handle data
|
||||||
typedef int (*FWriteToCache)(void *ahandle, void *pHead, int type);
|
typedef int (*FWriteToCache)(void *ahandle, void *pHead, int type);
|
||||||
|
|
|
@ -19,9 +19,11 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TAOS_WAL_NOLOG 0
|
typedef enum {
|
||||||
#define TAOS_WAL_WRITE 1
|
TAOS_WAL_NOLOG = 0,
|
||||||
#define TAOS_WAL_FSYNC 2
|
TAOS_WAL_WRITE = 1,
|
||||||
|
TAOS_WAL_FSYNC = 2
|
||||||
|
} EWalType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t msgType;
|
int8_t msgType;
|
||||||
|
@ -34,8 +36,9 @@ typedef struct {
|
||||||
} SWalHead;
|
} SWalHead;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t walLevel; // wal level
|
int32_t vgId;
|
||||||
int32_t fsyncPeriod; // millisecond
|
int32_t fsyncPeriod; // millisecond
|
||||||
|
int8_t walLevel; // wal level
|
||||||
int8_t wals; // number of WAL files;
|
int8_t wals; // number of WAL files;
|
||||||
int8_t keep; // keep the wal file when closed
|
int8_t keep; // keep the wal file when closed
|
||||||
} SWalCfg;
|
} SWalCfg;
|
||||||
|
@ -43,14 +46,17 @@ typedef struct {
|
||||||
typedef void* twalh; // WAL HANDLE
|
typedef void* twalh; // WAL HANDLE
|
||||||
typedef int (*FWalWrite)(void *ahandle, void *pHead, int type);
|
typedef int (*FWalWrite)(void *ahandle, void *pHead, int type);
|
||||||
|
|
||||||
twalh walOpen(const char *path, const SWalCfg *pCfg);
|
int32_t walInit();
|
||||||
int walAlter(twalh pWal, const SWalCfg *pCfg);
|
void walCleanUp();
|
||||||
|
|
||||||
|
twalh walOpen(char *path, SWalCfg *pCfg);
|
||||||
|
int32_t walAlter(twalh pWal, SWalCfg *pCfg);
|
||||||
void walClose(twalh);
|
void walClose(twalh);
|
||||||
int walRenew(twalh);
|
int32_t walRenew(twalh);
|
||||||
int walWrite(twalh, SWalHead *);
|
int32_t walWrite(twalh, SWalHead *);
|
||||||
void walFsync(twalh);
|
void walFsync(twalh);
|
||||||
int walRestore(twalh, void *pVnode, FWalWrite writeFp);
|
int32_t walRestore(twalh, void *pVnode, FWalWrite writeFp);
|
||||||
int walGetWalFile(twalh, char *name, uint32_t *index);
|
int32_t walGetWalFile(twalh, char *fileName, int64_t *fileId);
|
||||||
int64_t walGetVersion(twalh);
|
int64_t walGetVersion(twalh);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -43,10 +43,10 @@ typedef struct {
|
||||||
|
|
||||||
extern char *vnodeStatus[];
|
extern char *vnodeStatus[];
|
||||||
|
|
||||||
int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg);
|
int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg);
|
||||||
int32_t vnodeDrop(int32_t vgId);
|
int32_t vnodeDrop(int32_t vgId);
|
||||||
int32_t vnodeOpen(int32_t vgId, char *rootDir);
|
int32_t vnodeOpen(int32_t vgId, char *rootDir);
|
||||||
int32_t vnodeAlter(void *pVnode, SMDCreateVnodeMsg *pVnodeCfg);
|
int32_t vnodeAlter(void *pVnode, SCreateVnodeMsg *pVnodeCfg);
|
||||||
int32_t vnodeClose(int32_t vgId);
|
int32_t vnodeClose(int32_t vgId);
|
||||||
|
|
||||||
void* vnodeAcquire(int32_t vgId); // add refcount
|
void* vnodeAcquire(int32_t vgId); // add refcount
|
||||||
|
@ -60,7 +60,7 @@ int32_t vnodeCheckWrite(void *pVnode);
|
||||||
int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes);
|
int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes);
|
||||||
void vnodeBuildStatusMsg(void *param);
|
void vnodeBuildStatusMsg(void *param);
|
||||||
void vnodeConfirmForward(void *param, uint64_t version, int32_t code);
|
void vnodeConfirmForward(void *param, uint64_t version, int32_t code);
|
||||||
void vnodeSetAccess(SDMVgroupAccess *pAccess, int32_t numOfVnodes);
|
void vnodeSetAccess(SVgroupAccess *pAccess, int32_t numOfVnodes);
|
||||||
|
|
||||||
int32_t vnodeInitResources();
|
int32_t vnodeInitResources();
|
||||||
void vnodeCleanupResources();
|
void vnodeCleanupResources();
|
||||||
|
|
|
@ -45,7 +45,7 @@ void mnodeCleanupProfile();
|
||||||
SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port, int32_t pid, const char* app);
|
SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port, int32_t pid, const char* app);
|
||||||
SConnObj *mnodeAccquireConn(int32_t connId, char *user, uint32_t ip, uint16_t port);
|
SConnObj *mnodeAccquireConn(int32_t connId, char *user, uint32_t ip, uint16_t port);
|
||||||
void mnodeReleaseConn(SConnObj *pConn);
|
void mnodeReleaseConn(SConnObj *pConn);
|
||||||
int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg);
|
int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pHBMsg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
static void * tsDbSdb = NULL;
|
static void * tsDbSdb = NULL;
|
||||||
static int32_t tsDbUpdateSize;
|
static int32_t tsDbUpdateSize;
|
||||||
|
|
||||||
static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, SMnodeMsg *pMsg);
|
static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg *pMsg);
|
||||||
static int32_t mnodeDropDb(SMnodeMsg *newMsg);
|
static int32_t mnodeDropDb(SMnodeMsg *newMsg);
|
||||||
static int32_t mnodeSetDbDropping(SDbObj *pDb);
|
static int32_t mnodeSetDbDropping(SDbObj *pDb);
|
||||||
static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
|
@ -358,7 +358,7 @@ static int32_t mnodeCreateDbCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, SMnodeMsg *pMsg) {
|
static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg *pMsg) {
|
||||||
int32_t code = acctCheck(pAcct, ACCT_GRANT_DB);
|
int32_t code = acctCheck(pAcct, ACCT_GRANT_DB);
|
||||||
if (code != 0) return code;
|
if (code != 0) return code;
|
||||||
|
|
||||||
|
@ -822,7 +822,7 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
|
||||||
SCMCreateDbMsg *pCreate = pMsg->rpcMsg.pCont;
|
SCreateDbMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
pCreate->maxTables = htonl(pCreate->maxTables);
|
pCreate->maxTables = htonl(pCreate->maxTables);
|
||||||
pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize);
|
pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize);
|
||||||
pCreate->totalBlocks = htonl(pCreate->totalBlocks);
|
pCreate->totalBlocks = htonl(pCreate->totalBlocks);
|
||||||
|
@ -847,7 +847,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
|
static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
|
||||||
SDbCfg newCfg = pDb->cfg;
|
SDbCfg newCfg = pDb->cfg;
|
||||||
int32_t maxTables = htonl(pAlter->maxTables);
|
int32_t maxTables = htonl(pAlter->maxTables);
|
||||||
int32_t cacheBlockSize = htonl(pAlter->cacheBlockSize);
|
int32_t cacheBlockSize = htonl(pAlter->cacheBlockSize);
|
||||||
|
@ -1000,7 +1000,7 @@ static int32_t mnodeAlterDbCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter, void *pMsg) {
|
static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) {
|
||||||
SDbCfg newCfg = mnodeGetAlterDbOption(pDb, pAlter);
|
SDbCfg newCfg = mnodeGetAlterDbOption(pDb, pAlter);
|
||||||
if (terrno != TSDB_CODE_SUCCESS) {
|
if (terrno != TSDB_CODE_SUCCESS) {
|
||||||
return terrno;
|
return terrno;
|
||||||
|
@ -1032,7 +1032,7 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter, void *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) {
|
||||||
SCMAlterDbMsg *pAlter = pMsg->rpcMsg.pCont;
|
SAlterDbMsg *pAlter = pMsg->rpcMsg.pCont;
|
||||||
mDebug("db:%s, alter db msg is received from thandle:%p", pAlter->db, pMsg->rpcMsg.handle);
|
mDebug("db:%s, alter db msg is received from thandle:%p", pAlter->db, pMsg->rpcMsg.handle);
|
||||||
|
|
||||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pAlter->db);
|
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pAlter->db);
|
||||||
|
@ -1083,7 +1083,7 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) {
|
||||||
SCMDropDbMsg *pDrop = pMsg->rpcMsg.pCont;
|
SDropDbMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||||
mDebug("db:%s, drop db msg is received from thandle:%p", pDrop->db, pMsg->rpcMsg.handle);
|
mDebug("db:%s, drop db msg is received from thandle:%p", pDrop->db, pMsg->rpcMsg.handle);
|
||||||
|
|
||||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pDrop->db);
|
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pDrop->db);
|
||||||
|
|
|
@ -39,11 +39,15 @@
|
||||||
#include "mnodeCluster.h"
|
#include "mnodeCluster.h"
|
||||||
|
|
||||||
int32_t tsAccessSquence = 0;
|
int32_t tsAccessSquence = 0;
|
||||||
static void *tsDnodeSdb = NULL;
|
static void * tsDnodeSdb = NULL;
|
||||||
static int32_t tsDnodeUpdateSize = 0;
|
static int32_t tsDnodeUpdateSize = 0;
|
||||||
extern void * tsMnodeSdb;
|
extern void * tsMnodeSdb;
|
||||||
extern void * tsVgroupSdb;
|
extern void * tsVgroupSdb;
|
||||||
|
|
||||||
|
static SDnodeEps*tsDnodeEps;
|
||||||
|
static int32_t tsDnodeEpsSize;
|
||||||
|
static pthread_mutex_t tsDnodeEpsMutex;
|
||||||
|
|
||||||
static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg);
|
static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg);
|
||||||
static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg);
|
static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg);
|
||||||
static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg);
|
static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg);
|
||||||
|
@ -59,6 +63,7 @@ static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, vo
|
||||||
static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
static char* mnodeGetDnodeAlternativeRoleStr(int32_t alternativeRole);
|
static char* mnodeGetDnodeAlternativeRoleStr(int32_t alternativeRole);
|
||||||
|
static void mnodeUpdateDnodeEps();
|
||||||
|
|
||||||
static char* offlineReason[] = {
|
static char* offlineReason[] = {
|
||||||
"",
|
"",
|
||||||
|
@ -95,6 +100,9 @@ static int32_t mnodeDnodeActionInsert(SSdbOper *pOper) {
|
||||||
pDnode->offlineReason = TAOS_DN_OFF_STATUS_NOT_RECEIVED;
|
pDnode->offlineReason = TAOS_DN_OFF_STATUS_NOT_RECEIVED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dnodeUpdateEp(pDnode->dnodeId, pDnode->dnodeEp, pDnode->dnodeFqdn, &pDnode->dnodePort);
|
||||||
|
mnodeUpdateDnodeEps();
|
||||||
|
|
||||||
mInfo("dnode:%d, fqdn:%s ep:%s port:%d, do insert action", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodeEp, pDnode->dnodePort);
|
mInfo("dnode:%d, fqdn:%s ep:%s port:%d, do insert action", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodeEp, pDnode->dnodePort);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -107,6 +115,7 @@ static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) {
|
||||||
#endif
|
#endif
|
||||||
mnodeDropMnodeLocal(pDnode->dnodeId);
|
mnodeDropMnodeLocal(pDnode->dnodeId);
|
||||||
balanceAsyncNotify();
|
balanceAsyncNotify();
|
||||||
|
mnodeUpdateDnodeEps();
|
||||||
|
|
||||||
mDebug("dnode:%d, all vgroups is dropped from sdb", pDnode->dnodeId);
|
mDebug("dnode:%d, all vgroups is dropped from sdb", pDnode->dnodeId);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -121,6 +130,7 @@ static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) {
|
||||||
}
|
}
|
||||||
mnodeDecDnodeRef(pDnode);
|
mnodeDecDnodeRef(pDnode);
|
||||||
|
|
||||||
|
mnodeUpdateDnodeEps();
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,12 +162,14 @@ static int32_t mnodeDnodeActionRestored() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mnodeUpdateDnodeEps();
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mnodeInitDnodes() {
|
int32_t mnodeInitDnodes() {
|
||||||
SDnodeObj tObj;
|
SDnodeObj tObj;
|
||||||
tsDnodeUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;
|
tsDnodeUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;
|
||||||
|
pthread_mutex_init(&tsDnodeEpsMutex, NULL);
|
||||||
|
|
||||||
SSdbTableDesc tableDesc = {
|
SSdbTableDesc tableDesc = {
|
||||||
.tableId = SDB_TABLE_DNODE,
|
.tableId = SDB_TABLE_DNODE,
|
||||||
|
@ -201,6 +213,9 @@ int32_t mnodeInitDnodes() {
|
||||||
|
|
||||||
void mnodeCleanupDnodes() {
|
void mnodeCleanupDnodes() {
|
||||||
sdbCloseTable(tsDnodeSdb);
|
sdbCloseTable(tsDnodeSdb);
|
||||||
|
pthread_mutex_destroy(&tsDnodeEpsMutex);
|
||||||
|
free(tsDnodeEps);
|
||||||
|
tsDnodeEps = NULL;
|
||||||
tsDnodeSdb = NULL;
|
tsDnodeSdb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +314,7 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
|
||||||
return TSDB_CODE_MND_NO_RIGHTS;
|
return TSDB_CODE_MND_NO_RIGHTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMCfgDnodeMsg *pCmCfgDnode = pMsg->rpcMsg.pCont;
|
SCfgDnodeMsg *pCmCfgDnode = pMsg->rpcMsg.pCont;
|
||||||
if (pCmCfgDnode->ep[0] == 0) {
|
if (pCmCfgDnode->ep[0] == 0) {
|
||||||
tstrncpy(pCmCfgDnode->ep, tsLocalEp, TSDB_EP_LEN);
|
tstrncpy(pCmCfgDnode->ep, tsLocalEp, TSDB_EP_LEN);
|
||||||
}
|
}
|
||||||
|
@ -334,7 +349,7 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
|
||||||
mnodeDecDnodeRef(pDnode);
|
mnodeDecDnodeRef(pDnode);
|
||||||
return code;
|
return code;
|
||||||
} else {
|
} else {
|
||||||
SMDCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SMDCfgDnodeMsg));
|
SCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SCfgDnodeMsg));
|
||||||
strcpy(pMdCfgDnode->ep, pCmCfgDnode->ep);
|
strcpy(pMdCfgDnode->ep, pCmCfgDnode->ep);
|
||||||
strcpy(pMdCfgDnode->config, pCmCfgDnode->config);
|
strcpy(pMdCfgDnode->config, pCmCfgDnode->config);
|
||||||
|
|
||||||
|
@ -343,7 +358,7 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
|
||||||
.code = 0,
|
.code = 0,
|
||||||
.msgType = TSDB_MSG_TYPE_MD_CONFIG_DNODE,
|
.msgType = TSDB_MSG_TYPE_MD_CONFIG_DNODE,
|
||||||
.pCont = pMdCfgDnode,
|
.pCont = pMdCfgDnode,
|
||||||
.contLen = sizeof(SMDCfgDnodeMsg)
|
.contLen = sizeof(SCfgDnodeMsg)
|
||||||
};
|
};
|
||||||
|
|
||||||
mInfo("dnode:%s, is configured by %s", pCmCfgDnode->ep, pMsg->pUser->user);
|
mInfo("dnode:%s, is configured by %s", pCmCfgDnode->ep, pMsg->pUser->user);
|
||||||
|
@ -418,9 +433,54 @@ static int32_t mnodeCheckClusterCfgPara(const SClusterCfg *clusterCfg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t mnodeGetDnodeEpsSize() {
|
||||||
|
pthread_mutex_lock(&tsDnodeEpsMutex);
|
||||||
|
int32_t size = tsDnodeEpsSize;
|
||||||
|
pthread_mutex_unlock(&tsDnodeEpsMutex);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mnodeGetDnodeEpsData(SDnodeEps *pEps, int32_t epsSize) {
|
||||||
|
pthread_mutex_lock(&tsDnodeEpsMutex);
|
||||||
|
if (epsSize == tsDnodeEpsSize) {
|
||||||
|
memcpy(pEps, tsDnodeEps, tsDnodeEpsSize);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&tsDnodeEpsMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mnodeUpdateDnodeEps() {
|
||||||
|
pthread_mutex_lock(&tsDnodeEpsMutex);
|
||||||
|
|
||||||
|
int32_t totalDnodes = mnodeGetDnodesNum();
|
||||||
|
tsDnodeEpsSize = sizeof(SDnodeEps) + totalDnodes * sizeof(SDnodeEp);
|
||||||
|
free(tsDnodeEps);
|
||||||
|
tsDnodeEps = calloc(1, tsDnodeEpsSize);
|
||||||
|
tsDnodeEps->dnodeNum = htonl(totalDnodes);
|
||||||
|
|
||||||
|
SDnodeObj *pDnode = NULL;
|
||||||
|
void * pIter = NULL;
|
||||||
|
int32_t dnodesNum = 0;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pIter = mnodeGetNextDnode(pIter, &pDnode);
|
||||||
|
if (pDnode == NULL) break;
|
||||||
|
if (dnodesNum >= totalDnodes) break;
|
||||||
|
|
||||||
|
SDnodeEp *pEp = &tsDnodeEps->dnodeEps[dnodesNum];
|
||||||
|
dnodesNum++;
|
||||||
|
pEp->dnodeId = htonl(pDnode->dnodeId);
|
||||||
|
pEp->dnodePort = htons(pDnode->dnodePort);
|
||||||
|
tstrncpy(pEp->dnodeFqdn, pDnode->dnodeFqdn, TSDB_FQDN_LEN);
|
||||||
|
mnodeDecDnodeRef(pDnode);
|
||||||
|
}
|
||||||
|
|
||||||
|
sdbFreeIter(pIter);
|
||||||
|
pthread_mutex_unlock(&tsDnodeEpsMutex);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
|
||||||
SDnodeObj *pDnode = NULL;
|
SDnodeObj *pDnode = NULL;
|
||||||
SDMStatusMsg *pStatus = pMsg->rpcMsg.pCont;
|
SStatusMsg *pStatus = pMsg->rpcMsg.pCont;
|
||||||
pStatus->dnodeId = htonl(pStatus->dnodeId);
|
pStatus->dnodeId = htonl(pStatus->dnodeId);
|
||||||
pStatus->moduleStatus = htonl(pStatus->moduleStatus);
|
pStatus->moduleStatus = htonl(pStatus->moduleStatus);
|
||||||
pStatus->lastReboot = htonl(pStatus->lastReboot);
|
pStatus->lastReboot = htonl(pStatus->lastReboot);
|
||||||
|
@ -477,8 +537,11 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t openVnodes = htons(pStatus->openVnodes);
|
int32_t openVnodes = htons(pStatus->openVnodes);
|
||||||
int32_t contLen = sizeof(SDMStatusRsp) + openVnodes * sizeof(SDMVgroupAccess);
|
int32_t epsSize = mnodeGetDnodeEpsSize();
|
||||||
SDMStatusRsp *pRsp = rpcMallocCont(contLen);
|
int32_t vgAccessSize = openVnodes * sizeof(SVgroupAccess);
|
||||||
|
int32_t contLen = sizeof(SStatusRsp) + vgAccessSize + epsSize;
|
||||||
|
|
||||||
|
SStatusRsp *pRsp = rpcMallocCont(contLen);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
mnodeDecDnodeRef(pDnode);
|
mnodeDecDnodeRef(pDnode);
|
||||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||||
|
@ -488,7 +551,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
|
||||||
pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt);
|
pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt);
|
||||||
pRsp->dnodeCfg.numOfVnodes = htonl(openVnodes);
|
pRsp->dnodeCfg.numOfVnodes = htonl(openVnodes);
|
||||||
tstrncpy(pRsp->dnodeCfg.clusterId, mnodeGetClusterId(), TSDB_CLUSTER_ID_LEN);
|
tstrncpy(pRsp->dnodeCfg.clusterId, mnodeGetClusterId(), TSDB_CLUSTER_ID_LEN);
|
||||||
SDMVgroupAccess *pAccess = (SDMVgroupAccess *)((char *)pRsp + sizeof(SDMStatusRsp));
|
SVgroupAccess *pAccess = (SVgroupAccess *)((char *)pRsp + sizeof(SStatusRsp));
|
||||||
|
|
||||||
for (int32_t j = 0; j < openVnodes; ++j) {
|
for (int32_t j = 0; j < openVnodes; ++j) {
|
||||||
SVnodeLoad *pVload = &pStatus->load[j];
|
SVnodeLoad *pVload = &pStatus->load[j];
|
||||||
|
@ -539,6 +602,9 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
mnodeDecDnodeRef(pDnode);
|
mnodeDecDnodeRef(pDnode);
|
||||||
|
|
||||||
|
SDnodeEps *pEps = (SDnodeEps *)((char *)pRsp + sizeof(SStatusRsp) + vgAccessSize);
|
||||||
|
mnodeGetDnodeEpsData(pEps, epsSize);
|
||||||
|
|
||||||
pMsg->rpcRsp.len = contLen;
|
pMsg->rpcRsp.len = contLen;
|
||||||
pMsg->rpcRsp.rsp = pRsp;
|
pMsg->rpcRsp.rsp = pRsp;
|
||||||
|
|
||||||
|
@ -645,7 +711,7 @@ static int32_t mnodeDropDnodeByEp(char *ep, SMnodeMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
|
||||||
SCMCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
SCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
|
|
||||||
if (strcmp(pMsg->pUser->user, TSDB_DEFAULT_USER) != 0) {
|
if (strcmp(pMsg->pUser->user, TSDB_DEFAULT_USER) != 0) {
|
||||||
return TSDB_CODE_MND_NO_RIGHTS;
|
return TSDB_CODE_MND_NO_RIGHTS;
|
||||||
|
@ -655,7 +721,7 @@ static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg) {
|
||||||
SCMDropDnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
SDropDnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||||
|
|
||||||
if (strcmp(pMsg->pUser->user, TSDB_DEFAULT_USER) != 0) {
|
if (strcmp(pMsg->pUser->user, TSDB_DEFAULT_USER) != 0) {
|
||||||
return TSDB_CODE_MND_NO_RIGHTS;
|
return TSDB_CODE_MND_NO_RIGHTS;
|
||||||
|
|
|
@ -38,7 +38,7 @@ static void * tsMnodeSdb = NULL;
|
||||||
static int32_t tsMnodeUpdateSize = 0;
|
static int32_t tsMnodeUpdateSize = 0;
|
||||||
static SRpcEpSet tsMnodeEpSetForShell;
|
static SRpcEpSet tsMnodeEpSetForShell;
|
||||||
static SRpcEpSet tsMnodeEpSetForPeer;
|
static SRpcEpSet tsMnodeEpSetForPeer;
|
||||||
static SDMMnodeInfos tsMnodeInfos;
|
static SMnodeInfos tsMnodeInfos;
|
||||||
static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
|
|
||||||
|
@ -71,7 +71,8 @@ static int32_t mnodeMnodeActionInsert(SSdbOper *pOper) {
|
||||||
pDnode->isMgmt = true;
|
pDnode->isMgmt = true;
|
||||||
mnodeDecDnodeRef(pDnode);
|
mnodeDecDnodeRef(pDnode);
|
||||||
|
|
||||||
mInfo("mnode:%d, fqdn:%s ep:%s port:%d, do insert action", pMnode->mnodeId, pDnode->dnodeFqdn, pDnode->dnodeEp, pDnode->dnodePort);
|
mInfo("mnode:%d, fqdn:%s ep:%s port:%u, do insert action", pMnode->mnodeId, pDnode->dnodeFqdn, pDnode->dnodeEp,
|
||||||
|
pDnode->dnodePort);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +203,7 @@ void mnodeUpdateMnodeEpSet() {
|
||||||
|
|
||||||
memset(&tsMnodeEpSetForShell, 0, sizeof(SRpcEpSet));
|
memset(&tsMnodeEpSetForShell, 0, sizeof(SRpcEpSet));
|
||||||
memset(&tsMnodeEpSetForPeer, 0, sizeof(SRpcEpSet));
|
memset(&tsMnodeEpSetForPeer, 0, sizeof(SRpcEpSet));
|
||||||
memset(&tsMnodeInfos, 0, sizeof(SDMMnodeInfos));
|
memset(&tsMnodeInfos, 0, sizeof(SMnodeInfos));
|
||||||
|
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
void * pIter = NULL;
|
void * pIter = NULL;
|
||||||
|
@ -221,8 +222,8 @@ void mnodeUpdateMnodeEpSet() {
|
||||||
tsMnodeEpSetForPeer.port[index] = htons(pDnode->dnodePort + TSDB_PORT_DNODEDNODE);
|
tsMnodeEpSetForPeer.port[index] = htons(pDnode->dnodePort + TSDB_PORT_DNODEDNODE);
|
||||||
mDebug("mnode:%d, for peer fqdn:%s %d", pDnode->dnodeId, tsMnodeEpSetForPeer.fqdn[index], htons(tsMnodeEpSetForPeer.port[index]));
|
mDebug("mnode:%d, for peer fqdn:%s %d", pDnode->dnodeId, tsMnodeEpSetForPeer.fqdn[index], htons(tsMnodeEpSetForPeer.port[index]));
|
||||||
|
|
||||||
tsMnodeInfos.nodeInfos[index].nodeId = htonl(pMnode->mnodeId);
|
tsMnodeInfos.mnodeInfos[index].mnodeId = htonl(pMnode->mnodeId);
|
||||||
strcpy(tsMnodeInfos.nodeInfos[index].nodeEp, pDnode->dnodeEp);
|
strcpy(tsMnodeInfos.mnodeInfos[index].mnodeEp, pDnode->dnodeEp);
|
||||||
|
|
||||||
if (pMnode->role == TAOS_SYNC_ROLE_MASTER) {
|
if (pMnode->role == TAOS_SYNC_ROLE_MASTER) {
|
||||||
tsMnodeEpSetForShell.inUse = index;
|
tsMnodeEpSetForShell.inUse = index;
|
||||||
|
@ -238,7 +239,7 @@ void mnodeUpdateMnodeEpSet() {
|
||||||
mnodeDecMnodeRef(pMnode);
|
mnodeDecMnodeRef(pMnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsMnodeInfos.nodeNum = index;
|
tsMnodeInfos.mnodeNum = index;
|
||||||
tsMnodeEpSetForShell.numOfEps = index;
|
tsMnodeEpSetForShell.numOfEps = index;
|
||||||
tsMnodeEpSetForPeer.numOfEps = index;
|
tsMnodeEpSetForPeer.numOfEps = index;
|
||||||
|
|
||||||
|
@ -260,19 +261,19 @@ void mnodeGetMnodeEpSetForShell(SRpcEpSet *epSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char* mnodeGetMnodeMasterEp() {
|
char* mnodeGetMnodeMasterEp() {
|
||||||
return tsMnodeInfos.nodeInfos[tsMnodeInfos.inUse].nodeEp;
|
return tsMnodeInfos.mnodeInfos[tsMnodeInfos.inUse].mnodeEp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeGetMnodeInfos(void *mnodeInfos) {
|
void mnodeGetMnodeInfos(void *mnodeInfos) {
|
||||||
mnodeMnodeRdLock();
|
mnodeMnodeRdLock();
|
||||||
*(SDMMnodeInfos *)mnodeInfos = tsMnodeInfos;
|
*(SMnodeInfos *)mnodeInfos = tsMnodeInfos;
|
||||||
mnodeMnodeUnLock();
|
mnodeMnodeUnLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeSendCreateMnodeMsg(int32_t dnodeId, char *dnodeEp) {
|
static int32_t mnodeSendCreateMnodeMsg(int32_t dnodeId, char *dnodeEp) {
|
||||||
mDebug("dnode:%d, send create mnode msg to dnode %s", dnodeId, dnodeEp);
|
mDebug("dnode:%d, send create mnode msg to dnode %s", dnodeId, dnodeEp);
|
||||||
|
|
||||||
SMDCreateMnodeMsg *pCreate = rpcMallocCont(sizeof(SMDCreateMnodeMsg));
|
SCreateMnodeMsg *pCreate = rpcMallocCont(sizeof(SCreateMnodeMsg));
|
||||||
if (pCreate == NULL) {
|
if (pCreate == NULL) {
|
||||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||||
} else {
|
} else {
|
||||||
|
@ -280,21 +281,21 @@ static int32_t mnodeSendCreateMnodeMsg(int32_t dnodeId, char *dnodeEp) {
|
||||||
tstrncpy(pCreate->dnodeEp, dnodeEp, sizeof(pCreate->dnodeEp));
|
tstrncpy(pCreate->dnodeEp, dnodeEp, sizeof(pCreate->dnodeEp));
|
||||||
pCreate->mnodes = tsMnodeInfos;
|
pCreate->mnodes = tsMnodeInfos;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int i = 0; i < pCreate->mnodes.nodeNum; ++i) {
|
for (int i = 0; i < pCreate->mnodes.mnodeNum; ++i) {
|
||||||
if (pCreate->mnodes.nodeInfos[i].nodeId == htonl(dnodeId)) {
|
if (pCreate->mnodes.mnodeInfos[i].mnodeId == htonl(dnodeId)) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
pCreate->mnodes.nodeInfos[pCreate->mnodes.nodeNum].nodeId = htonl(dnodeId);
|
pCreate->mnodes.mnodeInfos[pCreate->mnodes.mnodeNum].mnodeId = htonl(dnodeId);
|
||||||
tstrncpy(pCreate->mnodes.nodeInfos[pCreate->mnodes.nodeNum].nodeEp, dnodeEp, sizeof(pCreate->dnodeEp));
|
tstrncpy(pCreate->mnodes.mnodeInfos[pCreate->mnodes.mnodeNum].mnodeEp, dnodeEp, sizeof(pCreate->dnodeEp));
|
||||||
pCreate->mnodes.nodeNum++;
|
pCreate->mnodes.mnodeNum++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {0};
|
||||||
rpcMsg.pCont = pCreate;
|
rpcMsg.pCont = pCreate;
|
||||||
rpcMsg.contLen = sizeof(SMDCreateMnodeMsg);
|
rpcMsg.contLen = sizeof(SCreateMnodeMsg);
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_MD_CREATE_MNODE;
|
rpcMsg.msgType = TSDB_MSG_TYPE_MD_CREATE_MNODE;
|
||||||
|
|
||||||
SRpcMsg rpcRsp = {0};
|
SRpcMsg rpcRsp = {0};
|
||||||
|
|
|
@ -280,7 +280,7 @@ static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, voi
|
||||||
}
|
}
|
||||||
|
|
||||||
// not thread safe, need optimized
|
// not thread safe, need optimized
|
||||||
int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg) {
|
int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pHBMsg) {
|
||||||
pConn->numOfQueries = htonl(pHBMsg->numOfQueries);
|
pConn->numOfQueries = htonl(pHBMsg->numOfQueries);
|
||||||
if (pConn->numOfQueries > 0) {
|
if (pConn->numOfQueries > 0) {
|
||||||
if (pConn->pQueries == NULL) {
|
if (pConn->pQueries == NULL) {
|
||||||
|
@ -561,7 +561,7 @@ static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) {
|
||||||
SUserObj *pUser = pMsg->pUser;
|
SUserObj *pUser = pMsg->pUser;
|
||||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
||||||
|
|
||||||
SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont;
|
SKillQueryMsg *pKill = pMsg->rpcMsg.pCont;
|
||||||
mInfo("kill query msg is received, queryId:%s", pKill->queryId);
|
mInfo("kill query msg is received, queryId:%s", pKill->queryId);
|
||||||
|
|
||||||
const char delim = ':';
|
const char delim = ':';
|
||||||
|
@ -592,7 +592,7 @@ static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) {
|
||||||
SUserObj *pUser = pMsg->pUser;
|
SUserObj *pUser = pMsg->pUser;
|
||||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
||||||
|
|
||||||
SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont;
|
SKillQueryMsg *pKill = pMsg->rpcMsg.pCont;
|
||||||
mInfo("kill stream msg is received, streamId:%s", pKill->queryId);
|
mInfo("kill stream msg is received, streamId:%s", pKill->queryId);
|
||||||
|
|
||||||
const char delim = ':';
|
const char delim = ':';
|
||||||
|
@ -623,7 +623,7 @@ static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg) {
|
||||||
SUserObj *pUser = pMsg->pUser;
|
SUserObj *pUser = pMsg->pUser;
|
||||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
||||||
|
|
||||||
SCMKillConnMsg *pKill = pMsg->rpcMsg.pCont;
|
SKillConnMsg *pKill = pMsg->rpcMsg.pCont;
|
||||||
int32_t connId = atoi(pKill->queryId);
|
int32_t connId = atoi(pKill->queryId);
|
||||||
SConnObj *pConn = taosCacheAcquireByKey(tsMnodeConnCache, &connId, sizeof(int32_t));
|
SConnObj *pConn = taosCacheAcquireByKey(tsMnodeConnCache, &connId, sizeof(int32_t));
|
||||||
if (pConn == NULL) {
|
if (pConn == NULL) {
|
||||||
|
|
|
@ -175,7 +175,7 @@ static void *sdbGetTableFromId(int32_t tableId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbInitWal() {
|
static int32_t sdbInitWal() {
|
||||||
SWalCfg walCfg = {.walLevel = 2, .wals = 2, .keep = 1, .fsyncPeriod = 0};
|
SWalCfg walCfg = {.vgId = 1, .walLevel = 2, .wals = 2, .keep = 1, .fsyncPeriod = 0};
|
||||||
char temp[TSDB_FILENAME_LEN];
|
char temp[TSDB_FILENAME_LEN];
|
||||||
sprintf(temp, "%s/wal", tsMnodeDir);
|
sprintf(temp, "%s/wal", tsMnodeDir);
|
||||||
tsSdbObj.wal = walOpen(temp, &walCfg);
|
tsSdbObj.wal = walOpen(temp, &walCfg);
|
||||||
|
@ -237,8 +237,8 @@ static uint32_t sdbGetFileInfo(void *ahandle, char *name, uint32_t *index, uint3
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdbGetWalInfo(void *ahandle, char *name, uint32_t *index) {
|
static int32_t sdbGetWalInfo(void *ahandle, char *fileName, int64_t *fileId) {
|
||||||
return walGetWalFile(tsSdbObj.wal, name, index);
|
return walGetWalFile(tsSdbObj.wal, fileName, fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sdbNotifyRole(void *ahandle, int8_t role) {
|
static void sdbNotifyRole(void *ahandle, int8_t role) {
|
||||||
|
@ -312,7 +312,7 @@ void sdbUpdateAsync() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdbUpdateSync(void *pMnodes) {
|
void sdbUpdateSync(void *pMnodes) {
|
||||||
SDMMnodeInfos *mnodes = pMnodes;
|
SMnodeInfos *mnodes = pMnodes;
|
||||||
if (!mnodeIsRunning()) {
|
if (!mnodeIsRunning()) {
|
||||||
mDebug("mnode not start yet, update sync config later");
|
mDebug("mnode not start yet, update sync config later");
|
||||||
return;
|
return;
|
||||||
|
@ -346,10 +346,10 @@ void sdbUpdateSync(void *pMnodes) {
|
||||||
syncCfg.replica = index;
|
syncCfg.replica = index;
|
||||||
mDebug("mnodes info not input, use infos in sdb, numOfMnodes:%d", syncCfg.replica);
|
mDebug("mnodes info not input, use infos in sdb, numOfMnodes:%d", syncCfg.replica);
|
||||||
} else {
|
} else {
|
||||||
for (index = 0; index < mnodes->nodeNum; ++index) {
|
for (index = 0; index < mnodes->mnodeNum; ++index) {
|
||||||
SDMMnodeInfo *node = &mnodes->nodeInfos[index];
|
SMnodeInfo *node = &mnodes->mnodeInfos[index];
|
||||||
syncCfg.nodeInfo[index].nodeId = node->nodeId;
|
syncCfg.nodeInfo[index].nodeId = node->mnodeId;
|
||||||
taosGetFqdnPortFromEp(node->nodeEp, syncCfg.nodeInfo[index].nodeFqdn, &syncCfg.nodeInfo[index].nodePort);
|
taosGetFqdnPortFromEp(node->mnodeEp, syncCfg.nodeInfo[index].nodeFqdn, &syncCfg.nodeInfo[index].nodePort);
|
||||||
syncCfg.nodeInfo[index].nodePort += TSDB_PORT_SYNC;
|
syncCfg.nodeInfo[index].nodePort += TSDB_PORT_SYNC;
|
||||||
}
|
}
|
||||||
syncCfg.replica = index;
|
syncCfg.replica = index;
|
||||||
|
|
|
@ -110,7 +110,7 @@ static char *mnodeGetShowType(int32_t showType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) {
|
||||||
SCMShowMsg *pShowMsg = pMsg->rpcMsg.pCont;
|
SShowMsg *pShowMsg = pMsg->rpcMsg.pCont;
|
||||||
if (pShowMsg->type >= TSDB_MGMT_TABLE_MAX) {
|
if (pShowMsg->type >= TSDB_MGMT_TABLE_MAX) {
|
||||||
return TSDB_CODE_MND_INVALID_MSG_TYPE;
|
return TSDB_CODE_MND_INVALID_MSG_TYPE;
|
||||||
}
|
}
|
||||||
|
@ -132,8 +132,8 @@ static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) {
|
||||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t size = sizeof(SCMShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE;
|
int32_t size = sizeof(SShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE;
|
||||||
SCMShowRsp *pShowRsp = rpcMallocCont(size);
|
SShowRsp *pShowRsp = rpcMallocCont(size);
|
||||||
if (pShowRsp == NULL) {
|
if (pShowRsp == NULL) {
|
||||||
mnodeReleaseShowObj(pShow, true);
|
mnodeReleaseShowObj(pShow, true);
|
||||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||||
|
@ -146,7 +146,7 @@ static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
pMsg->rpcRsp.rsp = pShowRsp;
|
pMsg->rpcRsp.rsp = pShowRsp;
|
||||||
pMsg->rpcRsp.len = sizeof(SCMShowRsp) + sizeof(SSchema) * pShow->numOfColumns;
|
pMsg->rpcRsp.len = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns;
|
||||||
mnodeReleaseShowObj(pShow, false);
|
mnodeReleaseShowObj(pShow, false);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
|
@ -232,12 +232,12 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
||||||
SCMHeartBeatRsp *pRsp = (SCMHeartBeatRsp *) rpcMallocCont(sizeof(SCMHeartBeatRsp));
|
SHeartBeatRsp *pRsp = (SHeartBeatRsp *)rpcMallocCont(sizeof(SHeartBeatRsp));
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMHeartBeatMsg *pHBMsg = pMsg->rpcMsg.pCont;
|
SHeartBeatMsg *pHBMsg = pMsg->rpcMsg.pCont;
|
||||||
if (taosCheckVersion(pHBMsg->clientVer, version, 3) != TSDB_CODE_SUCCESS) {
|
if (taosCheckVersion(pHBMsg->clientVer, version, 3) != TSDB_CODE_SUCCESS) {
|
||||||
return TSDB_CODE_TSC_INVALID_VERSION; // todo change the error code
|
return TSDB_CODE_TSC_INVALID_VERSION; // todo change the error code
|
||||||
}
|
}
|
||||||
|
@ -280,15 +280,15 @@ static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
||||||
mnodeGetMnodeEpSetForShell(&pRsp->epSet);
|
mnodeGetMnodeEpSetForShell(&pRsp->epSet);
|
||||||
|
|
||||||
pMsg->rpcRsp.rsp = pRsp;
|
pMsg->rpcRsp.rsp = pRsp;
|
||||||
pMsg->rpcRsp.len = sizeof(SCMHeartBeatRsp);
|
pMsg->rpcRsp.len = sizeof(SHeartBeatRsp);
|
||||||
|
|
||||||
mnodeReleaseConn(pConn);
|
mnodeReleaseConn(pConn);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
|
||||||
SCMConnectMsg *pConnectMsg = pMsg->rpcMsg.pCont;
|
SConnectMsg *pConnectMsg = pMsg->rpcMsg.pCont;
|
||||||
SCMConnectRsp *pConnectRsp = NULL;
|
SConnectRsp *pConnectRsp = NULL;
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
SRpcConnInfo connInfo = {0};
|
SRpcConnInfo connInfo = {0};
|
||||||
|
@ -324,7 +324,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
}
|
}
|
||||||
|
|
||||||
pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp));
|
pConnectRsp = rpcMallocCont(sizeof(SConnectRsp));
|
||||||
if (pConnectRsp == NULL) {
|
if (pConnectRsp == NULL) {
|
||||||
code = TSDB_CODE_MND_OUT_OF_MEMORY;
|
code = TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||||
goto connect_over;
|
goto connect_over;
|
||||||
|
@ -353,14 +353,14 @@ connect_over:
|
||||||
} else {
|
} else {
|
||||||
mLInfo("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code));
|
mLInfo("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code));
|
||||||
pMsg->rpcRsp.rsp = pConnectRsp;
|
pMsg->rpcRsp.rsp = pConnectRsp;
|
||||||
pMsg->rpcRsp.len = sizeof(SCMConnectRsp);
|
pMsg->rpcRsp.len = sizeof(SConnectRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessUseMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessUseMsg(SMnodeMsg *pMsg) {
|
||||||
SCMUseDbMsg *pUseDbMsg = pMsg->rpcMsg.pCont;
|
SUseDbMsg *pUseDbMsg = pMsg->rpcMsg.pCont;
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pUseDbMsg->db);
|
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pUseDbMsg->db);
|
||||||
|
|
|
@ -778,7 +778,7 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) {
|
||||||
SCMTableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
STableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||||
pInfo->createFlag = htons(pInfo->createFlag);
|
pInfo->createFlag = htons(pInfo->createFlag);
|
||||||
mDebug("app:%p:%p, table:%s, table meta msg is received from thandle:%p, createFlag:%d", pMsg->rpcMsg.ahandle, pMsg,
|
mDebug("app:%p:%p, table:%s, table meta msg is received from thandle:%p, createFlag:%d", pMsg->rpcMsg.ahandle, pMsg,
|
||||||
pInfo->tableId, pMsg->rpcMsg.handle, pInfo->createFlag);
|
pInfo->tableId, pMsg->rpcMsg.handle, pInfo->createFlag);
|
||||||
|
@ -915,8 +915,8 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
|
||||||
SVgObj *pVgroup = mnodeGetVgroup(*pVgId);
|
SVgObj *pVgroup = mnodeGetVgroup(*pVgId);
|
||||||
if (pVgroup == NULL) break;
|
if (pVgroup == NULL) break;
|
||||||
|
|
||||||
SMDDropSTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropSTableMsg));
|
SDropSTableMsg *pDrop = rpcMallocCont(sizeof(SDropSTableMsg));
|
||||||
pDrop->contLen = htonl(sizeof(SMDDropSTableMsg));
|
pDrop->contLen = htonl(sizeof(SDropSTableMsg));
|
||||||
pDrop->vgId = htonl(pVgroup->vgId);
|
pDrop->vgId = htonl(pVgroup->vgId);
|
||||||
pDrop->uid = htobe64(pStable->uid);
|
pDrop->uid = htobe64(pStable->uid);
|
||||||
mnodeExtractTableName(pStable->info.tableId, pDrop->tableId);
|
mnodeExtractTableName(pStable->info.tableId, pDrop->tableId);
|
||||||
|
@ -924,7 +924,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
|
||||||
mInfo("app:%p:%p, stable:%s, send drop stable msg to vgId:%d", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId,
|
mInfo("app:%p:%p, stable:%s, send drop stable msg to vgId:%d", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId,
|
||||||
pVgroup->vgId);
|
pVgroup->vgId);
|
||||||
SRpcEpSet epSet = mnodeGetEpSetFromVgroup(pVgroup);
|
SRpcEpSet epSet = mnodeGetEpSetFromVgroup(pVgroup);
|
||||||
SRpcMsg rpcMsg = {.pCont = pDrop, .contLen = sizeof(SMDDropSTableMsg), .msgType = TSDB_MSG_TYPE_MD_DROP_STABLE};
|
SRpcMsg rpcMsg = {.pCont = pDrop, .contLen = sizeof(SDropSTableMsg), .msgType = TSDB_MSG_TYPE_MD_DROP_STABLE};
|
||||||
dnodeSendMsgToDnode(&epSet, &rpcMsg);
|
dnodeSendMsgToDnode(&epSet, &rpcMsg);
|
||||||
mnodeDecVgroupRef(pVgroup);
|
mnodeDecVgroupRef(pVgroup);
|
||||||
}
|
}
|
||||||
|
@ -1472,31 +1472,31 @@ static int32_t mnodeGetSuperTableMeta(SMnodeMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
|
||||||
SCMSTableVgroupMsg *pInfo = pMsg->rpcMsg.pCont;
|
SSTableVgroupMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||||
int32_t numOfTable = htonl(pInfo->numOfTables);
|
int32_t numOfTable = htonl(pInfo->numOfTables);
|
||||||
|
|
||||||
// reserve space
|
// reserve space
|
||||||
int32_t contLen = sizeof(SCMSTableVgroupRspMsg) + 32 * sizeof(SCMVgroupMsg) + sizeof(SVgroupsMsg);
|
int32_t contLen = sizeof(SSTableVgroupRspMsg) + 32 * sizeof(SVgroupMsg) + sizeof(SVgroupsMsg);
|
||||||
for (int32_t i = 0; i < numOfTable; ++i) {
|
for (int32_t i = 0; i < numOfTable; ++i) {
|
||||||
char *stableName = (char*)pInfo + sizeof(SCMSTableVgroupMsg) + (TSDB_TABLE_FNAME_LEN) * i;
|
char *stableName = (char *)pInfo + sizeof(SSTableVgroupMsg) + (TSDB_TABLE_FNAME_LEN)*i;
|
||||||
SSuperTableObj *pTable = mnodeGetSuperTable(stableName);
|
SSuperTableObj *pTable = mnodeGetSuperTable(stableName);
|
||||||
if (pTable != NULL && pTable->vgHash != NULL) {
|
if (pTable != NULL && pTable->vgHash != NULL) {
|
||||||
contLen += (taosHashGetSize(pTable->vgHash) * sizeof(SCMVgroupMsg) + sizeof(SVgroupsMsg));
|
contLen += (taosHashGetSize(pTable->vgHash) * sizeof(SVgroupMsg) + sizeof(SVgroupsMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeDecTableRef(pTable);
|
mnodeDecTableRef(pTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCMSTableVgroupRspMsg *pRsp = rpcMallocCont(contLen);
|
SSTableVgroupRspMsg *pRsp = rpcMallocCont(contLen);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
pRsp->numOfTables = 0;
|
pRsp->numOfTables = 0;
|
||||||
char *msg = (char *)pRsp + sizeof(SCMSTableVgroupRspMsg);
|
char *msg = (char *)pRsp + sizeof(SSTableVgroupRspMsg);
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfTable; ++i) {
|
for (int32_t i = 0; i < numOfTable; ++i) {
|
||||||
char * stableName = (char *)pInfo + sizeof(SCMSTableVgroupMsg) + (TSDB_TABLE_FNAME_LEN)*i;
|
char * stableName = (char *)pInfo + sizeof(SSTableVgroupMsg) + (TSDB_TABLE_FNAME_LEN)*i;
|
||||||
SSuperTableObj *pTable = mnodeGetSuperTable(stableName);
|
SSuperTableObj *pTable = mnodeGetSuperTable(stableName);
|
||||||
if (pTable == NULL) {
|
if (pTable == NULL) {
|
||||||
mError("app:%p:%p, stable:%s, not exist while get stable vgroup info", pMsg->rpcMsg.ahandle, pMsg, stableName);
|
mError("app:%p:%p, stable:%s, not exist while get stable vgroup info", pMsg->rpcMsg.ahandle, pMsg, stableName);
|
||||||
|
@ -1548,7 +1548,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
|
||||||
pVgroupMsg->numOfVgroups = htonl(vgSize);
|
pVgroupMsg->numOfVgroups = htonl(vgSize);
|
||||||
|
|
||||||
// one table is done, try the next table
|
// one table is done, try the next table
|
||||||
msg += sizeof(SVgroupsMsg) + vgSize * sizeof(SCMVgroupMsg);
|
msg += sizeof(SVgroupsMsg) + vgSize * sizeof(SVgroupMsg);
|
||||||
pRsp->numOfTables++;
|
pRsp->numOfTables++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2146,7 +2146,7 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
|
static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
|
||||||
SCMTableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
STableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||||
STagData *pTags = (STagData *)pInfo->tags;
|
STagData *pTags = (STagData *)pInfo->tags;
|
||||||
int32_t tagLen = htonl(pTags->dataLen);
|
int32_t tagLen = htonl(pTags->dataLen);
|
||||||
if (pTags->name[0] == 0) {
|
if (pTags->name[0] == 0) {
|
||||||
|
@ -2307,7 +2307,7 @@ static SChildTableObj* mnodeGetTableByPos(int32_t vnode, int32_t tid) {
|
||||||
static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) {
|
||||||
return TSDB_CODE_COM_OPS_NOT_SUPPORT;
|
return TSDB_CODE_COM_OPS_NOT_SUPPORT;
|
||||||
#if 0
|
#if 0
|
||||||
SDMConfigTableMsg *pCfg = pMsg->rpcMsg.pCont;
|
SConfigTableMsg *pCfg = pMsg->rpcMsg.pCont;
|
||||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||||
pCfg->vgId = htonl(pCfg->vgId);
|
pCfg->vgId = htonl(pCfg->vgId);
|
||||||
pCfg->sid = htonl(pCfg->sid);
|
pCfg->sid = htonl(pCfg->sid);
|
||||||
|
@ -2469,7 +2469,7 @@ static void mnodeProcessAlterTableRsp(SRpcMsg *rpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
|
||||||
SCMMultiTableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
SMultiTableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||||
pInfo->numOfTables = htonl(pInfo->numOfTables);
|
pInfo->numOfTables = htonl(pInfo->numOfTables);
|
||||||
|
|
||||||
int32_t totalMallocLen = 4 * 1024 * 1024; // first malloc 4 MB, subsequent reallocation as twice
|
int32_t totalMallocLen = 4 * 1024 * 1024; // first malloc 4 MB, subsequent reallocation as twice
|
||||||
|
@ -2705,7 +2705,7 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
|
||||||
SCMAlterTableMsg *pAlter = pMsg->rpcMsg.pCont;
|
SAlterTableMsg *pAlter = pMsg->rpcMsg.pCont;
|
||||||
mDebug("app:%p:%p, table:%s, alter table msg is received from thandle:%p", pMsg->rpcMsg.ahandle, pMsg,
|
mDebug("app:%p:%p, table:%s, alter table msg is received from thandle:%p", pMsg->rpcMsg.ahandle, pMsg,
|
||||||
pAlter->tableId, pMsg->rpcMsg.handle);
|
pAlter->tableId, pMsg->rpcMsg.handle);
|
||||||
|
|
||||||
|
|
|
@ -414,7 +414,7 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
||||||
SUserObj *pOperUser = pMsg->pUser;
|
SUserObj *pOperUser = pMsg->pUser;
|
||||||
|
|
||||||
if (pOperUser->superAuth) {
|
if (pOperUser->superAuth) {
|
||||||
SCMCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
|
SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
return mnodeCreateUser(pOperUser->pAcct, pCreate->user, pCreate->pass, pMsg);
|
return mnodeCreateUser(pOperUser->pAcct, pCreate->user, pCreate->pass, pMsg);
|
||||||
} else {
|
} else {
|
||||||
mError("user:%s, no rights to create user", pOperUser->user);
|
mError("user:%s, no rights to create user", pOperUser->user);
|
||||||
|
@ -426,7 +426,7 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
SUserObj *pOperUser = pMsg->pUser;
|
SUserObj *pOperUser = pMsg->pUser;
|
||||||
|
|
||||||
SCMAlterUserMsg *pAlter = pMsg->rpcMsg.pCont;
|
SAlterUserMsg *pAlter = pMsg->rpcMsg.pCont;
|
||||||
SUserObj *pUser = mnodeGetUser(pAlter->user);
|
SUserObj *pUser = mnodeGetUser(pAlter->user);
|
||||||
if (pUser == NULL) {
|
if (pUser == NULL) {
|
||||||
return TSDB_CODE_MND_INVALID_USER;
|
return TSDB_CODE_MND_INVALID_USER;
|
||||||
|
@ -514,7 +514,7 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
SUserObj *pOperUser = pMsg->pUser;
|
SUserObj *pOperUser = pMsg->pUser;
|
||||||
|
|
||||||
SCMDropUserMsg *pDrop = pMsg->rpcMsg.pCont;
|
SDropUserMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||||
SUserObj *pUser = mnodeGetUser(pDrop->user);
|
SUserObj *pUser = mnodeGetUser(pDrop->user);
|
||||||
if (pUser == NULL) {
|
if (pUser == NULL) {
|
||||||
return TSDB_CODE_MND_INVALID_USER;
|
return TSDB_CODE_MND_INVALID_USER;
|
||||||
|
@ -604,11 +604,11 @@ int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, cha
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg) {
|
||||||
SDMAuthMsg *pAuthMsg = pMsg->rpcMsg.pCont;
|
SAuthMsg *pAuthMsg = pMsg->rpcMsg.pCont;
|
||||||
SDMAuthRsp *pAuthRsp = rpcMallocCont(sizeof(SDMAuthRsp));
|
SAuthRsp *pAuthRsp = rpcMallocCont(sizeof(SAuthRsp));
|
||||||
|
|
||||||
pMsg->rpcRsp.rsp = pAuthRsp;
|
pMsg->rpcRsp.rsp = pAuthRsp;
|
||||||
pMsg->rpcRsp.len = sizeof(SDMAuthRsp);
|
pMsg->rpcRsp.len = sizeof(SAuthRsp);
|
||||||
|
|
||||||
return mnodeRetriveAuth(pAuthMsg->user, &pAuthRsp->spi, &pAuthRsp->encrypt, pAuthRsp->secret, pAuthRsp->ckey);
|
return mnodeRetriveAuth(pAuthMsg->user, &pAuthRsp->spi, &pAuthRsp->encrypt, pAuthRsp->secret, pAuthRsp->ckey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -818,11 +818,11 @@ void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SMDCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) {
|
static SCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) {
|
||||||
SDbObj *pDb = pVgroup->pDb;
|
SDbObj *pDb = pVgroup->pDb;
|
||||||
if (pDb == NULL) return NULL;
|
if (pDb == NULL) return NULL;
|
||||||
|
|
||||||
SMDCreateVnodeMsg *pVnode = rpcMallocCont(sizeof(SMDCreateVnodeMsg));
|
SCreateVnodeMsg *pVnode = rpcMallocCont(sizeof(SCreateVnodeMsg));
|
||||||
if (pVnode == NULL) return NULL;
|
if (pVnode == NULL) return NULL;
|
||||||
|
|
||||||
strcpy(pVnode->db, pVgroup->dbName);
|
strcpy(pVnode->db, pVgroup->dbName);
|
||||||
|
@ -830,7 +830,7 @@ static SMDCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) {
|
||||||
//TODO: dynamic alloc tables in tsdb
|
//TODO: dynamic alloc tables in tsdb
|
||||||
maxTables = MAX(10000, tsMaxTablePerVnode);
|
maxTables = MAX(10000, tsMaxTablePerVnode);
|
||||||
|
|
||||||
SMDVnodeCfg *pCfg = &pVnode->cfg;
|
SVnodeCfg *pCfg = &pVnode->cfg;
|
||||||
pCfg->vgId = htonl(pVgroup->vgId);
|
pCfg->vgId = htonl(pVgroup->vgId);
|
||||||
pCfg->cfgVersion = htonl(pDb->cfgVersion);
|
pCfg->cfgVersion = htonl(pDb->cfgVersion);
|
||||||
pCfg->cacheBlockSize = htonl(pDb->cfg.cacheBlockSize);
|
pCfg->cacheBlockSize = htonl(pDb->cfg.cacheBlockSize);
|
||||||
|
@ -852,7 +852,7 @@ static SMDCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) {
|
||||||
pCfg->quorum = pDb->cfg.quorum;
|
pCfg->quorum = pDb->cfg.quorum;
|
||||||
pCfg->update = pDb->cfg.update;
|
pCfg->update = pDb->cfg.update;
|
||||||
|
|
||||||
SMDVnodeDesc *pNodes = pVnode->nodes;
|
SVnodeDesc *pNodes = pVnode->nodes;
|
||||||
for (int32_t j = 0; j < pVgroup->numOfVnodes; ++j) {
|
for (int32_t j = 0; j < pVgroup->numOfVnodes; ++j) {
|
||||||
SDnodeObj *pDnode = pVgroup->vnodeGid[j].pDnode;
|
SDnodeObj *pDnode = pVgroup->vnodeGid[j].pDnode;
|
||||||
if (pDnode != NULL) {
|
if (pDnode != NULL) {
|
||||||
|
@ -887,11 +887,11 @@ SRpcEpSet mnodeGetEpSetFromIp(char *ep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeSendAlterVnodeMsg(SVgObj *pVgroup, SRpcEpSet *epSet) {
|
static void mnodeSendAlterVnodeMsg(SVgObj *pVgroup, SRpcEpSet *epSet) {
|
||||||
SMDAlterVnodeMsg *pAlter = mnodeBuildVnodeMsg(pVgroup);
|
SAlterVnodeMsg *pAlter = mnodeBuildVnodeMsg(pVgroup);
|
||||||
SRpcMsg rpcMsg = {
|
SRpcMsg rpcMsg = {
|
||||||
.ahandle = NULL,
|
.ahandle = NULL,
|
||||||
.pCont = pAlter,
|
.pCont = pAlter,
|
||||||
.contLen = pAlter ? sizeof(SMDAlterVnodeMsg) : 0,
|
.contLen = pAlter ? sizeof(SAlterVnodeMsg) : 0,
|
||||||
.code = 0,
|
.code = 0,
|
||||||
.msgType = TSDB_MSG_TYPE_MD_ALTER_VNODE
|
.msgType = TSDB_MSG_TYPE_MD_ALTER_VNODE
|
||||||
};
|
};
|
||||||
|
@ -910,11 +910,11 @@ void mnodeSendAlterVgroupMsg(SVgObj *pVgroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeSendCreateVnodeMsg(SVgObj *pVgroup, SRpcEpSet *epSet, void *ahandle) {
|
static void mnodeSendCreateVnodeMsg(SVgObj *pVgroup, SRpcEpSet *epSet, void *ahandle) {
|
||||||
SMDCreateVnodeMsg *pCreate = mnodeBuildVnodeMsg(pVgroup);
|
SCreateVnodeMsg *pCreate = mnodeBuildVnodeMsg(pVgroup);
|
||||||
SRpcMsg rpcMsg = {
|
SRpcMsg rpcMsg = {
|
||||||
.ahandle = ahandle,
|
.ahandle = ahandle,
|
||||||
.pCont = pCreate,
|
.pCont = pCreate,
|
||||||
.contLen = pCreate ? sizeof(SMDCreateVnodeMsg) : 0,
|
.contLen = pCreate ? sizeof(SCreateVnodeMsg) : 0,
|
||||||
.code = 0,
|
.code = 0,
|
||||||
.msgType = TSDB_MSG_TYPE_MD_CREATE_VNODE
|
.msgType = TSDB_MSG_TYPE_MD_CREATE_VNODE
|
||||||
};
|
};
|
||||||
|
@ -983,8 +983,8 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SMDDropVnodeMsg *mnodeBuildDropVnodeMsg(int32_t vgId) {
|
static SDropVnodeMsg *mnodeBuildDropVnodeMsg(int32_t vgId) {
|
||||||
SMDDropVnodeMsg *pDrop = rpcMallocCont(sizeof(SMDDropVnodeMsg));
|
SDropVnodeMsg *pDrop = rpcMallocCont(sizeof(SDropVnodeMsg));
|
||||||
if (pDrop == NULL) return NULL;
|
if (pDrop == NULL) return NULL;
|
||||||
|
|
||||||
pDrop->vgId = htonl(vgId);
|
pDrop->vgId = htonl(vgId);
|
||||||
|
@ -992,11 +992,11 @@ static SMDDropVnodeMsg *mnodeBuildDropVnodeMsg(int32_t vgId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeSendDropVnodeMsg(int32_t vgId, SRpcEpSet *epSet, void *ahandle) {
|
void mnodeSendDropVnodeMsg(int32_t vgId, SRpcEpSet *epSet, void *ahandle) {
|
||||||
SMDDropVnodeMsg *pDrop = mnodeBuildDropVnodeMsg(vgId);
|
SDropVnodeMsg *pDrop = mnodeBuildDropVnodeMsg(vgId);
|
||||||
SRpcMsg rpcMsg = {
|
SRpcMsg rpcMsg = {
|
||||||
.ahandle = ahandle,
|
.ahandle = ahandle,
|
||||||
.pCont = pDrop,
|
.pCont = pDrop,
|
||||||
.contLen = pDrop ? sizeof(SMDDropVnodeMsg) : 0,
|
.contLen = pDrop ? sizeof(SDropVnodeMsg) : 0,
|
||||||
.code = 0,
|
.code = 0,
|
||||||
.msgType = TSDB_MSG_TYPE_MD_DROP_VNODE
|
.msgType = TSDB_MSG_TYPE_MD_DROP_VNODE
|
||||||
};
|
};
|
||||||
|
@ -1045,7 +1045,7 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) {
|
||||||
SDMConfigVnodeMsg *pCfg = pMsg->rpcMsg.pCont;
|
SConfigVnodeMsg *pCfg = pMsg->rpcMsg.pCont;
|
||||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||||
pCfg->vgId = htonl(pCfg->vgId);
|
pCfg->vgId = htonl(pCfg->vgId);
|
||||||
|
|
||||||
|
|
|
@ -15,16 +15,21 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
|
||||||
#ifndef TAOS_OS_FUNC_FILE_GETTMPFILEPATH
|
#ifndef TAOS_OS_FUNC_FILE_GETTMPFILEPATH
|
||||||
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) {
|
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) {
|
||||||
const char *tdengineTmpFileNamePrefix = "tdengine-";
|
const char *tdengineTmpFileNamePrefix = "tdengine-";
|
||||||
|
|
||||||
char tmpPath[PATH_MAX];
|
char tmpPath[PATH_MAX];
|
||||||
char *tmpDir = "/tmp/";
|
int32_t len = strlen(tsTempDir);
|
||||||
|
memcpy(tmpPath, tsTempDir, len);
|
||||||
|
|
||||||
strcpy(tmpPath, tmpDir);
|
if (tmpPath[len - 1] != '/') {
|
||||||
strcat(tmpPath, tdengineTmpFileNamePrefix);
|
tmpPath[len++] = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(tmpPath + len, tdengineTmpFileNamePrefix);
|
||||||
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
||||||
strcat(tmpPath, fileNamePrefix);
|
strcat(tmpPath, fileNamePrefix);
|
||||||
strcat(tmpPath, "-%d-%s");
|
strcat(tmpPath, "-%d-%s");
|
||||||
|
|
|
@ -46,5 +46,16 @@ void osInit() {
|
||||||
strcpy(tsDnodeDir, "");
|
strcpy(tsDnodeDir, "");
|
||||||
strcpy(tsMnodeDir, "");
|
strcpy(tsMnodeDir, "");
|
||||||
strcpy(tsOsName, "Windows");
|
strcpy(tsOsName, "Windows");
|
||||||
|
|
||||||
|
const char *tmpDir = getenv("tmp");
|
||||||
|
if (tmpDir != NULL) {
|
||||||
|
tmpDir = getenv("temp");
|
||||||
|
}
|
||||||
|
if (tmpDir != NULL) {
|
||||||
|
strcpy(tsTempDir, tmpDir);
|
||||||
|
} else {
|
||||||
|
strcpy(tsTempDir, "C:\\Windows\\Temp");
|
||||||
|
}
|
||||||
|
|
||||||
taosWinSocketInit();
|
taosWinSocketInit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,20 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tulog.h"
|
#include "tulog.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
|
||||||
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) {
|
void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) {
|
||||||
const char* tdengineTmpFileNamePrefix = "tdengine-";
|
const char* tdengineTmpFileNamePrefix = "tdengine-";
|
||||||
char tmpPath[PATH_MAX];
|
char tmpPath[PATH_MAX];
|
||||||
|
|
||||||
char *tmpDir = getenv("tmp");
|
int32_t len = (int32_t)strlen(tsTempDir);
|
||||||
if (tmpDir == NULL) {
|
memcpy(tmpPath, tsTempDir, len);
|
||||||
tmpDir = "";
|
|
||||||
|
if (tmpPath[len - 1] != '/' && tmpPath[len - 1] != '\\') {
|
||||||
|
tmpPath[len++] = '\\';
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(tmpPath, tmpDir);
|
strcpy(tmpPath + len, tdengineTmpFileNamePrefix);
|
||||||
strcat(tmpPath, tdengineTmpFileNamePrefix);
|
strcat(tmpPath, tdengineTmpFileNamePrefix);
|
||||||
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
||||||
strcat(tmpPath, fileNamePrefix);
|
strcat(tmpPath, fileNamePrefix);
|
||||||
|
|
|
@ -341,7 +341,7 @@ void *rpcMallocCont(int contLen) {
|
||||||
tError("failed to malloc msg, size:%d", size);
|
tError("failed to malloc msg, size:%d", size);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
tTrace("malloc mem: %p", start);
|
tTrace("malloc mem:%p size:%d", start, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return start + sizeof(SRpcReqContext) + sizeof(SRpcHead);
|
return start + sizeof(SRpcReqContext) + sizeof(SRpcHead);
|
||||||
|
@ -557,10 +557,7 @@ void rpcCancelRequest(void *handle) {
|
||||||
int code = taosAcquireRef(tsRpcRefId, pContext);
|
int code = taosAcquireRef(tsRpcRefId, pContext);
|
||||||
if (code < 0) return;
|
if (code < 0) return;
|
||||||
|
|
||||||
if (pContext->pConn) {
|
rpcCloseConn(pContext->pConn);
|
||||||
tDebug("%s, app tries to cancel request", pContext->pConn->info);
|
|
||||||
rpcCloseConn(pContext->pConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
taosReleaseRef(tsRpcRefId, pContext);
|
taosReleaseRef(tsRpcRefId, pContext);
|
||||||
}
|
}
|
||||||
|
@ -655,6 +652,7 @@ static void rpcReleaseConn(SRpcConn *pConn) {
|
||||||
|
|
||||||
static void rpcCloseConn(void *thandle) {
|
static void rpcCloseConn(void *thandle) {
|
||||||
SRpcConn *pConn = (SRpcConn *)thandle;
|
SRpcConn *pConn = (SRpcConn *)thandle;
|
||||||
|
if (pConn == NULL) return;
|
||||||
|
|
||||||
rpcLockConn(pConn);
|
rpcLockConn(pConn);
|
||||||
|
|
||||||
|
@ -1026,6 +1024,7 @@ static void rpcProcessBrokenLink(SRpcConn *pConn) {
|
||||||
if (pConn->outType) {
|
if (pConn->outType) {
|
||||||
SRpcReqContext *pContext = pConn->pContext;
|
SRpcReqContext *pContext = pConn->pContext;
|
||||||
pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
|
pContext->pConn = NULL;
|
||||||
pConn->pReqMsg = NULL;
|
pConn->pReqMsg = NULL;
|
||||||
taosTmrStart(rpcProcessConnError, 0, pContext, pRpc->tmrCtrl);
|
taosTmrStart(rpcProcessConnError, 0, pContext, pRpc->tmrCtrl);
|
||||||
}
|
}
|
||||||
|
@ -1135,6 +1134,7 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead, SRpcReqConte
|
||||||
// it's a response
|
// it's a response
|
||||||
rpcMsg.handle = pContext;
|
rpcMsg.handle = pContext;
|
||||||
rpcMsg.ahandle = pContext->ahandle;
|
rpcMsg.ahandle = pContext->ahandle;
|
||||||
|
pContext->pConn = NULL;
|
||||||
|
|
||||||
// for UDP, port may be changed by server, the port in epSet shall be used for cache
|
// for UDP, port may be changed by server, the port in epSet shall be used for cache
|
||||||
if (pHead->code != TSDB_CODE_RPC_TOO_SLOW) {
|
if (pHead->code != TSDB_CODE_RPC_TOO_SLOW) {
|
||||||
|
@ -1370,6 +1370,7 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) {
|
||||||
tDebug("%s, failed to send msg:%s to %s:%hu", pConn->info, taosMsg[pConn->outType], pConn->peerFqdn, pConn->peerPort);
|
tDebug("%s, failed to send msg:%s to %s:%hu", pConn->info, taosMsg[pConn->outType], pConn->peerFqdn, pConn->peerPort);
|
||||||
if (pConn->pContext) {
|
if (pConn->pContext) {
|
||||||
pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
|
pConn->pContext->pConn = NULL;
|
||||||
pConn->pReqMsg = NULL;
|
pConn->pReqMsg = NULL;
|
||||||
taosTmrStart(rpcProcessConnError, 0, pConn->pContext, pRpc->tmrCtrl);
|
taosTmrStart(rpcProcessConnError, 0, pConn->pContext, pRpc->tmrCtrl);
|
||||||
rpcReleaseConn(pConn);
|
rpcReleaseConn(pConn);
|
||||||
|
@ -1478,7 +1479,7 @@ static SRpcHead *rpcDecompressRpcMsg(SRpcHead *pHead) {
|
||||||
pNewHead->msgLen = rpcMsgLenFromCont(origLen);
|
pNewHead->msgLen = rpcMsgLenFromCont(origLen);
|
||||||
rpcFreeMsg(pHead); // free the compressed message buffer
|
rpcFreeMsg(pHead); // free the compressed message buffer
|
||||||
pHead = pNewHead;
|
pHead = pNewHead;
|
||||||
tTrace("decomp malloc mem: %p", temp);
|
tTrace("decomp malloc mem:%p", temp);
|
||||||
} else {
|
} else {
|
||||||
tError("failed to allocate memory to decompress msg, contLen:%d", contLen);
|
tError("failed to allocate memory to decompress msg, contLen:%d", contLen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,12 +437,13 @@ static int taosReadTcpData(SFdObj *pFdObj, SRecvInfo *pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
msgLen = (int32_t)htonl((uint32_t)rpcHead.msgLen);
|
msgLen = (int32_t)htonl((uint32_t)rpcHead.msgLen);
|
||||||
buffer = malloc(msgLen + tsRpcOverhead);
|
int32_t size = msgLen + tsRpcOverhead;
|
||||||
|
buffer = malloc(size);
|
||||||
if (NULL == buffer) {
|
if (NULL == buffer) {
|
||||||
tError("%s %p TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen);
|
tError("%s %p TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
tTrace("TCP malloc mem: %p", buffer);
|
tTrace("TCP malloc mem:%p size:%d", buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = buffer + tsRpcOverhead;
|
msg = buffer + tsRpcOverhead;
|
||||||
|
|
|
@ -209,12 +209,13 @@ static void *taosRecvUdpData(void *param) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *tmsg = malloc(dataLen + tsRpcOverhead);
|
int32_t size = dataLen + tsRpcOverhead;
|
||||||
|
char *tmsg = malloc(size);
|
||||||
if (NULL == tmsg) {
|
if (NULL == tmsg) {
|
||||||
tError("%s failed to allocate memory, size:%" PRId64, pConn->label, (int64_t)dataLen);
|
tError("%s failed to allocate memory, size:%" PRId64, pConn->label, (int64_t)dataLen);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
tTrace("UDP malloc mem: %p", tmsg);
|
tTrace("UDP malloc mem:%p size:%d", tmsg, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmsg += tsRpcOverhead; // overhead for SRpcReqContext
|
tmsg += tsRpcOverhead; // overhead for SRpcReqContext
|
||||||
|
|
|
@ -287,7 +287,7 @@ static int syncRetrieveLastWal(SSyncPeer *pPeer, char *name, uint64_t fversion,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int syncProcessLastWal(SSyncPeer *pPeer, char *wname, uint32_t index) {
|
static int syncProcessLastWal(SSyncPeer *pPeer, char *wname, int64_t index) {
|
||||||
SSyncNode *pNode = pPeer->pSyncNode;
|
SSyncNode *pNode = pPeer->pSyncNode;
|
||||||
int code = -1;
|
int code = -1;
|
||||||
char fname[TSDB_FILENAME_LEN * 2]; // full path to wal file
|
char fname[TSDB_FILENAME_LEN * 2]; // full path to wal file
|
||||||
|
@ -377,7 +377,7 @@ static int syncRetrieveWal(SSyncPeer *pPeer) {
|
||||||
int32_t size;
|
int32_t size;
|
||||||
struct stat fstat;
|
struct stat fstat;
|
||||||
int code = -1;
|
int code = -1;
|
||||||
uint32_t index = 0;
|
int64_t index = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// retrieve wal info
|
// retrieve wal info
|
||||||
|
|
|
@ -254,7 +254,7 @@ uint32_t getFileInfo(void *ahandle, char *name, uint32_t *index, uint32_t eindex
|
||||||
return magic;
|
return magic;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getWalInfo(void *ahandle, char *name, uint32_t *index) {
|
int getWalInfo(void *ahandle, char *name, int64_t *index) {
|
||||||
struct stat fstat;
|
struct stat fstat;
|
||||||
char aname[280];
|
char aname[280];
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TDENGINE_UTIL_ALLOC_H
|
||||||
|
#define TDENGINE_UTIL_ALLOC_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TSDB_USE_SYS_MEM
|
||||||
|
|
||||||
|
#ifdef TSDB_USE_SYS_MEM
|
||||||
|
#define tmalloc(size) malloc(size)
|
||||||
|
#define tcalloc(size) calloc(1, size)
|
||||||
|
#define trealloc(p, size) realloc(p, size)
|
||||||
|
#define tmemalign(alignment, size) malloc(size)
|
||||||
|
#define tfree(p) free(p)
|
||||||
|
#define tmemzero(p, size) memset(p, 0, size)
|
||||||
|
#else
|
||||||
|
void *tmalloc(int32_t size);
|
||||||
|
void *tcalloc(int32_t size);
|
||||||
|
void *trealloc(void *p, int32_t size);
|
||||||
|
void *tmemalign(int32_t alignment, int32_t size);
|
||||||
|
void tfree(void *p);
|
||||||
|
void tmemzero(void *p, int32_t size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "taoserror.h"
|
||||||
|
#include "tulog.h"
|
||||||
|
#include "talloc.h"
|
||||||
|
|
||||||
|
#define TSDB_HAVE_MEMALIGN
|
||||||
|
#ifndef TSDB_USE_SYS_MEM
|
||||||
|
|
||||||
|
void *tmalloc(int32_t size) {
|
||||||
|
void *p = malloc(size);
|
||||||
|
if (p == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
uError("failed to malloc memory, size:%d reason:%s", size, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *tcalloc(int32_t size) {
|
||||||
|
void *p = calloc(1, size);
|
||||||
|
if (p == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
uError("failed to calloc memory, size:%d reason:%s", size, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *trealloc(void *p, int32_t size) {
|
||||||
|
p = realloc(p, size);
|
||||||
|
if (p == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
uError("failed to realloc memory, size:%d reason:%s", size, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tfree(void *p) { free(p); }
|
||||||
|
|
||||||
|
void tmemzero(void *p, int32_t size) { memset(p, 0, size); }
|
||||||
|
|
||||||
|
#ifdef TSDB_HAVE_MEMALIGN
|
||||||
|
|
||||||
|
void *tmemalign(int32_t alignment, int32_t size) {
|
||||||
|
void *p;
|
||||||
|
|
||||||
|
int err = posix_memalign(&p, alignment, size);
|
||||||
|
if (err) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
uError("failed to memalign memory, alignment:%d size:%d reason:%s", alignment, size, strerror(err));
|
||||||
|
p = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
void *tmemalign(int32_t alignment, int32_t size) { return tmalloc(size); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
|
@ -356,6 +356,10 @@ bool taosReadGlobalCfg() {
|
||||||
|
|
||||||
taosTFree(line);
|
taosTFree(line);
|
||||||
|
|
||||||
|
if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) {
|
||||||
|
taosSetAllDebugFlag();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,16 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_WAL_MGMT_H
|
#ifndef TDENGINE_VNODE_CFG_H
|
||||||
#define TDENGINE_WAL_MGMT_H
|
#define TDENGINE_VNODE_CFG_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int32_t vnodeReadCfg(SVnodeObj *pVnode);
|
||||||
|
int32_t vnodeWriteCfg(SCreateVnodeMsg *pVnodeCfg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TDENGINE_VNODE_VERSION_H
|
||||||
|
#define TDENGINE_VNODE_VERSION_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int32_t vnodeReadVersion(SVnodeObj *pVnode);
|
||||||
|
int32_t vnodeSaveVersion(SVnodeObj *pVnode);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,326 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "taosmsg.h"
|
||||||
|
#include "taoserror.h"
|
||||||
|
#include "cJSON.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
#include "tsdb.h"
|
||||||
|
#include "dnode.h"
|
||||||
|
#include "vnodeInt.h"
|
||||||
|
#include "vnodeVersion.h"
|
||||||
|
#include "vnodeCfg.h"
|
||||||
|
|
||||||
|
static void vnodeLoadCfg(SVnodeObj *pVnode, SCreateVnodeMsg* vnodeMsg) {
|
||||||
|
strcpy(pVnode->db, vnodeMsg->db);
|
||||||
|
pVnode->cfgVersion = vnodeMsg->cfg.cfgVersion;
|
||||||
|
pVnode->tsdbCfg.cacheBlockSize = vnodeMsg->cfg.cacheBlockSize;
|
||||||
|
pVnode->tsdbCfg.totalBlocks = vnodeMsg->cfg.totalBlocks;
|
||||||
|
pVnode->tsdbCfg.daysPerFile = vnodeMsg->cfg.daysPerFile;
|
||||||
|
pVnode->tsdbCfg.keep = vnodeMsg->cfg.daysToKeep;
|
||||||
|
pVnode->tsdbCfg.keep1 = vnodeMsg->cfg.daysToKeep1;
|
||||||
|
pVnode->tsdbCfg.keep2 = vnodeMsg->cfg.daysToKeep2;
|
||||||
|
pVnode->tsdbCfg.minRowsPerFileBlock = vnodeMsg->cfg.minRowsPerFileBlock;
|
||||||
|
pVnode->tsdbCfg.maxRowsPerFileBlock = vnodeMsg->cfg.maxRowsPerFileBlock;
|
||||||
|
pVnode->tsdbCfg.precision = vnodeMsg->cfg.precision;
|
||||||
|
pVnode->tsdbCfg.compression = vnodeMsg->cfg.compression;
|
||||||
|
pVnode->walCfg.walLevel = vnodeMsg->cfg.walLevel;
|
||||||
|
pVnode->walCfg.fsyncPeriod = vnodeMsg->cfg.fsyncPeriod;
|
||||||
|
pVnode->walCfg.wals = vnodeMsg->cfg.wals;
|
||||||
|
pVnode->walCfg.keep = 0;
|
||||||
|
pVnode->syncCfg.replica = vnodeMsg->cfg.replications;
|
||||||
|
pVnode->syncCfg.quorum = vnodeMsg->cfg.quorum;
|
||||||
|
|
||||||
|
for (int i = 0; i < pVnode->syncCfg.replica; ++i) {
|
||||||
|
SVnodeDesc *node = &vnodeMsg->nodes[i];
|
||||||
|
pVnode->syncCfg.nodeInfo[i].nodeId = node->nodeId;
|
||||||
|
taosGetFqdnPortFromEp(node->nodeEp, pVnode->syncCfg.nodeInfo[i].nodeFqdn, &pVnode->syncCfg.nodeInfo[i].nodePort);
|
||||||
|
pVnode->syncCfg.nodeInfo[i].nodePort += TSDB_PORT_SYNC;
|
||||||
|
}
|
||||||
|
|
||||||
|
vInfo("vgId:%d, load vnode cfg successfully, replcia:%d", pVnode->vgId, pVnode->syncCfg.replica);
|
||||||
|
for (int32_t i = 0; i < pVnode->syncCfg.replica; i++) {
|
||||||
|
SNodeInfo *node = &pVnode->syncCfg.nodeInfo[i];
|
||||||
|
vInfo("vgId:%d, dnode:%d, %s:%u", pVnode->vgId, node->nodeId, node->nodeFqdn, node->nodePort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t vnodeReadCfg(SVnodeObj *pVnode) {
|
||||||
|
int32_t ret = TSDB_CODE_VND_APP_ERROR;
|
||||||
|
int32_t len = 0;
|
||||||
|
int maxLen = 1000;
|
||||||
|
char * content = calloc(1, maxLen + 1);
|
||||||
|
cJSON * root = NULL;
|
||||||
|
FILE * fp = NULL;
|
||||||
|
bool nodeChanged = false;
|
||||||
|
SCreateVnodeMsg vnodeMsg;
|
||||||
|
|
||||||
|
char file[TSDB_FILENAME_LEN + 30] = {0};
|
||||||
|
sprintf(file, "%s/vnode%d/config.json", tsVnodeDir, pVnode->vgId);
|
||||||
|
|
||||||
|
vnodeMsg.cfg.vgId = pVnode->vgId;
|
||||||
|
|
||||||
|
fp = fopen(file, "r");
|
||||||
|
if (!fp) {
|
||||||
|
vError("vgId:%d, failed to open vnode cfg file:%s to read, error:%s", pVnode->vgId, file, strerror(errno));
|
||||||
|
ret = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = fread(content, 1, maxLen, fp);
|
||||||
|
if (len <= 0) {
|
||||||
|
vError("vgId:%d, failed to read %s, content is null", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
content[len] = 0;
|
||||||
|
root = cJSON_Parse(content);
|
||||||
|
if (root == NULL) {
|
||||||
|
vError("vgId:%d, failed to read %s, invalid json format", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *db = cJSON_GetObjectItem(root, "db");
|
||||||
|
if (!db || db->type != cJSON_String || db->valuestring == NULL) {
|
||||||
|
vError("vgId:%d, failed to read %s, db not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
strcpy(vnodeMsg.db, db->valuestring);
|
||||||
|
|
||||||
|
cJSON *cfgVersion = cJSON_GetObjectItem(root, "cfgVersion");
|
||||||
|
if (!cfgVersion || cfgVersion->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, cfgVersion not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.cfgVersion = cfgVersion->valueint;
|
||||||
|
|
||||||
|
cJSON *cacheBlockSize = cJSON_GetObjectItem(root, "cacheBlockSize");
|
||||||
|
if (!cacheBlockSize || cacheBlockSize->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, cacheBlockSize not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.cacheBlockSize = cacheBlockSize->valueint;
|
||||||
|
|
||||||
|
cJSON *totalBlocks = cJSON_GetObjectItem(root, "totalBlocks");
|
||||||
|
if (!totalBlocks || totalBlocks->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, totalBlocks not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.totalBlocks = totalBlocks->valueint;
|
||||||
|
|
||||||
|
cJSON *daysPerFile = cJSON_GetObjectItem(root, "daysPerFile");
|
||||||
|
if (!daysPerFile || daysPerFile->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, daysPerFile not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.daysPerFile = daysPerFile->valueint;
|
||||||
|
|
||||||
|
cJSON *daysToKeep = cJSON_GetObjectItem(root, "daysToKeep");
|
||||||
|
if (!daysToKeep || daysToKeep->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, daysToKeep not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.daysToKeep = daysToKeep->valueint;
|
||||||
|
|
||||||
|
cJSON *daysToKeep1 = cJSON_GetObjectItem(root, "daysToKeep1");
|
||||||
|
if (!daysToKeep1 || daysToKeep1->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, daysToKeep1 not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.daysToKeep1 = daysToKeep1->valueint;
|
||||||
|
|
||||||
|
cJSON *daysToKeep2 = cJSON_GetObjectItem(root, "daysToKeep2");
|
||||||
|
if (!daysToKeep2 || daysToKeep2->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, daysToKeep2 not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.daysToKeep2 = daysToKeep2->valueint;
|
||||||
|
|
||||||
|
cJSON *minRowsPerFileBlock = cJSON_GetObjectItem(root, "minRowsPerFileBlock");
|
||||||
|
if (!minRowsPerFileBlock || minRowsPerFileBlock->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, minRowsPerFileBlock not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.minRowsPerFileBlock = minRowsPerFileBlock->valueint;
|
||||||
|
|
||||||
|
cJSON *maxRowsPerFileBlock = cJSON_GetObjectItem(root, "maxRowsPerFileBlock");
|
||||||
|
if (!maxRowsPerFileBlock || maxRowsPerFileBlock->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, maxRowsPerFileBlock not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.maxRowsPerFileBlock = maxRowsPerFileBlock->valueint;
|
||||||
|
|
||||||
|
cJSON *precision = cJSON_GetObjectItem(root, "precision");
|
||||||
|
if (!precision || precision->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, precision not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.precision = (int8_t)precision->valueint;
|
||||||
|
|
||||||
|
cJSON *compression = cJSON_GetObjectItem(root, "compression");
|
||||||
|
if (!compression || compression->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, compression not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.compression = (int8_t)compression->valueint;
|
||||||
|
|
||||||
|
cJSON *walLevel = cJSON_GetObjectItem(root, "walLevel");
|
||||||
|
if (!walLevel || walLevel->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, walLevel not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.walLevel = (int8_t)walLevel->valueint;
|
||||||
|
|
||||||
|
cJSON *fsyncPeriod = cJSON_GetObjectItem(root, "fsync");
|
||||||
|
if (!walLevel || walLevel->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, fsyncPeriod not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.fsyncPeriod = fsyncPeriod->valueint;
|
||||||
|
|
||||||
|
cJSON *wals = cJSON_GetObjectItem(root, "wals");
|
||||||
|
if (!wals || wals->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, wals not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.wals = (int8_t)wals->valueint;
|
||||||
|
|
||||||
|
cJSON *replica = cJSON_GetObjectItem(root, "replica");
|
||||||
|
if (!replica || replica->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, replica not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.replications = (int8_t)replica->valueint;
|
||||||
|
|
||||||
|
cJSON *quorum = cJSON_GetObjectItem(root, "quorum");
|
||||||
|
if (!quorum || quorum->type != cJSON_Number) {
|
||||||
|
vError("vgId: %d, failed to read %s, quorum not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
vnodeMsg.cfg.quorum = (int8_t)quorum->valueint;
|
||||||
|
|
||||||
|
cJSON *nodeInfos = cJSON_GetObjectItem(root, "nodeInfos");
|
||||||
|
if (!nodeInfos || nodeInfos->type != cJSON_Array) {
|
||||||
|
vError("vgId:%d, failed to read %s, nodeInfos not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int size = cJSON_GetArraySize(nodeInfos);
|
||||||
|
if (size != vnodeMsg.cfg.replications) {
|
||||||
|
vError("vgId:%d, failed to read %s, nodeInfos size not matched", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
cJSON *nodeInfo = cJSON_GetArrayItem(nodeInfos, i);
|
||||||
|
if (nodeInfo == NULL) continue;
|
||||||
|
SVnodeDesc *node = &vnodeMsg.nodes[i];
|
||||||
|
|
||||||
|
cJSON *nodeId = cJSON_GetObjectItem(nodeInfo, "nodeId");
|
||||||
|
if (!nodeId || nodeId->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, nodeId not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
node->nodeId = nodeId->valueint;
|
||||||
|
|
||||||
|
cJSON *nodeEp = cJSON_GetObjectItem(nodeInfo, "nodeEp");
|
||||||
|
if (!nodeEp || nodeEp->type != cJSON_String || nodeEp->valuestring == NULL) {
|
||||||
|
vError("vgId:%d, failed to read %s, nodeFqdn not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VCFG_ERROR;
|
||||||
|
}
|
||||||
|
tstrncpy(node->nodeEp, nodeEp->valuestring, TSDB_EP_LEN);
|
||||||
|
|
||||||
|
if (!nodeChanged) {
|
||||||
|
nodeChanged = dnodeCheckEpChanged(node->nodeId, node->nodeEp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
PARSE_VCFG_ERROR:
|
||||||
|
if (content != NULL) free(content);
|
||||||
|
if (root != NULL) cJSON_Delete(root);
|
||||||
|
if (fp != NULL) fclose(fp);
|
||||||
|
|
||||||
|
if (nodeChanged) {
|
||||||
|
vnodeWriteCfg(&vnodeMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == TSDB_CODE_SUCCESS) {
|
||||||
|
vnodeLoadCfg(pVnode, &vnodeMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
terrno = 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t vnodeWriteCfg(SCreateVnodeMsg *pMsg) {
|
||||||
|
char file[TSDB_FILENAME_LEN + 30] = {0};
|
||||||
|
sprintf(file, "%s/vnode%d/config.json", tsVnodeDir, pMsg->cfg.vgId);
|
||||||
|
|
||||||
|
FILE *fp = fopen(file, "w");
|
||||||
|
if (!fp) {
|
||||||
|
vError("vgId:%d, failed to write %s error:%s", pMsg->cfg.vgId, file, strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t len = 0;
|
||||||
|
int32_t maxLen = 1000;
|
||||||
|
char * content = calloc(1, maxLen + 1);
|
||||||
|
|
||||||
|
len += snprintf(content + len, maxLen - len, "{\n");
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"db\": \"%s\",\n", pMsg->db);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"cfgVersion\": %d,\n", pMsg->cfg.cfgVersion);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"cacheBlockSize\": %d,\n", pMsg->cfg.cacheBlockSize);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"totalBlocks\": %d,\n", pMsg->cfg.totalBlocks);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"daysPerFile\": %d,\n", pMsg->cfg.daysPerFile);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"daysToKeep\": %d,\n", pMsg->cfg.daysToKeep);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"daysToKeep1\": %d,\n", pMsg->cfg.daysToKeep1);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"daysToKeep2\": %d,\n", pMsg->cfg.daysToKeep2);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"minRowsPerFileBlock\": %d,\n", pMsg->cfg.minRowsPerFileBlock);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"maxRowsPerFileBlock\": %d,\n", pMsg->cfg.maxRowsPerFileBlock);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"precision\": %d,\n", pMsg->cfg.precision);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"compression\": %d,\n", pMsg->cfg.compression);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"walLevel\": %d,\n", pMsg->cfg.walLevel);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"fsync\": %d,\n", pMsg->cfg.fsyncPeriod);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"replica\": %d,\n", pMsg->cfg.replications);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"wals\": %d,\n", pMsg->cfg.wals);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"quorum\": %d,\n", pMsg->cfg.quorum);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"nodeInfos\": [{\n");
|
||||||
|
for (int32_t i = 0; i < pMsg->cfg.replications; i++) {
|
||||||
|
SVnodeDesc *node = &pMsg->nodes[i];
|
||||||
|
dnodeUpdateEp(node->nodeId, node->nodeEp, NULL, NULL);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"nodeId\": %d,\n", node->nodeId);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"nodeEp\": \"%s\"\n", node->nodeEp);
|
||||||
|
if (i < pMsg->cfg.replications - 1) {
|
||||||
|
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||||
|
} else {
|
||||||
|
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len += snprintf(content + len, maxLen - len, "}\n");
|
||||||
|
|
||||||
|
fwrite(content, 1, len, fp);
|
||||||
|
fflush(fp);
|
||||||
|
fclose(fp);
|
||||||
|
free(content);
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
|
vInfo("vgId:%d, successed to write %s", pMsg->cfg.vgId, file);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
|
@ -31,18 +31,14 @@
|
||||||
#include "vnodeInt.h"
|
#include "vnodeInt.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "dnode.h"
|
#include "dnode.h"
|
||||||
|
#include "vnodeCfg.h"
|
||||||
#define TSDB_VNODE_VERSION_CONTENT_LEN 31
|
#include "vnodeVersion.h"
|
||||||
|
|
||||||
static SHashObj*tsDnodeVnodesHash;
|
static SHashObj*tsDnodeVnodesHash;
|
||||||
static void vnodeCleanUp(SVnodeObj *pVnode);
|
static void vnodeCleanUp(SVnodeObj *pVnode);
|
||||||
static int32_t vnodeSaveCfg(SMDCreateVnodeMsg *pVnodeCfg);
|
|
||||||
static int32_t vnodeReadCfg(SVnodeObj *pVnode);
|
|
||||||
static int32_t vnodeSaveVersion(SVnodeObj *pVnode);
|
|
||||||
static int32_t vnodeReadVersion(SVnodeObj *pVnode);
|
|
||||||
static int vnodeProcessTsdbStatus(void *arg, int status);
|
static int vnodeProcessTsdbStatus(void *arg, int status);
|
||||||
static uint32_t vnodeGetFileInfo(void *ahandle, char *name, uint32_t *index, uint32_t eindex, int64_t *size, uint64_t *fversion);
|
static uint32_t vnodeGetFileInfo(void *ahandle, char *name, uint32_t *index, uint32_t eindex, int64_t *size, uint64_t *fversion);
|
||||||
static int vnodeGetWalInfo(void *ahandle, char *name, uint32_t *index);
|
static int vnodeGetWalInfo(void *ahandle, char *fileName, int64_t *fileId);
|
||||||
static void vnodeNotifyRole(void *ahandle, int8_t role);
|
static void vnodeNotifyRole(void *ahandle, int8_t role);
|
||||||
static void vnodeCtrlFlow(void *handle, int32_t mseconds);
|
static void vnodeCtrlFlow(void *handle, int32_t mseconds);
|
||||||
static int vnodeNotifyFileSynced(void *ahandle, uint64_t fversion);
|
static int vnodeNotifyFileSynced(void *ahandle, uint64_t fversion);
|
||||||
|
@ -90,7 +86,7 @@ void vnodeCleanupResources() {
|
||||||
syncCleanUp();
|
syncCleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) {
|
int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
|
|
||||||
SVnodeObj *pVnode = vnodeAcquire(pVnodeCfg->cfg.vgId);
|
SVnodeObj *pVnode = vnodeAcquire(pVnodeCfg->cfg.vgId);
|
||||||
|
@ -128,7 +124,7 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
code = vnodeSaveCfg(pVnodeCfg);
|
code = vnodeWriteCfg(pVnodeCfg);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
vError("vgId:%d, failed to save vnode cfg, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(code));
|
vError("vgId:%d, failed to save vnode cfg, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
|
@ -138,7 +134,6 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) {
|
||||||
tsdbCfg.tsdbId = pVnodeCfg->cfg.vgId;
|
tsdbCfg.tsdbId = pVnodeCfg->cfg.vgId;
|
||||||
tsdbCfg.cacheBlockSize = pVnodeCfg->cfg.cacheBlockSize;
|
tsdbCfg.cacheBlockSize = pVnodeCfg->cfg.cacheBlockSize;
|
||||||
tsdbCfg.totalBlocks = pVnodeCfg->cfg.totalBlocks;
|
tsdbCfg.totalBlocks = pVnodeCfg->cfg.totalBlocks;
|
||||||
// tsdbCfg.maxTables = pVnodeCfg->cfg.maxTables;
|
|
||||||
tsdbCfg.daysPerFile = pVnodeCfg->cfg.daysPerFile;
|
tsdbCfg.daysPerFile = pVnodeCfg->cfg.daysPerFile;
|
||||||
tsdbCfg.keep = pVnodeCfg->cfg.daysToKeep;
|
tsdbCfg.keep = pVnodeCfg->cfg.daysToKeep;
|
||||||
tsdbCfg.minRowsPerFileBlock = pVnodeCfg->cfg.minRowsPerFileBlock;
|
tsdbCfg.minRowsPerFileBlock = pVnodeCfg->cfg.minRowsPerFileBlock;
|
||||||
|
@ -177,7 +172,7 @@ int32_t vnodeDrop(int32_t vgId) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vnodeAlter(void *param, SMDCreateVnodeMsg *pVnodeCfg) {
|
int32_t vnodeAlter(void *param, SCreateVnodeMsg *pVnodeCfg) {
|
||||||
SVnodeObj *pVnode = param;
|
SVnodeObj *pVnode = param;
|
||||||
|
|
||||||
// vnode in non-ready state and still needs to return success instead of TSDB_CODE_VND_INVALID_STATUS
|
// vnode in non-ready state and still needs to return success instead of TSDB_CODE_VND_INVALID_STATUS
|
||||||
|
@ -187,7 +182,7 @@ int32_t vnodeAlter(void *param, SMDCreateVnodeMsg *pVnodeCfg) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = vnodeSaveCfg(pVnodeCfg);
|
int32_t code = vnodeWriteCfg(pVnodeCfg);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pVnode->status = TAOS_VN_STATUS_READY;
|
pVnode->status = TAOS_VN_STATUS_READY;
|
||||||
return code;
|
return code;
|
||||||
|
@ -304,6 +299,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(temp, "%s/wal", rootDir);
|
sprintf(temp, "%s/wal", rootDir);
|
||||||
|
pVnode->walCfg.vgId = pVnode->vgId;
|
||||||
pVnode->wal = walOpen(temp, &pVnode->walCfg);
|
pVnode->wal = walOpen(temp, &pVnode->walCfg);
|
||||||
if (pVnode->wal == NULL) {
|
if (pVnode->wal == NULL) {
|
||||||
vnodeCleanUp(pVnode);
|
vnodeCleanUp(pVnode);
|
||||||
|
@ -315,6 +311,8 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
||||||
pVnode->version = walGetVersion(pVnode->wal);
|
pVnode->version = walGetVersion(pVnode->wal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
walRenew(pVnode->wal);
|
||||||
|
|
||||||
SSyncInfo syncInfo;
|
SSyncInfo syncInfo;
|
||||||
syncInfo.vgId = pVnode->vgId;
|
syncInfo.vgId = pVnode->vgId;
|
||||||
syncInfo.version = pVnode->version;
|
syncInfo.version = pVnode->version;
|
||||||
|
@ -500,7 +498,7 @@ void *vnodeGetWal(void *pVnode) {
|
||||||
return ((SVnodeObj *)pVnode)->wal;
|
return ((SVnodeObj *)pVnode)->wal;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vnodeBuildVloadMsg(SVnodeObj *pVnode, SDMStatusMsg *pStatus) {
|
static void vnodeBuildVloadMsg(SVnodeObj *pVnode, SStatusMsg *pStatus) {
|
||||||
int64_t totalStorage = 0;
|
int64_t totalStorage = 0;
|
||||||
int64_t compStorage = 0;
|
int64_t compStorage = 0;
|
||||||
int64_t pointsWritten = 0;
|
int64_t pointsWritten = 0;
|
||||||
|
@ -544,7 +542,7 @@ int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeBuildStatusMsg(void *param) {
|
void vnodeBuildStatusMsg(void *param) {
|
||||||
SDMStatusMsg *pStatus = param;
|
SStatusMsg *pStatus = param;
|
||||||
SHashMutableIterator *pIter = taosHashCreateIter(tsDnodeVnodesHash);
|
SHashMutableIterator *pIter = taosHashCreateIter(tsDnodeVnodesHash);
|
||||||
|
|
||||||
while (taosHashIterNext(pIter)) {
|
while (taosHashIterNext(pIter)) {
|
||||||
|
@ -558,7 +556,7 @@ void vnodeBuildStatusMsg(void *param) {
|
||||||
taosHashDestroyIter(pIter);
|
taosHashDestroyIter(pIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeSetAccess(SDMVgroupAccess *pAccess, int32_t numOfVnodes) {
|
void vnodeSetAccess(SVgroupAccess *pAccess, int32_t numOfVnodes) {
|
||||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||||
pAccess[i].vgId = htonl(pAccess[i].vgId);
|
pAccess[i].vgId = htonl(pAccess[i].vgId);
|
||||||
SVnodeObj *pVnode = vnodeAcquire(pAccess[i].vgId);
|
SVnodeObj *pVnode = vnodeAcquire(pAccess[i].vgId);
|
||||||
|
@ -610,21 +608,23 @@ static int vnodeProcessTsdbStatus(void *arg, int status) {
|
||||||
return walRenew(pVnode->wal);
|
return walRenew(pVnode->wal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == TSDB_STATUS_COMMIT_OVER)
|
if (status == TSDB_STATUS_COMMIT_OVER) {
|
||||||
return vnodeSaveVersion(pVnode);
|
return vnodeSaveVersion(pVnode);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t vnodeGetFileInfo(void *ahandle, char *name, uint32_t *index, uint32_t eindex, int64_t *size, uint64_t *fversion) {
|
static uint32_t vnodeGetFileInfo(void *ahandle, char *name, uint32_t *index, uint32_t eindex, int64_t *size,
|
||||||
|
uint64_t *fversion) {
|
||||||
SVnodeObj *pVnode = ahandle;
|
SVnodeObj *pVnode = ahandle;
|
||||||
*fversion = pVnode->fversion;
|
*fversion = pVnode->fversion;
|
||||||
return tsdbGetFileInfo(pVnode->tsdb, name, index, eindex, size);
|
return tsdbGetFileInfo(pVnode->tsdb, name, index, eindex, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vnodeGetWalInfo(void *ahandle, char *name, uint32_t *index) {
|
static int vnodeGetWalInfo(void *ahandle, char *fileName, int64_t *fileId) {
|
||||||
SVnodeObj *pVnode = ahandle;
|
SVnodeObj *pVnode = ahandle;
|
||||||
return walGetWalFile(pVnode->wal, name, index);
|
return walGetWalFile(pVnode->wal, fileName, fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vnodeNotifyRole(void *ahandle, int8_t role) {
|
static void vnodeNotifyRole(void *ahandle, int8_t role) {
|
||||||
|
@ -641,17 +641,18 @@ static void vnodeNotifyRole(void *ahandle, int8_t role) {
|
||||||
|
|
||||||
static void vnodeCtrlFlow(void *ahandle, int32_t mseconds) {
|
static void vnodeCtrlFlow(void *ahandle, int32_t mseconds) {
|
||||||
SVnodeObj *pVnode = ahandle;
|
SVnodeObj *pVnode = ahandle;
|
||||||
if (pVnode->delay != mseconds)
|
if (pVnode->delay != mseconds) {
|
||||||
vInfo("vgId:%d, sync flow control, mseconds:%d", pVnode->vgId, mseconds);
|
vInfo("vgId:%d, sync flow control, mseconds:%d", pVnode->vgId, mseconds);
|
||||||
|
}
|
||||||
pVnode->delay = mseconds;
|
pVnode->delay = mseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vnodeResetTsdb(SVnodeObj *pVnode)
|
static int vnodeResetTsdb(SVnodeObj *pVnode) {
|
||||||
{
|
|
||||||
char rootDir[128] = "\0";
|
char rootDir[128] = "\0";
|
||||||
sprintf(rootDir, "%s/tsdb", pVnode->rootDir);
|
sprintf(rootDir, "%s/tsdb", pVnode->rootDir);
|
||||||
|
|
||||||
if (atomic_val_compare_exchange_8(&pVnode->status, TAOS_VN_STATUS_READY, TAOS_VN_STATUS_RESET) != TAOS_VN_STATUS_READY) {
|
if (atomic_val_compare_exchange_8(&pVnode->status, TAOS_VN_STATUS_READY, TAOS_VN_STATUS_RESET) !=
|
||||||
|
TAOS_VN_STATUS_READY) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -691,360 +692,3 @@ static int vnodeNotifyFileSynced(void *ahandle, uint64_t fversion) {
|
||||||
|
|
||||||
return vnodeResetTsdb(pVnode);
|
return vnodeResetTsdb(pVnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vnodeSaveCfg(SMDCreateVnodeMsg *pVnodeCfg) {
|
|
||||||
char cfgFile[TSDB_FILENAME_LEN + 30] = {0};
|
|
||||||
sprintf(cfgFile, "%s/vnode%d/config.json", tsVnodeDir, pVnodeCfg->cfg.vgId);
|
|
||||||
FILE *fp = fopen(cfgFile, "w");
|
|
||||||
if (!fp) {
|
|
||||||
vError("vgId:%d, failed to open vnode cfg file for write, file:%s error:%s", pVnodeCfg->cfg.vgId, cfgFile,
|
|
||||||
strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t len = 0;
|
|
||||||
int32_t maxLen = 1000;
|
|
||||||
char * content = calloc(1, maxLen + 1);
|
|
||||||
if (content == NULL) {
|
|
||||||
fclose(fp);
|
|
||||||
return TSDB_CODE_VND_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"db\": \"%s\",\n", pVnodeCfg->db);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"cfgVersion\": %d,\n", pVnodeCfg->cfg.cfgVersion);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"cacheBlockSize\": %d,\n", pVnodeCfg->cfg.cacheBlockSize);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"totalBlocks\": %d,\n", pVnodeCfg->cfg.totalBlocks);
|
|
||||||
// len += snprintf(content + len, maxLen - len, " \"maxTables\": %d,\n", pVnodeCfg->cfg.maxTables);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"daysPerFile\": %d,\n", pVnodeCfg->cfg.daysPerFile);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"daysToKeep\": %d,\n", pVnodeCfg->cfg.daysToKeep);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"daysToKeep1\": %d,\n", pVnodeCfg->cfg.daysToKeep1);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"daysToKeep2\": %d,\n", pVnodeCfg->cfg.daysToKeep2);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"minRowsPerFileBlock\": %d,\n", pVnodeCfg->cfg.minRowsPerFileBlock);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"maxRowsPerFileBlock\": %d,\n", pVnodeCfg->cfg.maxRowsPerFileBlock);
|
|
||||||
// len += snprintf(content + len, maxLen - len, " \"commitTime\": %d,\n", pVnodeCfg->cfg.commitTime);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"precision\": %d,\n", pVnodeCfg->cfg.precision);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"compression\": %d,\n", pVnodeCfg->cfg.compression);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"walLevel\": %d,\n", pVnodeCfg->cfg.walLevel);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"fsync\": %d,\n", pVnodeCfg->cfg.fsyncPeriod);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"replica\": %d,\n", pVnodeCfg->cfg.replications);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"wals\": %d,\n", pVnodeCfg->cfg.wals);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"quorum\": %d,\n", pVnodeCfg->cfg.quorum);
|
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"nodeInfos\": [{\n");
|
|
||||||
|
|
||||||
vInfo("vgId:%d, save vnode cfg, replica:%d", pVnodeCfg->cfg.vgId, pVnodeCfg->cfg.replications);
|
|
||||||
for (int32_t i = 0; i < pVnodeCfg->cfg.replications; i++) {
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"nodeId\": %d,\n", pVnodeCfg->nodes[i].nodeId);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"nodeEp\": \"%s\"\n", pVnodeCfg->nodes[i].nodeEp);
|
|
||||||
vInfo("vgId:%d, save vnode cfg, nodeId:%d nodeEp:%s", pVnodeCfg->cfg.vgId, pVnodeCfg->nodes[i].nodeId,
|
|
||||||
pVnodeCfg->nodes[i].nodeEp);
|
|
||||||
|
|
||||||
if (i < pVnodeCfg->cfg.replications - 1) {
|
|
||||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
|
||||||
} else {
|
|
||||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
|
||||||
|
|
||||||
fwrite(content, 1, len, fp);
|
|
||||||
fflush(fp);
|
|
||||||
fclose(fp);
|
|
||||||
free(content);
|
|
||||||
|
|
||||||
vInfo("vgId:%d, save vnode cfg successed", pVnodeCfg->cfg.vgId);
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t vnodeReadCfg(SVnodeObj *pVnode) {
|
|
||||||
cJSON *root = NULL;
|
|
||||||
char *content = NULL;
|
|
||||||
char cfgFile[TSDB_FILENAME_LEN + 30] = {0};
|
|
||||||
int maxLen = 1000;
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_VND_APP_ERROR;
|
|
||||||
sprintf(cfgFile, "%s/vnode%d/config.json", tsVnodeDir, pVnode->vgId);
|
|
||||||
FILE *fp = fopen(cfgFile, "r");
|
|
||||||
if (!fp) {
|
|
||||||
vError("vgId:%d, failed to open vnode cfg file:%s to read, error:%s", pVnode->vgId,
|
|
||||||
cfgFile, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
content = calloc(1, maxLen + 1);
|
|
||||||
if (content == NULL) goto PARSE_OVER;
|
|
||||||
int len = fread(content, 1, maxLen, fp);
|
|
||||||
if (len <= 0) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, content is null", pVnode->vgId);
|
|
||||||
free(content);
|
|
||||||
fclose(fp);
|
|
||||||
return errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
root = cJSON_Parse(content);
|
|
||||||
if (root == NULL) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, invalid json format", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *db = cJSON_GetObjectItem(root, "db");
|
|
||||||
if (!db || db->type != cJSON_String || db->valuestring == NULL) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, db not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
strcpy(pVnode->db, db->valuestring);
|
|
||||||
|
|
||||||
cJSON *cfgVersion = cJSON_GetObjectItem(root, "cfgVersion");
|
|
||||||
if (!cfgVersion || cfgVersion->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, cfgVersion not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->cfgVersion = cfgVersion->valueint;
|
|
||||||
|
|
||||||
cJSON *cacheBlockSize = cJSON_GetObjectItem(root, "cacheBlockSize");
|
|
||||||
if (!cacheBlockSize || cacheBlockSize->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, cacheBlockSize not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->tsdbCfg.cacheBlockSize = cacheBlockSize->valueint;
|
|
||||||
|
|
||||||
cJSON *totalBlocks = cJSON_GetObjectItem(root, "totalBlocks");
|
|
||||||
if (!totalBlocks || totalBlocks->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, totalBlocks not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->tsdbCfg.totalBlocks = totalBlocks->valueint;
|
|
||||||
|
|
||||||
// cJSON *maxTables = cJSON_GetObjectItem(root, "maxTables");
|
|
||||||
// if (!maxTables || maxTables->type != cJSON_Number) {
|
|
||||||
// vError("vgId:%d, failed to read vnode cfg, maxTables not found", pVnode->vgId);
|
|
||||||
// goto PARSE_OVER;
|
|
||||||
// }
|
|
||||||
// pVnode->tsdbCfg.maxTables = maxTables->valueint;
|
|
||||||
|
|
||||||
cJSON *daysPerFile = cJSON_GetObjectItem(root, "daysPerFile");
|
|
||||||
if (!daysPerFile || daysPerFile->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, daysPerFile not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->tsdbCfg.daysPerFile = daysPerFile->valueint;
|
|
||||||
|
|
||||||
cJSON *daysToKeep = cJSON_GetObjectItem(root, "daysToKeep");
|
|
||||||
if (!daysToKeep || daysToKeep->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, daysToKeep not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->tsdbCfg.keep = daysToKeep->valueint;
|
|
||||||
|
|
||||||
cJSON *daysToKeep1 = cJSON_GetObjectItem(root, "daysToKeep1");
|
|
||||||
if (!daysToKeep1 || daysToKeep1->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, daysToKeep1 not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->tsdbCfg.keep1 = daysToKeep1->valueint;
|
|
||||||
|
|
||||||
cJSON *daysToKeep2 = cJSON_GetObjectItem(root, "daysToKeep2");
|
|
||||||
if (!daysToKeep2 || daysToKeep2->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, daysToKeep2 not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->tsdbCfg.keep2 = daysToKeep2->valueint;
|
|
||||||
|
|
||||||
cJSON *minRowsPerFileBlock = cJSON_GetObjectItem(root, "minRowsPerFileBlock");
|
|
||||||
if (!minRowsPerFileBlock || minRowsPerFileBlock->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, minRowsPerFileBlock not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->tsdbCfg.minRowsPerFileBlock = minRowsPerFileBlock->valueint;
|
|
||||||
|
|
||||||
cJSON *maxRowsPerFileBlock = cJSON_GetObjectItem(root, "maxRowsPerFileBlock");
|
|
||||||
if (!maxRowsPerFileBlock || maxRowsPerFileBlock->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, maxRowsPerFileBlock not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->tsdbCfg.maxRowsPerFileBlock = maxRowsPerFileBlock->valueint;
|
|
||||||
|
|
||||||
// cJSON *commitTime = cJSON_GetObjectItem(root, "commitTime");
|
|
||||||
// if (!commitTime || commitTime->type != cJSON_Number) {
|
|
||||||
// vError("vgId:%d, failed to read vnode cfg, commitTime not found", pVnode->vgId);
|
|
||||||
// goto PARSE_OVER;
|
|
||||||
// }
|
|
||||||
// pVnode->tsdbCfg.commitTime = (int8_t)commitTime->valueint;
|
|
||||||
|
|
||||||
cJSON *precision = cJSON_GetObjectItem(root, "precision");
|
|
||||||
if (!precision || precision->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, precision not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->tsdbCfg.precision = (int8_t)precision->valueint;
|
|
||||||
|
|
||||||
cJSON *compression = cJSON_GetObjectItem(root, "compression");
|
|
||||||
if (!compression || compression->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, compression not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->tsdbCfg.compression = (int8_t)compression->valueint;
|
|
||||||
|
|
||||||
cJSON *walLevel = cJSON_GetObjectItem(root, "walLevel");
|
|
||||||
if (!walLevel || walLevel->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, walLevel not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->walCfg.walLevel = (int8_t) walLevel->valueint;
|
|
||||||
|
|
||||||
cJSON *fsyncPeriod = cJSON_GetObjectItem(root, "fsync");
|
|
||||||
if (!walLevel || walLevel->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, fsyncPeriod not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->walCfg.fsyncPeriod = fsyncPeriod->valueint;
|
|
||||||
|
|
||||||
cJSON *wals = cJSON_GetObjectItem(root, "wals");
|
|
||||||
if (!wals || wals->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, wals not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->walCfg.wals = (int8_t)wals->valueint;
|
|
||||||
pVnode->walCfg.keep = 0;
|
|
||||||
|
|
||||||
cJSON *replica = cJSON_GetObjectItem(root, "replica");
|
|
||||||
if (!replica || replica->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, replica not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->syncCfg.replica = (int8_t)replica->valueint;
|
|
||||||
|
|
||||||
cJSON *quorum = cJSON_GetObjectItem(root, "quorum");
|
|
||||||
if (!quorum || quorum->type != cJSON_Number) {
|
|
||||||
vError("vgId: %d, failed to read vnode cfg, quorum not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->syncCfg.quorum = (int8_t)quorum->valueint;
|
|
||||||
|
|
||||||
cJSON *nodeInfos = cJSON_GetObjectItem(root, "nodeInfos");
|
|
||||||
if (!nodeInfos || nodeInfos->type != cJSON_Array) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, nodeInfos not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
int size = cJSON_GetArraySize(nodeInfos);
|
|
||||||
if (size != pVnode->syncCfg.replica) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, nodeInfos size not matched", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i) {
|
|
||||||
cJSON *nodeInfo = cJSON_GetArrayItem(nodeInfos, i);
|
|
||||||
if (nodeInfo == NULL) continue;
|
|
||||||
|
|
||||||
cJSON *nodeId = cJSON_GetObjectItem(nodeInfo, "nodeId");
|
|
||||||
if (!nodeId || nodeId->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, nodeId not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->syncCfg.nodeInfo[i].nodeId = nodeId->valueint;
|
|
||||||
|
|
||||||
cJSON *nodeEp = cJSON_GetObjectItem(nodeInfo, "nodeEp");
|
|
||||||
if (!nodeEp || nodeEp->type != cJSON_String || nodeEp->valuestring == NULL) {
|
|
||||||
vError("vgId:%d, failed to read vnode cfg, nodeFqdn not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
taosGetFqdnPortFromEp(nodeEp->valuestring, pVnode->syncCfg.nodeInfo[i].nodeFqdn, &pVnode->syncCfg.nodeInfo[i].nodePort);
|
|
||||||
pVnode->syncCfg.nodeInfo[i].nodePort += TSDB_PORT_SYNC;
|
|
||||||
}
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_SUCCESS;
|
|
||||||
|
|
||||||
vInfo("vgId:%d, read vnode cfg successfully, replcia:%d", pVnode->vgId, pVnode->syncCfg.replica);
|
|
||||||
for (int32_t i = 0; i < pVnode->syncCfg.replica; i++) {
|
|
||||||
vInfo("vgId:%d, dnode:%d, %s:%d", pVnode->vgId, pVnode->syncCfg.nodeInfo[i].nodeId,
|
|
||||||
pVnode->syncCfg.nodeInfo[i].nodeFqdn, pVnode->syncCfg.nodeInfo[i].nodePort);
|
|
||||||
}
|
|
||||||
|
|
||||||
PARSE_OVER:
|
|
||||||
taosTFree(content);
|
|
||||||
cJSON_Delete(root);
|
|
||||||
if (fp) fclose(fp);
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t vnodeSaveVersion(SVnodeObj *pVnode) {
|
|
||||||
char versionFile[TSDB_FILENAME_LEN + 30] = {0};
|
|
||||||
sprintf(versionFile, "%s/vnode%d/version.json", tsVnodeDir, pVnode->vgId);
|
|
||||||
FILE *fp = fopen(versionFile, "w");
|
|
||||||
if (!fp) {
|
|
||||||
vError("vgId:%d, failed to open vnode version file for write, file:%s error:%s", pVnode->vgId,
|
|
||||||
versionFile, strerror(errno));
|
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t len = 0;
|
|
||||||
int32_t maxLen = 30;
|
|
||||||
char content[TSDB_VNODE_VERSION_CONTENT_LEN] = {0};
|
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"version\": %" PRId64 "\n", pVnode->fversion);
|
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
|
||||||
|
|
||||||
fwrite(content, 1, len, fp);
|
|
||||||
fflush(fp);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
vInfo("vgId:%d, save vnode version:%" PRId64 " succeed", pVnode->vgId, pVnode->fversion);
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t vnodeReadVersion(SVnodeObj *pVnode) {
|
|
||||||
char versionFile[TSDB_FILENAME_LEN + 30] = {0};
|
|
||||||
char *content = NULL;
|
|
||||||
cJSON *root = NULL;
|
|
||||||
int maxLen = 100;
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_VND_INVALID_VRESION_FILE;
|
|
||||||
sprintf(versionFile, "%s/vnode%d/version.json", tsVnodeDir, pVnode->vgId);
|
|
||||||
FILE *fp = fopen(versionFile, "r");
|
|
||||||
if (!fp) {
|
|
||||||
if (errno != ENOENT) {
|
|
||||||
vError("vgId:%d, failed to open version file:%s error:%s", pVnode->vgId, versionFile, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
} else {
|
|
||||||
terrno = TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
content = calloc(1, maxLen + 1);
|
|
||||||
int len = fread(content, 1, maxLen, fp);
|
|
||||||
if (len <= 0) {
|
|
||||||
vError("vgId:%d, failed to read vnode version, content is null", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
root = cJSON_Parse(content);
|
|
||||||
if (root == NULL) {
|
|
||||||
vError("vgId:%d, failed to read vnode version, invalid json format", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *ver = cJSON_GetObjectItem(root, "version");
|
|
||||||
if (!ver || ver->type != cJSON_Number) {
|
|
||||||
vError("vgId:%d, failed to read vnode version, version not found", pVnode->vgId);
|
|
||||||
goto PARSE_OVER;
|
|
||||||
}
|
|
||||||
pVnode->version = ver->valueint;
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_SUCCESS;
|
|
||||||
vInfo("vgId:%d, read vnode version successfully, version:%" PRId64, pVnode->vgId, pVnode->version);
|
|
||||||
|
|
||||||
PARSE_OVER:
|
|
||||||
taosTFree(content);
|
|
||||||
cJSON_Delete(root);
|
|
||||||
if (fp) fclose(fp);
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "taoserror.h"
|
||||||
|
#include "cJSON.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
#include "tsdb.h"
|
||||||
|
#include "vnodeInt.h"
|
||||||
|
#include "vnodeVersion.h"
|
||||||
|
|
||||||
|
int32_t vnodeReadVersion(SVnodeObj *pVnode) {
|
||||||
|
int32_t len = 0;
|
||||||
|
int32_t maxLen = 100;
|
||||||
|
char * content = calloc(1, maxLen + 1);
|
||||||
|
cJSON * root = NULL;
|
||||||
|
FILE * fp = NULL;
|
||||||
|
|
||||||
|
terrno = TSDB_CODE_VND_INVALID_VRESION_FILE;
|
||||||
|
char file[TSDB_FILENAME_LEN + 30] = {0};
|
||||||
|
sprintf(file, "%s/vnode%d/version.json", tsVnodeDir, pVnode->vgId);
|
||||||
|
|
||||||
|
fp = fopen(file, "r");
|
||||||
|
if (!fp) {
|
||||||
|
if (errno != ENOENT) {
|
||||||
|
vError("vgId:%d, failed to read %s, error:%s", pVnode->vgId, file, strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
} else {
|
||||||
|
terrno = TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
goto PARSE_VER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = fread(content, 1, maxLen, fp);
|
||||||
|
if (len <= 0) {
|
||||||
|
vError("vgId:%d, failed to read %s, content is null", pVnode->vgId, file);
|
||||||
|
goto PARSE_VER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
root = cJSON_Parse(content);
|
||||||
|
if (root == NULL) {
|
||||||
|
vError("vgId:%d, failed to read %s, invalid json format", pVnode->vgId, file);
|
||||||
|
goto PARSE_VER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *ver = cJSON_GetObjectItem(root, "version");
|
||||||
|
if (!ver || ver->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read %s, version not found", pVnode->vgId, file);
|
||||||
|
goto PARSE_VER_ERROR;
|
||||||
|
}
|
||||||
|
pVnode->version = ver->valueint;
|
||||||
|
|
||||||
|
terrno = TSDB_CODE_SUCCESS;
|
||||||
|
vInfo("vgId:%d, read %s successfully, version:%" PRId64, pVnode->vgId, file, pVnode->version);
|
||||||
|
|
||||||
|
PARSE_VER_ERROR:
|
||||||
|
if (content != NULL) free(content);
|
||||||
|
if (root != NULL) cJSON_Delete(root);
|
||||||
|
if (fp != NULL) fclose(fp);
|
||||||
|
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t vnodeSaveVersion(SVnodeObj *pVnode) {
|
||||||
|
char file[TSDB_FILENAME_LEN + 30] = {0};
|
||||||
|
sprintf(file, "%s/vnode%d/version.json", tsVnodeDir, pVnode->vgId);
|
||||||
|
|
||||||
|
FILE *fp = fopen(file, "w");
|
||||||
|
if (!fp) {
|
||||||
|
vError("vgId:%d, failed to write %s, reason:%s", pVnode->vgId, file, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t len = 0;
|
||||||
|
int32_t maxLen = 100;
|
||||||
|
char * content = calloc(1, maxLen + 1);
|
||||||
|
|
||||||
|
len += snprintf(content + len, maxLen - len, "{\n");
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"version\": %" PRId64 "\n", pVnode->fversion);
|
||||||
|
len += snprintf(content + len, maxLen - len, "}\n");
|
||||||
|
|
||||||
|
fwrite(content, 1, len, fp);
|
||||||
|
fflush(fp);
|
||||||
|
fclose(fp);
|
||||||
|
free(content);
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
|
vInfo("vgId:%d, successed to write %s, version:%" PRId64, pVnode->vgId, file, pVnode->fversion);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
|
@ -183,7 +183,7 @@ static int32_t vnodeProcessAlterTableMsg(SVnodeObj *pVnode, void *pCont, SRspRet
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vnodeProcessDropStableMsg(SVnodeObj *pVnode, void *pCont, SRspRet *pRet) {
|
static int32_t vnodeProcessDropStableMsg(SVnodeObj *pVnode, void *pCont, SRspRet *pRet) {
|
||||||
SMDDropSTableMsg *pTable = pCont;
|
SDropSTableMsg *pTable = pCont;
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
vDebug("vgId:%d, stable:%s, start to drop", pVnode->vgId, pTable->tableId);
|
vDebug("vgId:%d, stable:%s, start to drop", pVnode->vgId, pTable->tableId);
|
||||||
|
@ -204,7 +204,6 @@ static int32_t vnodeProcessUpdateTagValMsg(SVnodeObj *pVnode, void *pCont, SRspR
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int vnodeWriteCqMsgToQueue(void *param, void *data, int type) {
|
int vnodeWriteCqMsgToQueue(void *param, void *data, int type) {
|
||||||
SVnodeObj *pVnode = param;
|
SVnodeObj *pVnode = param;
|
||||||
SWalHead * pHead = data;
|
SWalHead * pHead = data;
|
||||||
|
@ -222,7 +221,6 @@ int vnodeWriteCqMsgToQueue(void *param, void *data, int type) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int vnodeWriteToQueue(void *param, void *data, int type) {
|
int vnodeWriteToQueue(void *param, void *data, int type) {
|
||||||
SVnodeObj *pVnode = param;
|
SVnodeObj *pVnode = param;
|
||||||
SWalHead * pHead = data;
|
SWalHead * pHead = data;
|
||||||
|
|
|
@ -31,8 +31,32 @@ extern int32_t wDebugFlag;
|
||||||
#define wDebug(...) { if (wDebugFlag & DEBUG_DEBUG) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }}
|
#define wDebug(...) { if (wDebugFlag & DEBUG_DEBUG) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }}
|
||||||
#define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }}
|
#define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define walPrefix "wal"
|
#define WAL_PREFIX "wal"
|
||||||
#define walSignature (uint32_t)(0xFAFBFDFE)
|
#define WAL_PREFIX_LEN 3
|
||||||
|
#define WAL_REFRESH_MS 1000
|
||||||
|
#define WAL_MAX_SIZE (1024 * 1024)
|
||||||
|
#define WAL_SIGNATURE ((uint32_t)(0xFAFBFDFE))
|
||||||
|
#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12)
|
||||||
|
#define WAL_FILE_LEN (TSDB_FILENAME_LEN + 32)
|
||||||
|
#define WAL_FILE_NUM 3
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint64_t version;
|
||||||
|
int64_t fileId;
|
||||||
|
int32_t vgId;
|
||||||
|
int32_t fd;
|
||||||
|
int32_t keep;
|
||||||
|
int32_t level;
|
||||||
|
int32_t fsyncPeriod;
|
||||||
|
int32_t fsyncSeq;
|
||||||
|
char path[WAL_PATH_LEN];
|
||||||
|
char name[WAL_FILE_LEN];
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
} SWal;
|
||||||
|
|
||||||
|
int32_t walGetNextFile(SWal *pWal, int64_t *nextFileId);
|
||||||
|
int32_t walGetOldFile(SWal *pWal, int64_t curFileId, int32_t minDiff, int64_t *oldFileId);
|
||||||
|
int32_t walGetNewFile(SWal *pWal, int64_t *newFileId);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,212 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
|
#include "talloc.h"
|
||||||
|
#include "tref.h"
|
||||||
#include "twal.h"
|
#include "twal.h"
|
||||||
#include "walInt.h"
|
#include "walInt.h"
|
||||||
#include "walMgmt.h"
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t refId;
|
||||||
|
int32_t seq;
|
||||||
|
int8_t stop;
|
||||||
|
pthread_t thread;
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
} SWalMgmt;
|
||||||
|
|
||||||
|
static SWalMgmt tsWal;
|
||||||
|
static int32_t walCreateThread();
|
||||||
|
static void walStopThread();
|
||||||
|
static int32_t walInitObj(SWal *pWal);
|
||||||
|
static void walFreeObj(void *pWal);
|
||||||
|
|
||||||
|
int32_t walInit() {
|
||||||
|
tmemzero(&tsWal, sizeof(SWalMgmt));
|
||||||
|
tsWal.refId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj);
|
||||||
|
|
||||||
|
int32_t code = walCreateThread();
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
wError("failed to init wal module since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
wInfo("wal module is initialized, refId:%d", tsWal.refId);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void walCleanUp() {
|
||||||
|
walStopThread();
|
||||||
|
taosCloseRef(tsWal.refId);
|
||||||
|
wInfo("wal module is cleaned up");
|
||||||
|
}
|
||||||
|
|
||||||
|
void *walOpen(char *path, SWalCfg *pCfg) {
|
||||||
|
SWal *pWal = tcalloc(sizeof(SWal));
|
||||||
|
if (pWal == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pWal->vgId = pCfg->vgId;
|
||||||
|
pWal->fd = -1;
|
||||||
|
pWal->fileId = -1;
|
||||||
|
pWal->level = pCfg->walLevel;
|
||||||
|
pWal->keep = pCfg->keep;
|
||||||
|
pWal->fsyncPeriod = pCfg->fsyncPeriod;
|
||||||
|
tstrncpy(pWal->path, path, sizeof(pWal->path));
|
||||||
|
pthread_mutex_init(&pWal->mutex, NULL);
|
||||||
|
|
||||||
|
pWal->fsyncSeq = pCfg->fsyncPeriod % 1000;
|
||||||
|
if (pWal->fsyncSeq <= 0) pWal->fsyncSeq = 1;
|
||||||
|
|
||||||
|
if (walInitObj(pWal) != TSDB_CODE_SUCCESS) {
|
||||||
|
walFreeObj(pWal);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosAddRef(tsWal.refId, pWal) != TSDB_CODE_SUCCESS) {
|
||||||
|
walFreeObj(pWal);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wDebug("vgId:%d, wal:%p is opened, level:%d fsyncPeriod:%d", pWal->vgId, pWal, pWal->level, pWal->fsyncPeriod);
|
||||||
|
|
||||||
|
return pWal;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t walAlter(void *handle, SWalCfg *pCfg) {
|
||||||
|
if (handle == NULL) return TSDB_CODE_WAL_APP_ERROR;
|
||||||
|
SWal *pWal = handle;
|
||||||
|
|
||||||
|
if (pWal->level == pCfg->walLevel && pWal->fsyncPeriod == pCfg->fsyncPeriod) {
|
||||||
|
wDebug("vgId:%d, old walLevel:%d fsync:%d, new walLevel:%d fsync:%d not change", pWal->vgId, pWal->level,
|
||||||
|
pWal->fsyncPeriod, pCfg->walLevel, pCfg->fsyncPeriod);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
wInfo("vgId:%d, change old walLevel:%d fsync:%d, new walLevel:%d fsync:%d", pWal->vgId, pWal->level,
|
||||||
|
pWal->fsyncPeriod, pCfg->walLevel, pCfg->fsyncPeriod);
|
||||||
|
|
||||||
|
pWal->level = pCfg->walLevel;
|
||||||
|
pWal->fsyncPeriod = pCfg->fsyncPeriod;
|
||||||
|
pWal->fsyncSeq = pCfg->fsyncPeriod % 1000;
|
||||||
|
if (pWal->fsyncSeq <= 0) pWal->fsyncSeq = 1;
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void walClose(void *handle) {
|
||||||
|
if (handle == NULL) return;
|
||||||
|
|
||||||
|
SWal *pWal = handle;
|
||||||
|
pthread_mutex_lock(&pWal->mutex);
|
||||||
|
|
||||||
|
taosClose(pWal->fd);
|
||||||
|
|
||||||
|
if (!pWal->keep) {
|
||||||
|
int64_t fileId = -1;
|
||||||
|
while (walGetNextFile(pWal, &fileId) >= 0) {
|
||||||
|
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, fileId);
|
||||||
|
|
||||||
|
if (fileId == pWal->fileId) {
|
||||||
|
wDebug("vgId:%d, wal:%p file:%s, it is closed and kept", pWal->vgId, pWal, pWal->name);
|
||||||
|
} else if (remove(pWal->name) < 0) {
|
||||||
|
wError("vgId:%d, wal:%p file:%s, failed to remove", pWal->vgId, pWal, pWal->name);
|
||||||
|
} else {
|
||||||
|
wDebug("vgId:%d, wal:%p file:%s, it is removed", pWal->vgId, pWal, pWal->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wDebug("vgId:%d, wal:%p file:%s, it is closed and kept", pWal->vgId, pWal, pWal->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&pWal->mutex);
|
||||||
|
taosRemoveRef(tsWal.refId, pWal);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t walInitObj(SWal *pWal) {
|
||||||
|
if (taosMkDir(pWal->path, 0755) != 0) {
|
||||||
|
wError("vgId:%d, path:%s, failed to create directory since %s", pWal->vgId, pWal->path, strerror(errno));
|
||||||
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
wDebug("vgId:%d, object is initialized", pWal->vgId);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void walFreeObj(void *wal) {
|
||||||
|
SWal *pWal = wal;
|
||||||
|
wDebug("vgId:%d, wal:%p is freed", pWal->vgId, pWal);
|
||||||
|
|
||||||
|
taosClose(pWal->fd);
|
||||||
|
pthread_mutex_destroy(&pWal->mutex);
|
||||||
|
tfree(pWal);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool walNeedFsync(SWal *pWal) {
|
||||||
|
if (pWal->fsyncPeriod <= 0 || pWal->level != TAOS_WAL_FSYNC) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsWal.seq % pWal->fsyncSeq == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void walUpdateSeq() {
|
||||||
|
taosMsleep(WAL_REFRESH_MS);
|
||||||
|
if (++tsWal.seq <= 0) {
|
||||||
|
tsWal.seq = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void walFsyncAll() {
|
||||||
|
SWal *pWal = taosIterateRef(tsWal.refId, NULL);
|
||||||
|
while (pWal) {
|
||||||
|
if (walNeedFsync(pWal)) {
|
||||||
|
wTrace("vgId:%d, do fsync, level:%d seq:%d rseq:%d", pWal->vgId, pWal->level, pWal->fsyncSeq, tsWal.seq);
|
||||||
|
int32_t code = fsync(pWal->fd);
|
||||||
|
if (code != 0) {
|
||||||
|
wError("vgId:%d, file:%s, failed to fsync since %s", pWal->vgId, pWal->name, strerror(code));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pWal = taosIterateRef(tsWal.refId, pWal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *walThreadFunc(void *param) {
|
||||||
|
while (1) {
|
||||||
|
walUpdateSeq();
|
||||||
|
walFsyncAll();
|
||||||
|
if (tsWal.stop) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t walCreateThread() {
|
||||||
|
pthread_attr_t thAttr;
|
||||||
|
pthread_attr_init(&thAttr);
|
||||||
|
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
|
||||||
|
if (pthread_create(&tsWal.thread, &thAttr, walThreadFunc, NULL) != 0) {
|
||||||
|
wError("failed to create wal thread since %s", strerror(errno));
|
||||||
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_attr_destroy(&thAttr);
|
||||||
|
wDebug("wal thread is launched");
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void walStopThread() {
|
||||||
|
tsWal.stop = 1;
|
||||||
|
if (tsWal.thread) {
|
||||||
|
pthread_join(tsWal.thread, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
wDebug("wal thread is stopped");
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "walInt.h"
|
||||||
|
|
||||||
|
int32_t walGetNextFile(SWal *pWal, int64_t *nextFileId) {
|
||||||
|
int64_t curFileId = *nextFileId;
|
||||||
|
int64_t minFileId = INT64_MAX;
|
||||||
|
|
||||||
|
DIR *dir = opendir(pWal->path);
|
||||||
|
if (dir == NULL) {
|
||||||
|
wError("vgId:%d, path:%s, failed to open since %s", pWal->vgId, pWal->path, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dirent *ent;
|
||||||
|
while ((ent = readdir(dir)) != NULL) {
|
||||||
|
char *name = ent->d_name;
|
||||||
|
|
||||||
|
if (strncmp(name, WAL_PREFIX, WAL_PREFIX_LEN) == 0) {
|
||||||
|
int64_t id = atoll(name + WAL_PREFIX_LEN);
|
||||||
|
if (id <= curFileId) continue;
|
||||||
|
|
||||||
|
if (id < minFileId) {
|
||||||
|
minFileId = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
|
if (minFileId == INT64_MAX) return -1;
|
||||||
|
|
||||||
|
*nextFileId = minFileId;
|
||||||
|
wTrace("vgId:%d, path:%s, curFileId:%" PRId64 " nextFileId:%" PRId64, pWal->vgId, pWal->path, curFileId, *nextFileId);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t walGetOldFile(SWal *pWal, int64_t curFileId, int32_t minDiff, int64_t *oldFileId) {
|
||||||
|
int64_t minFileId = INT64_MAX;
|
||||||
|
|
||||||
|
DIR *dir = opendir(pWal->path);
|
||||||
|
if (dir == NULL) {
|
||||||
|
wError("vgId:%d, path:%s, failed to open since %s", pWal->vgId, pWal->path, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dirent *ent;
|
||||||
|
while ((ent = readdir(dir)) != NULL) {
|
||||||
|
char *name = ent->d_name;
|
||||||
|
|
||||||
|
if (strncmp(name, WAL_PREFIX, WAL_PREFIX_LEN) == 0) {
|
||||||
|
int64_t id = atoll(name + WAL_PREFIX_LEN);
|
||||||
|
if (id >= curFileId) continue;
|
||||||
|
|
||||||
|
minDiff--;
|
||||||
|
if (id < minFileId) {
|
||||||
|
minFileId = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
|
if (minFileId == INT64_MAX) return -1;
|
||||||
|
if (minDiff > 0) return -1;
|
||||||
|
|
||||||
|
*oldFileId = minFileId;
|
||||||
|
wTrace("vgId:%d, path:%s, curFileId:%" PRId64 " oldFildId:%" PRId64, pWal->vgId, pWal->path, curFileId, *oldFileId);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t walGetNewFile(SWal *pWal, int64_t *newFileId) {
|
||||||
|
int64_t maxFileId = INT64_MIN;
|
||||||
|
|
||||||
|
DIR *dir = opendir(pWal->path);
|
||||||
|
if (dir == NULL) {
|
||||||
|
wError("vgId:%d, path:%s, failed to open since %s", pWal->vgId, pWal->path, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dirent *ent;
|
||||||
|
while ((ent = readdir(dir)) != NULL) {
|
||||||
|
char *name = ent->d_name;
|
||||||
|
|
||||||
|
if (strncmp(name, WAL_PREFIX, WAL_PREFIX_LEN) == 0) {
|
||||||
|
int64_t id = atoll(name + WAL_PREFIX_LEN);
|
||||||
|
if (id > maxFileId) {
|
||||||
|
maxFileId = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
|
if (maxFileId == INT64_MIN) {
|
||||||
|
*newFileId = 0;
|
||||||
|
} else {
|
||||||
|
*newFileId = maxFileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
wTrace("vgId:%d, path:%s, newFileId:%" PRId64, pWal->vgId, pWal->path, *newFileId);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -15,238 +15,95 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "talloc.h"
|
||||||
|
#include "taoserror.h"
|
||||||
|
#include "tchecksum.h"
|
||||||
#include "twal.h"
|
#include "twal.h"
|
||||||
#include "walInt.h"
|
#include "walInt.h"
|
||||||
#include "walMgmt.h"
|
|
||||||
#include "tchecksum.h"
|
|
||||||
#include "tutil.h"
|
|
||||||
#include "ttimer.h"
|
|
||||||
#include "taoserror.h"
|
|
||||||
#include "twal.h"
|
|
||||||
#include "tqueue.h"
|
|
||||||
|
|
||||||
|
static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, char *name, int64_t fileId);
|
||||||
|
|
||||||
typedef struct {
|
int32_t walRenew(void *handle) {
|
||||||
uint64_t version;
|
|
||||||
int fd;
|
|
||||||
int keep;
|
|
||||||
int level;
|
|
||||||
int32_t fsyncPeriod;
|
|
||||||
void *timer;
|
|
||||||
void *signature;
|
|
||||||
int max; // maximum number of wal files
|
|
||||||
uint32_t id; // increase continuously
|
|
||||||
int num; // number of wal files
|
|
||||||
char path[TSDB_FILENAME_LEN];
|
|
||||||
char name[TSDB_FILENAME_LEN+16];
|
|
||||||
pthread_mutex_t mutex;
|
|
||||||
} SWal;
|
|
||||||
|
|
||||||
static void *walTmrCtrl = NULL;
|
|
||||||
static int tsWalNum = 0;
|
|
||||||
static pthread_once_t walModuleInit = PTHREAD_ONCE_INIT;
|
|
||||||
static int walHandleExistingFiles(const char *path);
|
|
||||||
static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp);
|
|
||||||
static int walRemoveWalFiles(const char *path);
|
|
||||||
static void walProcessFsyncTimer(void *param, void *tmrId);
|
|
||||||
static void walRelease(SWal *pWal);
|
|
||||||
static int walGetMaxOldFileId(char *odir);
|
|
||||||
|
|
||||||
static void walModuleInitFunc() {
|
|
||||||
walTmrCtrl = taosTmrInit(1000, 100, 300000, "WAL");
|
|
||||||
if (walTmrCtrl == NULL)
|
|
||||||
walModuleInit = PTHREAD_ONCE_INIT;
|
|
||||||
else
|
|
||||||
wDebug("WAL module is initialized");
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool walNeedFsyncTimer(SWal *pWal) {
|
|
||||||
if (pWal->fsyncPeriod > 0 && pWal->level == TAOS_WAL_FSYNC) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *walOpen(const char *path, const SWalCfg *pCfg) {
|
|
||||||
SWal *pWal = calloc(sizeof(SWal), 1);
|
|
||||||
if (pWal == NULL) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_once(&walModuleInit, walModuleInitFunc);
|
|
||||||
if (walTmrCtrl == NULL) {
|
|
||||||
free(pWal);
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
atomic_add_fetch_32(&tsWalNum, 1);
|
|
||||||
pWal->fd = -1;
|
|
||||||
pWal->max = pCfg->wals;
|
|
||||||
pWal->id = 0;
|
|
||||||
pWal->num = 0;
|
|
||||||
pWal->level = pCfg->walLevel;
|
|
||||||
pWal->keep = pCfg->keep;
|
|
||||||
pWal->fsyncPeriod = pCfg->fsyncPeriod;
|
|
||||||
pWal->signature = pWal;
|
|
||||||
tstrncpy(pWal->path, path, sizeof(pWal->path));
|
|
||||||
pthread_mutex_init(&pWal->mutex, NULL);
|
|
||||||
|
|
||||||
if (walNeedFsyncTimer(pWal)) {
|
|
||||||
pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl);
|
|
||||||
if (pWal->timer == NULL) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
walRelease(pWal);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taosMkDir(path, 0755) != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
wError("wal:%s, failed to create directory(%s)", path, strerror(errno));
|
|
||||||
walRelease(pWal);
|
|
||||||
pWal = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pCfg->keep == 1) return pWal;
|
|
||||||
|
|
||||||
if (walHandleExistingFiles(path) == 0) walRenew(pWal);
|
|
||||||
|
|
||||||
if (pWal && pWal->fd < 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
wError("wal:%s, failed to open(%s)", path, strerror(errno));
|
|
||||||
walRelease(pWal);
|
|
||||||
pWal = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pWal) wDebug("wal:%s, it is open, level:%d fsyncPeriod:%d", path, pWal->level, pWal->fsyncPeriod);
|
|
||||||
return pWal;
|
|
||||||
}
|
|
||||||
|
|
||||||
int walAlter(twalh wal, const SWalCfg *pCfg) {
|
|
||||||
SWal *pWal = wal;
|
|
||||||
if (pWal == NULL) {
|
|
||||||
return TSDB_CODE_WAL_APP_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pWal->level == pCfg->walLevel && pWal->fsyncPeriod == pCfg->fsyncPeriod) {
|
|
||||||
wDebug("wal:%s, old walLevel:%d fsync:%d, new walLevel:%d fsync:%d not change", pWal->name, pWal->level,
|
|
||||||
pWal->fsyncPeriod, pCfg->walLevel, pCfg->fsyncPeriod);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
wInfo("wal:%s, change old walLevel:%d fsync:%d, new walLevel:%d fsync:%d", pWal->name, pWal->level, pWal->fsyncPeriod,
|
|
||||||
pCfg->walLevel, pCfg->fsyncPeriod);
|
|
||||||
|
|
||||||
pthread_mutex_lock(&pWal->mutex);
|
|
||||||
pWal->level = pCfg->walLevel;
|
|
||||||
pWal->fsyncPeriod = pCfg->fsyncPeriod;
|
|
||||||
if (walNeedFsyncTimer(pWal)) {
|
|
||||||
wInfo("wal:%s, reset fsync timer, walLevel:%d fsyncPeriod:%d", pWal->name, pWal->level, pWal->fsyncPeriod);
|
|
||||||
taosTmrReset(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, &pWal->timer, walTmrCtrl);
|
|
||||||
} else {
|
|
||||||
wInfo("wal:%s, stop fsync timer, walLevel:%d fsyncPeriod:%d", pWal->name, pWal->level, pWal->fsyncPeriod);
|
|
||||||
taosTmrStop(pWal->timer);
|
|
||||||
pWal->timer = NULL;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&pWal->mutex);
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void walClose(void *handle) {
|
|
||||||
if (handle == NULL) return;
|
|
||||||
|
|
||||||
SWal *pWal = handle;
|
|
||||||
taosClose(pWal->fd);
|
|
||||||
if (pWal->timer) taosTmrStopA(&pWal->timer);
|
|
||||||
|
|
||||||
if (pWal->keep == 0) {
|
|
||||||
// remove all files in the directory
|
|
||||||
for (int i = 0; i < pWal->num; ++i) {
|
|
||||||
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%d", pWal->path, walPrefix, pWal->id - i);
|
|
||||||
if (remove(pWal->name) < 0) {
|
|
||||||
wError("wal:%s, failed to remove", pWal->name);
|
|
||||||
} else {
|
|
||||||
wDebug("wal:%s, it is removed", pWal->name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
wDebug("wal:%s, it is closed and kept", pWal->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
walRelease(pWal);
|
|
||||||
}
|
|
||||||
|
|
||||||
int walRenew(void *handle) {
|
|
||||||
if (handle == NULL) return 0;
|
if (handle == NULL) return 0;
|
||||||
SWal *pWal = handle;
|
|
||||||
|
|
||||||
terrno = 0;
|
SWal * pWal = handle;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
pthread_mutex_lock(&pWal->mutex);
|
pthread_mutex_lock(&pWal->mutex);
|
||||||
|
|
||||||
if (pWal->fd >= 0) {
|
if (pWal->fd >= 0) {
|
||||||
close(pWal->fd);
|
close(pWal->fd);
|
||||||
pWal->id++;
|
wDebug("vgId:%d, file:%s, it is closed", pWal->vgId, pWal->name);
|
||||||
wDebug("wal:%s, it is closed", pWal->name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pWal->num++;
|
if (pWal->keep) {
|
||||||
|
pWal->fileId = 0;
|
||||||
|
} else {
|
||||||
|
if (walGetNewFile(pWal, &pWal->fileId) != 0) pWal->fileId = 0;
|
||||||
|
pWal->fileId++;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%d", pWal->path, walPrefix, pWal->id);
|
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, pWal->fileId);
|
||||||
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
|
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
|
|
||||||
if (pWal->fd < 0) {
|
if (pWal->fd < 0) {
|
||||||
wError("wal:%s, failed to open(%s)", pWal->name, strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
wError("vgId:%d, file:%s, failed to open since %s", pWal->vgId, pWal->name, strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
wDebug("wal:%s, it is created", pWal->name);
|
wDebug("vgId:%d, file:%s, it is created", pWal->vgId, pWal->name);
|
||||||
|
}
|
||||||
|
|
||||||
if (pWal->num > pWal->max) {
|
if (!pWal->keep) {
|
||||||
// remove the oldest wal file
|
// remove the oldest wal file
|
||||||
char name[TSDB_FILENAME_LEN * 3];
|
int64_t oldFileId = -1;
|
||||||
snprintf(name, sizeof(name), "%s/%s%d", pWal->path, walPrefix, pWal->id - pWal->max);
|
if (walGetOldFile(pWal, pWal->fileId, WAL_FILE_NUM, &oldFileId) == 0) {
|
||||||
if (remove(name) < 0) {
|
char walName[WAL_FILE_LEN] = {0};
|
||||||
wError("wal:%s, failed to remove(%s)", name, strerror(errno));
|
snprintf(walName, sizeof(walName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, oldFileId);
|
||||||
|
|
||||||
|
if (remove(walName) < 0) {
|
||||||
|
wError("vgId:%d, file:%s, failed to remove since %s", pWal->vgId, walName, strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
wDebug("wal:%s, it is removed", name);
|
wDebug("vgId:%d, file:%s, it is removed", pWal->vgId, walName);
|
||||||
}
|
}
|
||||||
|
|
||||||
pWal->num--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&pWal->mutex);
|
pthread_mutex_unlock(&pWal->mutex);
|
||||||
|
|
||||||
return terrno;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int walWrite(void *handle, SWalHead *pHead) {
|
int32_t walWrite(void *handle, SWalHead *pHead) {
|
||||||
SWal *pWal = handle;
|
if (handle == NULL) return -1;
|
||||||
if (pWal == NULL) return -1;
|
|
||||||
|
|
||||||
terrno = 0;
|
SWal * pWal = handle;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
// no wal
|
// no wal
|
||||||
|
if (pWal->fd <= 0) return 0;
|
||||||
if (pWal->level == TAOS_WAL_NOLOG) return 0;
|
if (pWal->level == TAOS_WAL_NOLOG) return 0;
|
||||||
if (pHead->version <= pWal->version) return 0;
|
if (pHead->version <= pWal->version) return 0;
|
||||||
|
|
||||||
pHead->signature = walSignature;
|
pHead->signature = WAL_SIGNATURE;
|
||||||
taosCalcChecksumAppend(0, (uint8_t *)pHead, sizeof(SWalHead));
|
taosCalcChecksumAppend(0, (uint8_t *)pHead, sizeof(SWalHead));
|
||||||
int contLen = pHead->len + sizeof(SWalHead);
|
int32_t contLen = pHead->len + sizeof(SWalHead);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&pWal->mutex);
|
||||||
|
|
||||||
if (taosTWrite(pWal->fd, pHead, contLen) != contLen) {
|
if (taosTWrite(pWal->fd, pHead, contLen) != contLen) {
|
||||||
wError("wal:%s, failed to write(%s)", pWal->name, strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
wError("vgId:%d, file:%s, failed to write since %s", pWal->vgId, pWal->name, strerror(errno));
|
||||||
return terrno;
|
|
||||||
} else {
|
} else {
|
||||||
|
wTrace("vgId:%d, fileId:%" PRId64 " fd:%d, write wal ver:%" PRId64 ", head ver:%" PRIu64 ", len:%d ", pWal->vgId,
|
||||||
|
pWal->fileId, pWal->fd, pWal->version, pHead->version, pHead->len);
|
||||||
pWal->version = pHead->version;
|
pWal->version = pHead->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&pWal->mutex);
|
||||||
|
|
||||||
ASSERT(contLen == pHead->len + sizeof(SWalHead));
|
ASSERT(contLen == pHead->len + sizeof(SWalHead));
|
||||||
|
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void walFsync(void *handle) {
|
void walFsync(void *handle) {
|
||||||
|
@ -255,295 +112,203 @@ void walFsync(void *handle) {
|
||||||
|
|
||||||
if (pWal->fsyncPeriod == 0) {
|
if (pWal->fsyncPeriod == 0) {
|
||||||
if (fsync(pWal->fd) < 0) {
|
if (fsync(pWal->fd) < 0) {
|
||||||
wError("wal:%s, fsync failed(%s)", pWal->name, strerror(errno));
|
wError("vgId:%d, file:%s, fsync failed since %s", pWal->vgId, pWal->name, strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *, int)) {
|
int32_t walRestore(void *handle, void *pVnode, int32_t (*writeFp)(void *, void *, int32_t)) {
|
||||||
SWal *pWal = handle;
|
if (handle == NULL) return -1;
|
||||||
struct dirent *ent;
|
|
||||||
int count = 0;
|
|
||||||
uint32_t maxId = 0, minId = -1, index =0;
|
|
||||||
|
|
||||||
terrno = 0;
|
SWal * pWal = handle;
|
||||||
int plen = strlen(walPrefix);
|
int32_t count = 0;
|
||||||
char opath[TSDB_FILENAME_LEN + 5];
|
int32_t code = 0;
|
||||||
|
int64_t fileId = -1;
|
||||||
|
|
||||||
int slen = snprintf(opath, sizeof(opath), "%s", pWal->path);
|
while ((code = walGetNextFile(pWal, &fileId)) >= 0) {
|
||||||
if (pWal->keep == 0) strcpy(opath + slen, "/old");
|
if (fileId == pWal->fileId) continue;
|
||||||
|
|
||||||
DIR *dir = opendir(opath);
|
char walName[WAL_FILE_LEN];
|
||||||
if (dir == NULL && errno == ENOENT) return 0;
|
snprintf(walName, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, fileId);
|
||||||
if (dir == NULL) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
wDebug("vgId:%d, file:%s, will be restored", pWal->vgId, walName);
|
||||||
if (strncmp(ent->d_name, walPrefix, plen) == 0) {
|
int32_t code = walRestoreWalFile(pWal, pVnode, writeFp, walName, fileId);
|
||||||
index = atol(ent->d_name + plen);
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
if (index > maxId) maxId = index;
|
wError("vgId:%d, file:%s, failed to restore since %s", pWal->vgId, walName, tstrerror(code));
|
||||||
if (index < minId) minId = index;
|
continue;
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!pWal->keep) {
|
||||||
|
wDebug("vgId:%d, file:%s, restore success, remove this file", pWal->vgId, walName);
|
||||||
|
remove(walName);
|
||||||
|
} else {
|
||||||
|
wDebug("vgId:%d, file:%s, restore success and keep it", pWal->vgId, walName);
|
||||||
|
}
|
||||||
|
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
if (!pWal->keep) return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
if (pWal->keep) terrno = walRenew(pWal);
|
wDebug("vgId:%d, file:%s not exist, renew it", pWal->vgId, pWal->name);
|
||||||
return terrno;
|
return walRenew(pWal);
|
||||||
}
|
|
||||||
|
|
||||||
if (count != (maxId - minId + 1)) {
|
|
||||||
wError("wal:%s, messed up, count:%d max:%d min:%d", opath, count, maxId, minId);
|
|
||||||
terrno = TSDB_CODE_WAL_APP_ERROR;
|
|
||||||
} else {
|
} else {
|
||||||
wDebug("wal:%s, %d files will be restored", opath, count);
|
// open the existing WAL file in append mode
|
||||||
|
pWal->fileId = 0;
|
||||||
for (index = minId; index <= maxId; ++index) {
|
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, pWal->fileId);
|
||||||
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%d", opath, walPrefix, index);
|
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
terrno = walRestoreWalFile(pWal, pVnode, writeFp);
|
if (pWal->fd < 0) {
|
||||||
if (terrno < 0) continue;
|
wError("vgId:%d, file:%s, failed to open since %s", pWal->vgId, pWal->name, strerror(errno));
|
||||||
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
|
wDebug("vgId:%d, file:%s open success", pWal->vgId, pWal->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (terrno == 0) {
|
return TSDB_CODE_SUCCESS;
|
||||||
if (pWal->keep == 0) {
|
|
||||||
terrno = walRemoveWalFiles(opath);
|
|
||||||
if (terrno == 0) {
|
|
||||||
if (remove(opath) < 0) {
|
|
||||||
wError("wal:%s, failed to remove directory(%s)", opath, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// open the existing WAL file in append mode
|
|
||||||
pWal->num = count;
|
|
||||||
pWal->id = maxId;
|
|
||||||
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%d", opath, walPrefix, maxId);
|
|
||||||
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO);
|
|
||||||
if (pWal->fd < 0) {
|
|
||||||
wError("wal:%s, failed to open file(%s)", pWal->name, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int walGetWalFile(void *handle, char *name, uint32_t *index) {
|
int32_t walGetWalFile(void *handle, char *fileName, int64_t *fileId) {
|
||||||
SWal * pWal = handle;
|
if (handle == NULL) return -1;
|
||||||
int code = 1;
|
SWal *pWal = handle;
|
||||||
int32_t first = 0;
|
|
||||||
|
|
||||||
name[0] = 0;
|
// for keep
|
||||||
if (pWal == NULL || pWal->num == 0) return 0;
|
if (*fileId == 0) *fileId = -1;
|
||||||
|
|
||||||
pthread_mutex_lock(&(pWal->mutex));
|
pthread_mutex_lock(&(pWal->mutex));
|
||||||
|
|
||||||
first = pWal->id + 1 - pWal->num;
|
int32_t code = walGetNextFile(pWal, fileId);
|
||||||
if (*index == 0) *index = first; // set to first one
|
if (code >= 0) {
|
||||||
|
sprintf(fileName, "wal/%s%" PRId64, WAL_PREFIX, *fileId);
|
||||||
if (*index < first && *index > pWal->id) {
|
code = (*fileId == pWal->fileId) ? 0 : 1;
|
||||||
code = -1; // index out of range
|
|
||||||
} else {
|
|
||||||
sprintf(name, "wal/%s%d", walPrefix, *index);
|
|
||||||
code = (*index == pWal->id) ? 0 : 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wTrace("vgId:%d, get wal file, code:%d curId:%" PRId64 " outId:%" PRId64, pWal->vgId, code, pWal->fileId, *fileId);
|
||||||
pthread_mutex_unlock(&(pWal->mutex));
|
pthread_mutex_unlock(&(pWal->mutex));
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void walRelease(SWal *pWal) {
|
static void walFtruncate(SWal *pWal, int32_t fd, int64_t offset) {
|
||||||
pthread_mutex_destroy(&pWal->mutex);
|
taosFtruncate(fd, offset);
|
||||||
pWal->signature = NULL;
|
fsync(fd);
|
||||||
free(pWal);
|
|
||||||
|
|
||||||
if (atomic_sub_fetch_32(&tsWalNum, 1) == 0) {
|
|
||||||
if (walTmrCtrl) taosTmrCleanUp(walTmrCtrl);
|
|
||||||
walTmrCtrl = NULL;
|
|
||||||
walModuleInit = PTHREAD_ONCE_INIT;
|
|
||||||
wDebug("WAL module is cleaned up");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp) {
|
static int32_t walSkipCorruptedRecord(SWal *pWal, SWalHead *pHead, int32_t fd, int64_t *offset) {
|
||||||
char *name = pWal->name;
|
int64_t pos = *offset;
|
||||||
int size = 1024 * 1024; // default 1M buffer size
|
|
||||||
|
|
||||||
terrno = 0;
|
|
||||||
char *buffer = malloc(size);
|
|
||||||
if (buffer == NULL) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
SWalHead *pHead = (SWalHead *)buffer;
|
|
||||||
|
|
||||||
int fd = open(name, O_RDWR);
|
|
||||||
if (fd < 0) {
|
|
||||||
wError("wal:%s, failed to open for restore(%s)", name, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
free(buffer);
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
wDebug("wal:%s, start to restore", name);
|
|
||||||
|
|
||||||
size_t offset = 0;
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int ret = taosTRead(fd, pHead, sizeof(SWalHead));
|
pos++;
|
||||||
|
|
||||||
|
if (lseek(fd, pos, SEEK_SET) < 0) {
|
||||||
|
wError("vgId:%d, failed to seek from corrupted wal file since %s", pWal->vgId, strerror(errno));
|
||||||
|
return TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosTRead(fd, pHead, sizeof(SWalHead)) <= 0) {
|
||||||
|
wError("vgId:%d, read to end of corrupted wal file, offset:%" PRId64, pWal->vgId, pos);
|
||||||
|
return TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pHead->signature != WAL_SIGNATURE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosCheckChecksumWhole((uint8_t *)pHead, sizeof(SWalHead))) {
|
||||||
|
wInfo("vgId:%d, wal head cksum check passed, offset:%" PRId64, pWal->vgId, pos);
|
||||||
|
*offset = pos;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, char *name, int64_t fileId) {
|
||||||
|
int32_t size = WAL_MAX_SIZE;
|
||||||
|
void * buffer = tmalloc(size);
|
||||||
|
if (buffer == NULL) {
|
||||||
|
wError("vgId:%d, file:%s, failed to open for restore since %s", pWal->vgId, name, strerror(errno));
|
||||||
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t fd = open(name, O_RDWR);
|
||||||
|
if (fd < 0) {
|
||||||
|
wError("vgId:%d, file:%s, failed to open for restore since %s", pWal->vgId, name, strerror(errno));
|
||||||
|
tfree(buffer);
|
||||||
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
wDebug("vgId:%d, file:%s, start to restore", pWal->vgId, name);
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int64_t offset = 0;
|
||||||
|
SWalHead *pHead = buffer;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
int32_t ret = taosTRead(fd, pHead, sizeof(SWalHead));
|
||||||
if (ret == 0) break;
|
if (ret == 0) break;
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
wError("wal:%s, failed to read wal head part since %s", name, strerror(errno));
|
wError("vgId:%d, file:%s, failed to read wal head since %s", pWal->vgId, name, strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < sizeof(SWalHead)) {
|
if (ret < sizeof(SWalHead)) {
|
||||||
wError("wal:%s, failed to read head, ret:%d, skip the rest of file", name, ret);
|
wError("vgId:%d, file:%s, failed to read wal head, ret is %d", pWal->vgId, name, ret);
|
||||||
taosFtruncate(fd, offset);
|
walFtruncate(pWal, fd, offset);
|
||||||
fsync(fd);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!taosCheckChecksumWhole((uint8_t *)pHead, sizeof(SWalHead))) {
|
if (!taosCheckChecksumWhole((uint8_t *)pHead, sizeof(SWalHead))) {
|
||||||
wWarn("wal:%s, cksum is messed up, skip the rest of file", name);
|
wError("vgId:%d, file:%s, wal head cksum is messed up, ver:%" PRIu64 " len:%d offset:%" PRId64, pWal->vgId, name,
|
||||||
terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
|
pHead->version, pHead->len, offset);
|
||||||
ASSERT(false);
|
code = walSkipCorruptedRecord(pWal, pHead, fd, &offset);
|
||||||
break;
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
walFtruncate(pWal, fd, offset);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pHead->len > size - sizeof(SWalHead)) {
|
if (pHead->len > size - sizeof(SWalHead)) {
|
||||||
size = sizeof(SWalHead) + pHead->len;
|
size = sizeof(SWalHead) + pHead->len;
|
||||||
buffer = realloc(buffer, size);
|
buffer = realloc(buffer, size);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
wError("vgId:%d, file:%s, failed to open for restore since %s", pWal->vgId, name, strerror(errno));
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pHead = (SWalHead *)buffer;
|
pHead = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = taosTRead(fd, pHead->cont, pHead->len);
|
ret = taosTRead(fd, pHead->cont, pHead->len);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
wError("wal:%s failed to read wal body part since %s", name, strerror(errno));
|
wError("vgId:%d, file:%s, failed to read wal body since %s", pWal->vgId, name, strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < pHead->len) {
|
if (ret < pHead->len) {
|
||||||
wError("wal:%s, failed to read body, len:%d ret:%d, skip the rest of file", name, pHead->len, ret);
|
wError("vgId:%d, file:%s, failed to read wal body, ret:%d len:%d", pWal->vgId, name, ret, pHead->len);
|
||||||
taosFtruncate(fd, offset);
|
offset += sizeof(SWalHead);
|
||||||
fsync(fd);
|
continue;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = offset + sizeof(SWalHead) + pHead->len;
|
offset = offset + sizeof(SWalHead) + pHead->len;
|
||||||
|
|
||||||
|
wTrace("vgId:%d, fileId:%" PRId64 ", restore wal ver:%" PRIu64 ", head ver:%" PRIu64 " len:%d", pWal->vgId, fileId,
|
||||||
|
pWal->version, pHead->version, pHead->len);
|
||||||
|
|
||||||
if (pWal->keep) pWal->version = pHead->version;
|
if (pWal->keep) pWal->version = pHead->version;
|
||||||
|
|
||||||
(*writeFp)(pVnode, pHead, TAOS_QTYPE_WAL);
|
(*writeFp)(pVnode, pHead, TAOS_QTYPE_WAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
free(buffer);
|
tfree(buffer);
|
||||||
|
|
||||||
return terrno;
|
return code;
|
||||||
}
|
|
||||||
|
|
||||||
int walHandleExistingFiles(const char *path) {
|
|
||||||
char oname[TSDB_FILENAME_LEN * 3];
|
|
||||||
char nname[TSDB_FILENAME_LEN * 3];
|
|
||||||
char opath[TSDB_FILENAME_LEN];
|
|
||||||
|
|
||||||
snprintf(opath, sizeof(opath), "%s/old", path);
|
|
||||||
|
|
||||||
struct dirent *ent;
|
|
||||||
DIR *dir = opendir(path);
|
|
||||||
int plen = strlen(walPrefix);
|
|
||||||
terrno = 0;
|
|
||||||
|
|
||||||
int midx = walGetMaxOldFileId(opath);
|
|
||||||
int count = 0;
|
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
|
||||||
if (strncmp(ent->d_name, walPrefix, plen) == 0) {
|
|
||||||
midx++;
|
|
||||||
snprintf(oname, sizeof(oname), "%s/%s", path, ent->d_name);
|
|
||||||
snprintf(nname, sizeof(nname), "%s/old/wal%d", path, midx);
|
|
||||||
if (taosMkDir(opath, 0755) != 0) {
|
|
||||||
wError("wal:%s, failed to create directory:%s(%s)", oname, opath, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rename(oname, nname) < 0) {
|
|
||||||
wError("wal:%s, failed to move to new:%s", oname, nname);
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
wDebug("wal:%s, %d files are moved for restoration", path, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int walRemoveWalFiles(const char *path) {
|
|
||||||
int plen = strlen(walPrefix);
|
|
||||||
char name[TSDB_FILENAME_LEN * 3];
|
|
||||||
|
|
||||||
terrno = 0;
|
|
||||||
|
|
||||||
struct dirent *ent;
|
|
||||||
DIR *dir = opendir(path);
|
|
||||||
if (dir == NULL && errno == ENOENT) return 0;
|
|
||||||
if (dir == NULL) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
|
||||||
if (strncmp(ent->d_name, walPrefix, plen) == 0) {
|
|
||||||
snprintf(name, sizeof(name), "%s/%s", path, ent->d_name);
|
|
||||||
if (remove(name) < 0) {
|
|
||||||
wError("wal:%s, failed to remove(%s)", name, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void walProcessFsyncTimer(void *param, void *tmrId) {
|
|
||||||
SWal *pWal = param;
|
|
||||||
|
|
||||||
if (pWal->signature != pWal) return;
|
|
||||||
if (pWal->fd < 0) return;
|
|
||||||
|
|
||||||
if (fsync(pWal->fd) < 0) {
|
|
||||||
wError("wal:%s, fsync failed(%s)", pWal->name, strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (walNeedFsyncTimer(pWal)) {
|
|
||||||
pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl);
|
|
||||||
} else {
|
|
||||||
wInfo("wal:%s, stop fsync timer for walLevel:%d fsyncPeriod:%d", pWal->name, pWal->level, pWal->fsyncPeriod);
|
|
||||||
taosTmrStop(pWal->timer);
|
|
||||||
pWal->timer = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t walGetVersion(twalh param) {
|
int64_t walGetVersion(twalh param) {
|
||||||
|
@ -552,29 +317,3 @@ int64_t walGetVersion(twalh param) {
|
||||||
|
|
||||||
return pWal->version;
|
return pWal->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int walGetMaxOldFileId(char *odir) {
|
|
||||||
int midx = 0;
|
|
||||||
DIR * dir = NULL;
|
|
||||||
struct dirent *dp = NULL;
|
|
||||||
int plen = strlen(walPrefix);
|
|
||||||
|
|
||||||
if (access(odir, F_OK) != 0) return midx;
|
|
||||||
|
|
||||||
dir = opendir(odir);
|
|
||||||
if (dir == NULL) {
|
|
||||||
wError("failed to open directory %s since %s", odir, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((dp = readdir(dir)) != NULL) {
|
|
||||||
if (strncmp(dp->d_name, walPrefix, plen) == 0) {
|
|
||||||
int idx = atol(dp->d_name + plen);
|
|
||||||
if (midx < idx) midx = idx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
return midx;
|
|
||||||
}
|
|
|
@ -115,17 +115,17 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
printf("%d wal files are written\n", total);
|
printf("%d wal files are written\n", total);
|
||||||
|
|
||||||
uint32_t index = 0;
|
int64_t index = 0;
|
||||||
char name[256];
|
char name[256];
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int code = walGetWalFile(pWal, name, &index);
|
int code = walGetWalFile(pWal, name, &index);
|
||||||
if (code == -1) {
|
if (code == -1) {
|
||||||
printf("failed to get wal file, index:%d\n", index);
|
printf("failed to get wal file, index:%" PRId64 "\n", index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("index:%d wal:%s\n", index, name);
|
printf("index:%" PRId64 " wal:%s\n", index, name);
|
||||||
if (code == 0) break;
|
if (code == 0) break;
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
|
@ -87,7 +87,7 @@ func init() {
|
||||||
|
|
||||||
func printAllArgs() {
|
func printAllArgs() {
|
||||||
fmt.Printf("\n============= args parse result: =============\n")
|
fmt.Printf("\n============= args parse result: =============\n")
|
||||||
fmt.Printf("dbName: %v\n", configPara.hostName)
|
fmt.Printf("hostName: %v\n", configPara.hostName)
|
||||||
fmt.Printf("serverPort: %v\n", configPara.serverPort)
|
fmt.Printf("serverPort: %v\n", configPara.serverPort)
|
||||||
fmt.Printf("usr: %v\n", configPara.user)
|
fmt.Printf("usr: %v\n", configPara.user)
|
||||||
fmt.Printf("password: %v\n", configPara.password)
|
fmt.Printf("password: %v\n", configPara.password)
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import threading
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
|
class RestfulInsert:
|
||||||
|
def init(self):
|
||||||
|
self.header = {'Authorization': 'Basic cm9vdDp0YW9zZGF0YQ=='}
|
||||||
|
self.url = "http://127.0.0.1:6041/rest/sql"
|
||||||
|
self.ts = 1500000000000
|
||||||
|
self.numOfThreads = 20
|
||||||
|
self.numOfTables = 10000
|
||||||
|
self.recordsPerTable = 10000
|
||||||
|
self.batchSize = 1000
|
||||||
|
self.tableNamePerfix = 't'
|
||||||
|
|
||||||
|
def createTable(self, threadID):
|
||||||
|
tablesPerThread = int (self.numOfTables / self.numOfThreads)
|
||||||
|
print("create table %d to %d" % (tablesPerThread * threadID, tablesPerThread * (threadID + 1) - 1))
|
||||||
|
for i in range(tablesPerThread):
|
||||||
|
tableID = threadID * tablesPerThread
|
||||||
|
name = 'beijing' if tableID % 2 == 0 else 'shanghai'
|
||||||
|
data = "create table test.%s%d using test.meters tags(%d, '%s')" % (self.tableNamePerfix, tableID + i, tableID + i, name)
|
||||||
|
requests.post(self.url, data, headers = self.header)
|
||||||
|
|
||||||
|
def insertData(self, threadID):
|
||||||
|
print("thread %d started" % threadID)
|
||||||
|
tablesPerThread = int (self.numOfTables / self.numOfThreads)
|
||||||
|
for i in range(tablesPerThread):
|
||||||
|
tableID = i + threadID * tablesPerThread
|
||||||
|
start = self.ts
|
||||||
|
for j in range(int(self.recordsPerTable / self.batchSize)):
|
||||||
|
data = "insert into test.%s%d values" % (self.tableNamePerfix, tableID)
|
||||||
|
for k in range(self.batchSize):
|
||||||
|
data += "(%d, %d, %d, %d)" % (start + j * self.batchSize + k, random.randint(1, 100), random.randint(1, 100), random.randint(1, 100))
|
||||||
|
requests.post(self.url, data, headers = self.header)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
data = "drop database if exists test"
|
||||||
|
requests.post(self.url, data, headers = self.header)
|
||||||
|
data = "create database test"
|
||||||
|
requests.post(self.url, data, headers = self.header)
|
||||||
|
data = "create table test.meters(ts timestamp, f1 int, f2 int, f3 int) tags(id int, loc nchar(20))"
|
||||||
|
requests.post(self.url, data, headers = self.header)
|
||||||
|
|
||||||
|
threads = []
|
||||||
|
startTime = time.time()
|
||||||
|
for i in range(self.numOfThreads):
|
||||||
|
thread = threading.Thread(target=self.createTable, args=(i,))
|
||||||
|
thread.start()
|
||||||
|
threads.append(thread)
|
||||||
|
for i in range(self.numOfThreads):
|
||||||
|
threads[i].join()
|
||||||
|
print("createing %d tables takes %d seconds" % (self.numOfTables, (time.time() - startTime)))
|
||||||
|
|
||||||
|
print("inserting data =======")
|
||||||
|
threads = []
|
||||||
|
startTime = time.time()
|
||||||
|
for i in range(self.numOfThreads):
|
||||||
|
thread = threading.Thread(target=self.insertData, args=(i,))
|
||||||
|
thread.start()
|
||||||
|
threads.append(thread)
|
||||||
|
|
||||||
|
for i in range(self.numOfThreads):
|
||||||
|
threads[i].join()
|
||||||
|
print("inserting %d records takes %d seconds" % (self.numOfTables * self.recordsPerTable, (time.time() - startTime)))
|
||||||
|
|
||||||
|
ri = RestfulInsert()
|
||||||
|
ri.init()
|
||||||
|
ri.run()
|
|
@ -0,0 +1,63 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import taos
|
||||||
|
from util.log import tdLog
|
||||||
|
from util.cases import tdCases
|
||||||
|
from util.sql import tdSql
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
class TDTestCase:
|
||||||
|
def init(self, conn, logSql):
|
||||||
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
|
tdSql.init(conn.cursor(), logSql)
|
||||||
|
|
||||||
|
self.ts = 1500000000000
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
tdSql.prepare()
|
||||||
|
|
||||||
|
tdSql.execute("create table meters(ts timestamp, col1 int) tags(id int, loc nchar(20))")
|
||||||
|
sql = "insert into t0 using meters tags(1, 'beijing') values"
|
||||||
|
for i in range(100):
|
||||||
|
sql += "(%d, %d)" % (self.ts + i * 1000, random.randint(1, 100))
|
||||||
|
tdSql.execute(sql)
|
||||||
|
|
||||||
|
sql = "insert into t1 using meters tags(2, 'shanghai') values"
|
||||||
|
for i in range(100):
|
||||||
|
sql += "(%d, %d)" % (self.ts + i * 1000, random.randint(1, 100))
|
||||||
|
tdSql.execute(sql)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from meters interval(10s) sliding(5s)")
|
||||||
|
tdSql.checkRows(21)
|
||||||
|
|
||||||
|
tdSql.error("select count(*) from meters sliding(5s)")
|
||||||
|
|
||||||
|
tdSql.error("select count(*) from meters sliding(5s) interval(10s)")
|
||||||
|
|
||||||
|
tdSql.error("select * from meters sliding(5s) order by ts desc")
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from meters group by loc")
|
||||||
|
tdSql.checkRows(2)
|
||||||
|
|
||||||
|
tdSql.error("select * from meters group by loc sliding(5s)")
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -134,13 +134,66 @@ sql select join_mt0.ts, join_mt1.t1, join_mt0.t1, join_mt1.tbname, join_mt0.tbna
|
||||||
|
|
||||||
#1970-01-01 08:01:40.800 | 10 | 45.000000000 | 0 | true | false | 0 |
|
#1970-01-01 08:01:40.800 | 10 | 45.000000000 | 0 | true | false | 0 |
|
||||||
#1970-01-01 08:01:40.790 | 10 | 945.000000000 | 90 | true | true | 0 |
|
#1970-01-01 08:01:40.790 | 10 | 945.000000000 | 90 | true | true | 0 |
|
||||||
|
|
||||||
sql select count(join_mt0.c1), sum(join_mt1.c2), first(join_mt0.c5), last(join_mt1.c7), first(join_mt1.c7) from join_mt0, join_mt1 where join_mt0.t1=join_mt1.t1 and join_mt0.ts=join_mt1.ts interval(10a) group by join_mt0.t1 order by join_mt0.ts desc limit 20 offset 19;
|
sql select count(join_mt0.c1), sum(join_mt1.c2), first(join_mt0.c5), last(join_mt1.c7), first(join_mt1.c7) from join_mt0, join_mt1 where join_mt0.t1=join_mt1.t1 and join_mt0.ts=join_mt1.ts interval(10a) group by join_mt0.t1 order by join_mt0.ts desc limit 20 offset 19;
|
||||||
if $rows != 100 then
|
if $rows != 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# c5 is null ! error
|
if $data00 != @70-01-01 08:01:40.800@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 10 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data02 != 45.000000000 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data03 != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data04 != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data05 != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data06 != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data10 != @70-01-01 08:01:40.790@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data11 != 10 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data12 != 945.000000000 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data13 != 90 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data14 != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data15 != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data16 != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
sql select count(join_mt0.c1), sum(join_mt0.c2)/count(*), avg(c2), first(join_mt0.c5), last(c7) from join_mt0 interval(10a) group by join_mt0.t1 order by join_mt0.ts desc;
|
sql select count(join_mt0.c1), sum(join_mt0.c2)/count(*), avg(c2), first(join_mt0.c5), last(c7) from join_mt0 interval(10a) group by join_mt0.t1 order by join_mt0.ts desc;
|
||||||
if $rows != 100 then
|
if $rows != 100 then
|
||||||
|
|
|
@ -49,7 +49,7 @@ print dnode1 $data4_2
|
||||||
if $data4_1 != ready then
|
if $data4_1 != ready then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data4_2 != offline then
|
if $data4_2 == ready then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue