Skip to content

Commit c41823e

Browse files
authored
All MySQL DBs limited to max 3 concurrent/idle connections #15 (#931)
* v1.1.0 * WIP: copying AUTO_INCREMENT value to ghost table Initial commit: towards setting up a test suite Signed-off-by: Shlomi Noach <[email protected]> * greping for 'expect_table_structure' content * Adding simple test for 'expect_table_structure' scenario * adding tests for AUTO_INCREMENT value after row deletes. Should initially fail * clear event beforehand * parsing AUTO_INCREMENT from alter query, reading AUTO_INCREMENT from original table, applying AUTO_INCREMENT value onto ghost table if applicable and user has not specified AUTO_INCREMENT in alter statement * support GetUint64 Signed-off-by: Shlomi Noach <[email protected]> * minor update to test Signed-off-by: Shlomi Noach <[email protected]> * adding test for user defined AUTO_INCREMENT statement * Generated column as part of UNIQUE (or PRIMARY) KEY Signed-off-by: Shlomi Noach <[email protected]> * skip analysis of generated column data type in unique key Signed-off-by: Shlomi Noach <[email protected]> * All MySQL DBs limited to max 3 concurrent/idle connections Signed-off-by: Shlomi Noach <[email protected]>
1 parent 8f42ded commit c41823e

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

go/logic/throttler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,12 @@ func (this *Throttler) collectControlReplicasLag() {
188188
dbUri := connectionConfig.GetDBUri("information_schema")
189189

190190
var heartbeatValue string
191-
if db, _, err := mysql.GetDB(this.migrationContext.Uuid, dbUri); err != nil {
191+
db, _, err := mysql.GetDB(this.migrationContext.Uuid, dbUri)
192+
if err != nil {
192193
return lag, err
193-
} else if err = db.QueryRow(replicationLagQuery).Scan(&heartbeatValue); err != nil {
194+
}
195+
196+
if err := db.QueryRow(replicationLagQuery).Scan(&heartbeatValue); err != nil {
194197
return lag, err
195198
}
196199

go/mysql/utils.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ import (
1818
"github.com/outbrain/golib/sqlutils"
1919
)
2020

21-
const MaxTableNameLength = 64
22-
const MaxReplicationPasswordLength = 32
21+
const (
22+
MaxTableNameLength = 64
23+
MaxReplicationPasswordLength = 32
24+
MaxDBPoolConnections = 3
25+
)
2326

2427
type ReplicationLagResult struct {
2528
Key InstanceKey
@@ -39,23 +42,22 @@ func (this *ReplicationLagResult) HasLag() bool {
3942
var knownDBs map[string]*gosql.DB = make(map[string]*gosql.DB)
4043
var knownDBsMutex = &sync.Mutex{}
4144

42-
func GetDB(migrationUuid string, mysql_uri string) (*gosql.DB, bool, error) {
45+
func GetDB(migrationUuid string, mysql_uri string) (db *gosql.DB, exists bool, err error) {
4346
cacheKey := migrationUuid + ":" + mysql_uri
4447

4548
knownDBsMutex.Lock()
46-
defer func() {
47-
knownDBsMutex.Unlock()
48-
}()
49-
50-
var exists bool
51-
if _, exists = knownDBs[cacheKey]; !exists {
52-
if db, err := gosql.Open("mysql", mysql_uri); err == nil {
53-
knownDBs[cacheKey] = db
54-
} else {
55-
return db, exists, err
49+
defer knownDBsMutex.Unlock()
50+
51+
if db, exists = knownDBs[cacheKey]; !exists {
52+
db, err = gosql.Open("mysql", mysql_uri)
53+
if err != nil {
54+
return nil, false, err
5655
}
56+
db.SetMaxOpenConns(MaxDBPoolConnections)
57+
db.SetMaxIdleConns(MaxDBPoolConnections)
58+
knownDBs[cacheKey] = db
5759
}
58-
return knownDBs[cacheKey], exists, nil
60+
return db, exists, nil
5961
}
6062

6163
// GetReplicationLagFromSlaveStatus returns replication lag for a given db; via SHOW SLAVE STATUS

0 commit comments

Comments
 (0)