Skip to content

Instantly share code, notes, and snippets.

@morgo
morgo / fast-zero-weight-move.patch
Created September 1, 2022 15:10
pd fast region transfer (doesn't work yet)
diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go
index 3897f926..efbe7bf0 100644
--- a/server/cluster/cluster.go
+++ b/server/cluster/cluster.go
@@ -49,6 +49,7 @@ import (
"github.com/tikv/pd/server/schedule/checker"
"github.com/tikv/pd/server/schedule/hbstream"
"github.com/tikv/pd/server/schedule/labeler"
+ "github.com/tikv/pd/server/schedule/operator"
"github.com/tikv/pd/server/schedule/placement"
@morgo
morgo / pfs-histogram.txt
Created April 1, 2020 20:48
Performance Schema Histogram
WITH histogram AS (
SELECT
digest,
CASE
WHEN bucket_timer_low > 10000000000000 THEN '10s'
WHEN bucket_timer_low > 1000000000000 THEN '1s'
WHEN bucket_timer_low > 100000000000 THEN '100ms'
WHEN bucket_timer_low > 10000000000 THEN '10ms'
WHEN bucket_timer_low > 1000000000 THEN '1ms'
WHEN bucket_timer_low > 100000000 THEN '100us'
@morgo
morgo / pfs.txt
Created March 31, 2020 17:28
Performance Schema: summarize row locks of oldest 100 transactions
SELECT
thr.processlist_id AS mysql_thread_id,
FORMAT_PICO_TIME(trx.timer_wait) as trx_duration,
COUNT(case when lock_status='GRANTED' then 1 else null end) AS row_locks_held,
COUNT(case when lock_status='PENDING' then 1 else null end) AS row_locks_pending,
GROUP_CONCAT(DISTINCT CONCAT(object_schema, '.', object_name)) AS tables_with_locks
FROM
performance_schema.events_transactions_current trx
INNER JOIN performance_schema.threads thr USING (thread_id)
LEFT JOIN data_locks USING (thread_id)
package main
import (
"bytes"
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"sync"
"time"
)
#!/bin/bash
source ./sb_include
# Setup DM between sandboxes
SOURCE=$1
if [ -z "$SOURCE" ]; then
echo "Usage: "
@morgo
morgo / dm-sandbox-mysql-to-tidb.sh
Created February 25, 2019 19:18
Setup DM between MySQL 5.7 and TiDB Sandboxes
#!/bin/bash
killall -9 dm-master
killall -9 dm-worker
# Setup DM between sandboxes
MYSQL_PORT="5725"
TIDB_PORT="3000"
echo "Downloading required packages"
@morgo
morgo / mydumper-test-case
Created October 10, 2018 14:20
mydumper-test-case
MySQL [test]> create table t1 (a int not null primary key auto_increment, b char(255));
Query OK, 0 rows affected (0.51 sec)
MySQL [test]> create table t2 (a char(255) not null primary key, b char(255));
Query OK, 0 rows affected (0.51 sec)
MySQL [test]> INSERT INTO t1 values (1, 'aaa');
Query OK, 1 row affected (0.15 sec)
MySQL [test]> INSERT INTO t2 values ('aaa', 'aaa');
morgo@ryzen:~/go/src/github.com/pingcap/tidb$ git diff
diff --git a/util/charset/charset_test.go b/util/charset/charset_test.go
index c400d97f..931b78ac 100644
--- a/util/charset/charset_test.go
+++ b/util/charset/charset_test.go
@@ -17,6 +17,8 @@ import (
"testing"
. "github.com/pingcap/check"
+ "github.com/pingcap/tidb/store/mockstore"
# Initial Data does not make sense
# should be either "Harvey Dent" or "Two Face"
id: 1, firstname: "Two Face", lastname: "Dent"
# Assume RR isolation
session1.start
session2.start
create table department (
id bigint not null,
budget bigint not null,
name varchar(255),
primary key (id)
) ENGINE=InnoDB;
create table employee (