add show trans
This commit is contained in:
parent
37c8476118
commit
6d582b2a29
|
@ -100,7 +100,7 @@ typedef enum _mgmt_table {
|
||||||
TSDB_MGMT_TABLE_STREAMS,
|
TSDB_MGMT_TABLE_STREAMS,
|
||||||
TSDB_MGMT_TABLE_VARIABLES,
|
TSDB_MGMT_TABLE_VARIABLES,
|
||||||
TSDB_MGMT_TABLE_CONNS,
|
TSDB_MGMT_TABLE_CONNS,
|
||||||
TSDB_MGMT_TABLE_SCORES,
|
TSDB_MGMT_TABLE_TRANS,
|
||||||
TSDB_MGMT_TABLE_GRANTS,
|
TSDB_MGMT_TABLE_GRANTS,
|
||||||
TSDB_MGMT_TABLE_VNODES,
|
TSDB_MGMT_TABLE_VNODES,
|
||||||
TSDB_MGMT_TABLE_CLUSTER,
|
TSDB_MGMT_TABLE_CLUSTER,
|
||||||
|
|
|
@ -214,6 +214,10 @@ do { \
|
||||||
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
||||||
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
||||||
|
|
||||||
|
#define TSDB_TRANS_STAGE_LEN 12
|
||||||
|
#define TSDB_TRANS_DESC_LEN 16
|
||||||
|
#define TSDB_TRANS_ERROR_LEN 128
|
||||||
|
|
||||||
#define TSDB_STEP_NAME_LEN 32
|
#define TSDB_STEP_NAME_LEN 32
|
||||||
#define TSDB_STEP_DESC_LEN 128
|
#define TSDB_STEP_DESC_LEN 128
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,10 @@ typedef enum {
|
||||||
TRN_STAGE_FINISHED = 8
|
TRN_STAGE_FINISHED = 8
|
||||||
} ETrnStage;
|
} ETrnStage;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TRN_TYPE_CREATE_DB = 0,
|
||||||
|
} ETrnType;
|
||||||
|
|
||||||
typedef enum { TRN_POLICY_ROLLBACK = 0, TRN_POLICY_RETRY = 1 } ETrnPolicy;
|
typedef enum { TRN_POLICY_ROLLBACK = 0, TRN_POLICY_RETRY = 1 } ETrnPolicy;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -135,6 +139,12 @@ typedef struct {
|
||||||
SArray* commitLogs;
|
SArray* commitLogs;
|
||||||
SArray* redoActions;
|
SArray* redoActions;
|
||||||
SArray* undoActions;
|
SArray* undoActions;
|
||||||
|
int64_t createdTime;
|
||||||
|
int64_t lastExecTime;
|
||||||
|
int32_t transType;
|
||||||
|
uint64_t dbUid;
|
||||||
|
char dbname[TSDB_DB_NAME_LEN];
|
||||||
|
char lastError[TSDB_TRANS_DESC_LEN];
|
||||||
} STrans;
|
} STrans;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -295,8 +295,8 @@ char *mndShowStr(int32_t showType) {
|
||||||
return "show configs";
|
return "show configs";
|
||||||
case TSDB_MGMT_TABLE_CONNS:
|
case TSDB_MGMT_TABLE_CONNS:
|
||||||
return "show connections";
|
return "show connections";
|
||||||
case TSDB_MGMT_TABLE_SCORES:
|
case TSDB_MGMT_TABLE_TRANS:
|
||||||
return "show scores";
|
return "show trans";
|
||||||
case TSDB_MGMT_TABLE_GRANTS:
|
case TSDB_MGMT_TABLE_GRANTS:
|
||||||
return "show grants";
|
return "show grants";
|
||||||
case TSDB_MGMT_TABLE_VNODES:
|
case TSDB_MGMT_TABLE_VNODES:
|
||||||
|
|
|
@ -15,10 +15,13 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
#include "mndAuth.h"
|
||||||
|
#include "mndShow.h"
|
||||||
#include "mndSync.h"
|
#include "mndSync.h"
|
||||||
|
#include "mndUser.h"
|
||||||
|
|
||||||
#define MND_TRANS_VER_NUMBER 1
|
#define MND_TRANS_VER_NUMBER 1
|
||||||
#define MND_TRANS_ARRAY_SIZE 8
|
#define MND_TRANS_ARRAY_SIZE 8
|
||||||
#define MND_TRANS_RESERVE_SIZE 64
|
#define MND_TRANS_RESERVE_SIZE 64
|
||||||
|
|
||||||
static SSdbRaw *mndTransActionEncode(STrans *pTrans);
|
static SSdbRaw *mndTransActionEncode(STrans *pTrans);
|
||||||
|
@ -53,6 +56,10 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans);
|
||||||
static void mndTransSendRpcRsp(STrans *pTrans);
|
static void mndTransSendRpcRsp(STrans *pTrans);
|
||||||
static int32_t mndProcessTransReq(SMnodeMsg *pMsg);
|
static int32_t mndProcessTransReq(SMnodeMsg *pMsg);
|
||||||
|
|
||||||
|
static int32_t mndGetTransMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta);
|
||||||
|
static int32_t mndRetrieveTrans(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||||
|
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter);
|
||||||
|
|
||||||
int32_t mndInitTrans(SMnode *pMnode) {
|
int32_t mndInitTrans(SMnode *pMnode) {
|
||||||
SSdbTable table = {.sdbType = SDB_TRANS,
|
SSdbTable table = {.sdbType = SDB_TRANS,
|
||||||
.keyType = SDB_KEY_INT32,
|
.keyType = SDB_KEY_INT32,
|
||||||
|
@ -63,6 +70,10 @@ int32_t mndInitTrans(SMnode *pMnode) {
|
||||||
.deleteFp = (SdbDeleteFp)mndTransActionDelete};
|
.deleteFp = (SdbDeleteFp)mndTransActionDelete};
|
||||||
|
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_TRANS, mndProcessTransReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_TRANS, mndProcessTransReq);
|
||||||
|
|
||||||
|
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndGetTransMeta);
|
||||||
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndRetrieveTrans);
|
||||||
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndCancelGetNextTrans);
|
||||||
return sdbSetTable(pMnode->pSdb, table);
|
return sdbSetTable(pMnode->pSdb, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,6 +332,15 @@ static const char *mndTransStr(ETrnStage stage) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *mndTransType(ETrnType type) {
|
||||||
|
switch (type) {
|
||||||
|
case TRN_TYPE_CREATE_DB:
|
||||||
|
return "create-db";
|
||||||
|
default:
|
||||||
|
return "invalid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
|
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
|
||||||
// pTrans->stage = TRN_STAGE_PREPARE;
|
// pTrans->stage = TRN_STAGE_PREPARE;
|
||||||
mTrace("trans:%d, perform insert action, row:%p stage:%s", pTrans->id, pTrans, mndTransStr(pTrans->stage));
|
mTrace("trans:%d, perform insert action, row:%p stage:%s", pTrans->id, pTrans, mndTransStr(pTrans->stage));
|
||||||
|
@ -988,3 +1008,122 @@ void mndTransPullup(SMnode *pMnode) {
|
||||||
|
|
||||||
sdbWriteFile(pMnode->pSdb);
|
sdbWriteFile(pMnode->pSdb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t mndGetTransMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) {
|
||||||
|
SMnode *pMnode = pReq->pMnode;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
|
||||||
|
int32_t cols = 0;
|
||||||
|
SSchema *pSchema = pMeta->pSchemas;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 4;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||||
|
strcpy(pSchema[cols].name, "id");
|
||||||
|
pSchema[cols].bytes = pShow->bytes[cols];
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 8;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
|
strcpy(pSchema[cols].name, "create_time");
|
||||||
|
pSchema[cols].bytes = pShow->bytes[cols];
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = TSDB_TRANS_STAGE_LEN + VARSTR_HEADER_SIZE;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
strcpy(pSchema[cols].name, "stage");
|
||||||
|
pSchema[cols].bytes = pShow->bytes[cols];
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
strcpy(pSchema[cols].name, "db");
|
||||||
|
pSchema[cols].bytes = pShow->bytes[cols];
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = (TSDB_TRANS_DESC_LEN - 1) + VARSTR_HEADER_SIZE;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
strcpy(pSchema[cols].name, "type");
|
||||||
|
pSchema[cols].bytes = pShow->bytes[cols];
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 8;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
|
strcpy(pSchema[cols].name, "last_exec_time");
|
||||||
|
pSchema[cols].bytes = pShow->bytes[cols];
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
strcpy(pSchema[cols].name, "last_error");
|
||||||
|
pSchema[cols].bytes = pShow->bytes[cols];
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pMeta->numOfColumns = 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 = sdbGetSize(pSdb, SDB_TRANS);
|
||||||
|
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||||
|
strcpy(pMeta->tbName, mndShowStr(pShow->type));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndRetrieveTrans(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||||
|
SMnode *pMnode = pReq->pMnode;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
int32_t numOfRows = 0;
|
||||||
|
STrans *pTrans = NULL;
|
||||||
|
int32_t cols = 0;
|
||||||
|
char *pWrite;
|
||||||
|
|
||||||
|
while (numOfRows < rows) {
|
||||||
|
pShow->pIter = sdbFetch(pSdb, SDB_TRANS, pShow->pIter, (void **)&pTrans);
|
||||||
|
if (pShow->pIter == NULL) break;
|
||||||
|
|
||||||
|
cols = 0;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int32_t *)pWrite = pTrans->id;
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int64_t *)pWrite = pTrans->createdTime;
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
STR_TO_VARSTR(pWrite, mndTransStr(pTrans->stage));
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
STR_TO_VARSTR(pWrite, pTrans->dbname);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
STR_TO_VARSTR(pWrite, mndTransType(pTrans->transType));
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int64_t *)pWrite = pTrans->lastExecTime;
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
STR_TO_VARSTR(pWrite, pTrans->lastError);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
numOfRows++;
|
||||||
|
sdbRelease(pSdb, pTrans);
|
||||||
|
}
|
||||||
|
|
||||||
|
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||||
|
pShow->numOfReads += numOfRows;
|
||||||
|
return numOfRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ cmd ::= SHOW QUERIES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_QUERIES, 0, 0);
|
||||||
cmd ::= SHOW CONNECTIONS.{ setShowOptions(pInfo, TSDB_MGMT_TABLE_CONNS, 0, 0);}
|
cmd ::= SHOW CONNECTIONS.{ setShowOptions(pInfo, TSDB_MGMT_TABLE_CONNS, 0, 0);}
|
||||||
cmd ::= SHOW STREAMS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_STREAMS, 0, 0); }
|
cmd ::= SHOW STREAMS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_STREAMS, 0, 0); }
|
||||||
cmd ::= SHOW VARIABLES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VARIABLES, 0, 0); }
|
cmd ::= SHOW VARIABLES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VARIABLES, 0, 0); }
|
||||||
cmd ::= SHOW SCORES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_SCORES, 0, 0); }
|
cmd ::= SHOW SCORES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_TRANS, 0, 0); }
|
||||||
cmd ::= SHOW GRANTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); }
|
cmd ::= SHOW GRANTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); }
|
||||||
|
|
||||||
cmd ::= SHOW VNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); }
|
cmd ::= SHOW VNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); }
|
||||||
|
|
|
@ -2262,7 +2262,7 @@ static void yy_reduce(
|
||||||
{ setShowOptions(pInfo, TSDB_MGMT_TABLE_VARIABLES, 0, 0); }
|
{ setShowOptions(pInfo, TSDB_MGMT_TABLE_VARIABLES, 0, 0); }
|
||||||
break;
|
break;
|
||||||
case 13: /* cmd ::= SHOW SCORES */
|
case 13: /* cmd ::= SHOW SCORES */
|
||||||
{ setShowOptions(pInfo, TSDB_MGMT_TABLE_SCORES, 0, 0); }
|
{ setShowOptions(pInfo, TSDB_MGMT_TABLE_TRANS, 0, 0); }
|
||||||
break;
|
break;
|
||||||
case 14: /* cmd ::= SHOW GRANTS */
|
case 14: /* cmd ::= SHOW GRANTS */
|
||||||
{ setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); }
|
{ setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); }
|
||||||
|
|
Loading…
Reference in New Issue