Skip to content

Commit

Permalink
[feat][dingo-executor] Add table dingo_trx to show transaction inform…
Browse files Browse the repository at this point in the history
…ations.
  • Loading branch information
nokiaMS authored and ketor committed Oct 16, 2024
1 parent 24cf23b commit 6a10fd9
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import com.google.auto.service.AutoService;
import io.dingodb.common.CommonId;
import io.dingodb.common.session.SessionUtil;
import io.dingodb.common.util.Optional;
import io.dingodb.exec.transaction.base.ITransaction;
import io.dingodb.store.api.transaction.data.IsolationLevel;
import io.dingodb.transaction.api.LockType;

import java.sql.Connection;
Expand Down Expand Up @@ -98,6 +100,98 @@ public Iterator<Object[]> getMdlInfo() {
.iterator();
}

/**
* Get the information of running transaction.
* @return
*/
@Override
public Iterator<Object[]> getTxnInfo() {
Map<String, Connection> connectionMap = SessionUtil.INSTANCE.getConnectionMap();
return connectionMap.values().stream()
.map(conn -> (DingoConnection)conn)
.filter(dc -> !dc.getMdlLockJobMap().isEmpty())
.filter(dc -> dc.getTransaction() != null)
.map(dc -> {
long jobId = dc.getMdlLockJobMap().keySet().stream().findFirst().orElse(0L);
ITransaction transaction = dc.getTransaction();
List<String> sqlList = dc.getTransaction().getSqlList();
Object[] res = new Object[14];

//Get transaction id as string.
res[0] = transaction.getTxnId().toString();

//Get transaction type as string.
res[1] = transaction.getType().toString();

//Get job id as long.
res[2] = jobId;

//Get transaction start timestamp as long.
res[3] = transaction.getStartTs();

//Get transaction commit timestamp as long.
res[4] = transaction.getCommitTs();

//Get sql list in transaction as string.
StringBuilder sqlBuilder = new StringBuilder();
for (String sql : sqlList) {
sqlBuilder.append(sql).append(";");
}
res[5] = sqlBuilder.toString();

//Get transaction status.
res[6] = transaction.getStatus().toString();

//Get transaction isolation level.
res[7] = IsolationLevel.of(transaction.getIsolationLevel()).toString();

//Get transaction auto commit flag.
res[8] = String.valueOf(transaction.isAutoCommit());

//Get transaction primary key.
try {
res[9] = (transaction.getPrimaryKey() != null) ? transaction.getPrimaryKey().toString() : "";
} catch (UnsupportedOperationException e) {
res[9] = "";
}

//Get forUpdateTs.
try {
res[10] = transaction.getForUpdateTs();
} catch (UnsupportedOperationException e) {
res[10] = 0;
}

//Get lock timeout time.
res[11] = transaction.getLockTimeOut();

//Get primary key lock.
try {
if (transaction.getPrimaryKeyLock() == null) {
res[12] = "";
} else {
StringBuilder hexString = new StringBuilder();
hexString.append("0X");
for (byte b : transaction.getPrimaryKeyLock()) {
hexString.append(String.format("%02X", b));
}
res[12] = hexString;
}
} catch(UnsupportedOperationException e) {
res[12] = "";
}

//Get Job Seq id.
try {
res[13] = String.valueOf(transaction.getJobSeqId());
} catch (UnsupportedOperationException e) {
res[13] = "";
}
return res;
})
.iterator();
}

@AutoService(io.dingodb.transaction.api.TransactionServiceProvider.class)
public static final class TransactionServiceProvider implements io.dingodb.transaction.api.TransactionServiceProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ private InfoSchemaScanOperator() {
return StmtSummaryMap.iterator();
case "DINGO_MDL_VIEW":
return getMdlView();
case "DINGO_TRX":
return getTxnInfo();
default:
throw new RuntimeException("no source");
}
Expand Down Expand Up @@ -375,4 +377,8 @@ private static Iterator<Object[]> getMdlView() {
return TransactionService.getDefault().getMdlInfo();
}

private static Iterator<Object[]> getTxnInfo() {
return TransactionService.getDefault().getTxnInfo();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public static void prepareInformation(String coordinators) {
initTableByTemplate(schemaName, "VIEWS", SYSTEM_VIEW, TXN_LSM, FIXED);
initTableByTemplate(schemaName, "COLLATIONS", SYSTEM_VIEW, TXN_LSM, FIXED);
initTableByTemplate(schemaName, "DINGO_MDL_VIEW", SYSTEM_VIEW, TXN_LSM, FIXED);
initTableByTemplate(schemaName, "DINGO_TRX", SYSTEM_VIEW, TXN_LSM, FIXED);
LogUtils.info(log, "prepare information meta table done");
}

Expand Down Expand Up @@ -574,6 +575,9 @@ private static List<ColumnDefinition> getColumnList(String tableName) throws IOE
case "DINGO_MDL_VIEW":
jsonFile = "/information-dingoMdlView.json";
break;
case "DINGO_TRX":
jsonFile = "/information-dingoTrx.json";
break;
case "DINGO_DDL_REORG":
jsonFile = "/mysql-dingoDdlReorg.json";
break;
Expand Down
113 changes: 113 additions & 0 deletions dingo-executor/src/main/resources/information-dingoTrx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
[
{
"name": "transaction_id",
"type": "varchar",
"precision": 128,
"scale": -2147483648,
"primary": 0,
"nullable": false
},
{
"name": "type",
"type": "varchar",
"precision": 32,
"scale": -2147483648,
"primary": -1,
"nullable": true
},
{
"name": "job_id",
"type": "bigint",
"scale": -2147483648,
"precision": -1,
"primary": -1,
"nullable": true
},
{
"name": "txnStart",
"type": "bigint",
"scale": -2147483648,
"precision": -1,
"primary": -1,
"nullable": true
},
{
"name": "txnCommit",
"type": "bigint",
"scale": -2147483648,
"precision": -1,
"primary": -1,
"nullable": true
},
{
"name": "SQL_DIGESTS",
"type": "varchar",
"scale": -2147483648,
"primary": -1,
"nullable": true
},
{
"name": "status",
"type": "varchar",
"precision": 32,
"scale": -2147483648,
"primary": -1,
"nullable": true
},
{
"name": "isolation_level",
"type": "varchar",
"precision": 32,
"scale": -2147483648,
"primary": -1,
"nullable": true
},
{
"name": "auto_commit",
"type": "varchar",
"precision": 16,
"scale": -2147483648,
"primary": -1,
"nullable": true
},
{
"name": "primary_key",
"type": "varchar",
"precision": 128,
"scale": -2147483648,
"primary": -1,
"nullable": true
},
{
"name": "for_update_ts",
"type": "bigint",
"scale": -2147483648,
"precision": -1,
"primary": -1,
"nullable": true
},
{
"name": "lock_timeout",
"type": "bigint",
"scale": -2147483648,
"precision": -1,
"primary": -1,
"nullable": true
},
{
"name": "primary_key_lock",
"type": "varchar",
"precision": 128,
"scale": -2147483648,
"primary": -1,
"nullable": true
},
{
"name": "job_seq_id",
"type": "varchar",
"precision": 64,
"scale": -2147483648,
"primary": -1,
"nullable": true
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ default void rollback(long txnId) throws SQLException {}
void unlockTable(Connection connection);

Iterator<Object[]> getMdlInfo();
Iterator<Object[]> getTxnInfo();
}

0 comments on commit 6a10fd9

Please sign in to comment.