Skip to content

Commit

Permalink
sql: add active user txn information to crdb_internal
Browse files Browse the repository at this point in the history
Fixes #46055.

Release justification: low risk change to existing functionality

Release note (sql change): This PR:
* Adds new internal tables `crdb_internal.node_transactions`
and `crdb_internal.cluster_transactions.`
* These tables contain some metadata about active user transactions.
* Adds the column `txn_id` to the `crdb_internal.node_queries` and
  `crdb_internal.cluster_queries` tables. These fields represent
  the transaction ID of each query in each row.
  • Loading branch information
rohany committed Mar 19, 2020
1 parent 7cfd35c commit 3da00f0
Show file tree
Hide file tree
Showing 19 changed files with 1,268 additions and 664 deletions.
2 changes: 2 additions & 0 deletions pkg/cli/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var debugZipTablesPerCluster = []string{
"crdb_internal.cluster_queries",
"crdb_internal.cluster_sessions",
"crdb_internal.cluster_settings",
"crdb_internal.cluster_transactions",

"crdb_internal.jobs",
"system.jobs", // get the raw, restorable jobs records too.
Expand Down Expand Up @@ -90,6 +91,7 @@ var debugZipTablesPerNode = []string{
"crdb_internal.node_runtime_info",
"crdb_internal.node_sessions",
"crdb_internal.node_statement_statistics",
"crdb_internal.node_transactions",
"crdb_internal.node_txn_stats",
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/cli/zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ requesting data for debug/reports/problemranges... writing: debug/reports/proble
retrieving SQL data for crdb_internal.cluster_queries... writing: debug/crdb_internal.cluster_queries.txt
retrieving SQL data for crdb_internal.cluster_sessions... writing: debug/crdb_internal.cluster_sessions.txt
retrieving SQL data for crdb_internal.cluster_settings... writing: debug/crdb_internal.cluster_settings.txt
retrieving SQL data for crdb_internal.cluster_transactions... writing: debug/crdb_internal.cluster_transactions.txt
retrieving SQL data for crdb_internal.jobs... writing: debug/crdb_internal.jobs.txt
retrieving SQL data for system.jobs... writing: debug/system.jobs.txt
retrieving SQL data for system.descriptor... writing: debug/system.descriptor.txt
Expand All @@ -161,6 +162,7 @@ retrieving SQL data for crdb_internal.node_queries... writing: debug/nodes/1/crd
retrieving SQL data for crdb_internal.node_runtime_info... writing: debug/nodes/1/crdb_internal.node_runtime_info.txt
retrieving SQL data for crdb_internal.node_sessions... writing: debug/nodes/1/crdb_internal.node_sessions.txt
retrieving SQL data for crdb_internal.node_statement_statistics... writing: debug/nodes/1/crdb_internal.node_statement_statistics.txt
retrieving SQL data for crdb_internal.node_transactions... writing: debug/nodes/1/crdb_internal.node_transactions.txt
retrieving SQL data for crdb_internal.node_txn_stats... writing: debug/nodes/1/crdb_internal.node_txn_stats.txt
requesting data for debug/nodes/1/details... writing: debug/nodes/1/details.json
requesting data for debug/nodes/1/gossip... writing: debug/nodes/1/gossip.json
Expand Down Expand Up @@ -427,6 +429,7 @@ requesting data for debug/reports/problemranges... writing: debug/reports/proble
retrieving SQL data for crdb_internal.cluster_queries... writing: debug/crdb_internal.cluster_queries.txt
retrieving SQL data for crdb_internal.cluster_sessions... writing: debug/crdb_internal.cluster_sessions.txt
retrieving SQL data for crdb_internal.cluster_settings... writing: debug/crdb_internal.cluster_settings.txt
retrieving SQL data for crdb_internal.cluster_transactions... writing: debug/crdb_internal.cluster_transactions.txt
retrieving SQL data for crdb_internal.jobs... writing: debug/crdb_internal.jobs.txt
^- resulted in ...
retrieving SQL data for system.jobs... writing: debug/system.jobs.txt
Expand Down Expand Up @@ -463,6 +466,7 @@ retrieving SQL data for crdb_internal.node_queries... writing: debug/nodes/1/crd
retrieving SQL data for crdb_internal.node_runtime_info... writing: debug/nodes/1/crdb_internal.node_runtime_info.txt
retrieving SQL data for crdb_internal.node_sessions... writing: debug/nodes/1/crdb_internal.node_sessions.txt
retrieving SQL data for crdb_internal.node_statement_statistics... writing: debug/nodes/1/crdb_internal.node_statement_statistics.txt
retrieving SQL data for crdb_internal.node_transactions... writing: debug/nodes/1/crdb_internal.node_transactions.txt
retrieving SQL data for crdb_internal.node_txn_stats... writing: debug/nodes/1/crdb_internal.node_txn_stats.txt
requesting data for debug/nodes/1/details... writing: debug/nodes/1/details.json
requesting data for debug/nodes/1/gossip... writing: debug/nodes/1/gossip.json
Expand Down Expand Up @@ -545,6 +549,7 @@ requesting data for debug/reports/problemranges... writing: debug/reports/proble
retrieving SQL data for crdb_internal.cluster_queries... writing: debug/crdb_internal.cluster_queries.txt
retrieving SQL data for crdb_internal.cluster_sessions... writing: debug/crdb_internal.cluster_sessions.txt
retrieving SQL data for crdb_internal.cluster_settings... writing: debug/crdb_internal.cluster_settings.txt
retrieving SQL data for crdb_internal.cluster_transactions... writing: debug/crdb_internal.cluster_transactions.txt
retrieving SQL data for crdb_internal.jobs... writing: debug/crdb_internal.jobs.txt
retrieving SQL data for system.jobs... writing: debug/system.jobs.txt
retrieving SQL data for system.descriptor... writing: debug/system.descriptor.txt
Expand All @@ -569,6 +574,7 @@ retrieving SQL data for crdb_internal.node_queries... writing: debug/nodes/1/crd
retrieving SQL data for crdb_internal.node_runtime_info... writing: debug/nodes/1/crdb_internal.node_runtime_info.txt
retrieving SQL data for crdb_internal.node_sessions... writing: debug/nodes/1/crdb_internal.node_sessions.txt
retrieving SQL data for crdb_internal.node_statement_statistics... writing: debug/nodes/1/crdb_internal.node_statement_statistics.txt
retrieving SQL data for crdb_internal.node_transactions... writing: debug/nodes/1/crdb_internal.node_transactions.txt
retrieving SQL data for crdb_internal.node_txn_stats... writing: debug/nodes/1/crdb_internal.node_txn_stats.txt
requesting data for debug/nodes/1/details... writing: debug/nodes/1/details.json
requesting data for debug/nodes/1/gossip... writing: debug/nodes/1/gossip.json
Expand Down Expand Up @@ -638,6 +644,8 @@ retrieving SQL data for crdb_internal.node_sessions... writing: debug/nodes/2/cr
^- resulted in ...
retrieving SQL data for crdb_internal.node_statement_statistics... writing: debug/nodes/2/crdb_internal.node_statement_statistics.txt
^- resulted in ...
retrieving SQL data for crdb_internal.node_transactions... writing: debug/nodes/2/crdb_internal.node_transactions.txt
^- resulted in ...
retrieving SQL data for crdb_internal.node_txn_stats... writing: debug/nodes/2/crdb_internal.node_txn_stats.txt
^- resulted in ...
requesting data for debug/nodes/2/details... writing: debug/nodes/2/details.json
Expand Down Expand Up @@ -674,6 +682,7 @@ retrieving SQL data for crdb_internal.node_queries... writing: debug/nodes/3/crd
retrieving SQL data for crdb_internal.node_runtime_info... writing: debug/nodes/3/crdb_internal.node_runtime_info.txt
retrieving SQL data for crdb_internal.node_sessions... writing: debug/nodes/3/crdb_internal.node_sessions.txt
retrieving SQL data for crdb_internal.node_statement_statistics... writing: debug/nodes/3/crdb_internal.node_statement_statistics.txt
retrieving SQL data for crdb_internal.node_transactions... writing: debug/nodes/3/crdb_internal.node_transactions.txt
retrieving SQL data for crdb_internal.node_txn_stats... writing: debug/nodes/3/crdb_internal.node_txn_stats.txt
requesting data for debug/nodes/3/details... writing: debug/nodes/3/details.json
requesting data for debug/nodes/3/gossip... writing: debug/nodes/3/gossip.json
Expand Down
7 changes: 7 additions & 0 deletions pkg/kv/kvclient/kvcoord/txn_coord_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,13 @@ func (tc *TxnCoordSender) SetDebugName(name string) {
tc.mu.txn.Name = name
}

// String is part of the client.TxnSender interface.
func (tc *TxnCoordSender) String() string {
tc.mu.Lock()
defer tc.mu.Unlock()
return tc.mu.txn.String()
}

// ReadTimestamp is part of the client.TxnSender interface.
func (tc *TxnCoordSender) ReadTimestamp() hlc.Timestamp {
tc.mu.Lock()
Expand Down
5 changes: 5 additions & 0 deletions pkg/kv/mock_transactional_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func (m *MockTransactionalSender) SetDebugName(name string) {
m.txn.Name = name
}

// String is part of the TxnSender interface.
func (m *MockTransactionalSender) String() string {
return m.txn.String()
}

// ReadTimestamp is part of the TxnSender interface.
func (m *MockTransactionalSender) ReadTimestamp() hlc.Timestamp {
return m.txn.ReadTimestamp
Expand Down
3 changes: 3 additions & 0 deletions pkg/kv/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ type TxnSender interface {
// SetDebugName sets the txn's debug name.
SetDebugName(name string)

// String returns a string representation of the txn.
String() string

// TxnStatus exports the txn's status.
TxnStatus() roachpb.TransactionStatus

Expand Down
7 changes: 7 additions & 0 deletions pkg/kv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ func (txn *Txn) debugNameLocked() string {
return fmt.Sprintf("%s (id: %s)", txn.mu.debugName, txn.mu.ID)
}

// String returns a string version of this transaction.
func (txn *Txn) String() string {
txn.mu.Lock()
defer txn.mu.Unlock()
return txn.mu.sender.String()
}

// ReadTimestamp returns the transaction's current read timestamp.
// Note a transaction can be internally pushed forward in time before
// committing so this is not guaranteed to be the commit timestamp.
Expand Down
Loading

0 comments on commit 3da00f0

Please sign in to comment.