MCPcopy
hub / github.com/pingcap/tidb / createConnWithConsistency

Function createConnWithConsistency

dumpling/export/sql.go:1024–1050  ·  view source on GitHub ↗
(ctx context.Context, db *sql.DB, repeatableRead bool)

Source from the content-addressed store, hash-verified

1022}
1023
1024func createConnWithConsistency(ctx context.Context, db *sql.DB, repeatableRead bool) (*sql.Conn, error) {
1025 conn, err := db.Conn(ctx)
1026 if err != nil {
1027 return nil, errors.Trace(err)
1028 }
1029 var query string
1030 if repeatableRead {
1031 query = "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ"
1032 _, err = conn.ExecContext(ctx, query)
1033 if err != nil {
1034 return nil, errors.Annotatef(err, "sql: %s", query)
1035 }
1036 }
1037 query = "START TRANSACTION /*!40108 WITH CONSISTENT SNAPSHOT */"
1038 _, err = conn.ExecContext(ctx, query)
1039 if err != nil {
1040 // Some MySQL Compatible databases like Vitess and MemSQL/SingleStore
1041 // are newer than 4.1.8 (the version comment) but don't actually support
1042 // `WITH CONSISTENT SNAPSHOT`. So retry without that if the statement fails.
1043 query = "START TRANSACTION"
1044 _, err = conn.ExecContext(ctx, query)
1045 if err != nil {
1046 return nil, errors.Annotatef(err, "sql: %s", query)
1047 }
1048 }
1049 return conn, nil
1050}
1051
1052// buildSelectField returns the selecting fields' string(joined by comma(`,`)),
1053// and the number of writable fields.

Callers 2

DumpMethod · 0.85
startWritersMethod · 0.85

Calls 1

ExecContextMethod · 0.65

Tested by

no test coverage detected