Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh:[td 29974]improve trans #29165

Open
wants to merge 31 commits into
base: 3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
623017b
dmchen/trans-improve-show
cadem Nov 7, 2024
d0d26c0
dmchen/add-detail-show
cadem Nov 7, 2024
d6d5be5
dmchen/trans-improve-show -vgid
cadem Nov 8, 2024
50affc9
dmchen/trans-improve-show-all
cadem Nov 8, 2024
43e7fc3
dmchen/trans-improve-show-all-trans
cadem Nov 8, 2024
6bda1a9
dmchen/trans-improve-format
cadem Nov 8, 2024
81c066e
fix/trans-improve-rename-field-name
cadem Nov 11, 2024
03ba1bd
fix/trans-improve-refactor
cadem Nov 11, 2024
cb87990
fix/trans-improve-field-len
cadem Nov 11, 2024
46877ca
fix/trans-improve-remove-todo
cadem Nov 11, 2024
c8252ad
fix/release iter
cadem Nov 12, 2024
930a193
fix/set lastaction
cadem Nov 12, 2024
11be1b1
fix/add-balance-leader-case
cadem Nov 13, 2024
2e3f9c0
fix/add-kill-restore-case
cadem Nov 13, 2024
ca8c1ea
fix/showtransaction detial case
cadem Nov 14, 2024
8c14e3b
fix/add-show-transaction-detail-case
cadem Nov 14, 2024
641816e
fix/remove-alter-db-kill-mode
cadem Nov 14, 2024
20cc54a
Merge branch 'enh/TD-29974-improve-trans' into dmchen/trans-improve
cadem Dec 16, 2024
7fee0a0
Merge pull request #29148 from taosdata/dmchen/trans-improve
cadem Dec 16, 2024
ce86b1d
change show transtion detial timestamp
cadem Dec 16, 2024
4b6eec2
enh/TD-29974-improve-trans-fix-case
cadem Dec 17, 2024
26507e6
enh/TD-29974-improve-trans-fix-case
cadem Dec 17, 2024
fead1a9
enh/TD-29974-improve-trans-fix-case
cadem Dec 17, 2024
134d593
enh/TD-29974-improve-trans-fix-case
cadem Dec 17, 2024
2d29f5a
enh/TD-29974-improve-trans-fix-case
cadem Dec 17, 2024
344c51f
enh/TD-29974-improve-trans-fix-case
cadem Dec 17, 2024
6f124e7
enh/TD-29974-improve-trans-fix-case
cadem Dec 17, 2024
69980ac
Merge pull request #29194 from taosdata/3.0
cadem Dec 18, 2024
79b3267
enh/TD-29974-improve-trans-fix-case
cadem Dec 18, 2024
5976d4e
enh/TD-29974-improve-trans-fix-case
cadem Dec 18, 2024
1bf7644
enh/TD-29974-improve-trans-fix-comment
cadem Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/en/08-operation/04-maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TDengine is designed for various writing scenarios, and many of these scenarios

```sql
COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY'];
SHOW COMPACTS [compact_id];
SHOW COMPACT [compact_id];
KILL COMPACT compact_id;
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en/14-reference/03-taos-sql/24-show.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ Displays information about all topics in the current database.

```sql
SHOW TRANSACTIONS;
SHOW TRANSACTION [tranaction_id];
```

Displays information about transactions currently being executed in the system (these transactions are only for metadata level, not for regular tables).
Displays information about one of or all transaction(s) currently being executed in the system (these transactions are only for metadata level, not for regular tables).

## SHOW USERS

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/08-operation/04-maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TDengine 面向多种写入场景,而很多写入场景下,TDengine 的存
```SQL
COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY'];
COMPACT [db_name.]VGROUPS IN (vgroup_id1, vgroup_id2, ...) [start with 'XXXX'] [end with 'YYYY'];
SHOW COMPACTS [compact_id];
SHOW COMPACT [compact_id];
KILL COMPACT compact_id;
```

Expand Down
3 changes: 2 additions & 1 deletion docs/zh/14-reference/03-taos-sql/24-show.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,10 @@ SHOW TOPICS;

```sql
SHOW TRANSACTIONS;
SHOW TRANSACTION [tranaction_id];
```

显示当前系统中正在执行的事务的信息(该事务仅针对除普通表以外的元数据级别)
显示当前系统中正在执行的所有或者某一个事务的信息(该事务仅针对除普通表以外的元数据级别)

## SHOW USERS

Expand Down
1 change: 1 addition & 0 deletions include/common/systable.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern "C" {
#define TSDB_INS_TABLE_TSMAS "ins_tsmas"
#define TSDB_INS_DISK_USAGE "ins_disk_usage"
#define TSDB_INS_TABLE_FILESETS "ins_filesets"
#define TSDB_INS_TABLE_TRANSACTION_DETAILS "ins_transaction_details"

#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
#define TSDB_PERFS_TABLE_SMAS "perf_smas"
Expand Down
2 changes: 2 additions & 0 deletions include/common/tmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ typedef enum _mgmt_table {
TSDB_MGMT_TABLE_ANODE_FULL,
TSDB_MGMT_TABLE_USAGE,
TSDB_MGMT_TABLE_FILESETS,
TSDB_MGMT_TABLE_TRANSACTION_DETAIL,
TSDB_MGMT_TABLE_MAX,
} EShowType;

Expand Down Expand Up @@ -405,6 +406,7 @@ typedef enum ENodeType {
QUERY_NODE_SHOW_CREATE_TSMA_STMT,
QUERY_NODE_DROP_TSMA_STMT,
QUERY_NODE_SHOW_FILESETS_STMT,
QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,

// logic plan node
QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
Expand Down
5 changes: 5 additions & 0 deletions include/libs/nodes/cmdnodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ typedef struct SShowCompactDetailsStmt {
SNode* pCompactId;
} SShowCompactDetailsStmt;

typedef struct SShowTransactionDetailsStmt {
ENodeType type;
SNode* pTransactionId;
} SShowTransactionDetailsStmt;

typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT, INDEX_TYPE_NORMAL } EIndexType;

typedef struct SIndexOptions {
Expand Down
1 change: 1 addition & 0 deletions include/util/taoserror.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ int32_t taosGetErrSize();
#define TSDB_CODE_MND_TRANS_CTX_SWITCH TAOS_DEF_ERROR_CODE(0, 0x03D8)
#define TSDB_CODE_MND_TRANS_CONFLICT_COMPACT TAOS_DEF_ERROR_CODE(0, 0x03D9)
#define TSDB_CODE_MND_TRANS_UNKNOW_ERROR TAOS_DEF_ERROR_CODE(0, 0x03DF)
#define TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED TAOS_DEF_ERROR_CODE(0, 0x03D2)

// mnode-mq
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0)
Expand Down
6 changes: 5 additions & 1 deletion include/util/tdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ typedef enum ELogicConditionType {

#define TSDB_TRANS_STAGE_LEN 12
#define TSDB_TRANS_TYPE_LEN 16
#define TSDB_TRANS_ERROR_LEN 512
#define TSDB_TRANS_ERROR_LEN 512
#define TSDB_TRANS_OBJTYPE_LEN 40
#define TSDB_TRANS_RESULT_LEN 100
#define TSDB_TRANS_TARGET_LEN 300
#define TSDB_TRANS_DETAIL_LEN 100

#define TSDB_STEP_NAME_LEN 32
#define TSDB_STEP_DESC_LEN 128
Expand Down
12 changes: 12 additions & 0 deletions source/common/src/systable.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ static const SSysDbTableSchema transSchema[] = {
{.name = "oper", .bytes = TSDB_TRANS_OPER_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "stable", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "killable", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
//{.name = "kill_mnode", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "failed_times", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
{.name = "last_action_info", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
Expand Down Expand Up @@ -403,6 +405,15 @@ static const SSysDbTableSchema userCompactsDetailSchema[] = {
{.name = "remain_time(s)", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = false},
};

static const SSysDbTableSchema userTransactionDetailSchema[] = {
{.name = "transaction_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "action", .bytes = 30 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "obj_type", .bytes = TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "result", .bytes = TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "target", .bytes = TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "detail", .bytes = TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
};

static const SSysDbTableSchema anodesSchema[] = {
{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
{.name = "url", .bytes = TSDB_ANALYTIC_ANODE_URL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
Expand Down Expand Up @@ -521,6 +532,7 @@ static const SSysTableMeta infosMeta[] = {
{TSDB_INS_TABLE_ANODES_FULL, anodesFullSchema, tListLen(anodesFullSchema), true},
{TSDB_INS_DISK_USAGE, diskUsageSchema, tListLen(diskUsageSchema), false},
{TSDB_INS_TABLE_FILESETS, filesetsFullSchema, tListLen(filesetsFullSchema), false},
{TSDB_INS_TABLE_TRANSACTION_DETAILS, userTransactionDetailSchema, tListLen(userTransactionDetailSchema), false},
};

static const SSysDbTableSchema connectionsSchema[] = {
Expand Down
1 change: 1 addition & 0 deletions source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
return TSDB_CODE_INVALID_MSG;
}
dInfo("retrieve table:%s, user:%s, compactId:%" PRId64, retrieveReq.tb, retrieveReq.user, retrieveReq.compactId);
#if 0
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
code = TSDB_CODE_MND_NO_RIGHTS;
Expand Down
8 changes: 8 additions & 0 deletions source/dnode/mnode/impl/inc/mndDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ typedef enum {
TRN_EXEC_SERIAL = 1,
} ETrnExec;

typedef enum {
TRN_KILL_MODE_SKIP = 0,
TRN_KILL_MODE_INTERUPT = 1,
//TRN_KILL_MODE_ROLLBACK = 2,
} ETrnKillMode;

typedef enum {
DND_REASON_ONLINE = 0,
DND_REASON_STATUS_MSG_TIMEOUT,
Expand Down Expand Up @@ -201,6 +207,8 @@ typedef struct {
SRWLatch lockRpcArray;
int64_t mTraceId;
TdThreadMutex mutex;
bool ableToBeKilled;
ETrnKillMode killMode;
} STrans;

typedef struct {
Expand Down
4 changes: 4 additions & 0 deletions source/dnode/mnode/impl/inc/mndTrans.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ typedef struct {
SSdbRaw *pRaw;

int64_t mTraceId;
int64_t startTime;
int64_t endTime;
} STransAction;

typedef void (*TransCbFp)(SMnode *pMnode, void *param, int32_t paramLen);
Expand All @@ -80,6 +82,8 @@ void mndTransSetCb(STrans *pTrans, ETrnFunc startFunc, ETrnFunc stopFunc, voi
void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbname);
void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId);
void mndTransSetSerial(STrans *pTrans);
void mndTransSetBeKilled(STrans *pTrans, bool ableToBeKilled);
void mndTransSetKillMode(STrans *pTrans, ETrnKillMode killMode);
void mndTransSetParallel(STrans *pTrans);
void mndTransSetChangeless(STrans *pTrans);
void mndTransSetOper(STrans *pTrans, EOperType oper);
Expand Down
2 changes: 2 additions & 0 deletions source/dnode/mnode/impl/src/mndCompactDetail.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
char *sep = NULL;
SDbObj *pDb = NULL;

mInfo("retrieve compact detail");

if (strlen(pShow->db) > 0) {
sep = strchr(pShow->db, '.');
if (sep &&
Expand Down
3 changes: 3 additions & 0 deletions source/dnode/mnode/impl/src/mndDb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
TAOS_RETURN(code);
}
mInfo("trans:%d, used to alter db:%s", pTrans->id, pOld->name);
mInfo("trans:%d, used to alter db, ableToBeKilled:%d, killMode:%d", pTrans->id, pTrans->ableToBeKilled, pTrans->killMode);

mndTransSetDbName(pTrans, pOld->name, NULL);
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
Expand All @@ -1278,6 +1279,8 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
TAOS_CHECK_GOTO(mndSetAlterDbPrepareLogs(pMnode, pTrans, pOld, pNew), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterDbCommitLogs(pMnode, pTrans, pOld, pNew), NULL, _OVER);
TAOS_CHECK_GOTO(mndSetAlterDbRedoActions(pMnode, pTrans, pOld, pNew), NULL, _OVER);

mInfo("trans:%d, used to alter db, ableToBeKilled:%d, killMode:%d", pTrans->id, pTrans->ableToBeKilled, pTrans->killMode);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
code = 0;

Expand Down
5 changes: 4 additions & 1 deletion source/dnode/mnode/impl/src/mndShow.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
type = TSDB_MGMT_TABLE_COMPACT;
} else if (strncasecmp(name, TSDB_INS_TABLE_COMPACT_DETAILS, len) == 0) {
type = TSDB_MGMT_TABLE_COMPACT_DETAIL;
} else if (strncasecmp(name, TSDB_INS_TABLE_TRANSACTION_DETAILS, len) == 0) {
type = TSDB_MGMT_TABLE_TRANSACTION_DETAIL;
} else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_FULL, len) == 0) {
type = TSDB_MGMT_TABLE_GRANTS_FULL;
} else if (strncasecmp(name, TSDB_INS_TABLE_GRANTS_LOGS, len) == 0) {
Expand Down Expand Up @@ -236,7 +238,8 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
SRetrieveTableReq retrieveReq = {0};
TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));

mDebug("process to retrieve systable req db:%s, tb:%s", retrieveReq.db, retrieveReq.tb);
mDebug("process to retrieve systable req db:%s, tb:%s, compactId:%" PRId64, retrieveReq.db, retrieveReq.tb,
retrieveReq.compactId);

if (retrieveReq.showId == 0) {
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
Expand Down
Loading