提交 01fa777c 编写于 作者: A Alex Duan

feat(mnode): support show cluster status and show db.status commands

上级 ac483443
...@@ -4098,7 +4098,8 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4098,7 +4098,8 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
*/ */
SShowInfo* pShowInfo = &pInfo->pMiscInfo->showOpt; SShowInfo* pShowInfo = &pInfo->pMiscInfo->showOpt;
int16_t showType = pShowInfo->showType; int16_t showType = pShowInfo->showType;
if (showType == TSDB_MGMT_TABLE_TABLE || showType == TSDB_MGMT_TABLE_METRIC || showType == TSDB_MGMT_TABLE_VGROUP) { if (showType == TSDB_MGMT_TABLE_TABLE || showType == TSDB_MGMT_TABLE_METRIC || showType == TSDB_MGMT_TABLE_VGROUP ||
showType == TSDB_MGMT_STATUS_DB) {
// db prefix in tagCond, show table conds in payload // db prefix in tagCond, show table conds in payload
SStrToken* pDbPrefixToken = &pShowInfo->prefix; SStrToken* pDbPrefixToken = &pShowInfo->prefix;
if (pDbPrefixToken->type != 0) { if (pDbPrefixToken->type != 0) {
......
...@@ -163,6 +163,8 @@ enum _mgmt_table { ...@@ -163,6 +163,8 @@ enum _mgmt_table {
TSDB_MGMT_TABLE_CLUSTER, TSDB_MGMT_TABLE_CLUSTER,
TSDB_MGMT_TABLE_TP, TSDB_MGMT_TABLE_TP,
TSDB_MGMT_TABLE_FUNCTION, TSDB_MGMT_TABLE_FUNCTION,
TSDB_MGMT_STATUS_DB, // show database status
TSDB_MGMT_STATUS_CLUSTER, // show cluster status
TSDB_MGMT_TABLE_MAX, TSDB_MGMT_TABLE_MAX,
}; };
......
...@@ -88,139 +88,140 @@ ...@@ -88,139 +88,140 @@
#define TK_TABLES 70 #define TK_TABLES 70
#define TK_STABLES 71 #define TK_STABLES 71
#define TK_VGROUPS 72 #define TK_VGROUPS 72
#define TK_DROP 73 #define TK_STATUS 73
#define TK_TOPIC 74 #define TK_CLUSTER 74
#define TK_FUNCTION 75 #define TK_DROP 75
#define TK_DNODE 76 #define TK_TOPIC 76
#define TK_USER 77 #define TK_FUNCTION 77
#define TK_ACCOUNT 78 #define TK_DNODE 78
#define TK_USE 79 #define TK_USER 79
#define TK_DESCRIBE 80 #define TK_ACCOUNT 80
#define TK_DESC 81 #define TK_USE 81
#define TK_ALTER 82 #define TK_DESCRIBE 82
#define TK_PASS 83 #define TK_DESC 83
#define TK_PRIVILEGE 84 #define TK_ALTER 84
#define TK_TAGS 85 #define TK_PASS 85
#define TK_LOCAL 86 #define TK_PRIVILEGE 86
#define TK_COMPACT 87 #define TK_TAGS 87
#define TK_LP 88 #define TK_LOCAL 88
#define TK_RP 89 #define TK_COMPACT 89
#define TK_IF 90 #define TK_LP 90
#define TK_EXISTS 91 #define TK_RP 91
#define TK_AS 92 #define TK_IF 92
#define TK_OUTPUTTYPE 93 #define TK_EXISTS 93
#define TK_AGGREGATE 94 #define TK_AS 94
#define TK_BUFSIZE 95 #define TK_OUTPUTTYPE 95
#define TK_PPS 96 #define TK_AGGREGATE 96
#define TK_TSERIES 97 #define TK_BUFSIZE 97
#define TK_DBS 98 #define TK_PPS 98
#define TK_STORAGE 99 #define TK_TSERIES 99
#define TK_QTIME 100 #define TK_DBS 100
#define TK_CONNS 101 #define TK_STORAGE 101
#define TK_STATE 102 #define TK_QTIME 102
#define TK_COMMA 103 #define TK_CONNS 103
#define TK_KEEP 104 #define TK_STATE 104
#define TK_CACHE 105 #define TK_COMMA 105
#define TK_REPLICA 106 #define TK_KEEP 106
#define TK_QUORUM 107 #define TK_CACHE 107
#define TK_DAYS 108 #define TK_REPLICA 108
#define TK_MINROWS 109 #define TK_QUORUM 109
#define TK_MAXROWS 110 #define TK_DAYS 110
#define TK_BLOCKS 111 #define TK_MINROWS 111
#define TK_CTIME 112 #define TK_MAXROWS 112
#define TK_WAL 113 #define TK_BLOCKS 113
#define TK_FSYNC 114 #define TK_CTIME 114
#define TK_COMP 115 #define TK_WAL 115
#define TK_PRECISION 116 #define TK_FSYNC 116
#define TK_UPDATE 117 #define TK_COMP 117
#define TK_CACHELAST 118 #define TK_PRECISION 118
#define TK_PARTITIONS 119 #define TK_UPDATE 119
#define TK_UNSIGNED 120 #define TK_CACHELAST 120
#define TK_USING 121 #define TK_PARTITIONS 121
#define TK_TO 122 #define TK_UNSIGNED 122
#define TK_SPLIT 123 #define TK_USING 123
#define TK_NULL 124 #define TK_TO 124
#define TK_NOW 125 #define TK_SPLIT 125
#define TK_VARIABLE 126 #define TK_NULL 126
#define TK_SELECT 127 #define TK_NOW 127
#define TK_UNION 128 #define TK_VARIABLE 128
#define TK_ALL 129 #define TK_SELECT 129
#define TK_DISTINCT 130 #define TK_UNION 130
#define TK_FROM 131 #define TK_ALL 131
#define TK_RANGE 132 #define TK_DISTINCT 132
#define TK_INTERVAL 133 #define TK_FROM 133
#define TK_EVERY 134 #define TK_RANGE 134
#define TK_SESSION 135 #define TK_INTERVAL 135
#define TK_STATE_WINDOW 136 #define TK_EVERY 136
#define TK_FILL 137 #define TK_SESSION 137
#define TK_SLIDING 138 #define TK_STATE_WINDOW 138
#define TK_ORDER 139 #define TK_FILL 139
#define TK_BY 140 #define TK_SLIDING 140
#define TK_ASC 141 #define TK_ORDER 141
#define TK_GROUP 142 #define TK_BY 142
#define TK_HAVING 143 #define TK_ASC 143
#define TK_LIMIT 144 #define TK_GROUP 144
#define TK_OFFSET 145 #define TK_HAVING 145
#define TK_SLIMIT 146 #define TK_LIMIT 146
#define TK_SOFFSET 147 #define TK_OFFSET 147
#define TK_WHERE 148 #define TK_SLIMIT 148
#define TK_TODAY 149 #define TK_SOFFSET 149
#define TK_RESET 150 #define TK_WHERE 150
#define TK_QUERY 151 #define TK_TODAY 151
#define TK_SYNCDB 152 #define TK_RESET 152
#define TK_ADD 153 #define TK_QUERY 153
#define TK_COLUMN 154 #define TK_SYNCDB 154
#define TK_MODIFY 155 #define TK_ADD 155
#define TK_TAG 156 #define TK_COLUMN 156
#define TK_CHANGE 157 #define TK_MODIFY 157
#define TK_SET 158 #define TK_TAG 158
#define TK_KILL 159 #define TK_CHANGE 159
#define TK_CONNECTION 160 #define TK_SET 160
#define TK_STREAM 161 #define TK_KILL 161
#define TK_COLON 162 #define TK_CONNECTION 162
#define TK_DELETE 163 #define TK_STREAM 163
#define TK_ABORT 164 #define TK_COLON 164
#define TK_AFTER 165 #define TK_DELETE 165
#define TK_ATTACH 166 #define TK_ABORT 166
#define TK_BEFORE 167 #define TK_AFTER 167
#define TK_BEGIN 168 #define TK_ATTACH 168
#define TK_CASCADE 169 #define TK_BEFORE 169
#define TK_CLUSTER 170 #define TK_BEGIN 170
#define TK_CONFLICT 171 #define TK_CASCADE 171
#define TK_COPY 172 #define TK_CONFLICT 172
#define TK_DEFERRED 173 #define TK_COPY 173
#define TK_DELIMITERS 174 #define TK_DEFERRED 174
#define TK_DETACH 175 #define TK_DELIMITERS 175
#define TK_EACH 176 #define TK_DETACH 176
#define TK_END 177 #define TK_EACH 177
#define TK_EXPLAIN 178 #define TK_END 178
#define TK_FAIL 179 #define TK_EXPLAIN 179
#define TK_FOR 180 #define TK_FAIL 180
#define TK_IGNORE 181 #define TK_FOR 181
#define TK_IMMEDIATE 182 #define TK_IGNORE 182
#define TK_INITIALLY 183 #define TK_IMMEDIATE 183
#define TK_INSTEAD 184 #define TK_INITIALLY 184
#define TK_KEY 185 #define TK_INSTEAD 185
#define TK_OF 186 #define TK_KEY 186
#define TK_RAISE 187 #define TK_OF 187
#define TK_REPLACE 188 #define TK_RAISE 188
#define TK_RESTRICT 189 #define TK_REPLACE 189
#define TK_ROW 190 #define TK_RESTRICT 190
#define TK_STATEMENT 191 #define TK_ROW 191
#define TK_TRIGGER 192 #define TK_STATEMENT 192
#define TK_VIEW 193 #define TK_TRIGGER 193
#define TK_IPTOKEN 194 #define TK_VIEW 194
#define TK_SEMI 195 #define TK_IPTOKEN 195
#define TK_NONE 196 #define TK_SEMI 196
#define TK_PREV 197 #define TK_NONE 197
#define TK_LINEAR 198 #define TK_PREV 198
#define TK_IMPORT 199 #define TK_LINEAR 199
#define TK_TBNAME 200 #define TK_IMPORT 200
#define TK_JOIN 201 #define TK_TBNAME 201
#define TK_INSERT 202 #define TK_JOIN 202
#define TK_INTO 203 #define TK_INSERT 203
#define TK_VALUES 204 #define TK_INTO 204
#define TK_FILE 205 #define TK_VALUES 205
#define TK_FILE 206
#define TK_SPACE 300 #define TK_SPACE 300
......
...@@ -110,6 +110,8 @@ static char *mnodeGetShowType(int32_t showType) { ...@@ -110,6 +110,8 @@ static char *mnodeGetShowType(int32_t showType) {
case TSDB_MGMT_TABLE_CLUSTER: return "show clusters"; case TSDB_MGMT_TABLE_CLUSTER: return "show clusters";
case TSDB_MGMT_TABLE_STREAMTABLES : return "show streamtables"; case TSDB_MGMT_TABLE_STREAMTABLES : return "show streamtables";
case TSDB_MGMT_TABLE_TP: return "show topics"; case TSDB_MGMT_TABLE_TP: return "show topics";
case TSDB_MGMT_STATUS_DB: return "show database status";
case TSDB_MGMT_STATUS_CLUSTER: return "show cluster status";
default: return "undefined"; default: return "undefined";
} }
} }
......
...@@ -235,6 +235,15 @@ int32_t mnodeInitVgroups() { ...@@ -235,6 +235,15 @@ int32_t mnodeInitVgroups() {
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_VGROUP, mnodeGetVgroupMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_VGROUP, mnodeGetVgroupMeta);
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_VGROUP, mnodeRetrieveVgroups); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_VGROUP, mnodeRetrieveVgroups);
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_VGROUP, mnodeCancelGetNextVgroup); mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_VGROUP, mnodeCancelGetNextVgroup);
// cluster status
mnodeAddShowMetaHandle(TSDB_MGMT_STATUS_CLUSTER, mnodeGetStatusMeta);
mnodeAddShowRetrieveHandle(TSDB_MGMT_STATUS_CLUSTER, mnodeRetrieveStatus);
mnodeAddShowFreeIterHandle(TSDB_MGMT_STATUS_CLUSTER, mnodeCancelGetNextVgroup);
// db status
mnodeAddShowMetaHandle(TSDB_MGMT_STATUS_DB, mnodeGetStatusMeta);
mnodeAddShowRetrieveHandle(TSDB_MGMT_STATUS_DB, mnodeRetrieveStatus);
mnodeAddShowFreeIterHandle(TSDB_MGMT_STATUS_DB, mnodeCancelGetNextVgroup);
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP, mnodeProcessCreateVnodeRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP, mnodeProcessCreateVnodeRsp);
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP, mnodeProcessAlterVnodeRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP, mnodeProcessAlterVnodeRsp);
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_COMPACT_VNODE_RSP, mnodeProcessCompactVnodeRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_COMPACT_VNODE_RSP, mnodeProcessCompactVnodeRsp);
...@@ -779,6 +788,170 @@ static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p ...@@ -779,6 +788,170 @@ static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p
return 0; return 0;
} }
static int32_t mnodeGetStatusMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) {
return TSDB_CODE_MND_DB_NOT_SELECTED;
}
if (pDb->status != TSDB_DB_STATUS_READY) {
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
mnodeDecDbRef(pDb);
return TSDB_CODE_MND_DB_IN_DROPPING;
}
int32_t cols = 0;
SSchema *pSchema = pMeta->schema;
pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "vgId");
pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++;
pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "tables");
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, "status");
pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++;
pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "onlines");
pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++;
pShow->maxReplica = 1;
for (int32_t v = 0; v < pDb->numOfVgroups; ++v) {
SVgObj *pVgroup = pDb->vgList[v];
if (pVgroup != NULL) {
pShow->maxReplica = pVgroup->numOfVnodes > pShow->maxReplica ? pVgroup->numOfVnodes : pShow->maxReplica;
}
}
for (int32_t i = 0; i < pShow->maxReplica; ++i) {
pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%d_dnode", i + 1);
pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++;
pShow->bytes[cols] = 9 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%d_status", i + 1);
pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++;
}
pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "compacting");
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 = pDb->numOfVgroups;
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
mnodeDecDbRef(pDb);
return 0;
}
static int32_t mnodeRetrieveStatus(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0;
SVgObj *pVgroup = NULL;
int32_t cols = 0;
char * pWrite;
SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) return 0;
if (pDb->status != TSDB_DB_STATUS_READY) {
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
mnodeDecDbRef(pDb);
return 0;
}
while (numOfRows < rows) {
pShow->pIter = mnodeGetNextVgroup(pShow->pIter, &pVgroup);
if (pVgroup == NULL) break;
if (pVgroup->pDb != pDb) {
mnodeDecVgroupRef(pVgroup);
continue;
}
cols = 0;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int32_t *) pWrite = pVgroup->vgId;
cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int32_t *) pWrite = pVgroup->numOfTables;
cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
char* status = vgroupStatus[pVgroup->status];
STR_TO_VARSTR(pWrite, status);
cols++;
int32_t onlineVnodes = 0;
for (int32_t i = 0; i < pShow->maxReplica; ++i) {
if (pVgroup->vnodeGid[i].role == TAOS_SYNC_ROLE_SLAVE || pVgroup->vnodeGid[i].role == TAOS_SYNC_ROLE_MASTER) {
onlineVnodes++;
}
}
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int32_t *)pWrite = onlineVnodes;
cols++;
for (int32_t i = 0; i < pShow->maxReplica; ++i) {
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int16_t *) pWrite = pVgroup->vnodeGid[i].dnodeId;
cols++;
SDnodeObj * pDnode = pVgroup->vnodeGid[i].pDnode;
const char *role = "NULL";
if (pDnode != NULL) {
role = syncRole[pVgroup->vnodeGid[i].role];
}
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, role, pShow->bytes[cols]);
cols++;
}
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int8_t *)pWrite = pVgroup->compact;
cols++;
mnodeDecVgroupRef(pVgroup);
numOfRows++;
}
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
pShow->numOfReads += numOfRows;
mnodeDecDbRef(pDb);
return numOfRows;
}
static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn) { static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
......
...@@ -127,6 +127,19 @@ cmd ::= SHOW dbPrefix(X) VGROUPS. { ...@@ -127,6 +127,19 @@ cmd ::= SHOW dbPrefix(X) VGROUPS. {
setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0); setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0);
} }
// show db.status
cmd ::= SHOW dbPrefix(X) STATUS. {
SStrToken token;
tSetDbName(&token, &X);
setShowOptions(pInfo, TSDB_MGMT_STATUS_DB, &token, 0);
}
// show cluster status
cmd ::= SHOW CLUSTER STATUS. {
SStrToken token;
setShowOptions(pInfo, TSDB_MGMT_STATUS_CLUSTER, &token, 0);
}
//drop configure for tables //drop configure for tables
cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). { cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). {
X.n += Z.n; X.n += Z.n;
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册