[TD-10431] remove mnode files
This commit is contained in:
parent
5db5e7c38d
commit
8f4da1545f
|
@ -1,7 +0,0 @@
|
|||
aux_source_directory(source MNODE_SRC)
|
||||
add_library(mnode ${MNODE_SRC})
|
||||
target_include_directories(
|
||||
mnode
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/mnode"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
)
|
|
@ -1,10 +0,0 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/dnode/inc)
|
||||
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
|
||||
ADD_LIBRARY(mnode ${SRC})
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_ACCT_H
|
||||
#define TDENGINE_MNODE_ACCT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tacct.h"
|
||||
|
||||
int32_t mnodeInitAccts();
|
||||
void mnodeCleanupAccts();
|
||||
void mnodeGetStatOfAllAcct(SAcctInfo* pAcctInfo);
|
||||
void * mnodeGetAcct(char *acctName);
|
||||
void * mnodeGetNextAcct(void *pIter, SAcctObj **pAcct);
|
||||
void mnodeCancelGetNextAcct(void *pIter);
|
||||
void mnodeIncAcctRef(SAcctObj *pAcct);
|
||||
void mnodeDecAcctRef(SAcctObj *pAcct);
|
||||
void mnodeAddDbToAcct(SAcctObj *pAcct, SDbObj *pDb);
|
||||
void mnodeDropDbFromAcct(SAcctObj *pAcct, SDbObj *pDb);
|
||||
void mnodeAddUserToAcct(SAcctObj *pAcct, SUserObj *pUser);
|
||||
void mnodeDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser);
|
||||
|
||||
int32_t mnodeCompactAccts();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_CLUSTER_H
|
||||
#define TDENGINE_MNODE_CLUSTER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitCluster();
|
||||
void mnodeCleanupCluster();
|
||||
void mnodeUpdateClusterId();
|
||||
const char* mnodeGetClusterId();
|
||||
|
||||
int32_t mnodeCompactCluster();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_DB_H
|
||||
#define TDENGINE_MNODE_DB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mnodeDef.h"
|
||||
|
||||
enum _TSDB_DB_STATUS {
|
||||
TSDB_DB_STATUS_READY,
|
||||
TSDB_DB_STATUS_DROPPING
|
||||
};
|
||||
|
||||
// api
|
||||
int32_t mnodeInitDbs();
|
||||
void mnodeCleanupDbs();
|
||||
int64_t mnodeGetDbNum();
|
||||
int32_t mnodeGetDbMaxReplica();
|
||||
SDbObj *mnodeGetDb(char *db);
|
||||
SDbObj *mnodeGetDbByTableName(char *db);
|
||||
void * mnodeGetNextDb(void *pIter, SDbObj **pDb);
|
||||
void mnodeCancelGetNextDb(void *pIter);
|
||||
void mnodeIncDbRef(SDbObj *pDb);
|
||||
void mnodeDecDbRef(SDbObj *pDb);
|
||||
bool mnodeCheckIsMonitorDB(char *db, char *monitordb);
|
||||
void mnodeDropAllDbs(SAcctObj *pAcct);
|
||||
int mnodeInsertAlterDbRow(SDbObj *pDb, void *pMsg);
|
||||
|
||||
int32_t mnodeCompactDbs();
|
||||
|
||||
// util func
|
||||
void mnodeAddSuperTableIntoDb(SDbObj *pDb);
|
||||
void mnodeRemoveSuperTableFromDb(SDbObj *pDb);
|
||||
void mnodeAddTableIntoDb(SDbObj *pDb);
|
||||
void mnodeRemoveTableFromDb(SDbObj *pDb);
|
||||
void mnodeAddVgroupIntoDb(SVgObj *pVgroup);
|
||||
void mnodeRemoveVgroupFromDb(SVgObj *pVgroup);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,292 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_DEF_H
|
||||
#define TDENGINE_MNODE_DEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "taosdef.h"
|
||||
#include "taosmsg.h"
|
||||
|
||||
struct SVgObj;
|
||||
struct SDbObj;
|
||||
struct SAcctObj;
|
||||
struct SUserObj;
|
||||
struct SMnodeObj;
|
||||
|
||||
/*
|
||||
struct define notes:
|
||||
1. The first field must be the xxxxId field or name field , e.g. 'int32_t dnodeId', 'int32_t mnodeId', 'char name[]', 'char user[]', ...
|
||||
2. From the dnodeId field to the updataEnd field, these information will be falled disc;
|
||||
3. The fields behind the updataEnd field can be changed;
|
||||
*/
|
||||
|
||||
typedef struct SClusterObj {
|
||||
char uid[TSDB_CLUSTER_ID_LEN];
|
||||
int64_t createdTime;
|
||||
int8_t reserved[12];
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
} SClusterObj;
|
||||
|
||||
typedef struct SDnodeObj {
|
||||
int32_t dnodeId;
|
||||
int32_t openVnodes;
|
||||
int64_t createdTime;
|
||||
int64_t lastAccess;
|
||||
int32_t customScore; // config by user
|
||||
uint16_t numOfCores; // from dnode status msg
|
||||
uint16_t dnodePort;
|
||||
char dnodeFqdn[TSDB_FQDN_LEN];
|
||||
char dnodeEp[TSDB_EP_LEN];
|
||||
int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode
|
||||
int8_t status; // set in balance function
|
||||
int8_t isMgmt;
|
||||
int8_t reserve1[11];
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
uint32_t moduleStatus;
|
||||
uint32_t lastReboot; // time stamp for last reboot
|
||||
float score; // calc in balance function
|
||||
float diskAvailable; // from dnode status msg
|
||||
int16_t diskAvgUsage; // calc from sys.disk
|
||||
int16_t cpuAvgUsage; // calc from sys.cpu
|
||||
int16_t memoryAvgUsage; // calc from sys.mem
|
||||
int16_t bandwidthUsage; // calc from sys.band
|
||||
int8_t offlineReason;
|
||||
int8_t reserved2[1];
|
||||
} SDnodeObj;
|
||||
|
||||
typedef struct SMnodeObj {
|
||||
int32_t mnodeId;
|
||||
int8_t reserved0[4];
|
||||
int64_t createdTime;
|
||||
int8_t reserved1[4];
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
int8_t role;
|
||||
int64_t roleTime;
|
||||
int8_t reserved2[3];
|
||||
} SMnodeObj;
|
||||
|
||||
typedef struct STableObj {
|
||||
char *tableId;
|
||||
int8_t type;
|
||||
} STableObj;
|
||||
|
||||
typedef struct SSTableObj {
|
||||
STableObj info;
|
||||
int8_t reserved0[9]; // for fill struct STableObj to 4byte align
|
||||
int16_t nextColId;
|
||||
int32_t sversion;
|
||||
uint64_t uid;
|
||||
int64_t createdTime;
|
||||
int32_t tversion;
|
||||
int32_t numOfColumns;
|
||||
int32_t numOfTags;
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
int32_t numOfTables;
|
||||
SSchema * schema;
|
||||
void * vgHash;
|
||||
} SSTableObj;
|
||||
|
||||
typedef struct {
|
||||
STableObj info;
|
||||
int8_t reserved0[9]; // for fill struct STableObj to 4byte align
|
||||
int16_t nextColId; //used by normal table
|
||||
int32_t sversion; //used by normal table
|
||||
uint64_t uid;
|
||||
uint64_t suid;
|
||||
int64_t createdTime;
|
||||
int32_t numOfColumns; //used by normal table
|
||||
int32_t tid;
|
||||
int32_t vgId;
|
||||
int32_t sqlLen;
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
char* sql; //used by normal table
|
||||
SSchema* schema; //used by normal table
|
||||
SSTableObj*superTable;
|
||||
} SCTableObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int8_t role;
|
||||
int8_t vver[3]; // To ensure compatibility, 3 bits are used to represent the remainder of 64 bit version
|
||||
SDnodeObj *pDnode;
|
||||
} SVnodeGid;
|
||||
|
||||
typedef struct SVgObj {
|
||||
uint32_t vgId;
|
||||
int32_t numOfVnodes;
|
||||
int64_t createdTime;
|
||||
int32_t lbDnodeId;
|
||||
int32_t lbTime;
|
||||
char dbName[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int8_t inUse;
|
||||
int8_t accessState;
|
||||
int8_t status;
|
||||
int8_t reserved0[4];
|
||||
SVnodeGid vnodeGid[TSDB_MAX_REPLICA];
|
||||
int32_t vgCfgVersion;
|
||||
int8_t compact;
|
||||
int8_t reserved1[8];
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
int32_t numOfTables;
|
||||
int64_t totalStorage;
|
||||
int64_t compStorage;
|
||||
int64_t pointsWritten;
|
||||
struct SDbObj *pDb;
|
||||
void * idPool;
|
||||
} SVgObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t cacheBlockSize;
|
||||
int32_t totalBlocks;
|
||||
int32_t maxTables;
|
||||
int32_t daysPerFile;
|
||||
int32_t daysToKeep0;
|
||||
int32_t daysToKeep1;
|
||||
int32_t daysToKeep2;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int32_t commitTime;
|
||||
int32_t fsyncPeriod;
|
||||
int8_t precision;
|
||||
int8_t compression;
|
||||
int8_t walLevel;
|
||||
int8_t replications;
|
||||
int8_t quorum;
|
||||
int8_t update;
|
||||
int8_t cacheLastRow;
|
||||
int8_t dbType;
|
||||
int16_t partitions;
|
||||
int8_t reserved[7];
|
||||
} SDbCfg;
|
||||
|
||||
typedef struct SDbObj {
|
||||
char name[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int8_t reserved0[4];
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
int32_t dbCfgVersion;
|
||||
SDbCfg cfg;
|
||||
int8_t status;
|
||||
int8_t reserved1[11];
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
int32_t numOfVgroups;
|
||||
int32_t numOfTables;
|
||||
int32_t numOfSuperTables;
|
||||
int32_t vgListSize;
|
||||
int32_t vgListIndex;
|
||||
SVgObj **vgList;
|
||||
struct SAcctObj *pAcct;
|
||||
pthread_mutex_t mutex;
|
||||
} SDbObj;
|
||||
|
||||
typedef struct SUserObj {
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
int8_t superAuth;
|
||||
int8_t writeAuth;
|
||||
int8_t reserved[10];
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
struct SAcctObj * pAcct;
|
||||
} SUserObj;
|
||||
|
||||
typedef struct SFuncObj {
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
char path[128];
|
||||
int32_t contLen;
|
||||
char cont[TSDB_FUNC_CODE_LEN];
|
||||
int32_t funcType;
|
||||
int32_t bufSize;
|
||||
int64_t createdTime;
|
||||
uint8_t resType;
|
||||
int16_t resBytes;
|
||||
int64_t sig; // partial md5 sign
|
||||
int16_t type; // [lua script|so|js]
|
||||
int8_t reserved[64];
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
} SFuncObj;
|
||||
|
||||
typedef struct {
|
||||
int64_t totalStorage; // Total storage wrtten from this account
|
||||
int64_t compStorage; // Compressed storage on disk
|
||||
int64_t queryTime;
|
||||
int64_t totalPoints;
|
||||
int64_t inblound;
|
||||
int64_t outbound;
|
||||
int64_t sKey;
|
||||
int32_t numOfUsers;
|
||||
int32_t numOfDbs;
|
||||
int32_t numOfTimeSeries;
|
||||
int32_t numOfPointsPerSecond;
|
||||
int32_t numOfConns;
|
||||
int32_t numOfQueries;
|
||||
int32_t numOfStreams;
|
||||
int8_t accessState; // Checked by mgmt heartbeat message
|
||||
int8_t reserved[3];
|
||||
} SAcctInfo;
|
||||
|
||||
typedef struct SAcctObj {
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
SAcctCfg cfg;
|
||||
int64_t createdTime;
|
||||
int32_t acctId;
|
||||
int8_t status;
|
||||
int8_t reserved0[7];
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
int8_t reserved1[4];
|
||||
SAcctInfo acctInfo;
|
||||
pthread_mutex_t mutex;
|
||||
} SAcctObj;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int8_t type;
|
||||
int16_t numOfColumns;
|
||||
int32_t index;
|
||||
int32_t rowSize;
|
||||
int32_t numOfRows;
|
||||
void * pIter;
|
||||
void * pVgIter;
|
||||
void ** ppShow;
|
||||
int16_t offset[TSDB_MAX_COLUMNS];
|
||||
int32_t bytes[TSDB_MAX_COLUMNS];
|
||||
int32_t numOfReads;
|
||||
int8_t maxReplica;
|
||||
int8_t reserved0[1];
|
||||
uint16_t payloadLen;
|
||||
char payload[];
|
||||
} SShowObj;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_DNODE_H
|
||||
#define TDENGINE_MNODE_DNODE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
TAOS_DN_STATUS_OFFLINE,
|
||||
TAOS_DN_STATUS_DROPPING,
|
||||
TAOS_DN_STATUS_BALANCING,
|
||||
TAOS_DN_STATUS_READY
|
||||
} EDnodeStatus;
|
||||
|
||||
typedef enum {
|
||||
TAOS_DN_ALTERNATIVE_ROLE_ANY,
|
||||
TAOS_DN_ALTERNATIVE_ROLE_MNODE,
|
||||
TAOS_DN_ALTERNATIVE_ROLE_VNODE
|
||||
} EDnodeAlternativeRole;
|
||||
|
||||
typedef enum EDnodeOfflineReason {
|
||||
TAOS_DN_OFF_ONLINE = 0,
|
||||
TAOS_DN_OFF_STATUS_MSG_TIMEOUT,
|
||||
TAOS_DN_OFF_STATUS_NOT_RECEIVED,
|
||||
TAOS_DN_OFF_RESET_BY_MNODE,
|
||||
TAOS_DN_OFF_VERSION_NOT_MATCH,
|
||||
TAOS_DN_OFF_DNODE_ID_NOT_MATCH,
|
||||
TAOS_DN_OFF_CLUSTER_ID_NOT_MATCH,
|
||||
TAOS_DN_OFF_NUM_OF_MNODES_NOT_MATCH,
|
||||
TAOS_DN_OFF_ENABLE_BALANCE_NOT_MATCH,
|
||||
TAOS_DN_OFF_MN_EQUAL_VN_NOT_MATCH,
|
||||
TAOS_DN_OFF_OFFLINE_THRESHOLD_NOT_MATCH,
|
||||
TAOS_DN_OFF_STATUS_INTERVAL_NOT_MATCH,
|
||||
TAOS_DN_OFF_MAX_TAB_PER_VN_NOT_MATCH,
|
||||
TAOS_DN_OFF_MAX_VG_PER_DB_NOT_MATCH,
|
||||
TAOS_DN_OFF_ARBITRATOR_NOT_MATCH,
|
||||
TAOS_DN_OFF_TIME_ZONE_NOT_MATCH,
|
||||
TAOS_DN_OFF_LOCALE_NOT_MATCH,
|
||||
TAOS_DN_OFF_CHARSET_NOT_MATCH,
|
||||
TAOS_DN_OFF_FLOW_CTRL_NOT_MATCH,
|
||||
TAOS_DN_OFF_SLAVE_QUERY_NOT_MATCH,
|
||||
TAOS_DN_OFF_ADJUST_MASTER_NOT_MATCH,
|
||||
TAOS_DN_OFF_OTHERS
|
||||
} EDnodeOfflineReason;
|
||||
|
||||
extern char* dnodeStatus[];
|
||||
extern char* dnodeRoles[];
|
||||
|
||||
int32_t mnodeInitDnodes();
|
||||
void mnodeCleanupDnodes();
|
||||
|
||||
int32_t mnodeGetDnodesNum();
|
||||
int32_t mnodeGetOnlinDnodesCpuCoreNum();
|
||||
int32_t mnodeGetOnlineDnodesNum();
|
||||
void mnodeGetOnlineAndTotalDnodesNum(int32_t *onlineNum, int32_t *totalNum);
|
||||
void * mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode);
|
||||
void mnodeCancelGetNextDnode(void *pIter);
|
||||
void mnodeIncDnodeRef(SDnodeObj *pDnode);
|
||||
void mnodeDecDnodeRef(SDnodeObj *pDnode);
|
||||
void * mnodeGetDnode(int32_t dnodeId);
|
||||
void * mnodeGetDnodeByEp(char *ep);
|
||||
void mnodeUpdateDnode(SDnodeObj *pDnode);
|
||||
int32_t mnodeDropDnode(SDnodeObj *pDnode, void *pMsg);
|
||||
|
||||
int32_t mnodeCompactDnodes();
|
||||
extern int64_t tsAccessSquence;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_FUNC_H
|
||||
#define TDENGINE_MNODE_FUNC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeDef.h"
|
||||
|
||||
int32_t mnodeInitFuncs();
|
||||
void mnodeCleanupFuncs();
|
||||
|
||||
SFuncObj *mnodeGetFunc(char *name);
|
||||
void * mnodeGetNextFunc(void *pIter, SFuncObj **pFunc);
|
||||
void mnodeCancelGetNextFunc(void *pIter);
|
||||
|
||||
void mnodeIncFuncRef(SFuncObj *pFunc);
|
||||
void mnodeDecFuncRef(SFuncObj *pFunc);
|
||||
|
||||
int32_t mnodeCreateFunc(SAcctObj *pAcct, char *name, int32_t codeLen, char *code, char *path, uint8_t outputType, int16_t outputLen, int32_t funcType, int32_t bufSize, SMnodeMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_LOG_H
|
||||
#define TDENGINE_MNODE_LOG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tlog.h"
|
||||
#include "monitor.h"
|
||||
|
||||
extern int32_t mDebugFlag;
|
||||
extern int32_t sdbDebugFlag;
|
||||
|
||||
// mnode log function
|
||||
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
|
||||
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
|
||||
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
|
||||
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }}
|
||||
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
#define sdbFatal(...) { if (sdbDebugFlag & DEBUG_FATAL) { taosPrintLog("SDB FATAL ", 255, __VA_ARGS__); }}
|
||||
#define sdbError(...) { if (sdbDebugFlag & DEBUG_ERROR) { taosPrintLog("SDB ERROR ", 255, __VA_ARGS__); }}
|
||||
#define sdbWarn(...) { if (sdbDebugFlag & DEBUG_WARN) { taosPrintLog("SDB WARN ", 255, __VA_ARGS__); }}
|
||||
#define sdbInfo(...) { if (sdbDebugFlag & DEBUG_INFO) { taosPrintLog("SDB ", 255, __VA_ARGS__); }}
|
||||
#define sdbDebug(...) { if (sdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("SDB ", sdbDebugFlag, __VA_ARGS__); }}
|
||||
#define sdbTrace(...) { if (sdbDebugFlag & DEBUG_TRACE) { taosPrintLog("SDB ", sdbDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
#define mLError(...) { monSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) }
|
||||
#define mLWarn(...) { monSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) }
|
||||
#define mLInfo(...) { monSaveLog(0, __VA_ARGS__); mInfo(__VA_ARGS__) }
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_MNODE_H
|
||||
#define TDENGINE_MNODE_MNODE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct SMnodeObj;
|
||||
|
||||
typedef enum {
|
||||
TAOS_MN_STATUS_OFFLINE,
|
||||
TAOS_MN_STATUS_DROPPING,
|
||||
TAOS_MN_STATUS_READY
|
||||
} EMnodeStatus;
|
||||
|
||||
int32_t mnodeInitMnodes();
|
||||
void mnodeCleanupMnodes();
|
||||
|
||||
void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm);
|
||||
int32_t mnodeDropMnode(int32_t dnodeId);
|
||||
void mnodeDropMnodeLocal(int32_t dnodeId);
|
||||
|
||||
void * mnodeGetMnode(int32_t mnodeId);
|
||||
int32_t mnodeGetMnodesNum();
|
||||
void * mnodeGetNextMnode(void *pIter, struct SMnodeObj **pMnode);
|
||||
void mnodeCancelGetNextMnode(void *pIter);
|
||||
void mnodeIncMnodeRef(struct SMnodeObj *pMnode);
|
||||
void mnodeDecMnodeRef(struct SMnodeObj *pMnode);
|
||||
|
||||
char * mnodeGetMnodeRoleStr();
|
||||
void mnodeGetMnodeEpSetForPeer(SRpcEpSet *epSet, bool redirect);
|
||||
void mnodeGetMnodeEpSetForShell(SRpcEpSet *epSet, bool redirect);
|
||||
char* mnodeGetMnodeMasterEp();
|
||||
|
||||
void mnodeGetMnodeInfos(void *mnodes);
|
||||
void mnodeUpdateMnodeEpSet(SMInfos *pMnodes);
|
||||
|
||||
int32_t mnodeCompactMnodes();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_PEER_H
|
||||
#define TDENGINE_MNODE_PEER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeDef.h"
|
||||
|
||||
void mnodeAddPeerRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg));
|
||||
void mnodeAddPeerMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg));
|
||||
int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg);
|
||||
void mnodeProcessPeerRsp(SRpcMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_PROFILE_H
|
||||
#define TDENGINE_MNODE_PROFILE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeDef.h"
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char appName[TSDB_APPNAME_LEN]; // app name that invokes taosc
|
||||
uint32_t pid; // pid of app that invokes taosc
|
||||
int8_t killed;
|
||||
uint16_t port;
|
||||
uint32_t ip;
|
||||
uint32_t connId;
|
||||
uint64_t stime;
|
||||
uint64_t lastAccess;
|
||||
uint32_t queryId;
|
||||
uint32_t streamId;
|
||||
int32_t numOfQueries;
|
||||
int32_t numOfStreams;
|
||||
SStreamDesc *pStreams;
|
||||
SQueryDesc * pQueries;
|
||||
} SConnObj;
|
||||
|
||||
int32_t mnodeInitProfile();
|
||||
void mnodeCleanupProfile();
|
||||
|
||||
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);
|
||||
void mnodeReleaseConn(SConnObj *pConn);
|
||||
int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pHBMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_READ_H
|
||||
#define TDENGINE_MNODE_READ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeDef.h"
|
||||
|
||||
void mnodeAddReadMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg));
|
||||
int32_t mnodeProcessRead(SMnodeMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,116 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_SDB_H
|
||||
#define TDENGINE_MNODE_SDB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mnode.h"
|
||||
#include "twal.h"
|
||||
|
||||
typedef enum {
|
||||
SDB_TABLE_CLUSTER = 0,
|
||||
SDB_TABLE_DNODE = 1,
|
||||
SDB_TABLE_MNODE = 2,
|
||||
SDB_TABLE_ACCOUNT = 3,
|
||||
SDB_TABLE_USER = 4,
|
||||
SDB_TABLE_DB = 5,
|
||||
SDB_TABLE_VGROUP = 6,
|
||||
SDB_TABLE_STABLE = 7,
|
||||
SDB_TABLE_CTABLE = 8,
|
||||
SDB_TABLE_FUNC = 9,
|
||||
SDB_TABLE_MAX = 10
|
||||
} ESdbTable;
|
||||
|
||||
typedef enum {
|
||||
SDB_KEY_STRING = 0,
|
||||
SDB_KEY_INT = 1,
|
||||
SDB_KEY_AUTO = 2,
|
||||
SDB_KEY_VAR_STRING = 3,
|
||||
} ESdbKey;
|
||||
|
||||
typedef enum {
|
||||
SDB_OPER_GLOBAL = 0,
|
||||
SDB_OPER_LOCAL = 1
|
||||
} ESdbOper;
|
||||
|
||||
typedef struct SSdbRow {
|
||||
ESdbOper type;
|
||||
int32_t processedCount; // for sync fwd callback
|
||||
int32_t code; // for callback in sdb queue
|
||||
int32_t rowSize;
|
||||
void * rowData;
|
||||
void * pObj;
|
||||
void * pTable;
|
||||
SMnodeMsg *pMsg;
|
||||
int32_t (*fpReq)(SMnodeMsg *pMsg);
|
||||
int32_t (*fpRsp)(SMnodeMsg *pMsg, int32_t code);
|
||||
char reserveForSync[24];
|
||||
SWalHead pHead;
|
||||
} SSdbRow;
|
||||
|
||||
typedef struct {
|
||||
char * name;
|
||||
int32_t hashSessions;
|
||||
int32_t maxRowSize;
|
||||
int32_t refCountPos;
|
||||
ESdbTable id;
|
||||
ESdbKey keyType;
|
||||
int32_t (*fpInsert)(SSdbRow *pRow);
|
||||
int32_t (*fpDelete)(SSdbRow *pRow);
|
||||
int32_t (*fpUpdate)(SSdbRow *pRow);
|
||||
int32_t (*fpEncode)(SSdbRow *pRow);
|
||||
int32_t (*fpDecode)(SSdbRow *pRow);
|
||||
int32_t (*fpDestroy)(SSdbRow *pRow);
|
||||
int32_t (*fpRestored)();
|
||||
} SSdbTableDesc;
|
||||
|
||||
int32_t sdbInitRef();
|
||||
void sdbCleanUpRef();
|
||||
int32_t sdbInit();
|
||||
void sdbCleanUp();
|
||||
int64_t sdbOpenTable(SSdbTableDesc *desc);
|
||||
void sdbCloseTable(int64_t rid);
|
||||
void* sdbGetTableByRid(int64_t rid);
|
||||
bool sdbIsMaster();
|
||||
bool sdbIsServing();
|
||||
void sdbUpdateMnodeRoles();
|
||||
int32_t sdbGetReplicaNum();
|
||||
|
||||
int32_t sdbInsertRow(SSdbRow *pRow);
|
||||
int32_t sdbInsertCompactRow(SSdbRow *pRow);
|
||||
int32_t sdbDeleteRow(SSdbRow *pRow);
|
||||
int32_t sdbUpdateRow(SSdbRow *pRow);
|
||||
int32_t sdbInsertRowToQueue(SSdbRow *pRow);
|
||||
|
||||
void * sdbGetRow(void *pTable, void *key);
|
||||
void * sdbFetchRow(void *pTable, void *pIter, void **ppRow);
|
||||
void sdbFreeIter(void *pTable, void *pIter);
|
||||
void sdbIncRef(void *pTable, void *pRow);
|
||||
void sdbDecRef(void *pTable, void *pRow);
|
||||
int64_t sdbGetNumOfRows(void *pTable);
|
||||
int32_t sdbGetId(void *pTable);
|
||||
uint64_t sdbGetVersion();
|
||||
bool sdbCheckRowDeleted(void *pTable, void *pRow);
|
||||
|
||||
int32_t mnodeCompactWal();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_SHELL_H
|
||||
#define TDENGINE_MNODE_SHELL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeDef.h"
|
||||
|
||||
int32_t mnodeInitShow();
|
||||
void mnodeCleanUpShow();
|
||||
|
||||
typedef int32_t (*SShowMetaFp)(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
typedef void (*SShowFreeIterFp)(void *pIter);
|
||||
void mnodeAddShowMetaHandle(uint8_t showType, SShowMetaFp fp);
|
||||
void mnodeAddShowRetrieveHandle(uint8_t showType, SShowRetrieveFp fp);
|
||||
void mnodeAddShowFreeIterHandle(uint8_t msgType, SShowFreeIterFp fp);
|
||||
void mnodeVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* 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 TBASE_MNODE_TABLE_H
|
||||
#define TBASE_MNODE_TABLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mnodeDef.h"
|
||||
|
||||
int32_t mnodeInitTables();
|
||||
void mnodeCleanupTables();
|
||||
int64_t mnodeGetSuperTableNum();
|
||||
int64_t mnodeGetChildTableNum();
|
||||
void * mnodeGetTable(char *tableId);
|
||||
void mnodeIncTableRef(void *pTable);
|
||||
void mnodeDecTableRef(void *pTable);
|
||||
void * mnodeGetNextChildTable(void *pIter, SCTableObj **pTable);
|
||||
void * mnodeGetNextSuperTable(void *pIter, SSTableObj **pTable);
|
||||
void mnodeCancelGetNextChildTable(void *pIter);
|
||||
void mnodeCancelGetNextSuperTable(void *pIter);
|
||||
void mnodeDropAllChildTables(SDbObj *pDropDb);
|
||||
void mnodeDropAllSuperTables(SDbObj *pDropDb);
|
||||
void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup);
|
||||
int32_t mnodeCompactTables();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_USER_H
|
||||
#define TDENGINE_MNODE_USER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeDef.h"
|
||||
|
||||
int32_t mnodeInitUsers();
|
||||
void mnodeCleanupUsers();
|
||||
SUserObj *mnodeGetUser(char *name);
|
||||
void * mnodeGetNextUser(void *pIter, SUserObj **pUser);
|
||||
void mnodeCancelGetNextUser(void *pIter);
|
||||
void mnodeIncUserRef(SUserObj *pUser);
|
||||
void mnodeDecUserRef(SUserObj *pUser);
|
||||
SUserObj *mnodeGetUserFromConn(void *pConn);
|
||||
char * mnodeGetUserFromMsg(void *pMnodeMsg);
|
||||
int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg);
|
||||
void mnodeDropAllUsers(SAcctObj *pAcct);
|
||||
|
||||
int32_t mnodeCompactUsers();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_VGROUP_H
|
||||
#define TDENGINE_MNODE_VGROUP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct SMnodeMsg;
|
||||
|
||||
int32_t mnodeInitVgroups();
|
||||
void mnodeCleanupVgroups();
|
||||
int64_t mnodeGetVgroupNum();
|
||||
SVgObj *mnodeGetVgroup(int32_t vgId);
|
||||
void mnodeIncVgroupRef(SVgObj *pVgroup);
|
||||
void mnodeDecVgroupRef(SVgObj *pVgroup);
|
||||
void mnodeDropAllDbVgroups(SDbObj *pDropDb);
|
||||
void mnodeSendDropAllDbVgroupsMsg(SDbObj *pDropDb);
|
||||
void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode);
|
||||
//void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb);
|
||||
int32_t mnodeCompactVgroups();
|
||||
|
||||
void * mnodeGetNextVgroup(void *pIter, SVgObj **pVgroup);
|
||||
void mnodeCancelGetNextVgroup(void *pIter);
|
||||
void mnodeUpdateVgroup(SVgObj *pVgroup);
|
||||
void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVload);
|
||||
void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t openVnodes);
|
||||
|
||||
int32_t mnodeCreateVgroup(struct SMnodeMsg *pMsg);
|
||||
void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle);
|
||||
void mnodeAlterVgroup(SVgObj *pVgroup, void *ahandle);
|
||||
int32_t mnodeGetAvailableVgroup(struct SMnodeMsg *pMsg, SVgObj **pVgroup, int32_t *sid);
|
||||
|
||||
int32_t mnodeAddTableIntoVgroup(SVgObj *pVgroup, SCTableObj *pTable, bool needCheck);
|
||||
void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SCTableObj *pTable);
|
||||
void mnodeSendDropVnodeMsg(int32_t vgId, SRpcEpSet *epSet, void *ahandle);
|
||||
void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle);
|
||||
void mnodeSendAlterVgroupMsg(SVgObj *pVgroup,SMnodeMsg *pMsg);
|
||||
void mnodeSendSyncVgroupMsg(SVgObj *pVgroup);
|
||||
void mnodeSendCompactVgroupMsg(SVgObj *pVgroup);
|
||||
|
||||
SRpcEpSet mnodeGetEpSetFromVgroup(SVgObj *pVgroup);
|
||||
SRpcEpSet mnodeGetEpSetFromIp(char *ep);
|
||||
|
||||
int32_t mnodeGetVgidVer(int8_t *vver);
|
||||
void mnodeSetVgidVer(int8_t *cver, uint64_t iver);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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_MNODE_WRITE_H
|
||||
#define TDENGINE_MNODE_WRITE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeDef.h"
|
||||
|
||||
void mnodeAddWriteMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg));
|
||||
int32_t mnodeProcessRead(SMnodeMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,273 +0,0 @@
|
|||
/*
|
||||
* 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 "tglobal.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
|
||||
int64_t tsAcctRid = -1;
|
||||
void * tsAcctSdb = NULL;
|
||||
static int32_t tsAcctUpdateSize;
|
||||
static int32_t mnodeCreateRootAcct();
|
||||
|
||||
static int32_t mnodeAcctActionDestroy(SSdbRow *pRow) {
|
||||
SAcctObj *pAcct = pRow->pObj;
|
||||
pthread_mutex_destroy(&pAcct->mutex);
|
||||
tfree(pRow->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionInsert(SSdbRow *pRow) {
|
||||
SAcctObj *pAcct = pRow->pObj;
|
||||
memset(&pAcct->acctInfo, 0, sizeof(SAcctInfo));
|
||||
pAcct->acctInfo.accessState = TSDB_VN_ALL_ACCCESS;
|
||||
pthread_mutex_init(&pAcct->mutex, NULL);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionDelete(SSdbRow *pRow) {
|
||||
SAcctObj *pAcct = pRow->pObj;
|
||||
mnodeDropAllUsers(pAcct);
|
||||
mnodeDropAllDbs(pAcct);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionUpdate(SSdbRow *pRow) {
|
||||
SAcctObj *pAcct = pRow->pObj;
|
||||
SAcctObj *pSaved = mnodeGetAcct(pAcct->user);
|
||||
if (pAcct != pSaved) {
|
||||
memcpy(pSaved, pAcct, tsAcctUpdateSize);
|
||||
free(pAcct);
|
||||
}
|
||||
mnodeDecAcctRef(pSaved);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionEncode(SSdbRow *pRow) {
|
||||
SAcctObj *pAcct = pRow->pObj;
|
||||
memcpy(pRow->rowData, pAcct, tsAcctUpdateSize);
|
||||
pRow->rowSize = tsAcctUpdateSize;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionDecode(SSdbRow *pRow) {
|
||||
SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj));
|
||||
if (pAcct == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
|
||||
memcpy(pAcct, pRow->rowData, tsAcctUpdateSize);
|
||||
pRow->pObj = pAcct;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionRestored() {
|
||||
int64_t numOfRows = sdbGetNumOfRows(tsAcctSdb);
|
||||
if (numOfRows <= 0 && dnodeIsFirstDeploy()) {
|
||||
mInfo("dnode first deploy, create root acct");
|
||||
int32_t code = mnodeCreateRootAcct();
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("failed to create root account, reason:%s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
acctInit();
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mnodeInitAccts() {
|
||||
SAcctObj tObj;
|
||||
tsAcctUpdateSize = (int32_t)((int8_t *)tObj.updateEnd - (int8_t *)&tObj);
|
||||
|
||||
SSdbTableDesc desc = {
|
||||
.id = SDB_TABLE_ACCOUNT,
|
||||
.name = "accounts",
|
||||
.hashSessions = TSDB_DEFAULT_ACCOUNTS_HASH_SIZE,
|
||||
.maxRowSize = tsAcctUpdateSize,
|
||||
.refCountPos = (int32_t)((int8_t *)(&tObj.refCount) - (int8_t *)&tObj),
|
||||
.keyType = SDB_KEY_STRING,
|
||||
.fpInsert = mnodeAcctActionInsert,
|
||||
.fpDelete = mnodeAcctActionDelete,
|
||||
.fpUpdate = mnodeAcctActionUpdate,
|
||||
.fpEncode = mnodeAcctActionEncode,
|
||||
.fpDecode = mnodeAcctActionDecode,
|
||||
.fpDestroy = mnodeAcctActionDestroy,
|
||||
.fpRestored = mnodeAcctActionRestored
|
||||
};
|
||||
|
||||
tsAcctRid = sdbOpenTable(&desc);
|
||||
tsAcctSdb = sdbGetTableByRid(tsAcctRid);
|
||||
if (tsAcctSdb == NULL) {
|
||||
mError("table:%s, failed to create hash", desc.name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mDebug("table:%s, hash is created", desc.name);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void mnodeCleanupAccts() {
|
||||
acctCleanUp();
|
||||
sdbCloseTable(tsAcctRid);
|
||||
tsAcctSdb = NULL;
|
||||
}
|
||||
|
||||
void mnodeGetStatOfAllAcct(SAcctInfo* pAcctInfo) {
|
||||
memset(pAcctInfo, 0, sizeof(*pAcctInfo));
|
||||
|
||||
void *pIter = NULL;
|
||||
SAcctObj *pAcct = NULL;
|
||||
while (1) {
|
||||
pIter = mnodeGetNextAcct(pIter, &pAcct);
|
||||
if (pAcct == NULL) {
|
||||
break;
|
||||
}
|
||||
pAcctInfo->numOfDbs += pAcct->acctInfo.numOfDbs;
|
||||
pAcctInfo->numOfTimeSeries += pAcct->acctInfo.numOfTimeSeries;
|
||||
mnodeDecAcctRef(pAcct);
|
||||
}
|
||||
|
||||
SVgObj *pVgroup = NULL;
|
||||
pIter = NULL;
|
||||
while (1) {
|
||||
pIter = mnodeGetNextVgroup(pIter, &pVgroup);
|
||||
if (pVgroup == NULL) {
|
||||
break;
|
||||
}
|
||||
pAcctInfo->totalStorage += pVgroup->totalStorage;
|
||||
pAcctInfo->compStorage += pVgroup->compStorage;
|
||||
pAcctInfo->totalPoints += pVgroup->pointsWritten;
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
}
|
||||
|
||||
void *mnodeGetAcct(char *name) {
|
||||
return sdbGetRow(tsAcctSdb, name);
|
||||
}
|
||||
|
||||
void *mnodeGetNextAcct(void *pIter, SAcctObj **pAcct) {
|
||||
return sdbFetchRow(tsAcctSdb, pIter, (void **)pAcct);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextAcct(void *pIter) {
|
||||
sdbFreeIter(tsAcctSdb, pIter);
|
||||
}
|
||||
|
||||
void mnodeIncAcctRef(SAcctObj *pAcct) {
|
||||
sdbIncRef(tsAcctSdb, pAcct);
|
||||
}
|
||||
|
||||
void mnodeDecAcctRef(SAcctObj *pAcct) {
|
||||
sdbDecRef(tsAcctSdb, pAcct);
|
||||
}
|
||||
|
||||
void mnodeAddDbToAcct(SAcctObj *pAcct, SDbObj *pDb) {
|
||||
atomic_add_fetch_32(&pAcct->acctInfo.numOfDbs, 1);
|
||||
pDb->pAcct = pAcct;
|
||||
mnodeIncAcctRef(pAcct);
|
||||
}
|
||||
|
||||
void mnodeDropDbFromAcct(SAcctObj *pAcct, SDbObj *pDb) {
|
||||
atomic_sub_fetch_32(&pAcct->acctInfo.numOfDbs, 1);
|
||||
pDb->pAcct = NULL;
|
||||
mnodeDecAcctRef(pAcct);
|
||||
}
|
||||
|
||||
void mnodeAddUserToAcct(SAcctObj *pAcct, SUserObj *pUser) {
|
||||
atomic_add_fetch_32(&pAcct->acctInfo.numOfUsers, 1);
|
||||
pUser->pAcct = pAcct;
|
||||
mnodeIncAcctRef(pAcct);
|
||||
}
|
||||
|
||||
void mnodeDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) {
|
||||
atomic_sub_fetch_32(&pAcct->acctInfo.numOfUsers, 1);
|
||||
pUser->pAcct = NULL;
|
||||
mnodeDecAcctRef(pAcct);
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateRootAcct() {
|
||||
int64_t numOfAccts = sdbGetNumOfRows(tsAcctSdb);
|
||||
if (numOfAccts != 0) return TSDB_CODE_SUCCESS;
|
||||
|
||||
SAcctObj *pAcct = malloc(sizeof(SAcctObj));
|
||||
memset(pAcct, 0, sizeof(SAcctObj));
|
||||
strcpy(pAcct->user, TSDB_DEFAULT_USER);
|
||||
taosEncryptPass((uint8_t *)TSDB_DEFAULT_PASS, strlen(TSDB_DEFAULT_PASS), pAcct->pass);
|
||||
pAcct->cfg = (SAcctCfg){
|
||||
.maxUsers = 128,
|
||||
.maxDbs = 128,
|
||||
.maxTimeSeries = INT32_MAX,
|
||||
.maxConnections = 1024,
|
||||
.maxStreams = 1000,
|
||||
.maxPointsPerSecond = 10000000,
|
||||
.maxStorage = INT64_MAX,
|
||||
.maxQueryTime = INT64_MAX,
|
||||
.maxInbound = 0,
|
||||
.maxOutbound = 0,
|
||||
.accessState = TSDB_VN_ALL_ACCCESS
|
||||
};
|
||||
pAcct->acctId = sdbGetId(tsAcctSdb);
|
||||
pAcct->createdTime = taosGetTimestampMs();
|
||||
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsAcctSdb,
|
||||
.pObj = pAcct,
|
||||
};
|
||||
|
||||
return sdbInsertRow(&row);
|
||||
}
|
||||
|
||||
int32_t mnodeCompactAccts() {
|
||||
void *pIter = NULL;
|
||||
SAcctObj *pAcct = NULL;
|
||||
|
||||
mInfo("start to compact accts table...");
|
||||
|
||||
while (1) {
|
||||
pIter = mnodeGetNextAcct(pIter, &pAcct);
|
||||
if (pAcct == NULL) break;
|
||||
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsAcctSdb,
|
||||
.pObj = pAcct,
|
||||
};
|
||||
|
||||
mInfo("compact accts %s", pAcct->user);
|
||||
|
||||
sdbInsertCompactRow(&row);
|
||||
}
|
||||
|
||||
mInfo("end to compact accts table...");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef _ACCT
|
||||
|
||||
int32_t acctInit() { return TSDB_CODE_SUCCESS; }
|
||||
void acctCleanUp() {}
|
||||
int32_t acctCheck(void *pAcct, EAcctGrantType type) { return TSDB_CODE_SUCCESS; }
|
||||
|
||||
#endif
|
|
@ -1,263 +0,0 @@
|
|||
/*
|
||||
* 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 "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeCluster.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
int64_t tsClusterRid = -1;
|
||||
static void * tsClusterSdb = NULL;
|
||||
static int32_t tsClusterUpdateSize;
|
||||
static char tsClusterId[TSDB_CLUSTER_ID_LEN];
|
||||
static int32_t mnodeCreateCluster();
|
||||
|
||||
static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
static void mnodeCancelGetNextCluster(void *pIter);
|
||||
|
||||
static int32_t mnodeClusterActionDestroy(SSdbRow *pRow) {
|
||||
tfree(pRow->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionInsert(SSdbRow *pRow) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionDelete(SSdbRow *pRow) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionUpdate(SSdbRow *pRow) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionEncode(SSdbRow *pRow) {
|
||||
SClusterObj *pCluster = pRow->pObj;
|
||||
memcpy(pRow->rowData, pCluster, tsClusterUpdateSize);
|
||||
pRow->rowSize = tsClusterUpdateSize;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionDecode(SSdbRow *pRow) {
|
||||
SClusterObj *pCluster = (SClusterObj *) calloc(1, sizeof(SClusterObj));
|
||||
if (pCluster == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
|
||||
memcpy(pCluster, pRow->rowData, tsClusterUpdateSize);
|
||||
pRow->pObj = pCluster;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionRestored() {
|
||||
int64_t numOfRows = sdbGetNumOfRows(tsClusterSdb);
|
||||
if (numOfRows <= 0 && dnodeIsFirstDeploy()) {
|
||||
mInfo("dnode first deploy, create cluster");
|
||||
int32_t code = mnodeCreateCluster();
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("failed to create cluster, reason:%s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
mnodeUpdateClusterId();
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mnodeInitCluster() {
|
||||
SClusterObj tObj;
|
||||
tsClusterUpdateSize = (int32_t)((int8_t *)tObj.updateEnd - (int8_t *)&tObj);
|
||||
|
||||
SSdbTableDesc desc = {
|
||||
.id = SDB_TABLE_CLUSTER,
|
||||
.name = "cluster",
|
||||
.hashSessions = TSDB_DEFAULT_CLUSTER_HASH_SIZE,
|
||||
.maxRowSize = tsClusterUpdateSize,
|
||||
.refCountPos = (int32_t)((int8_t *)(&tObj.refCount) - (int8_t *)&tObj),
|
||||
.keyType = SDB_KEY_STRING,
|
||||
.fpInsert = mnodeClusterActionInsert,
|
||||
.fpDelete = mnodeClusterActionDelete,
|
||||
.fpUpdate = mnodeClusterActionUpdate,
|
||||
.fpEncode = mnodeClusterActionEncode,
|
||||
.fpDecode = mnodeClusterActionDecode,
|
||||
.fpDestroy = mnodeClusterActionDestroy,
|
||||
.fpRestored = mnodeClusterActionRestored
|
||||
};
|
||||
|
||||
tsClusterRid = sdbOpenTable(&desc);
|
||||
tsClusterSdb = sdbGetTableByRid(tsClusterRid);
|
||||
if (tsClusterSdb == NULL) {
|
||||
mError("table:%s, rid:%" PRId64 ", failed to create hash", desc.name, tsClusterRid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeGetClusterMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeRetrieveClusters);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeCancelGetNextCluster);
|
||||
|
||||
mDebug("table:%s, hash is created", desc.name);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void mnodeCleanupCluster() {
|
||||
sdbCloseTable(tsClusterRid);
|
||||
tsClusterSdb = NULL;
|
||||
}
|
||||
|
||||
void *mnodeGetNextCluster(void *pIter, SClusterObj **pCluster) {
|
||||
return sdbFetchRow(tsClusterSdb, pIter, (void **)pCluster);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextCluster(void *pIter) {
|
||||
sdbFreeIter(tsClusterSdb, pIter);
|
||||
}
|
||||
|
||||
void mnodeIncClusterRef(SClusterObj *pCluster) {
|
||||
sdbIncRef(tsClusterSdb, pCluster);
|
||||
}
|
||||
|
||||
void mnodeDecClusterRef(SClusterObj *pCluster) {
|
||||
sdbDecRef(tsClusterSdb, pCluster);
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateCluster() {
|
||||
int64_t numOfClusters = sdbGetNumOfRows(tsClusterSdb);
|
||||
if (numOfClusters != 0) return TSDB_CODE_SUCCESS;
|
||||
|
||||
SClusterObj *pCluster = malloc(sizeof(SClusterObj));
|
||||
memset(pCluster, 0, sizeof(SClusterObj));
|
||||
pCluster->createdTime = taosGetTimestampMs();
|
||||
bool getuid = taosGetSystemUid(pCluster->uid);
|
||||
if (!getuid) {
|
||||
strcpy(pCluster->uid, "tdengine2.0");
|
||||
mError("failed to get uid from system, set to default val %s", pCluster->uid);
|
||||
} else {
|
||||
mDebug("uid is %s", pCluster->uid);
|
||||
}
|
||||
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsClusterSdb,
|
||||
.pObj = pCluster,
|
||||
};
|
||||
|
||||
return sdbInsertRow(&row);
|
||||
}
|
||||
|
||||
const char* mnodeGetClusterId() {
|
||||
return tsClusterId;
|
||||
}
|
||||
|
||||
void mnodeUpdateClusterId() {
|
||||
SClusterObj *pCluster = NULL;
|
||||
void *pIter = mnodeGetNextCluster(NULL, &pCluster);
|
||||
if (pCluster != NULL) {
|
||||
tstrncpy(tsClusterId, pCluster->uid, TSDB_CLUSTER_ID_LEN);
|
||||
mDebug("cluster id is set to %s", tsClusterId);
|
||||
}
|
||||
|
||||
mnodeDecClusterRef(pCluster);
|
||||
mnodeCancelGetNextCluster(pIter);
|
||||
}
|
||||
|
||||
static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
int32_t cols = 0;
|
||||
SSchema *pSchema = pMeta->schema;
|
||||
|
||||
pShow->bytes[cols] = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "clusterId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
strcpy(pMeta->tableFname, "show cluster");
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
for (int32_t i = 1; i < cols; ++i) {
|
||||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
}
|
||||
|
||||
pShow->numOfRows = 1;
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
char * pWrite;
|
||||
SClusterObj *pCluster = NULL;
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pShow->pIter = mnodeGetNextCluster(pShow->pIter, &pCluster);
|
||||
if (pCluster == NULL) break;
|
||||
|
||||
cols = 0;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pCluster->uid, TSDB_CLUSTER_ID_LEN);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *) pWrite = pCluster->createdTime;
|
||||
cols++;
|
||||
|
||||
mnodeDecClusterRef(pCluster);
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
int32_t mnodeCompactCluster() {
|
||||
SClusterObj *pCluster = NULL;
|
||||
void *pIter;
|
||||
|
||||
mInfo("start to compact cluster table...");
|
||||
|
||||
pIter = mnodeGetNextCluster(NULL, &pCluster);
|
||||
while (pCluster) {
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsClusterSdb,
|
||||
.pObj = pCluster,
|
||||
};
|
||||
|
||||
sdbInsertCompactRow(&row);
|
||||
|
||||
pIter = mnodeGetNextCluster(pIter, &pCluster);
|
||||
}
|
||||
|
||||
mInfo("end to compact cluster table...");
|
||||
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,485 +0,0 @@
|
|||
/*
|
||||
* 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 "trpc.h"
|
||||
#include "tutil.h"
|
||||
#include "tglobal.h"
|
||||
#include "tgrant.h"
|
||||
#include "tdataformat.h"
|
||||
#include "tkey.h"
|
||||
#include "mnode.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeFunc.h"
|
||||
#include "mnodeWrite.h"
|
||||
#include "mnodeRead.h"
|
||||
#include "mnodePeer.h"
|
||||
|
||||
int64_t tsFuncRid = -1;
|
||||
static void * tsFuncSdb = NULL;
|
||||
static int32_t tsFuncUpdateSize = 0;
|
||||
static int32_t mnodeGetFuncMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveFuncs(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
static int32_t mnodeProcessRetrieveFuncImplMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mnodeProcessCreateFuncMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mnodeProcessDropFuncMsg(SMnodeMsg *pMsg);
|
||||
|
||||
static int32_t mnodeFuncActionDestroy(SSdbRow *pRow) {
|
||||
tfree(pRow->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeFuncActionInsert(SSdbRow *pRow) {
|
||||
SFuncObj *pFunc = pRow->pObj;
|
||||
|
||||
mTrace("func:%s, contLen: %d, insert into sdb", pFunc->name, pFunc->contLen);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeFuncActionDelete(SSdbRow *pRow) {
|
||||
SFuncObj *pFunc = pRow->pObj;
|
||||
|
||||
mTrace("func:%s, length: %d, delete from sdb", pFunc->name, pFunc->contLen);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeFuncActionUpdate(SSdbRow *pRow) {
|
||||
SFuncObj *pFunc = pRow->pObj;
|
||||
|
||||
SFuncObj *pSaved = mnodeGetFunc(pFunc->name);
|
||||
if (pFunc != pSaved) {
|
||||
memcpy(pSaved, pFunc, tsFuncUpdateSize);
|
||||
free(pFunc);
|
||||
}
|
||||
|
||||
mnodeDecFuncRef(pSaved);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeFuncActionEncode(SSdbRow *pRow) {
|
||||
SFuncObj *pFunc = pRow->pObj;
|
||||
|
||||
memcpy(pRow->rowData, pFunc, tsFuncUpdateSize);
|
||||
pRow->rowSize = tsFuncUpdateSize;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeFuncActionDecode(SSdbRow *pRow) {
|
||||
SFuncObj *pFunc = (SFuncObj *)calloc(1, sizeof(SFuncObj));
|
||||
if (pFunc == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
|
||||
memcpy(pFunc, pRow->rowData, tsFuncUpdateSize);
|
||||
pRow->pObj = pFunc;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeFuncActionRestored() {
|
||||
int64_t numOfRows = sdbGetNumOfRows(tsFuncSdb);
|
||||
|
||||
if (numOfRows <= 0 && dnodeIsFirstDeploy()) {
|
||||
mInfo("dnode first deploy, func restored.");
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mnodeInitFuncs() {
|
||||
SFuncObj tObj;
|
||||
tsFuncUpdateSize = (int32_t)((int8_t *)tObj.updateEnd - (int8_t *)&tObj);
|
||||
|
||||
SSdbTableDesc desc = {
|
||||
.id = SDB_TABLE_FUNC,
|
||||
.name = "funcs",
|
||||
.hashSessions = TSDB_DEFAULT_USERS_HASH_SIZE,
|
||||
.maxRowSize = tsFuncUpdateSize,
|
||||
.refCountPos = (int32_t)((int8_t *)(&tObj.refCount) - (int8_t *)&tObj),
|
||||
.keyType = SDB_KEY_STRING,
|
||||
.fpInsert = mnodeFuncActionInsert,
|
||||
.fpDelete = mnodeFuncActionDelete,
|
||||
.fpUpdate = mnodeFuncActionUpdate,
|
||||
.fpEncode = mnodeFuncActionEncode,
|
||||
.fpDecode = mnodeFuncActionDecode,
|
||||
.fpDestroy = mnodeFuncActionDestroy,
|
||||
.fpRestored = mnodeFuncActionRestored
|
||||
};
|
||||
|
||||
tsFuncRid = sdbOpenTable(&desc);
|
||||
tsFuncSdb = sdbGetTableByRid(tsFuncRid);
|
||||
if (tsFuncSdb == NULL) {
|
||||
mError("table:%s, failed to create hash", desc.name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_CREATE_FUNCTION, mnodeProcessCreateFuncMsg);
|
||||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_DROP_FUNCTION, mnodeProcessDropFuncMsg);
|
||||
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_RETRIEVE_FUNC, mnodeProcessRetrieveFuncImplMsg);
|
||||
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_FUNCTION, mnodeGetFuncMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_FUNCTION, mnodeRetrieveFuncs);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_FUNCTION, mnodeCancelGetNextFunc);
|
||||
|
||||
mDebug("table:%s, hash is created", desc.name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupFuncs() {
|
||||
sdbCloseTable(tsFuncRid);
|
||||
tsFuncSdb = NULL;
|
||||
}
|
||||
|
||||
SFuncObj *mnodeGetFunc(char *name) {
|
||||
return (SFuncObj *)sdbGetRow(tsFuncSdb, name);
|
||||
}
|
||||
|
||||
void *mnodeGetNextFunc(void *pIter, SFuncObj **pFunc) {
|
||||
return sdbFetchRow(tsFuncSdb, pIter, (void **)pFunc);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextFunc(void *pIter) {
|
||||
sdbFreeIter(tsFuncSdb, pIter);
|
||||
}
|
||||
|
||||
void mnodeIncFuncRef(SFuncObj *pFunc) {
|
||||
sdbIncRef(tsFuncSdb, pFunc);
|
||||
}
|
||||
|
||||
void mnodeDecFuncRef(SFuncObj *pFunc) {
|
||||
sdbDecRef(tsFuncSdb, pFunc);
|
||||
}
|
||||
/*
|
||||
static int32_t mnodeUpdateFunc(SFuncObj *pFunc, void *pMsg) {
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsFuncSdb,
|
||||
.pObj = pFunc,
|
||||
.pMsg = pMsg
|
||||
};
|
||||
|
||||
int32_t code = sdbUpdateRow(&row);
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("func:%s, failed to alter by %s, reason:%s", pFunc->name, mnodeGetUserFromMsg(pMsg), tstrerror(code));
|
||||
} else {
|
||||
mLInfo("func:%s, is altered by %s", pFunc->name, mnodeGetUserFromMsg(pMsg));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
*/
|
||||
int32_t mnodeCreateFunc(SAcctObj *pAcct, char *name, int32_t codeLen, char *codeScript, char *path, uint8_t outputType, int16_t outputLen, int32_t funcType, int32_t bufSize, SMnodeMsg *pMsg) {
|
||||
if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_GRANT_EXPIRED;
|
||||
}
|
||||
|
||||
if (!pMsg->pUser->writeAuth) {
|
||||
return TSDB_CODE_MND_NO_RIGHTS;
|
||||
}
|
||||
|
||||
int32_t code = acctCheck(pAcct, ACCT_GRANT_USER);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = grantCheck(TSDB_GRANT_USER);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (name[0] == 0) {
|
||||
return TSDB_CODE_MND_INVALID_FUNC_NAME;
|
||||
}
|
||||
|
||||
if (codeScript[0] == 0) {
|
||||
return TSDB_CODE_MND_INVALID_FUNC_CODE;
|
||||
}
|
||||
|
||||
if (codeLen < 0 || codeLen > TSDB_FUNC_CODE_LEN) {
|
||||
return TSDB_CODE_MND_INVALID_FUNC_CODE;
|
||||
}
|
||||
|
||||
if (bufSize < 0 || bufSize > TSDB_FUNC_BUF_SIZE) {
|
||||
return TSDB_CODE_MND_INVALID_FUNC_BUFSIZE;
|
||||
}
|
||||
|
||||
SFuncObj *pFunc = mnodeGetFunc(name);
|
||||
if (pFunc != NULL) {
|
||||
mDebug("func:%s, is already there", name);
|
||||
mnodeDecFuncRef(pFunc);
|
||||
return TSDB_CODE_MND_FUNC_ALREADY_EXIST;
|
||||
}
|
||||
|
||||
pFunc = calloc(1, sizeof(SFuncObj));
|
||||
tstrncpy(pFunc->name, name, TSDB_FUNC_NAME_LEN);
|
||||
tstrncpy(pFunc->path, path, tListLen(pFunc->path));
|
||||
memcpy(pFunc->cont, codeScript, codeLen);
|
||||
pFunc->contLen = codeLen;
|
||||
pFunc->createdTime = taosGetTimestampMs();
|
||||
pFunc->resType = outputType;
|
||||
pFunc->resBytes = outputLen;
|
||||
pFunc->funcType = funcType;
|
||||
pFunc->bufSize = bufSize;
|
||||
pFunc->sig = 0;
|
||||
pFunc->type = 1; //lua script, refactor
|
||||
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsFuncSdb,
|
||||
.pObj = pFunc,
|
||||
.rowSize = sizeof(SFuncObj),
|
||||
.pMsg = pMsg
|
||||
};
|
||||
|
||||
code = sdbInsertRow(&row);
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("func:%s, failed to create by %s, reason:%s", pFunc->name, mnodeGetUserFromMsg(pMsg), tstrerror(code));
|
||||
tfree(pFunc);
|
||||
} else {
|
||||
mLInfo("func:%s, is created by %s", pFunc->name, mnodeGetUserFromMsg(pMsg));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeDropFunc(SFuncObj *pFunc, void *pMsg) {
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsFuncSdb,
|
||||
.pObj = pFunc,
|
||||
.pMsg = pMsg
|
||||
};
|
||||
|
||||
int32_t code = sdbDeleteRow(&row);
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("func:%s, failed to drop by %s, reason:%s", pFunc->name, mnodeGetUserFromMsg(pMsg), tstrerror(code));
|
||||
} else {
|
||||
mLInfo("func:%s, is dropped by %s", pFunc->name, mnodeGetUserFromMsg(pMsg));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeGetFuncsNum() {
|
||||
return (int32_t)sdbGetNumOfRows(tsFuncSdb);
|
||||
}
|
||||
|
||||
static int32_t mnodeGetFuncMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
SUserObj *pUser = mnodeGetUserFromConn(pConn);
|
||||
if (pUser == NULL) {
|
||||
return TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
}
|
||||
|
||||
int32_t cols = 0;
|
||||
SSchema *pSchema = pMeta->schema;
|
||||
|
||||
pShow->bytes[cols] = TSDB_FUNC_NAME_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "name");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = PATH_MAX + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "path");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "aggregate");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_TYPE_STR_MAX_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "outputtype");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "code_len");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "bufsize");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
strcpy(pMeta->tableFname, "show funcs");
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
for (int32_t i = 1; i < cols; ++i) {
|
||||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
}
|
||||
|
||||
pShow->numOfRows = mnodeGetFuncsNum();
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
|
||||
mnodeDecUserRef(pUser);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void* mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int16_t len) {
|
||||
char *msg = "unknown";
|
||||
if (type >= sizeof(tDataTypes)/sizeof(tDataTypes[0])) {
|
||||
return msg;
|
||||
}
|
||||
|
||||
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) {
|
||||
int32_t bytes = len > 0 ? (int)(len - VARSTR_HEADER_SIZE) : len;
|
||||
|
||||
snprintf(buf, buflen - 1, "%s(%d)", tDataTypes[type].name, type == TSDB_DATA_TYPE_NCHAR ? bytes/4 : bytes);
|
||||
buf[buflen - 1] = 0;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
return tDataTypes[type].name;
|
||||
}
|
||||
|
||||
static int32_t mnodeRetrieveFuncs(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
||||
int32_t numOfRows = 0;
|
||||
SFuncObj *pFunc = NULL;
|
||||
int32_t cols = 0;
|
||||
char *pWrite;
|
||||
char buf[TSDB_TYPE_STR_MAX_LEN];
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pShow->pIter = mnodeGetNextFunc(pShow->pIter, &pFunc);
|
||||
if (pFunc == NULL) break;
|
||||
|
||||
cols = 0;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pFunc->name, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pFunc->path, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = pFunc->funcType == TSDB_UDF_TYPE_AGGREGATE ? 1 : 0;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->resType, pFunc->resBytes), pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = pFunc->createdTime;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = pFunc->contLen;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = pFunc->bufSize;
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
mnodeDecFuncRef(pFunc);
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessCreateFuncMsg(SMnodeMsg *pMsg) {
|
||||
SCreateFuncMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
pCreate->codeLen = htonl(pCreate->codeLen);
|
||||
pCreate->outputLen = htons(pCreate->outputLen);
|
||||
pCreate->funcType = htonl(pCreate->funcType);
|
||||
pCreate->bufSize = htonl(pCreate->bufSize);
|
||||
|
||||
return mnodeCreateFunc(pMsg->pUser->pAcct, pCreate->name, pCreate->codeLen, pCreate->code, pCreate->path, pCreate->outputType, pCreate->outputLen, pCreate->funcType, pCreate->bufSize, pMsg);
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessDropFuncMsg(SMnodeMsg *pMsg) {
|
||||
SDropFuncMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
|
||||
SFuncObj *pFunc = mnodeGetFunc(pDrop->name);
|
||||
if (pFunc == NULL) {
|
||||
return TSDB_CODE_MND_INVALID_FUNC;
|
||||
}
|
||||
|
||||
return mnodeDropFunc(pFunc, pMsg);
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessRetrieveFuncImplMsg(SMnodeMsg *pMsg) {
|
||||
SRetrieveFuncMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||
pInfo->num = htonl(pInfo->num);
|
||||
|
||||
int32_t t = sizeof(SUdfFuncMsg) + (sizeof(SFunctionInfoMsg) + TSDB_FUNC_CODE_LEN) * pInfo->num + 16384;
|
||||
|
||||
SUdfFuncMsg *pFuncMsg = rpcMallocCont(t);
|
||||
pFuncMsg->num = htonl(pInfo->num);
|
||||
char* pOutput = pFuncMsg->content;
|
||||
tstr* name = (tstr*) pInfo->name;
|
||||
|
||||
for(int32_t i = 0; i < pInfo->num; ++i) {
|
||||
char buf[TSDB_FUNC_NAME_LEN] = {0};
|
||||
tstrncpy(buf, name->data, htons(name->len) + 1);
|
||||
|
||||
SFuncObj* pFuncObj = mnodeGetFunc(buf);
|
||||
if (pFuncObj == NULL) {
|
||||
mError("function %s does not exist", buf);
|
||||
return TSDB_CODE_MND_INVALID_FUNC;
|
||||
}
|
||||
|
||||
SFunctionInfoMsg* pFuncInfo = (SFunctionInfoMsg*) pOutput;
|
||||
|
||||
strcpy(pFuncInfo->name, buf);
|
||||
pFuncInfo->len = htonl(pFuncObj->contLen);
|
||||
memcpy(pFuncInfo->content, pFuncObj->cont, pFuncObj->contLen);
|
||||
|
||||
pFuncInfo->funcType = htonl(pFuncObj->funcType);
|
||||
pFuncInfo->resType = pFuncObj->resType;
|
||||
pFuncInfo->resBytes = htons(pFuncObj->resBytes);
|
||||
pFuncInfo->bufSize = htonl(pFuncObj->bufSize);
|
||||
|
||||
pOutput += sizeof(SFunctionInfoMsg) + pFuncObj->contLen;
|
||||
name =(tstr *)((char *)name + sizeof(*name) + htons(name->len));
|
||||
}
|
||||
|
||||
pMsg->rpcRsp.rsp = pFuncMsg;
|
||||
pMsg->rpcRsp.len = (int32_t)(pOutput - (char*)pFuncMsg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
#ifndef _GRANT
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "tgrant.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t grantInit() { return TSDB_CODE_SUCCESS; }
|
||||
void grantCleanUp() {}
|
||||
void grantParseParameter() { mError("can't parsed parameter k"); }
|
||||
int32_t grantCheck(EGrantType grant) { return TSDB_CODE_SUCCESS; }
|
||||
void grantReset(EGrantType grant, uint64_t value) {}
|
||||
void grantAdd(EGrantType grant, uint64_t value) {}
|
||||
void grantRestore(EGrantType grant, uint64_t value) {}
|
||||
|
||||
#endif
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* 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 "trpc.h"
|
||||
#include "tqueue.h"
|
||||
#include "mnode.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeProfile.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeTable.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
|
||||
void *mnodeCreateMsg(SRpcMsg *pRpcMsg) {
|
||||
int32_t size = sizeof(SMnodeMsg) + pRpcMsg->contLen;
|
||||
SMnodeMsg *pMsg = taosAllocateQitem(size);
|
||||
|
||||
pMsg->rpcMsg = *pRpcMsg;
|
||||
pMsg->rpcMsg.pCont = pMsg->pCont;
|
||||
pMsg->incomingTs = taosGetTimestampSec();
|
||||
memcpy(pMsg->pCont, pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
int32_t mnodeInitMsg(SMnodeMsg *pMsg) {
|
||||
if (pMsg->pUser != NULL) {
|
||||
mTrace("msg:%p, app:%p user info already inited", pMsg, pMsg->rpcMsg.ahandle);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pMsg->pUser = mnodeGetUserFromConn(pMsg->rpcMsg.handle);
|
||||
if (pMsg->pUser == NULL) {
|
||||
return TSDB_CODE_MND_INVALID_USER;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void mnodeCleanupMsg(SMnodeMsg *pMsg) {
|
||||
if (pMsg != NULL) {
|
||||
if (pMsg->rpcMsg.pCont != pMsg->pCont) {
|
||||
tfree(pMsg->rpcMsg.pCont);
|
||||
}
|
||||
if (pMsg->pUser) mnodeDecUserRef(pMsg->pUser);
|
||||
if (pMsg->pDb) mnodeDecDbRef(pMsg->pDb);
|
||||
if (pMsg->pVgroup) mnodeDecVgroupRef(pMsg->pVgroup);
|
||||
if (pMsg->pTable) mnodeDecTableRef(pMsg->pTable);
|
||||
if (pMsg->pSTable) mnodeDecTableRef(pMsg->pSTable);
|
||||
if (pMsg->pAcct) mnodeDecAcctRef(pMsg->pAcct);
|
||||
if (pMsg->pDnode) mnodeDecDnodeRef(pMsg->pDnode);
|
||||
}
|
||||
}
|
|
@ -1,194 +0,0 @@
|
|||
/*
|
||||
* 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 "taosdef.h"
|
||||
#include "tsched.h"
|
||||
#include "tbn.h"
|
||||
#include "tgrant.h"
|
||||
#include "ttimer.h"
|
||||
#include "tglobal.h"
|
||||
#include "mnode.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeVgroup.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeFunc.h"
|
||||
#include "mnodeTable.h"
|
||||
#include "mnodeCluster.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeProfile.h"
|
||||
|
||||
void *tsMnodeTmr = NULL;
|
||||
static bool tsMgmtIsRunning = false;
|
||||
|
||||
static SStep tsMnodeSteps[] = {
|
||||
{"sdbref", sdbInitRef, sdbCleanUpRef},
|
||||
{"profile", mnodeInitProfile, mnodeCleanupProfile},
|
||||
{"cluster", mnodeInitCluster, mnodeCleanupCluster},
|
||||
{"accts", mnodeInitAccts, mnodeCleanupAccts},
|
||||
{"users", mnodeInitUsers, mnodeCleanupUsers},
|
||||
{"funcs", mnodeInitFuncs, mnodeCleanupFuncs},
|
||||
{"dnodes", mnodeInitDnodes, mnodeCleanupDnodes},
|
||||
{"dbs", mnodeInitDbs, mnodeCleanupDbs},
|
||||
{"vgroups", mnodeInitVgroups, mnodeCleanupVgroups},
|
||||
{"tables", mnodeInitTables, mnodeCleanupTables},
|
||||
{"mnodes", mnodeInitMnodes, mnodeCleanupMnodes},
|
||||
{"sdb", sdbInit, sdbCleanUp},
|
||||
{"balance", bnInit, bnCleanUp},
|
||||
{"grant", grantInit, grantCleanUp},
|
||||
{"show", mnodeInitShow, mnodeCleanUpShow}
|
||||
};
|
||||
|
||||
static SStep tsMnodeCompactSteps[] = {
|
||||
{"cluster", mnodeCompactCluster, NULL},
|
||||
{"dnodes", mnodeCompactDnodes, NULL},
|
||||
{"mnodes", mnodeCompactMnodes, NULL},
|
||||
{"accts", mnodeCompactAccts, NULL},
|
||||
{"users", mnodeCompactUsers, NULL},
|
||||
{"dbs", mnodeCompactDbs, NULL},
|
||||
{"vgroups", mnodeCompactVgroups, NULL},
|
||||
{"tables", mnodeCompactTables, NULL},
|
||||
|
||||
};
|
||||
|
||||
static void mnodeInitTimer();
|
||||
static void mnodeCleanupTimer();
|
||||
static bool mnodeNeedStart() ;
|
||||
|
||||
static void mnodeCleanupComponents() {
|
||||
int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep);
|
||||
dnodeStepCleanup(tsMnodeSteps, stepSize);
|
||||
}
|
||||
|
||||
static int32_t mnodeInitComponents() {
|
||||
int32_t stepSize = sizeof(tsMnodeSteps) / sizeof(SStep);
|
||||
return dnodeStepInit(tsMnodeSteps, stepSize);
|
||||
}
|
||||
|
||||
int32_t mnodeCompactComponents() {
|
||||
int32_t stepSize = sizeof(tsMnodeCompactSteps) / sizeof(SStep);
|
||||
return dnodeStepInit(tsMnodeCompactSteps, stepSize);
|
||||
}
|
||||
|
||||
int32_t mnodeStartSystem() {
|
||||
if (tsMgmtIsRunning) {
|
||||
mInfo("mnode module already started...");
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
mInfo("starting to initialize mnode ...");
|
||||
if (mkdir(tsMnodeDir, 0755) != 0 && errno != EEXIST) {
|
||||
mError("failed to init mnode dir:%s, reason:%s", tsMnodeDir, strerror(errno));
|
||||
return TSDB_CODE_MND_FAILED_TO_CREATE_DIR;
|
||||
}
|
||||
|
||||
dnodeAllocMWritequeue();
|
||||
dnodeAllocMReadQueue();
|
||||
dnodeAllocateMPeerQueue();
|
||||
|
||||
if (mnodeInitComponents() != 0) {
|
||||
return TSDB_CODE_MND_FAILED_TO_INIT_STEP;
|
||||
}
|
||||
|
||||
dnodeReportStep("mnode-grant", "start to set grant infomation", 0);
|
||||
grantReset(TSDB_GRANT_ALL, 0);
|
||||
tsMgmtIsRunning = true;
|
||||
|
||||
mInfo("mnode is initialized successfully");
|
||||
|
||||
sdbUpdateSync(NULL);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mnodeInitSystem() {
|
||||
mnodeInitTimer();
|
||||
if (mnodeNeedStart() || tsCompactMnodeWal) {
|
||||
return mnodeStartSystem();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupSystem() {
|
||||
if (tsMgmtIsRunning) {
|
||||
mInfo("starting to clean up mnode");
|
||||
tsMgmtIsRunning = false;
|
||||
|
||||
dnodeFreeMWritequeue();
|
||||
dnodeFreeMReadQueue();
|
||||
dnodeFreeMPeerQueue();
|
||||
mnodeCleanupTimer();
|
||||
mnodeCleanupComponents();
|
||||
|
||||
mInfo("mnode is cleaned up");
|
||||
}
|
||||
}
|
||||
|
||||
void mnodeStopSystem() {
|
||||
if (sdbIsMaster()) {
|
||||
mDebug("it is a master mnode, it could not be stopped");
|
||||
return;
|
||||
}
|
||||
|
||||
mnodeCleanupSystem();
|
||||
|
||||
if (remove(tsMnodeDir) != 0) {
|
||||
mInfo("failed to remove mnode file, reason:%s", strerror(errno));
|
||||
} else {
|
||||
mInfo("mnode file is removed");
|
||||
}
|
||||
}
|
||||
|
||||
static void mnodeInitTimer() {
|
||||
if (tsMnodeTmr == NULL) {
|
||||
tsMnodeTmr = taosTmrInit(tsMaxShellConns, 200, 3600000, "MND");
|
||||
}
|
||||
}
|
||||
|
||||
static void mnodeCleanupTimer() {
|
||||
if (tsMnodeTmr != NULL) {
|
||||
taosTmrCleanUp(tsMnodeTmr);
|
||||
tsMnodeTmr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool mnodeNeedStart() {
|
||||
struct stat dirstat;
|
||||
char mnodeFileName[TSDB_FILENAME_LEN * 2] = {0};
|
||||
sprintf(mnodeFileName, "%s/wal/wal0", tsMnodeDir);
|
||||
|
||||
bool fileExist = (stat(mnodeFileName, &dirstat) == 0);
|
||||
bool asMaster = (strcmp(tsFirst, tsLocalEp) == 0);
|
||||
|
||||
if (asMaster || fileExist) {
|
||||
mDebug("mnode module start, asMaster:%d fileExist:%d", asMaster, fileExist);
|
||||
return true;
|
||||
} else {
|
||||
mDebug("mnode module won't start, asMaster:%d fileExist:%d", asMaster, fileExist);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool mnodeIsRunning() {
|
||||
return tsMgmtIsRunning;
|
||||
}
|
|
@ -1,606 +0,0 @@
|
|||
/*
|
||||
* 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 "tglobal.h"
|
||||
#include "trpc.h"
|
||||
#include "tsync.h"
|
||||
#include "tbn.h"
|
||||
#include "tutil.h"
|
||||
#include "tsocket.h"
|
||||
#include "tdataformat.h"
|
||||
#include "dnode.h"
|
||||
#include "mnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
|
||||
int64_t tsMnodeRid = -1;
|
||||
static void * tsMnodeSdb = NULL;
|
||||
static int32_t tsMnodeUpdateSize = 0;
|
||||
static SRpcEpSet tsMEpForShell;
|
||||
static SRpcEpSet tsMEpForPeer;
|
||||
static SMInfos tsMInfos;
|
||||
static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
|
||||
#if defined(LINUX)
|
||||
static pthread_rwlock_t tsMnodeLock;
|
||||
#define mnodeMnodeWrLock() pthread_rwlock_wrlock(&tsMnodeLock)
|
||||
#define mnodeMnodeRdLock() pthread_rwlock_rdlock(&tsMnodeLock)
|
||||
#define mnodeMnodeUnLock() pthread_rwlock_unlock(&tsMnodeLock)
|
||||
#define mnodeMnodeInitLock() pthread_rwlock_init(&tsMnodeLock, NULL)
|
||||
#define mnodeMnodeDestroyLock() pthread_rwlock_destroy(&tsMnodeLock)
|
||||
#else
|
||||
static pthread_mutex_t tsMnodeLock;
|
||||
#define mnodeMnodeWrLock() pthread_mutex_lock(&tsMnodeLock)
|
||||
#define mnodeMnodeRdLock() pthread_mutex_lock(&tsMnodeLock)
|
||||
#define mnodeMnodeUnLock() pthread_mutex_unlock(&tsMnodeLock)
|
||||
#define mnodeMnodeInitLock() pthread_mutex_init(&tsMnodeLock, NULL)
|
||||
#define mnodeMnodeDestroyLock() pthread_mutex_destroy(&tsMnodeLock)
|
||||
#endif
|
||||
|
||||
static int32_t mnodeMnodeActionDestroy(SSdbRow *pRow) {
|
||||
tfree(pRow->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeMnodeActionInsert(SSdbRow *pRow) {
|
||||
SMnodeObj *pMnode = pRow->pObj;
|
||||
SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
|
||||
if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
|
||||
pDnode->isMgmt = true;
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
|
||||
mInfo("mnode:%d, fqdn:%s ep:%s port:%u is created", pMnode->mnodeId, pDnode->dnodeFqdn, pDnode->dnodeEp,
|
||||
pDnode->dnodePort);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeMnodeActionDelete(SSdbRow *pRow) {
|
||||
SMnodeObj *pMnode = pRow->pObj;
|
||||
|
||||
SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
|
||||
if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
pDnode->isMgmt = false;
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
|
||||
mDebug("mnode:%d, is dropped from sdb", pMnode->mnodeId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeMnodeActionUpdate(SSdbRow *pRow) {
|
||||
SMnodeObj *pMnode = pRow->pObj;
|
||||
SMnodeObj *pSaved = mnodeGetMnode(pMnode->mnodeId);
|
||||
if (pMnode != pSaved) {
|
||||
memcpy(pSaved, pMnode, pRow->rowSize);
|
||||
free(pMnode);
|
||||
}
|
||||
mnodeDecMnodeRef(pSaved);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeMnodeActionEncode(SSdbRow *pRow) {
|
||||
SMnodeObj *pMnode = pRow->pObj;
|
||||
memcpy(pRow->rowData, pMnode, tsMnodeUpdateSize);
|
||||
pRow->rowSize = tsMnodeUpdateSize;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeMnodeActionDecode(SSdbRow *pRow) {
|
||||
SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj));
|
||||
if (pMnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
|
||||
memcpy(pMnode, pRow->rowData, tsMnodeUpdateSize);
|
||||
pRow->pObj = pMnode;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeMnodeActionRestored() {
|
||||
if (mnodeGetMnodesNum() == 1) {
|
||||
SMnodeObj *pMnode = NULL;
|
||||
void *pIter = mnodeGetNextMnode(NULL, &pMnode);
|
||||
if (pMnode != NULL) {
|
||||
pMnode->role = TAOS_SYNC_ROLE_MASTER;
|
||||
pMnode->roleTime = taosGetTimestampMs();
|
||||
mnodeDecMnodeRef(pMnode);
|
||||
}
|
||||
mnodeCancelGetNextMnode(pIter);
|
||||
}
|
||||
|
||||
mnodeUpdateMnodeEpSet(NULL);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mnodeInitMnodes() {
|
||||
mnodeMnodeInitLock();
|
||||
|
||||
SMnodeObj tObj;
|
||||
tsMnodeUpdateSize = (int32_t)((int8_t *)tObj.updateEnd - (int8_t *)&tObj);
|
||||
|
||||
SSdbTableDesc desc = {
|
||||
.id = SDB_TABLE_MNODE,
|
||||
.name = "mnodes",
|
||||
.hashSessions = TSDB_DEFAULT_MNODES_HASH_SIZE,
|
||||
.maxRowSize = tsMnodeUpdateSize,
|
||||
.refCountPos = (int32_t)((int8_t *)(&tObj.refCount) - (int8_t *)&tObj),
|
||||
.keyType = SDB_KEY_INT,
|
||||
.fpInsert = mnodeMnodeActionInsert,
|
||||
.fpDelete = mnodeMnodeActionDelete,
|
||||
.fpUpdate = mnodeMnodeActionUpdate,
|
||||
.fpEncode = mnodeMnodeActionEncode,
|
||||
.fpDecode = mnodeMnodeActionDecode,
|
||||
.fpDestroy = mnodeMnodeActionDestroy,
|
||||
.fpRestored = mnodeMnodeActionRestored
|
||||
};
|
||||
|
||||
tsMnodeRid = sdbOpenTable(&desc);
|
||||
tsMnodeSdb = sdbGetTableByRid(tsMnodeRid);
|
||||
if (tsMnodeSdb == NULL) {
|
||||
mError("failed to init mnodes data");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_MNODE, mnodeGetMnodeMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_MNODE, mnodeRetrieveMnodes);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_MNODE, mnodeCancelGetNextMnode);
|
||||
|
||||
mDebug("table:mnodes table is created");
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void mnodeCleanupMnodes() {
|
||||
sdbCloseTable(tsMnodeRid);
|
||||
tsMnodeSdb = NULL;
|
||||
mnodeMnodeDestroyLock();
|
||||
}
|
||||
|
||||
int32_t mnodeGetMnodesNum() {
|
||||
return (int32_t)sdbGetNumOfRows(tsMnodeSdb);
|
||||
}
|
||||
|
||||
void *mnodeGetMnode(int32_t mnodeId) {
|
||||
return sdbGetRow(tsMnodeSdb, &mnodeId);
|
||||
}
|
||||
|
||||
void mnodeIncMnodeRef(SMnodeObj *pMnode) {
|
||||
sdbIncRef(tsMnodeSdb, pMnode);
|
||||
}
|
||||
|
||||
void mnodeDecMnodeRef(SMnodeObj *pMnode) {
|
||||
sdbDecRef(tsMnodeSdb, pMnode);
|
||||
}
|
||||
|
||||
void *mnodeGetNextMnode(void *pIter, SMnodeObj **pMnode) {
|
||||
return sdbFetchRow(tsMnodeSdb, pIter, (void **)pMnode);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextMnode(void *pIter) {
|
||||
sdbFreeIter(tsMnodeSdb, pIter);
|
||||
}
|
||||
|
||||
void mnodeUpdateMnodeEpSet(SMInfos *pMinfos) {
|
||||
bool set = false;
|
||||
SMInfos mInfos = {0};
|
||||
|
||||
if (pMinfos != NULL) {
|
||||
mInfo("vgId:1, update mnodes epSet, numOfMinfos:%d", pMinfos->mnodeNum);
|
||||
set = true;
|
||||
mInfos = *pMinfos;
|
||||
} else {
|
||||
mInfo("vgId:1, update mnodes epSet, numOfMnodes:%d", mnodeGetMnodesNum());
|
||||
int32_t index = 0;
|
||||
void * pIter = NULL;
|
||||
while (1) {
|
||||
SMnodeObj *pMnode = NULL;
|
||||
pIter = mnodeGetNextMnode(pIter, &pMnode);
|
||||
if (pMnode == NULL) break;
|
||||
|
||||
SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
|
||||
if (pDnode != NULL) {
|
||||
set = true;
|
||||
mInfos.mnodeInfos[index].mnodeId = pMnode->mnodeId;
|
||||
strcpy(mInfos.mnodeInfos[index].mnodeEp, pDnode->dnodeEp);
|
||||
if (pMnode->role == TAOS_SYNC_ROLE_MASTER) mInfos.inUse = index;
|
||||
index++;
|
||||
} else {
|
||||
set = false;
|
||||
}
|
||||
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
mnodeDecMnodeRef(pMnode);
|
||||
}
|
||||
|
||||
mInfos.mnodeNum = index;
|
||||
if (mInfos.mnodeNum < sdbGetReplicaNum()) {
|
||||
set = false;
|
||||
mDebug("vgId:1, mnodes info not synced, current:%d syncCfgNum:%d", mInfos.mnodeNum, sdbGetReplicaNum());
|
||||
}
|
||||
}
|
||||
|
||||
mnodeMnodeWrLock();
|
||||
|
||||
if (set) {
|
||||
memset(&tsMEpForShell, 0, sizeof(SRpcEpSet));
|
||||
memset(&tsMEpForPeer, 0, sizeof(SRpcEpSet));
|
||||
memcpy(&tsMInfos, &mInfos, sizeof(SMInfos));
|
||||
tsMEpForShell.inUse = tsMInfos.inUse;
|
||||
tsMEpForPeer.inUse = tsMInfos.inUse;
|
||||
tsMEpForShell.numOfEps = tsMInfos.mnodeNum;
|
||||
tsMEpForPeer.numOfEps = tsMInfos.mnodeNum;
|
||||
|
||||
mInfo("vgId:1, mnodes epSet is set, num:%d inUse:%d", tsMInfos.mnodeNum, tsMInfos.inUse);
|
||||
for (int index = 0; index < mInfos.mnodeNum; ++index) {
|
||||
SMInfo *pInfo = &tsMInfos.mnodeInfos[index];
|
||||
taosGetFqdnPortFromEp(pInfo->mnodeEp, tsMEpForShell.fqdn[index], &tsMEpForShell.port[index]);
|
||||
taosGetFqdnPortFromEp(pInfo->mnodeEp, tsMEpForPeer.fqdn[index], &tsMEpForPeer.port[index]);
|
||||
tsMEpForPeer.port[index] = tsMEpForPeer.port[index] + TSDB_PORT_DNODEDNODE;
|
||||
|
||||
mInfo("vgId:1, mnode:%d, fqdn:%s shell:%u peer:%u", pInfo->mnodeId, tsMEpForShell.fqdn[index],
|
||||
tsMEpForShell.port[index], tsMEpForPeer.port[index]);
|
||||
|
||||
tsMEpForShell.port[index] = htons(tsMEpForShell.port[index]);
|
||||
tsMEpForPeer.port[index] = htons(tsMEpForPeer.port[index]);
|
||||
pInfo->mnodeId = htonl(pInfo->mnodeId);
|
||||
}
|
||||
} else {
|
||||
mInfo("vgId:1, mnodes epSet not set, num:%d inUse:%d", tsMInfos.mnodeNum, tsMInfos.inUse);
|
||||
for (int index = 0; index < tsMInfos.mnodeNum; ++index) {
|
||||
mInfo("vgId:1, index:%d, ep:%s:%u", index, tsMEpForShell.fqdn[index], htons(tsMEpForShell.port[index]));
|
||||
}
|
||||
}
|
||||
|
||||
mnodeMnodeUnLock();
|
||||
}
|
||||
|
||||
void mnodeGetMnodeEpSetForPeer(SRpcEpSet *epSet, bool redirect) {
|
||||
mnodeMnodeRdLock();
|
||||
*epSet = tsMEpForPeer;
|
||||
mnodeMnodeUnLock();
|
||||
|
||||
mTrace("vgId:1, mnodes epSet for peer is returned, num:%d inUse:%d", tsMEpForPeer.numOfEps, tsMEpForPeer.inUse);
|
||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||
if (redirect && strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort + TSDB_PORT_DNODEDNODE) {
|
||||
epSet->inUse = (i + 1) % epSet->numOfEps;
|
||||
mTrace("vgId:1, mnode:%d, for peer ep:%s:%u, set inUse to %d", i, epSet->fqdn[i], htons(epSet->port[i]), epSet->inUse);
|
||||
} else {
|
||||
mTrace("vgId:1, mpeer:%d, for peer ep:%s:%u", i, epSet->fqdn[i], htons(epSet->port[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mnodeGetMnodeEpSetForShell(SRpcEpSet *epSet, bool redirect) {
|
||||
mnodeMnodeRdLock();
|
||||
*epSet = tsMEpForShell;
|
||||
mnodeMnodeUnLock();
|
||||
|
||||
if (mnodeGetDnodesNum() <= 1) {
|
||||
epSet->numOfEps = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
mTrace("vgId:1, mnodes epSet for shell is returned, num:%d inUse:%d", tsMEpForShell.numOfEps, tsMEpForShell.inUse);
|
||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||
if (redirect && strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort) {
|
||||
epSet->inUse = (i + 1) % epSet->numOfEps;
|
||||
mTrace("vgId:1, mnode:%d, for shell ep:%s:%u, set inUse to %d", i, epSet->fqdn[i], htons(epSet->port[i]), epSet->inUse);
|
||||
} else {
|
||||
mTrace("vgId:1, mnode:%d, for shell ep:%s:%u", i, epSet->fqdn[i], htons(epSet->port[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char* mnodeGetMnodeMasterEp() {
|
||||
return tsMInfos.mnodeInfos[tsMInfos.inUse].mnodeEp;
|
||||
}
|
||||
|
||||
void mnodeGetMnodeInfos(void *pMinfos) {
|
||||
mnodeMnodeRdLock();
|
||||
*(SMInfos *)pMinfos = tsMInfos;
|
||||
mnodeMnodeUnLock();
|
||||
}
|
||||
|
||||
static int32_t mnodeSendCreateMnodeMsg(int32_t dnodeId, char *dnodeEp) {
|
||||
SCreateMnodeMsg *pCreate = rpcMallocCont(sizeof(SCreateMnodeMsg));
|
||||
if (pCreate == NULL) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
} else {
|
||||
pCreate->dnodeId = htonl(dnodeId);
|
||||
tstrncpy(pCreate->dnodeEp, dnodeEp, sizeof(pCreate->dnodeEp));
|
||||
mnodeGetMnodeInfos(&pCreate->mnodes);
|
||||
bool found = false;
|
||||
for (int i = 0; i < pCreate->mnodes.mnodeNum; ++i) {
|
||||
if (pCreate->mnodes.mnodeInfos[i].mnodeId == htonl(dnodeId)) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
pCreate->mnodes.mnodeInfos[pCreate->mnodes.mnodeNum].mnodeId = htonl(dnodeId);
|
||||
tstrncpy(pCreate->mnodes.mnodeInfos[pCreate->mnodes.mnodeNum].mnodeEp, dnodeEp, sizeof(pCreate->dnodeEp));
|
||||
pCreate->mnodes.mnodeNum++;
|
||||
}
|
||||
}
|
||||
|
||||
mDebug("dnode:%d, send create mnode msg to dnode %s, numOfMnodes:%d", dnodeId, dnodeEp, pCreate->mnodes.mnodeNum);
|
||||
for (int32_t i = 0; i < pCreate->mnodes.mnodeNum; ++i) {
|
||||
mDebug("index:%d, mnodeId:%d ep:%s", i, pCreate->mnodes.mnodeInfos[i].mnodeId, pCreate->mnodes.mnodeInfos[i].mnodeEp);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pCreate;
|
||||
rpcMsg.contLen = sizeof(SCreateMnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_MD_CREATE_MNODE;
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
SRpcEpSet epSet = mnodeGetEpSetFromIp(pCreate->dnodeEp);
|
||||
dnodeSendMsgToDnodeRecv(&rpcMsg, &rpcRsp, &epSet);
|
||||
|
||||
if (rpcRsp.code != TSDB_CODE_SUCCESS) {
|
||||
mError("dnode:%d, failed to send create mnode msg, ep:%s reason:%s", dnodeId, dnodeEp, tstrerror(rpcRsp.code));
|
||||
} else {
|
||||
mDebug("dnode:%d, create mnode msg is disposed, mnode is created in dnode", dnodeId);
|
||||
}
|
||||
|
||||
rpcFreeCont(rpcRsp.pCont);
|
||||
return rpcRsp.code;
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateMnodeCb(SMnodeMsg *pMsg, int32_t code) {
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
mError("failed to create mnode, reason:%s", tstrerror(code));
|
||||
} else {
|
||||
mDebug("mnode is created successfully");
|
||||
mnodeUpdateMnodeEpSet(NULL);
|
||||
sdbUpdateAsync();
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool mnodeAllOnline() {
|
||||
void *pIter = NULL;
|
||||
bool allOnline = true;
|
||||
|
||||
sdbUpdateMnodeRoles();
|
||||
|
||||
while (1) {
|
||||
SMnodeObj *pMnode = NULL;
|
||||
pIter = mnodeGetNextMnode(pIter, &pMnode);
|
||||
if (pMnode == NULL) break;
|
||||
if (pMnode->role != TAOS_SYNC_ROLE_MASTER && pMnode->role != TAOS_SYNC_ROLE_SLAVE) {
|
||||
allOnline = false;
|
||||
mDebug("mnode:%d, role:%s, not online", pMnode->mnodeId, syncRole[pMnode->role]);
|
||||
mnodeDecMnodeRef(pMnode);
|
||||
}
|
||||
}
|
||||
mnodeCancelGetNextMnode(pIter);
|
||||
|
||||
return allOnline;
|
||||
}
|
||||
|
||||
void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) {
|
||||
SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj));
|
||||
pMnode->mnodeId = dnodeId;
|
||||
pMnode->createdTime = taosGetTimestampMs();
|
||||
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsMnodeSdb,
|
||||
.pObj = pMnode,
|
||||
.fpRsp = mnodeCreateMnodeCb
|
||||
};
|
||||
|
||||
if (needConfirm && !mnodeAllOnline()) {
|
||||
mDebug("wait all mnode online then create new mnode");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (needConfirm) {
|
||||
code = mnodeSendCreateMnodeMsg(dnodeId, dnodeEp);
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tfree(pMnode);
|
||||
return;
|
||||
}
|
||||
|
||||
code = sdbInsertRow(&row);
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("dnode:%d, failed to create mnode, ep:%s reason:%s", dnodeId, dnodeEp, tstrerror(code));
|
||||
tfree(pMnode);
|
||||
}
|
||||
}
|
||||
|
||||
void mnodeDropMnodeLocal(int32_t dnodeId) {
|
||||
SMnodeObj *pMnode = mnodeGetMnode(dnodeId);
|
||||
if (pMnode != NULL) {
|
||||
SSdbRow row = {.type = SDB_OPER_LOCAL, .pTable = tsMnodeSdb, .pObj = pMnode};
|
||||
sdbDeleteRow(&row);
|
||||
mnodeDecMnodeRef(pMnode);
|
||||
}
|
||||
|
||||
mnodeUpdateMnodeEpSet(NULL);
|
||||
sdbUpdateAsync();
|
||||
}
|
||||
|
||||
int32_t mnodeDropMnode(int32_t dnodeId) {
|
||||
SMnodeObj *pMnode = mnodeGetMnode(dnodeId);
|
||||
if (pMnode == NULL) {
|
||||
return TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsMnodeSdb,
|
||||
.pObj = pMnode
|
||||
};
|
||||
|
||||
int32_t code = sdbDeleteRow(&row);
|
||||
|
||||
sdbDecRef(tsMnodeSdb, pMnode);
|
||||
|
||||
mnodeUpdateMnodeEpSet(NULL);
|
||||
sdbUpdateAsync();
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
sdbUpdateMnodeRoles();
|
||||
SUserObj *pUser = mnodeGetUserFromConn(pConn);
|
||||
if (pUser == NULL) return 0;
|
||||
|
||||
if (strcmp(pUser->pAcct->user, TSDB_DEFAULT_USER) != 0) {
|
||||
mnodeDecUserRef(pUser);
|
||||
return TSDB_CODE_MND_NO_RIGHTS;
|
||||
}
|
||||
|
||||
int32_t cols = 0;
|
||||
SSchema *pSchema = pMeta->schema;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "id");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "end_point");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 12 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "role");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "role_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
for (int32_t i = 1; i < cols; ++i) {
|
||||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
}
|
||||
|
||||
pShow->numOfRows = mnodeGetMnodesNum();
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
pShow->pIter = NULL;
|
||||
mnodeDecUserRef(pUser);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
SMnodeObj *pMnode = NULL;
|
||||
char *pWrite;
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pShow->pIter = mnodeGetNextMnode(pShow->pIter, &pMnode);
|
||||
if (pMnode == NULL) break;
|
||||
|
||||
cols = 0;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = pMnode->mnodeId;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
|
||||
SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
|
||||
if (pDnode != NULL) {
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols]);
|
||||
} else {
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, "invalid ep", pShow->bytes[cols]);
|
||||
}
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
char* roles = syncRole[pMnode->role];
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, roles, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = pMnode->roleTime;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = pMnode->createdTime;
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
|
||||
mnodeDecMnodeRef(pMnode);
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
int32_t mnodeCompactMnodes() {
|
||||
void *pIter = NULL;
|
||||
SMnodeObj *pMnode = NULL;
|
||||
|
||||
mInfo("start to compact mnodes table...");
|
||||
|
||||
while (1) {
|
||||
pIter = mnodeGetNextMnode(pIter, &pMnode);
|
||||
if (pMnode == NULL) break;
|
||||
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsMnodeSdb,
|
||||
.pObj = pMnode,
|
||||
.rowSize = sizeof(SMnodeObj),
|
||||
};
|
||||
|
||||
mInfo("compact mnode %d", pMnode->mnodeId);
|
||||
|
||||
sdbInsertCompactRow(&row);
|
||||
}
|
||||
|
||||
mInfo("end to compact mnodes table...");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* 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 "tsched.h"
|
||||
#include "tutil.h"
|
||||
#include "tgrant.h"
|
||||
#include "tbn.h"
|
||||
#include "tglobal.h"
|
||||
#include "mnode.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeProfile.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeTable.h"
|
||||
#include "mnodeVgroup.h"
|
||||
|
||||
static int32_t (*tsMnodeProcessPeerMsgFp[TSDB_MSG_TYPE_MAX])(SMnodeMsg *);
|
||||
static void (*tsMnodeProcessPeerRspFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
|
||||
|
||||
void mnodeAddPeerMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg)) {
|
||||
tsMnodeProcessPeerMsgFp[msgType] = fp;
|
||||
}
|
||||
|
||||
void mnodeAddPeerRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)) {
|
||||
tsMnodeProcessPeerRspFp[msgType] = fp;
|
||||
}
|
||||
|
||||
int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) {
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, ahandle:%p type:%s in mpeer queue, content is null", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
|
||||
return TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
}
|
||||
|
||||
if (!sdbIsMaster()) {
|
||||
SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
||||
mnodeGetMnodeEpSetForPeer(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SRpcEpSet);
|
||||
|
||||
mDebug("msg:%p, ahandle:%p type:%s in mpeer queue is redirected, numOfEps:%d inUse:%d", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
return TSDB_CODE_RPC_REDIRECT;
|
||||
}
|
||||
|
||||
if (tsMnodeProcessPeerMsgFp[pMsg->rpcMsg.msgType] == NULL) {
|
||||
mError("msg:%p, ahandle:%p type:%s in mpeer queue, not processed", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType]);
|
||||
return TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
}
|
||||
|
||||
return (*tsMnodeProcessPeerMsgFp[pMsg->rpcMsg.msgType])(pMsg);
|
||||
}
|
||||
|
||||
void mnodeProcessPeerRsp(SRpcMsg *pMsg) {
|
||||
if (!sdbIsMaster()) {
|
||||
mError("msg:%p, ahandle:%p type:%s is not processed for it is not master", pMsg, pMsg->ahandle,
|
||||
taosMsg[pMsg->msgType]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tsMnodeProcessPeerRspFp[pMsg->msgType]) {
|
||||
(*tsMnodeProcessPeerRspFp[pMsg->msgType])(pMsg);
|
||||
} else {
|
||||
mError("msg:%p, ahandle:%p type:%s is not processed", pMsg, pMsg->ahandle, taosMsg[pMsg->msgType]);
|
||||
}
|
||||
}
|
|
@ -1,742 +0,0 @@
|
|||
/*
|
||||
* 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 "tutil.h"
|
||||
#include "tcache.h"
|
||||
#include "tglobal.h"
|
||||
#include "tdataformat.h"
|
||||
#include "mnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeProfile.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeWrite.h"
|
||||
|
||||
#define CONN_KEEP_TIME (tsShellActivityTimer * 3)
|
||||
#define CONN_CHECK_TIME (tsShellActivityTimer * 2)
|
||||
#define QUERY_ID_SIZE 20
|
||||
#define QUERY_OBJ_ID_SIZE 18
|
||||
#define SUBQUERY_INFO_SIZE 6
|
||||
#define QUERY_STREAM_SAVE_SIZE 20
|
||||
|
||||
static SCacheObj *tsMnodeConnCache = NULL;
|
||||
static int32_t tsConnIndex = 0;
|
||||
|
||||
static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
static void mnodeCancelGetNextConn(void *pIter);
|
||||
static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
static void mnodeFreeConn(void *data);
|
||||
static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg);
|
||||
|
||||
int32_t mnodeInitProfile() {
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_QUERIES, mnodeGetQueryMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_QUERIES, mnodeRetrieveQueries);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_QUERIES, mnodeCancelGetNextConn);
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CONNS, mnodeGetConnsMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CONNS, mnodeRetrieveConns);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_CONNS, mnodeCancelGetNextConn);
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_STREAMS, mnodeGetStreamMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_STREAMS, mnodeRetrieveStreams);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_STREAMS, mnodeCancelGetNextConn);
|
||||
|
||||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_QUERY, mnodeProcessKillQueryMsg);
|
||||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_STREAM, mnodeProcessKillStreamMsg);
|
||||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_CONN, mnodeProcessKillConnectionMsg);
|
||||
|
||||
tsMnodeConnCache = taosCacheInit(TSDB_DATA_TYPE_INT, CONN_CHECK_TIME, true, mnodeFreeConn, "conn");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupProfile() {
|
||||
if (tsMnodeConnCache != NULL) {
|
||||
taosCacheCleanup(tsMnodeConnCache);
|
||||
tsMnodeConnCache = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port, int32_t pid, const char* app) {
|
||||
#if 0
|
||||
int32_t connSize = taosHashGetSize(tsMnodeConnCache->pHashTable);
|
||||
if (connSize > tsMaxShellConns) {
|
||||
mError("failed to create conn for user:%s ip:%s:%u, conns:%d larger than maxShellConns:%d, ", user, taosIpStr(ip),
|
||||
port, connSize, tsMaxShellConns);
|
||||
terrno = TSDB_CODE_MND_TOO_MANY_SHELL_CONNS;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t connId = atomic_add_fetch_32(&tsConnIndex, 1);
|
||||
if (connId == 0) atomic_add_fetch_32(&tsConnIndex, 1);
|
||||
|
||||
SConnObj connObj = {
|
||||
.ip = ip,
|
||||
.port = port,
|
||||
.connId = connId,
|
||||
.stime = taosGetTimestampMs(),
|
||||
.pid = pid,
|
||||
};
|
||||
|
||||
tstrncpy(connObj.user, user, tListLen(connObj.user));
|
||||
tstrncpy(connObj.appName, app, tListLen(connObj.appName));
|
||||
|
||||
connObj.lastAccess = connObj.stime;
|
||||
|
||||
SConnObj *pConn = taosCachePut(tsMnodeConnCache, &connId, sizeof(int32_t), &connObj, sizeof(connObj), CONN_KEEP_TIME * 1000);
|
||||
|
||||
mDebug("connId:%d, is created, user:%s ip:%s:%u", connId, user, taosIpStr(ip), port);
|
||||
return pConn;
|
||||
}
|
||||
|
||||
void mnodeReleaseConn(SConnObj *pConn) {
|
||||
if (pConn == NULL) return;
|
||||
taosCacheRelease(tsMnodeConnCache, (void **)&pConn, false);
|
||||
}
|
||||
|
||||
SConnObj *mnodeAccquireConn(int32_t connId, char *user, uint32_t ip, uint16_t port) {
|
||||
SConnObj *pConn = taosCacheAcquireByKey(tsMnodeConnCache, &connId, sizeof(int32_t));
|
||||
if (pConn == NULL) {
|
||||
mDebug("connId:%d, is already destroyed, user:%s ip:%s:%u", connId, user, taosIpStr(ip), port);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (/* pConn->ip != ip || */ pConn->port != port /* || strcmp(pConn->user, user) != 0 */) {
|
||||
mDebug("connId:%d, incoming conn user:%s ip:%s:%u, not match exist conn user:%s ip:%s:%u", connId, user,
|
||||
taosIpStr(ip), port, pConn->user, taosIpStr(pConn->ip), pConn->port);
|
||||
pConn->port = port;
|
||||
//taosCacheRelease(tsMnodeConnCache, (void **)&pConn, false);
|
||||
//return NULL;
|
||||
}
|
||||
|
||||
// mDebug("connId:%d, is incoming, user:%s ip:%s:%u", connId, pConn->user, taosIpStr(pConn->ip), pConn->port);
|
||||
pConn->lastAccess = CONN_KEEP_TIME * 1000 + (uint64_t)taosGetTimestampMs();
|
||||
return pConn;
|
||||
}
|
||||
|
||||
static void mnodeFreeConn(void *data) {
|
||||
SConnObj *pConn = data;
|
||||
tfree(pConn->pQueries);
|
||||
tfree(pConn->pStreams);
|
||||
|
||||
mDebug("connId:%d, is destroyed", pConn->connId);
|
||||
}
|
||||
|
||||
static void *mnodeGetNextConn(void *pIter, SConnObj **pConn) {
|
||||
*pConn = NULL;
|
||||
|
||||
pIter = taosHashIterate(tsMnodeConnCache->pHashTable, pIter);
|
||||
if (pIter == NULL) return NULL;
|
||||
|
||||
SCacheDataNode **pNode = pIter;
|
||||
if (pNode == NULL || *pNode == NULL) {
|
||||
taosHashCancelIterate(tsMnodeConnCache->pHashTable, pIter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*pConn = (SConnObj*)((*pNode)->data);
|
||||
return pIter;
|
||||
}
|
||||
|
||||
static void mnodeCancelGetNextConn(void *pIter) {
|
||||
taosHashCancelIterate(tsMnodeConnCache->pHashTable, pIter);
|
||||
}
|
||||
|
||||
static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
SUserObj *pUser = mnodeGetUserFromConn(pConn);
|
||||
if (pUser == NULL) return 0;
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
||||
|
||||
int32_t cols = 0;
|
||||
SSchema *pSchema = pMeta->schema;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "connId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "user");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
// app name
|
||||
pShow->bytes[cols] = TSDB_APPNAME_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "program");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
// app pid
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "pid");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "ip:port");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "login_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "last_access");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
for (int32_t i = 1; i < cols; ++i) {
|
||||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
}
|
||||
|
||||
pShow->numOfRows = taosHashGetSize(tsMnodeConnCache->pHashTable);
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
||||
int32_t numOfRows = 0;
|
||||
SConnObj *pConnObj = NULL;
|
||||
int32_t cols = 0;
|
||||
char * pWrite;
|
||||
char ipStr[TSDB_IPv4ADDR_LEN + 6];
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pShow->pIter = mnodeGetNextConn(pShow->pIter, &pConnObj);
|
||||
if (pConnObj == NULL) break;
|
||||
|
||||
cols = 0;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *) pWrite = pConnObj->connId;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
// app name
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->appName, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
// app pid
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t*)pWrite = pConnObj->pid;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port);
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = pConnObj->stime;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
if (pConnObj->lastAccess < pConnObj->stime) pConnObj->lastAccess = pConnObj->stime;
|
||||
*(int64_t *)pWrite = pConnObj->lastAccess;
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
pShow->numOfReads += numOfRows;
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
// not thread safe, need optimized
|
||||
int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pHBMsg) {
|
||||
pConn->numOfQueries = 0;
|
||||
pConn->numOfStreams = 0;
|
||||
int32_t numOfQueries = htonl(pHBMsg->numOfQueries);
|
||||
int32_t numOfStreams = htonl(pHBMsg->numOfStreams);
|
||||
|
||||
if (numOfQueries > 0) {
|
||||
if (pConn->pQueries == NULL) {
|
||||
pConn->pQueries = calloc(sizeof(SQueryDesc), QUERY_STREAM_SAVE_SIZE);
|
||||
}
|
||||
|
||||
pConn->numOfQueries = MIN(QUERY_STREAM_SAVE_SIZE, numOfQueries);
|
||||
|
||||
int32_t saveSize = pConn->numOfQueries * sizeof(SQueryDesc);
|
||||
if (saveSize > 0 && pConn->pQueries != NULL) {
|
||||
memcpy(pConn->pQueries, pHBMsg->pData, saveSize);
|
||||
}
|
||||
}
|
||||
|
||||
if (numOfStreams > 0) {
|
||||
if (pConn->pStreams == NULL) {
|
||||
pConn->pStreams = calloc(sizeof(SStreamDesc), QUERY_STREAM_SAVE_SIZE);
|
||||
}
|
||||
|
||||
pConn->numOfStreams = MIN(QUERY_STREAM_SAVE_SIZE, numOfStreams);
|
||||
|
||||
int32_t saveSize = pConn->numOfStreams * sizeof(SStreamDesc);
|
||||
if (saveSize > 0 && pConn->pStreams != NULL) {
|
||||
memcpy(pConn->pStreams, pHBMsg->pData + numOfQueries * sizeof(SQueryDesc), saveSize);
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
SUserObj *pUser = mnodeGetUserFromConn(pConn);
|
||||
if (pUser == NULL) return 0;
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
||||
|
||||
int32_t cols = 0;
|
||||
SSchema *pSchema = pMeta->schema;
|
||||
|
||||
pShow->bytes[cols] = QUERY_ID_SIZE + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "query_id");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "user");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "ip:port");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 24;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "qid");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "created_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BIGINT;
|
||||
strcpy(pSchema[cols].name, "time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "sql_obj_id");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "pid");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "ep");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 1;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BOOL;
|
||||
strcpy(pSchema[cols].name, "stable_query");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "sub_queries");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "sub_query_info");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "sql");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
for (int32_t i = 1; i < cols; ++i) {
|
||||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
}
|
||||
|
||||
pShow->numOfRows = 1000000;
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
||||
int32_t numOfRows = 0;
|
||||
SConnObj *pConnObj = NULL;
|
||||
int32_t cols = 0;
|
||||
char * pWrite;
|
||||
void * pIter;
|
||||
char str[TSDB_IPv4ADDR_LEN + 6] = {0};
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pIter = mnodeGetNextConn(pShow->pIter, &pConnObj);
|
||||
if (pConnObj == NULL) {
|
||||
pShow->pIter = pIter;
|
||||
break;
|
||||
}
|
||||
|
||||
if (numOfRows + pConnObj->numOfQueries >= rows) {
|
||||
mnodeCancelGetNextConn(pIter);
|
||||
break;
|
||||
}
|
||||
|
||||
pShow->pIter = pIter;
|
||||
for (int32_t i = 0; i < pConnObj->numOfQueries; ++i) {
|
||||
SQueryDesc *pDesc = pConnObj->pQueries + i;
|
||||
cols = 0;
|
||||
|
||||
snprintf(str, QUERY_ID_SIZE + 1, "%u:%u", pConnObj->connId, htonl(pDesc->queryId));
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, str, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
snprintf(str, tListLen(str), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port);
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, str, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
char handleBuf[24] = {0};
|
||||
snprintf(handleBuf, tListLen(handleBuf), "%"PRIu64, htobe64(pDesc->qId));
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, handleBuf, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = htobe64(pDesc->stime);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = htobe64(pDesc->useconds);
|
||||
cols++;
|
||||
|
||||
snprintf(str, tListLen(str), "0x%" PRIx64, htobe64(pDesc->sqlObjId));
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, str, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = htonl(pDesc->pid);
|
||||
cols++;
|
||||
|
||||
char epBuf[TSDB_EP_LEN + 1] = {0};
|
||||
snprintf(epBuf, tListLen(epBuf), "%s:%u", pDesc->fqdn, pConnObj->port);
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, epBuf, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(bool *)pWrite = pDesc->stableQuery;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = htonl(pDesc->numOfSub);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->subSqlInfo, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
}
|
||||
|
||||
pShow->numOfReads += numOfRows;
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
SUserObj *pUser = mnodeGetUserFromConn(pConn);
|
||||
if (pUser == NULL) return 0;
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
||||
|
||||
int32_t cols = 0;
|
||||
SSchema *pSchema = pMeta->schema;
|
||||
|
||||
pShow->bytes[cols] = QUERY_ID_SIZE + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "streamId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "user");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "dest table");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "ip:port");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "created time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "exec time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BIGINT;
|
||||
strcpy(pSchema[cols].name, "time(us)");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "sql");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "cycles");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
for (int32_t i = 1; i < cols; ++i) {
|
||||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
}
|
||||
|
||||
pShow->numOfRows = 1000000;
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
||||
int32_t numOfRows = 0;
|
||||
SConnObj *pConnObj = NULL;
|
||||
int32_t cols = 0;
|
||||
char * pWrite;
|
||||
void * pIter;
|
||||
char ipStr[TSDB_IPv4ADDR_LEN + 6];
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pIter = mnodeGetNextConn(pShow->pIter, &pConnObj);
|
||||
if (pConnObj == NULL) {
|
||||
pShow->pIter = pIter;
|
||||
break;
|
||||
}
|
||||
|
||||
if (numOfRows + pConnObj->numOfStreams >= rows) {
|
||||
mnodeCancelGetNextConn(pIter);
|
||||
break;
|
||||
}
|
||||
|
||||
pShow->pIter = pIter;
|
||||
for (int32_t i = 0; i < pConnObj->numOfStreams; ++i) {
|
||||
SStreamDesc *pDesc = pConnObj->pStreams + i;
|
||||
cols = 0;
|
||||
|
||||
snprintf(ipStr, QUERY_ID_SIZE + 1, "%u:%u", pConnObj->connId, htonl(pDesc->streamId));
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->dstTable, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port);
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = htobe64(pDesc->ctime);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = htobe64(pDesc->stime);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = htobe64(pDesc->useconds);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = (int32_t)htobe64(pDesc->num);
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
}
|
||||
|
||||
pShow->numOfReads += numOfRows;
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) {
|
||||
SUserObj *pUser = pMsg->pUser;
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
||||
|
||||
SKillQueryMsg *pKill = pMsg->rpcMsg.pCont;
|
||||
mInfo("kill query msg is received, queryId:%s", pKill->queryId);
|
||||
|
||||
const char delim = ':';
|
||||
char* connIdStr = strtok(pKill->queryId, &delim);
|
||||
char* queryIdStr = strtok(NULL, &delim);
|
||||
|
||||
if (queryIdStr == NULL || connIdStr == NULL) {
|
||||
mInfo("failed to kill query, queryId:%s", pKill->queryId);
|
||||
return TSDB_CODE_MND_INVALID_QUERY_ID;
|
||||
}
|
||||
|
||||
int32_t queryId = (int32_t)strtol(queryIdStr, NULL, 10);
|
||||
|
||||
int32_t connId = atoi(connIdStr);
|
||||
SConnObj *pConn = taosCacheAcquireByKey(tsMnodeConnCache, &connId, sizeof(int32_t));
|
||||
if (pConn == NULL) {
|
||||
mError("connId:%s, failed to kill queryId:%d, conn not exist", connIdStr, queryId);
|
||||
return TSDB_CODE_MND_INVALID_CONN_ID;
|
||||
} else {
|
||||
mInfo("connId:%s, queryId:%d is killed by user:%s", connIdStr, queryId, pUser->user);
|
||||
pConn->queryId = queryId;
|
||||
taosCacheRelease(tsMnodeConnCache, (void **)&pConn, false);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) {
|
||||
SUserObj *pUser = pMsg->pUser;
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
||||
|
||||
SKillQueryMsg *pKill = pMsg->rpcMsg.pCont;
|
||||
mInfo("kill stream msg is received, streamId:%s", pKill->queryId);
|
||||
|
||||
const char delim = ':';
|
||||
char* connIdStr = strtok(pKill->queryId, &delim);
|
||||
char* streamIdStr = strtok(NULL, &delim);
|
||||
|
||||
if (streamIdStr == NULL || connIdStr == NULL) {
|
||||
mInfo("failed to kill stream, streamId:%s", pKill->queryId);
|
||||
return TSDB_CODE_MND_INVALID_STREAM_ID;
|
||||
}
|
||||
|
||||
int32_t streamId = (int32_t)strtol(streamIdStr, NULL, 10);
|
||||
int32_t connId = atoi(connIdStr);
|
||||
|
||||
SConnObj *pConn = taosCacheAcquireByKey(tsMnodeConnCache, &connId, sizeof(int32_t));
|
||||
if (pConn == NULL) {
|
||||
mError("connId:%s, failed to kill streamId:%d, conn not exist", connIdStr, streamId);
|
||||
return TSDB_CODE_MND_INVALID_CONN_ID;
|
||||
} else {
|
||||
mInfo("connId:%s, streamId:%d is killed by user:%s", connIdStr, streamId, pUser->user);
|
||||
pConn->streamId = streamId;
|
||||
taosCacheRelease(tsMnodeConnCache, (void **)&pConn, false);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg) {
|
||||
SUserObj *pUser = pMsg->pUser;
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS;
|
||||
|
||||
SKillConnMsg *pKill = pMsg->rpcMsg.pCont;
|
||||
int32_t connId = atoi(pKill->queryId);
|
||||
SConnObj *pConn = taosCacheAcquireByKey(tsMnodeConnCache, &connId, sizeof(int32_t));
|
||||
if (pConn == NULL) {
|
||||
mError("connId:%s, failed to kill, conn not exist", pKill->queryId);
|
||||
return TSDB_CODE_MND_INVALID_CONN_ID;
|
||||
} else {
|
||||
mInfo("connId:%s, is killed by user:%s", pKill->queryId, pUser->user);
|
||||
pConn->killed = 1;
|
||||
taosCacheRelease(tsMnodeConnCache, (void**)&pConn, false);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* 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 "taosdef.h"
|
||||
#include "tsched.h"
|
||||
#include "tbn.h"
|
||||
#include "tgrant.h"
|
||||
#include "ttimer.h"
|
||||
#include "tglobal.h"
|
||||
#include "mnode.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeVgroup.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeTable.h"
|
||||
#include "mnodeShow.h"
|
||||
|
||||
static int32_t (*tsMnodeProcessReadMsgFp[TSDB_MSG_TYPE_MAX])(SMnodeMsg *);
|
||||
|
||||
void mnodeAddReadMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *pMsg)) {
|
||||
tsMnodeProcessReadMsgFp[msgType] = fp;
|
||||
}
|
||||
|
||||
int32_t mnodeProcessRead(SMnodeMsg *pMsg) {
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, content is null", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
|
||||
return TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
}
|
||||
|
||||
if (!sdbIsMaster()) {
|
||||
SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
||||
if (!epSet) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
}
|
||||
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SRpcEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in mread queue is redirected, numOfEps:%d inUse:%d", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
return TSDB_CODE_RPC_REDIRECT;
|
||||
}
|
||||
|
||||
if (tsMnodeProcessReadMsgFp[pMsg->rpcMsg.msgType] == NULL) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, not processed", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType]);
|
||||
return TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
}
|
||||
|
||||
int32_t code = mnodeInitMsg(pMsg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, not processed reason:%s", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType], tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
return (*tsMnodeProcessReadMsgFp[pMsg->rpcMsg.msgType])(pMsg);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,452 +0,0 @@
|
|||
/*
|
||||
* 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 "tsched.h"
|
||||
#include "tutil.h"
|
||||
#include "ttimer.h"
|
||||
#include "tgrant.h"
|
||||
#include "tglobal.h"
|
||||
#include "tcache.h"
|
||||
#include "mnode.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeProfile.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeTable.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
#include "mnodeWrite.h"
|
||||
#include "mnodeRead.h"
|
||||
|
||||
static int32_t mnodeProcessShowMsg(SMnodeMsg *mnodeMsg);
|
||||
static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *mnodeMsg);
|
||||
static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *mnodeMsg);
|
||||
static int32_t mnodeProcessConnectMsg(SMnodeMsg *mnodeMsg);
|
||||
static int32_t mnodeProcessUseMsg(SMnodeMsg *mnodeMsg);
|
||||
|
||||
static void mnodeFreeShowObj(void *data);
|
||||
static bool mnodeAccquireShowObj(SShowObj *pShow);
|
||||
static bool mnodeCheckShowFinished(SShowObj *pShow);
|
||||
static void *mnodePutShowObj(SShowObj *pShow);
|
||||
static void mnodeReleaseShowObj(SShowObj *pShow, bool forceRemove);
|
||||
|
||||
static void *tsMnodeShowCache = NULL;
|
||||
static int32_t tsShowObjIndex = 0;
|
||||
static SShowMetaFp tsMnodeShowMetaFp[TSDB_MGMT_TABLE_MAX] = {0};
|
||||
static SShowRetrieveFp tsMnodeShowRetrieveFp[TSDB_MGMT_TABLE_MAX] = {0};
|
||||
static SShowFreeIterFp tsMnodeShowFreeIterFp[TSDB_MGMT_TABLE_MAX] = {0};
|
||||
|
||||
int32_t mnodeInitShow() {
|
||||
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_SHOW, mnodeProcessShowMsg);
|
||||
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_RETRIEVE, mnodeProcessRetrieveMsg);
|
||||
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_HEARTBEAT, mnodeProcessHeartBeatMsg);
|
||||
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_CONNECT, mnodeProcessConnectMsg);
|
||||
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_USE_DB, mnodeProcessUseMsg);
|
||||
|
||||
tsMnodeShowCache = taosCacheInit(TSDB_CACHE_PTR_KEY, 5, true, mnodeFreeShowObj, "show");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanUpShow() {
|
||||
if (tsMnodeShowCache != NULL) {
|
||||
mInfo("show cache is cleanup");
|
||||
taosCacheCleanup(tsMnodeShowCache);
|
||||
tsMnodeShowCache = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void mnodeAddShowMetaHandle(uint8_t showType, SShowMetaFp fp) {
|
||||
tsMnodeShowMetaFp[showType] = fp;
|
||||
}
|
||||
|
||||
void mnodeAddShowRetrieveHandle(uint8_t msgType, SShowRetrieveFp fp) {
|
||||
tsMnodeShowRetrieveFp[msgType] = fp;
|
||||
}
|
||||
|
||||
void mnodeAddShowFreeIterHandle(uint8_t msgType, SShowFreeIterFp fp) {
|
||||
tsMnodeShowFreeIterFp[msgType] = fp;
|
||||
}
|
||||
|
||||
static char *mnodeGetShowType(int32_t showType) {
|
||||
switch (showType) {
|
||||
case TSDB_MGMT_TABLE_ACCT: return "show accounts";
|
||||
case TSDB_MGMT_TABLE_USER: return "show users";
|
||||
case TSDB_MGMT_TABLE_DB: return "show databases";
|
||||
case TSDB_MGMT_TABLE_TABLE: return "show tables";
|
||||
case TSDB_MGMT_TABLE_DNODE: return "show dnodes";
|
||||
case TSDB_MGMT_TABLE_MNODE: return "show mnodes";
|
||||
case TSDB_MGMT_TABLE_VGROUP: return "show vgroups";
|
||||
case TSDB_MGMT_TABLE_METRIC: return "show stables";
|
||||
case TSDB_MGMT_TABLE_MODULE: return "show modules";
|
||||
case TSDB_MGMT_TABLE_QUERIES: return "show queries";
|
||||
case TSDB_MGMT_TABLE_STREAMS: return "show streams";
|
||||
case TSDB_MGMT_TABLE_VARIABLES: return "show configs";
|
||||
case TSDB_MGMT_TABLE_CONNS: return "show connections";
|
||||
case TSDB_MGMT_TABLE_SCORES: return "show scores";
|
||||
case TSDB_MGMT_TABLE_GRANTS: return "show grants";
|
||||
case TSDB_MGMT_TABLE_VNODES: return "show vnodes";
|
||||
case TSDB_MGMT_TABLE_CLUSTER: return "show clusters";
|
||||
case TSDB_MGMT_TABLE_STREAMTABLES : return "show streamtables";
|
||||
case TSDB_MGMT_TABLE_TP: return "show topics";
|
||||
default: return "undefined";
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) {
|
||||
SShowMsg *pShowMsg = pMsg->rpcMsg.pCont;
|
||||
if (pShowMsg->type >= TSDB_MGMT_TABLE_MAX) {
|
||||
return TSDB_CODE_MND_INVALID_MSG_TYPE;
|
||||
}
|
||||
|
||||
if (!tsMnodeShowMetaFp[pShowMsg->type] || !tsMnodeShowRetrieveFp[pShowMsg->type]) {
|
||||
mError("show type:%s is not support", mnodeGetShowType(pShowMsg->type));
|
||||
return TSDB_CODE_COM_OPS_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t showObjSize = sizeof(SShowObj) + htons(pShowMsg->payloadLen);
|
||||
SShowObj *pShow = calloc(1, showObjSize);
|
||||
pShow->type = pShowMsg->type;
|
||||
pShow->payloadLen = htons(pShowMsg->payloadLen);
|
||||
tstrncpy(pShow->db, pShowMsg->db, TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN);
|
||||
memcpy(pShow->payload, pShowMsg->payload, pShow->payloadLen);
|
||||
|
||||
pShow = mnodePutShowObj(pShow);
|
||||
if (pShow == NULL) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE;
|
||||
SShowRsp *pShowRsp = rpcMallocCont(size);
|
||||
if (pShowRsp == NULL) {
|
||||
mnodeReleaseShowObj(pShow, true);
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
}
|
||||
pShowRsp->qhandle = htobe64((uint64_t) pShow);
|
||||
|
||||
int32_t code = (*tsMnodeShowMetaFp[pShowMsg->type])(&pShowRsp->tableMeta, pShow, pMsg->rpcMsg.handle);
|
||||
mDebug("%p, show type:%s index:%d, get meta finished, numOfRows:%d cols:%d result:%s", pShow,
|
||||
mnodeGetShowType(pShowMsg->type), pShow->index, pShow->numOfRows, pShow->numOfColumns, tstrerror(code));
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
pMsg->rpcRsp.rsp = pShowRsp;
|
||||
pMsg->rpcRsp.len = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns;
|
||||
mnodeReleaseShowObj(pShow, false);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
rpcFreeCont(pShowRsp);
|
||||
mnodeReleaseShowObj(pShow, true);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) {
|
||||
int32_t rowsToRead = 0;
|
||||
int32_t size = 0;
|
||||
int32_t rowsRead = 0;
|
||||
SRetrieveTableMsg *pRetrieve = pMsg->rpcMsg.pCont;
|
||||
pRetrieve->qhandle = htobe64(pRetrieve->qhandle);
|
||||
|
||||
SShowObj *pShow = (SShowObj *)pRetrieve->qhandle;
|
||||
|
||||
/*
|
||||
* in case of server restart, apps may hold qhandle created by server before
|
||||
* restart, which is actually invalid, therefore, signature check is required.
|
||||
*/
|
||||
if (!mnodeAccquireShowObj(pShow)) {
|
||||
mError("%p, show is invalid", pShow);
|
||||
return TSDB_CODE_MND_INVALID_SHOWOBJ;
|
||||
}
|
||||
|
||||
mDebug("%p, show type:%s index:%d, start retrieve data, numOfReads:%d numOfRows:%d", pShow,
|
||||
mnodeGetShowType(pShow->type), pShow->index, pShow->numOfReads, pShow->numOfRows);
|
||||
|
||||
if (mnodeCheckShowFinished(pShow)) {
|
||||
mDebug("%p, show is already read finished, numOfReads:%d numOfRows:%d", pShow, pShow->numOfReads, pShow->numOfRows);
|
||||
pShow->numOfReads = pShow->numOfRows;
|
||||
}
|
||||
|
||||
if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) {
|
||||
rowsToRead = pShow->numOfRows - pShow->numOfReads;
|
||||
}
|
||||
|
||||
/* return no more than 100 tables in one round trip */
|
||||
if (rowsToRead > 100) rowsToRead = 100;
|
||||
|
||||
/*
|
||||
* the actual number of table may be larger than the value of pShow->numOfRows, if a query is
|
||||
* issued during a continuous create table operation. Therefore, rowToRead may be less than 0.
|
||||
*/
|
||||
if (rowsToRead < 0) rowsToRead = 0;
|
||||
size = pShow->rowSize * rowsToRead;
|
||||
|
||||
size += 100;
|
||||
SRetrieveTableRsp *pRsp = rpcMallocCont(size);
|
||||
|
||||
// if free flag is set, client wants to clean the resources
|
||||
if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE)
|
||||
rowsRead = (*tsMnodeShowRetrieveFp[pShow->type])(pShow, pRsp->data, rowsToRead, pMsg->rpcMsg.handle);
|
||||
|
||||
mDebug("%p, show type:%s index:%d, stop retrieve data, rowsRead:%d rowsToRead:%d", pShow,
|
||||
mnodeGetShowType(pShow->type), pShow->index, rowsRead, rowsToRead);
|
||||
|
||||
if (rowsRead < 0) {
|
||||
rpcFreeCont(pRsp);
|
||||
mnodeReleaseShowObj(pShow, false);
|
||||
assert(false);
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
pRsp->numOfRows = htonl(rowsRead);
|
||||
pRsp->precision = (int16_t)htonl(TSDB_TIME_PRECISION_MILLI); // millisecond time precision
|
||||
|
||||
pMsg->rpcRsp.rsp = pRsp;
|
||||
pMsg->rpcRsp.len = size;
|
||||
|
||||
if (rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) {
|
||||
pRsp->completed = 1;
|
||||
mDebug("%p, retrieve completed", pShow);
|
||||
mnodeReleaseShowObj(pShow, true);
|
||||
} else {
|
||||
mDebug("%p, retrieve not completed yet", pShow);
|
||||
mnodeReleaseShowObj(pShow, false);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
||||
SHeartBeatRsp *pRsp = (SHeartBeatRsp *)rpcMallocCont(sizeof(SHeartBeatRsp));
|
||||
if (pRsp == NULL) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SHeartBeatMsg *pHBMsg = pMsg->rpcMsg.pCont;
|
||||
if (taosCheckVersion(pHBMsg->clientVer, version, 3) != TSDB_CODE_SUCCESS) {
|
||||
rpcFreeCont(pRsp);
|
||||
return TSDB_CODE_TSC_INVALID_VERSION; // todo change the error code
|
||||
}
|
||||
|
||||
SRpcConnInfo connInfo = {0};
|
||||
rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo);
|
||||
|
||||
int32_t connId = htonl(pHBMsg->connId);
|
||||
SConnObj *pConn = mnodeAccquireConn(connId, connInfo.user, connInfo.clientIp, connInfo.clientPort);
|
||||
if (pConn == NULL) {
|
||||
pHBMsg->pid = htonl(pHBMsg->pid);
|
||||
pConn = mnodeCreateConn(connInfo.user, connInfo.clientIp, connInfo.clientPort, pHBMsg->pid, pHBMsg->appName);
|
||||
}
|
||||
|
||||
if (pConn == NULL) {
|
||||
// do not close existing links, otherwise
|
||||
// mError("failed to create connId, close connect");
|
||||
// pRsp->killConnection = 1;
|
||||
} else {
|
||||
pRsp->connId = htonl(pConn->connId);
|
||||
mnodeSaveQueryStreamList(pConn, pHBMsg);
|
||||
|
||||
if (pConn->killed != 0) {
|
||||
pRsp->killConnection = 1;
|
||||
}
|
||||
|
||||
if (pConn->streamId != 0) {
|
||||
pRsp->streamId = htonl(pConn->streamId);
|
||||
pConn->streamId = 0;
|
||||
}
|
||||
|
||||
if (pConn->queryId != 0) {
|
||||
pRsp->queryId = htonl(pConn->queryId);
|
||||
pConn->queryId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t onlineDnodes = 0, totalDnodes = 0;
|
||||
mnodeGetOnlineAndTotalDnodesNum(&onlineDnodes, &totalDnodes);
|
||||
|
||||
pRsp->onlineDnodes = htonl(onlineDnodes);
|
||||
pRsp->totalDnodes = htonl(totalDnodes);
|
||||
mnodeGetMnodeEpSetForShell(&pRsp->epSet, false);
|
||||
|
||||
pMsg->rpcRsp.rsp = pRsp;
|
||||
pMsg->rpcRsp.len = sizeof(SHeartBeatRsp);
|
||||
|
||||
mnodeReleaseConn(pConn);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
|
||||
SConnectMsg *pConnectMsg = pMsg->rpcMsg.pCont;
|
||||
SConnectRsp *pConnectRsp = NULL;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SRpcConnInfo connInfo = {0};
|
||||
if (rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo) != 0) {
|
||||
mError("thandle:%p is already released while process connect msg", pMsg->rpcMsg.handle);
|
||||
code = TSDB_CODE_MND_INVALID_CONNECTION;
|
||||
goto connect_over;
|
||||
}
|
||||
|
||||
code = taosCheckVersion(pConnectMsg->clientVersion, version, 3);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto connect_over;
|
||||
}
|
||||
|
||||
SUserObj *pUser = pMsg->pUser;
|
||||
SAcctObj *pAcct = pUser->pAcct;
|
||||
|
||||
if (pConnectMsg->db[0]) {
|
||||
char dbName[TSDB_TABLE_FNAME_LEN * 3] = {0};
|
||||
sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db);
|
||||
SDbObj *pDb = mnodeGetDb(dbName);
|
||||
if (pDb == NULL) {
|
||||
code = TSDB_CODE_MND_INVALID_DB;
|
||||
goto connect_over;
|
||||
}
|
||||
|
||||
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||
code = TSDB_CODE_MND_DB_IN_DROPPING;
|
||||
mnodeDecDbRef(pDb);
|
||||
goto connect_over;
|
||||
}
|
||||
mnodeDecDbRef(pDb);
|
||||
}
|
||||
|
||||
pConnectRsp = rpcMallocCont(sizeof(SConnectRsp));
|
||||
if (pConnectRsp == NULL) {
|
||||
code = TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
goto connect_over;
|
||||
}
|
||||
|
||||
pConnectMsg->pid = htonl(pConnectMsg->pid);
|
||||
SConnObj *pConn = mnodeCreateConn(connInfo.user, connInfo.clientIp, connInfo.clientPort, pConnectMsg->pid, pConnectMsg->appName);
|
||||
if (pConn == NULL) {
|
||||
code = terrno;
|
||||
} else {
|
||||
pConnectRsp->connId = htonl(pConn->connId);
|
||||
mnodeReleaseConn(pConn);
|
||||
}
|
||||
|
||||
sprintf(pConnectRsp->acctId, "%x", pAcct->acctId);
|
||||
memcpy(pConnectRsp->serverVersion, version, TSDB_VERSION_LEN);
|
||||
pConnectRsp->writeAuth = pUser->writeAuth;
|
||||
pConnectRsp->superAuth = pUser->superAuth;
|
||||
|
||||
mnodeGetMnodeEpSetForShell(&pConnectRsp->epSet, false);
|
||||
|
||||
dnodeGetClusterId(pConnectRsp->clusterId);
|
||||
|
||||
connect_over:
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
if (pConnectRsp) rpcFreeCont(pConnectRsp);
|
||||
mLError("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code));
|
||||
} else {
|
||||
mLInfo("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code));
|
||||
pMsg->rpcRsp.rsp = pConnectRsp;
|
||||
pMsg->rpcRsp.len = sizeof(SConnectRsp);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessUseMsg(SMnodeMsg *pMsg) {
|
||||
SUseDbMsg *pUseDbMsg = pMsg->rpcMsg.pCont;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pUseDbMsg->db);
|
||||
if (pMsg->pDb == NULL) {
|
||||
return TSDB_CODE_MND_INVALID_DB;
|
||||
}
|
||||
|
||||
if (pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
||||
mError("db:%s, status:%d, in dropping", pMsg->pDb->name, pMsg->pDb->status);
|
||||
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool mnodeCheckShowFinished(SShowObj *pShow) {
|
||||
if (pShow->pIter == NULL && pShow->numOfReads != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool mnodeAccquireShowObj(SShowObj *pShow) {
|
||||
TSDB_CACHE_PTR_TYPE handleVal = (TSDB_CACHE_PTR_TYPE)pShow;
|
||||
SShowObj **ppShow = taosCacheAcquireByKey(tsMnodeShowCache, &handleVal, sizeof(TSDB_CACHE_PTR_TYPE));
|
||||
if (ppShow) {
|
||||
mDebug("%p, show is accquired from cache, data:%p, index:%d", pShow, ppShow, pShow->index);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void* mnodePutShowObj(SShowObj *pShow) {
|
||||
const int32_t DEFAULT_SHOWHANDLE_LIFE_SPAN = tsShellActivityTimer * 6 * 1000;
|
||||
|
||||
if (tsMnodeShowCache != NULL) {
|
||||
pShow->index = atomic_add_fetch_32(&tsShowObjIndex, 1);
|
||||
TSDB_CACHE_PTR_TYPE handleVal = (TSDB_CACHE_PTR_TYPE)pShow;
|
||||
SShowObj **ppShow = taosCachePut(tsMnodeShowCache, &handleVal, sizeof(TSDB_CACHE_PTR_TYPE), &pShow, sizeof(TSDB_CACHE_PTR_TYPE), DEFAULT_SHOWHANDLE_LIFE_SPAN);
|
||||
pShow->ppShow = (void**)ppShow;
|
||||
mDebug("%p, show is put into cache, data:%p index:%d", pShow, ppShow, pShow->index);
|
||||
return pShow;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void mnodeFreeShowObj(void *data) {
|
||||
SShowObj *pShow = *(SShowObj **)data;
|
||||
if (tsMnodeShowFreeIterFp[pShow->type] != NULL) {
|
||||
if (pShow->pVgIter != NULL) {
|
||||
// only used in 'show vnodes "ep"'
|
||||
(*tsMnodeShowFreeIterFp[pShow->type])(pShow->pVgIter);
|
||||
} else {
|
||||
if (pShow->pIter != NULL) (*tsMnodeShowFreeIterFp[pShow->type])(pShow->pIter);
|
||||
}
|
||||
}
|
||||
|
||||
mDebug("%p, show is destroyed, data:%p index:%d", pShow, data, pShow->index);
|
||||
tfree(pShow);
|
||||
}
|
||||
|
||||
static void mnodeReleaseShowObj(SShowObj *pShow, bool forceRemove) {
|
||||
SShowObj **ppShow = (SShowObj **)pShow->ppShow;
|
||||
mDebug("%p, show is released, force:%s data:%p index:%d", pShow, forceRemove ? "true" : "false", ppShow,
|
||||
pShow->index);
|
||||
|
||||
taosCacheRelease(tsMnodeShowCache, (void **)(&ppShow), forceRemove);
|
||||
}
|
||||
|
||||
void mnodeVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow) {
|
||||
if (rows < capacity) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
memmove(data + pShow->offset[i] * rows, data + pShow->offset[i] * capacity, pShow->bytes[i] * rows);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,646 +0,0 @@
|
|||
/*
|
||||
* 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 "trpc.h"
|
||||
#include "tutil.h"
|
||||
#include "tglobal.h"
|
||||
#include "tgrant.h"
|
||||
#include "tdataformat.h"
|
||||
#include "tkey.h"
|
||||
#include "mnode.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeWrite.h"
|
||||
#include "mnodePeer.h"
|
||||
|
||||
int64_t tsUserRid = -1;
|
||||
static void * tsUserSdb = NULL;
|
||||
static int32_t tsUserUpdateSize = 0;
|
||||
static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg);
|
||||
|
||||
static int32_t mnodeUserActionDestroy(SSdbRow *pRow) {
|
||||
tfree(pRow->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionInsert(SSdbRow *pRow) {
|
||||
SUserObj *pUser = pRow->pObj;
|
||||
SAcctObj *pAcct = mnodeGetAcct(pUser->acct);
|
||||
|
||||
if (pAcct != NULL) {
|
||||
mnodeAddUserToAcct(pAcct, pUser);
|
||||
mnodeDecAcctRef(pAcct);
|
||||
} else {
|
||||
mError("user:%s, acct:%s info not exist in sdb", pUser->user, pUser->acct);
|
||||
return TSDB_CODE_MND_INVALID_ACCT;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionDelete(SSdbRow *pRow) {
|
||||
SUserObj *pUser = pRow->pObj;
|
||||
SAcctObj *pAcct = mnodeGetAcct(pUser->acct);
|
||||
|
||||
if (pAcct != NULL) {
|
||||
mnodeDropUserFromAcct(pAcct, pUser);
|
||||
mnodeDecAcctRef(pAcct);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionUpdate(SSdbRow *pRow) {
|
||||
SUserObj *pUser = pRow->pObj;
|
||||
SUserObj *pSaved = mnodeGetUser(pUser->user);
|
||||
if (pUser != pSaved) {
|
||||
memcpy(pSaved, pUser, tsUserUpdateSize);
|
||||
free(pUser);
|
||||
}
|
||||
mnodeDecUserRef(pSaved);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionEncode(SSdbRow *pRow) {
|
||||
SUserObj *pUser = pRow->pObj;
|
||||
memcpy(pRow->rowData, pUser, tsUserUpdateSize);
|
||||
pRow->rowSize = tsUserUpdateSize;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionDecode(SSdbRow *pRow) {
|
||||
SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj));
|
||||
if (pUser == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
|
||||
memcpy(pUser, pRow->rowData, tsUserUpdateSize);
|
||||
pRow->pObj = pUser;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void mnodePrintUserAuth() {
|
||||
FILE *fp = fopen("auth.txt", "w");
|
||||
if (!fp) {
|
||||
mDebug("failed to auth.txt for write");
|
||||
return;
|
||||
}
|
||||
|
||||
void * pIter = NULL;
|
||||
SUserObj *pUser = NULL;
|
||||
|
||||
while (1) {
|
||||
pIter = mnodeGetNextUser(pIter, &pUser);
|
||||
if (pUser == NULL) break;
|
||||
|
||||
char *base64 = base64_encode((const unsigned char *)pUser->pass, TSDB_KEY_LEN * 2);
|
||||
fprintf(fp, "user:%24s auth:%s\n", pUser->user, base64);
|
||||
free(base64);
|
||||
|
||||
mnodeDecUserRef(pUser);
|
||||
}
|
||||
|
||||
taosFsync(fileno(fp));
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionRestored() {
|
||||
int64_t numOfRows = sdbGetNumOfRows(tsUserSdb);
|
||||
if (numOfRows <= 0 && dnodeIsFirstDeploy()) {
|
||||
mInfo("dnode first deploy, create root user");
|
||||
SAcctObj *pAcct = mnodeGetAcct(TSDB_DEFAULT_USER);
|
||||
mnodeCreateUser(pAcct, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS, NULL);
|
||||
mnodeCreateUser(pAcct, "monitor", tsInternalPass, NULL);
|
||||
mnodeCreateUser(pAcct, "_"TSDB_DEFAULT_USER, tsInternalPass, NULL);
|
||||
mnodeDecAcctRef(pAcct);
|
||||
}
|
||||
|
||||
if (tsPrintAuth != 0) {
|
||||
mInfo("print user auth, for -A parameter is set");
|
||||
mnodePrintUserAuth();
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mnodeInitUsers() {
|
||||
SUserObj tObj;
|
||||
tsUserUpdateSize = (int32_t)((int8_t *)tObj.updateEnd - (int8_t *)&tObj);
|
||||
|
||||
SSdbTableDesc desc = {
|
||||
.id = SDB_TABLE_USER,
|
||||
.name = "users",
|
||||
.hashSessions = TSDB_DEFAULT_USERS_HASH_SIZE,
|
||||
.maxRowSize = tsUserUpdateSize,
|
||||
.refCountPos = (int32_t)((int8_t *)(&tObj.refCount) - (int8_t *)&tObj),
|
||||
.keyType = SDB_KEY_STRING,
|
||||
.fpInsert = mnodeUserActionInsert,
|
||||
.fpDelete = mnodeUserActionDelete,
|
||||
.fpUpdate = mnodeUserActionUpdate,
|
||||
.fpEncode = mnodeUserActionEncode,
|
||||
.fpDecode = mnodeUserActionDecode,
|
||||
.fpDestroy = mnodeUserActionDestroy,
|
||||
.fpRestored = mnodeUserActionRestored
|
||||
};
|
||||
|
||||
tsUserRid = sdbOpenTable(&desc);
|
||||
tsUserSdb = sdbGetTableByRid(tsUserRid);
|
||||
if (tsUserSdb == NULL) {
|
||||
mError("table:%s, failed to create hash", desc.name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_CREATE_USER, mnodeProcessCreateUserMsg);
|
||||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_ALTER_USER, mnodeProcessAlterUserMsg);
|
||||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_DROP_USER, mnodeProcessDropUserMsg);
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_USER, mnodeGetUserMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_USER, mnodeRetrieveUsers);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_USER, mnodeCancelGetNextUser);
|
||||
|
||||
mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_AUTH, mnodeProcessAuthMsg);
|
||||
|
||||
mDebug("table:%s, hash is created", desc.name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupUsers() {
|
||||
sdbCloseTable(tsUserRid);
|
||||
tsUserSdb = NULL;
|
||||
}
|
||||
|
||||
SUserObj *mnodeGetUser(char *name) {
|
||||
return (SUserObj *)sdbGetRow(tsUserSdb, name);
|
||||
}
|
||||
|
||||
void *mnodeGetNextUser(void *pIter, SUserObj **pUser) {
|
||||
return sdbFetchRow(tsUserSdb, pIter, (void **)pUser);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextUser(void *pIter) {
|
||||
sdbFreeIter(tsUserSdb, pIter);
|
||||
}
|
||||
|
||||
void mnodeIncUserRef(SUserObj *pUser) {
|
||||
sdbIncRef(tsUserSdb, pUser);
|
||||
}
|
||||
|
||||
void mnodeDecUserRef(SUserObj *pUser) {
|
||||
sdbDecRef(tsUserSdb, pUser);
|
||||
}
|
||||
|
||||
static int32_t mnodeUpdateUser(SUserObj *pUser, void *pMsg) {
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsUserSdb,
|
||||
.pObj = pUser,
|
||||
.pMsg = pMsg
|
||||
};
|
||||
|
||||
int32_t code = sdbUpdateRow(&row);
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("user:%s, failed to alter by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code));
|
||||
} else {
|
||||
mLInfo("user:%s, is altered by %s", pUser->user, mnodeGetUserFromMsg(pMsg));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) {
|
||||
int32_t code = acctCheck(pAcct, ACCT_GRANT_USER);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (name[0] == 0) {
|
||||
return TSDB_CODE_MND_INVALID_USER_FORMAT;
|
||||
}
|
||||
|
||||
if (pass[0] == 0) {
|
||||
return TSDB_CODE_MND_INVALID_PASS_FORMAT;
|
||||
}
|
||||
|
||||
SUserObj *pUser = mnodeGetUser(name);
|
||||
if (pUser != NULL) {
|
||||
mDebug("user:%s, is already there", name);
|
||||
mnodeDecUserRef(pUser);
|
||||
return TSDB_CODE_MND_USER_ALREADY_EXIST;
|
||||
}
|
||||
|
||||
code = grantCheck(TSDB_GRANT_USER);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
pUser = calloc(1, sizeof(SUserObj));
|
||||
tstrncpy(pUser->user, name, TSDB_USER_LEN);
|
||||
taosEncryptPass((uint8_t*) pass, strlen(pass), pUser->pass);
|
||||
strcpy(pUser->acct, pAcct->user);
|
||||
pUser->createdTime = taosGetTimestampMs();
|
||||
pUser->superAuth = 0;
|
||||
pUser->writeAuth = 1;
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0 || strcmp(pUser->user, pUser->acct) == 0) {
|
||||
pUser->superAuth = 1;
|
||||
}
|
||||
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsUserSdb,
|
||||
.pObj = pUser,
|
||||
.rowSize = sizeof(SUserObj),
|
||||
.pMsg = pMsg
|
||||
};
|
||||
|
||||
code = sdbInsertRow(&row);
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("user:%s, failed to create by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code));
|
||||
tfree(pUser);
|
||||
} else {
|
||||
mLInfo("user:%s, is created by %s", pUser->user, mnodeGetUserFromMsg(pMsg));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeDropUser(SUserObj *pUser, void *pMsg) {
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsUserSdb,
|
||||
.pObj = pUser,
|
||||
.pMsg = pMsg
|
||||
};
|
||||
|
||||
int32_t code = sdbDeleteRow(&row);
|
||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("user:%s, failed to drop by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code));
|
||||
} else {
|
||||
mLInfo("user:%s, is dropped by %s", pUser->user, mnodeGetUserFromMsg(pMsg));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
SUserObj *pUser = mnodeGetUserFromConn(pConn);
|
||||
if (pUser == NULL) {
|
||||
return TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
}
|
||||
|
||||
int32_t cols = 0;
|
||||
SSchema *pSchema = pMeta->schema;
|
||||
|
||||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "name");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "privilege");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "account");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
strcpy(pMeta->tableFname, "show users");
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
for (int32_t i = 1; i < cols; ++i) {
|
||||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
}
|
||||
|
||||
pShow->numOfRows = pUser->pAcct->acctInfo.numOfUsers;
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
|
||||
mnodeDecUserRef(pUser);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
||||
int32_t numOfRows = 0;
|
||||
SUserObj *pUser = NULL;
|
||||
int32_t cols = 0;
|
||||
char *pWrite;
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pShow->pIter = mnodeGetNextUser(pShow->pIter, &pUser);
|
||||
if (pUser == NULL) break;
|
||||
|
||||
cols = 0;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->user, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
if (pUser->superAuth) {
|
||||
const char *src = "super";
|
||||
STR_WITH_SIZE_TO_VARSTR(pWrite, src, strlen(src));
|
||||
} else if (pUser->writeAuth) {
|
||||
const char *src = "writable";
|
||||
STR_WITH_SIZE_TO_VARSTR(pWrite, src, strlen(src));
|
||||
} else {
|
||||
const char *src = "readable";
|
||||
STR_WITH_SIZE_TO_VARSTR(pWrite, src, strlen(src));
|
||||
}
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = pUser->createdTime;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->acct, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
mnodeDecUserRef(pUser);
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
SUserObj *mnodeGetUserFromConn(void *pConn) {
|
||||
SRpcConnInfo connInfo = {0};
|
||||
if (rpcGetConnInfo(pConn, &connInfo) == 0) {
|
||||
return mnodeGetUser(connInfo.user);
|
||||
} else {
|
||||
mError("can not get user from conn:%p", pConn);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char *mnodeGetUserFromMsg(void *pMsg) {
|
||||
SMnodeMsg *pMnodeMsg = pMsg;
|
||||
if (pMnodeMsg != NULL && pMnodeMsg->pUser != NULL) {
|
||||
return pMnodeMsg->pUser->user;
|
||||
} else {
|
||||
return "system";
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
||||
SUserObj *pOperUser = pMsg->pUser;
|
||||
|
||||
if (pOperUser->superAuth) {
|
||||
SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
return mnodeCreateUser(pOperUser->pAcct, pCreate->user, pCreate->pass, pMsg);
|
||||
} else {
|
||||
mError("user:%s, no rights to create user", pOperUser->user);
|
||||
return TSDB_CODE_MND_NO_RIGHTS;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) {
|
||||
int32_t code;
|
||||
SUserObj *pOperUser = pMsg->pUser;
|
||||
|
||||
SAlterUserMsg *pAlter = pMsg->rpcMsg.pCont;
|
||||
SUserObj *pUser = mnodeGetUser(pAlter->user);
|
||||
if (pUser == NULL) {
|
||||
return TSDB_CODE_MND_INVALID_USER;
|
||||
}
|
||||
|
||||
if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) {
|
||||
mnodeDecUserRef(pUser);
|
||||
return TSDB_CODE_MND_NO_RIGHTS;
|
||||
}
|
||||
|
||||
if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) {
|
||||
bool hasRight = false;
|
||||
if (strcmp(pOperUser->user, TSDB_DEFAULT_USER) == 0) {
|
||||
hasRight = true;
|
||||
} else if (strcmp(pUser->user, pOperUser->user) == 0) {
|
||||
hasRight = true;
|
||||
} else if (pOperUser->superAuth) {
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0) {
|
||||
hasRight = false;
|
||||
} else if (strcmp(pOperUser->acct, pUser->acct) != 0) {
|
||||
hasRight = false;
|
||||
} else {
|
||||
hasRight = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasRight) {
|
||||
memset(pUser->pass, 0, sizeof(pUser->pass));
|
||||
taosEncryptPass((uint8_t*)pAlter->pass, strlen(pAlter->pass), pUser->pass);
|
||||
code = mnodeUpdateUser(pUser, pMsg);
|
||||
} else {
|
||||
mError("user:%s, no rights to alter user", pOperUser->user);
|
||||
code = TSDB_CODE_MND_NO_RIGHTS;
|
||||
}
|
||||
} else if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) {
|
||||
bool hasRight = false;
|
||||
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0) {
|
||||
hasRight = false;
|
||||
} else if (strcmp(pUser->user, pUser->acct) == 0) {
|
||||
hasRight = false;
|
||||
} else if (strcmp(pOperUser->user, TSDB_DEFAULT_USER) == 0) {
|
||||
hasRight = true;
|
||||
} else if (strcmp(pUser->user, pOperUser->user) == 0) {
|
||||
hasRight = false;
|
||||
} else if (pOperUser->superAuth) {
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0) {
|
||||
hasRight = false;
|
||||
} else if (strcmp(pOperUser->acct, pUser->acct) != 0) {
|
||||
hasRight = false;
|
||||
} else {
|
||||
hasRight = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (pAlter->privilege == 1) { // super
|
||||
hasRight = false;
|
||||
}
|
||||
|
||||
if (hasRight) {
|
||||
if (pAlter->privilege == 2) { // read
|
||||
pUser->superAuth = 0;
|
||||
pUser->writeAuth = 0;
|
||||
}
|
||||
if (pAlter->privilege == 3) { // write
|
||||
pUser->superAuth = 0;
|
||||
pUser->writeAuth = 1;
|
||||
}
|
||||
|
||||
code = mnodeUpdateUser(pUser, pMsg);
|
||||
} else {
|
||||
mError("user:%s, no rights to alter user", pOperUser->user);
|
||||
code = TSDB_CODE_MND_NO_RIGHTS;
|
||||
}
|
||||
} else {
|
||||
mError("user:%s, no rights to alter user", pOperUser->user);
|
||||
code = TSDB_CODE_MND_NO_RIGHTS;
|
||||
}
|
||||
|
||||
mnodeDecUserRef(pUser);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg) {
|
||||
int32_t code;
|
||||
SUserObj *pOperUser = pMsg->pUser;
|
||||
|
||||
SDropUserMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
SUserObj *pUser = mnodeGetUser(pDrop->user);
|
||||
if (pUser == NULL) {
|
||||
return TSDB_CODE_MND_INVALID_USER;
|
||||
}
|
||||
|
||||
if (strcmp(pUser->user, "monitor") == 0 || strcmp(pUser->user, pUser->acct) == 0 ||
|
||||
(strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) {
|
||||
mnodeDecUserRef(pUser);
|
||||
return TSDB_CODE_MND_NO_RIGHTS;
|
||||
}
|
||||
|
||||
bool hasRight = false;
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0) {
|
||||
hasRight = false;
|
||||
} else if (strcmp(pOperUser->user, TSDB_DEFAULT_USER) == 0) {
|
||||
hasRight = true;
|
||||
} else if (strcmp(pUser->user, pOperUser->user) == 0) {
|
||||
hasRight = false;
|
||||
} else if (pOperUser->superAuth) {
|
||||
if (strcmp(pOperUser->acct, pUser->acct) != 0) {
|
||||
hasRight = false;
|
||||
} else {
|
||||
hasRight = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasRight) {
|
||||
code = mnodeDropUser(pUser, pMsg);
|
||||
} else {
|
||||
code = TSDB_CODE_MND_NO_RIGHTS;
|
||||
}
|
||||
|
||||
mnodeDecUserRef(pUser);
|
||||
return code;
|
||||
}
|
||||
|
||||
void mnodeDropAllUsers(SAcctObj *pAcct) {
|
||||
void * pIter = NULL;
|
||||
int32_t numOfUsers = 0;
|
||||
int32_t acctNameLen = (int32_t)strlen(pAcct->user);
|
||||
SUserObj *pUser = NULL;
|
||||
|
||||
while (1) {
|
||||
pIter = mnodeGetNextUser(pIter, &pUser);
|
||||
if (pUser == NULL) break;
|
||||
|
||||
if (strncmp(pUser->acct, pAcct->user, acctNameLen) == 0) {
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_LOCAL,
|
||||
.pTable = tsUserSdb,
|
||||
.pObj = pUser,
|
||||
};
|
||||
sdbDeleteRow(&row);
|
||||
numOfUsers++;
|
||||
}
|
||||
|
||||
mnodeDecUserRef(pUser);
|
||||
}
|
||||
|
||||
mDebug("acct:%s, all users:%d is dropped from sdb", pAcct->user, numOfUsers);
|
||||
}
|
||||
|
||||
int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
if (!sdbIsMaster()) {
|
||||
*secret = 0;
|
||||
mDebug("user:%s, failed to auth user, mnode is not master", user);
|
||||
return TSDB_CODE_APP_NOT_READY;
|
||||
}
|
||||
|
||||
SUserObj *pUser = mnodeGetUser(user);
|
||||
if (pUser == NULL) {
|
||||
*secret = 0;
|
||||
mError("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_MND_INVALID_USER));
|
||||
return TSDB_CODE_MND_INVALID_USER;
|
||||
} else {
|
||||
*spi = 1;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
|
||||
memcpy(secret, pUser->pass, TSDB_KEY_LEN);
|
||||
mnodeDecUserRef(pUser);
|
||||
mDebug("user:%s, auth info is returned", user);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg) {
|
||||
SAuthMsg *pAuthMsg = pMsg->rpcMsg.pCont;
|
||||
SAuthRsp *pAuthRsp = rpcMallocCont(sizeof(SAuthRsp));
|
||||
|
||||
pMsg->rpcRsp.rsp = pAuthRsp;
|
||||
pMsg->rpcRsp.len = sizeof(SAuthRsp);
|
||||
|
||||
return mnodeRetriveAuth(pAuthMsg->user, &pAuthRsp->spi, &pAuthRsp->encrypt, pAuthRsp->secret, pAuthRsp->ckey);
|
||||
}
|
||||
|
||||
int32_t mnodeCompactUsers() {
|
||||
void *pIter = NULL;
|
||||
SUserObj *pUser = NULL;
|
||||
|
||||
mInfo("start to compact users table...");
|
||||
|
||||
while (1) {
|
||||
pIter = mnodeGetNextUser(pIter, &pUser);
|
||||
if (pUser == NULL) break;
|
||||
|
||||
SSdbRow row = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.pTable = tsUserSdb,
|
||||
.pObj = pUser,
|
||||
.rowSize = sizeof(SUserObj),
|
||||
};
|
||||
|
||||
mInfo("compact users %s", pUser->user);
|
||||
|
||||
sdbInsertCompactRow(&row);
|
||||
}
|
||||
|
||||
mInfo("end to compact users table...");
|
||||
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* 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 "taosdef.h"
|
||||
#include "tsched.h"
|
||||
#include "tbn.h"
|
||||
#include "tgrant.h"
|
||||
#include "tglobal.h"
|
||||
#include "trpc.h"
|
||||
#include "mnode.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeVgroup.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeTable.h"
|
||||
#include "mnodeShow.h"
|
||||
|
||||
static int32_t (*tsMnodeProcessWriteMsgFp[TSDB_MSG_TYPE_MAX])(SMnodeMsg *);
|
||||
|
||||
void mnodeAddWriteMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg)) {
|
||||
tsMnodeProcessWriteMsgFp[msgType] = fp;
|
||||
}
|
||||
|
||||
int32_t mnodeProcessWrite(SMnodeMsg *pMsg) {
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, app:%p type:%s content is null", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
|
||||
return TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
}
|
||||
|
||||
if (!sdbIsMaster()) {
|
||||
SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
||||
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SRpcEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in write queue, is redirected, numOfEps:%d inUse:%d", pMsg,
|
||||
pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
return TSDB_CODE_RPC_REDIRECT;
|
||||
}
|
||||
|
||||
if (tsMnodeProcessWriteMsgFp[pMsg->rpcMsg.msgType] == NULL) {
|
||||
mError("msg:%p, app:%p type:%s not processed", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
|
||||
return TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
}
|
||||
|
||||
int32_t code = grantCheck(TSDB_GRANT_TIME);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
mError("msg:%p, app:%p type:%s not processed, reason:%s", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType],
|
||||
tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
code = mnodeInitMsg(pMsg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
mError("msg:%p, app:%p type:%s not processed, reason:%s", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType],
|
||||
tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (!pMsg->pUser->writeAuth) {
|
||||
mError("msg:%p, app:%p type:%s not processed, no write auth", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType]);
|
||||
return TSDB_CODE_MND_NO_RIGHTS;
|
||||
}
|
||||
|
||||
return (*tsMnodeProcessWriteMsgFp[pMsg->rpcMsg.msgType])(pMsg);
|
||||
}
|
Loading…
Reference in New Issue