From 860e5d483cd952ec833c40312a2141bb3e4ef579 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 29 May 2017 15:46:35 -0400 Subject: PLT-6341/PLT-6342 Update gorp to mattermost fork and add connection timeout setting (#6410) * Update gorp to mattermost fork and add connection timeout setting * Add go dependency * Rename from connection timeout to query timeout * Properly add gorp dependency --- store/sql_channel_store.go | 2 +- store/sql_oauth_store.go | 2 +- store/sql_preference_store.go | 2 +- store/sql_reaction_store.go | 2 +- store/sql_store.go | 34 ++++++++++++++++++---------------- 5 files changed, 22 insertions(+), 20 deletions(-) (limited to 'store') diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index c9b6d89b8..e25387f50 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -11,7 +11,7 @@ import ( "strings" l4g "github.com/alecthomas/log4go" - "github.com/go-gorp/gorp" + "github.com/mattermost/gorp" "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" diff --git a/store/sql_oauth_store.go b/store/sql_oauth_store.go index 6311b56dd..0849353a0 100644 --- a/store/sql_oauth_store.go +++ b/store/sql_oauth_store.go @@ -7,7 +7,7 @@ import ( "net/http" "strings" - "github.com/go-gorp/gorp" + "github.com/mattermost/gorp" "github.com/mattermost/platform/model" ) diff --git a/store/sql_preference_store.go b/store/sql_preference_store.go index 1ee7c4297..231da069a 100644 --- a/store/sql_preference_store.go +++ b/store/sql_preference_store.go @@ -5,7 +5,7 @@ package store import ( l4g "github.com/alecthomas/log4go" - "github.com/go-gorp/gorp" + "github.com/mattermost/gorp" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" ) diff --git a/store/sql_reaction_store.go b/store/sql_reaction_store.go index 0d94a500f..1b927c106 100644 --- a/store/sql_reaction_store.go +++ b/store/sql_reaction_store.go @@ -4,12 +4,12 @@ package store import ( + "github.com/mattermost/gorp" "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" l4g "github.com/alecthomas/log4go" - "github.com/go-gorp/gorp" ) const ( diff --git a/store/sql_store.go b/store/sql_store.go index 4261c849a..1a681fe81 100644 --- a/store/sql_store.go +++ b/store/sql_store.go @@ -24,9 +24,9 @@ import ( l4g "github.com/alecthomas/log4go" - "github.com/go-gorp/gorp" _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" + "github.com/mattermost/gorp" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" ) @@ -211,12 +211,14 @@ func setupConnection(con_type string, driver string, dataSource string, maxIdle var dbmap *gorp.DbMap + connectionTimeout := time.Duration(*utils.Cfg.SqlSettings.QueryTimeout) * time.Second + if driver == "sqlite3" { - dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.SqliteDialect{}} + dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.SqliteDialect{}, QueryTimeout: connectionTimeout} } else if driver == model.DATABASE_DRIVER_MYSQL { - dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8MB4"}} + dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8MB4"}, QueryTimeout: connectionTimeout} } else if driver == model.DATABASE_DRIVER_POSTGRES { - dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.PostgresDialect{}} + dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.PostgresDialect{}, QueryTimeout: connectionTimeout} } else { l4g.Critical(utils.T("store.sql.dialect_driver.critical")) time.Sleep(time.Second) @@ -384,7 +386,7 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string, } if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES { - _, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " ADD " + columnName + " " + postgresColType + " DEFAULT '" + defaultValue + "'") + _, err := ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + postgresColType + " DEFAULT '" + defaultValue + "'") if err != nil { l4g.Critical(utils.T("store.sql.create_column.critical"), err) time.Sleep(time.Second) @@ -394,7 +396,7 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string, return true } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL { - _, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " ADD " + columnName + " " + mySqlColType + " DEFAULT '" + defaultValue + "'") + _, err := ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + mySqlColType + " DEFAULT '" + defaultValue + "'") if err != nil { l4g.Critical(utils.T("store.sql.create_column.critical"), err) time.Sleep(time.Second) @@ -417,7 +419,7 @@ func (ss *SqlStore) RemoveColumnIfExists(tableName string, columnName string) bo return false } - _, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " DROP COLUMN " + columnName) + _, err := ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " DROP COLUMN " + columnName) if err != nil { l4g.Critical("Failed to drop column %v", err) time.Sleep(time.Second) @@ -432,7 +434,7 @@ func (ss *SqlStore) RemoveTableIfExists(tableName string) bool { return false } - _, err := ss.GetMaster().Exec("DROP TABLE " + tableName) + _, err := ss.GetMaster().ExecNoTimeout("DROP TABLE " + tableName) if err != nil { l4g.Critical("Failed to drop table %v", err) time.Sleep(time.Second) @@ -449,9 +451,9 @@ func (ss *SqlStore) RenameColumnIfExists(tableName string, oldColumnName string, var err error if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL { - _, err = ss.GetMaster().Exec("ALTER TABLE " + tableName + " CHANGE " + oldColumnName + " " + newColumnName + " " + colType) + _, err = ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " CHANGE " + oldColumnName + " " + newColumnName + " " + colType) } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES { - _, err = ss.GetMaster().Exec("ALTER TABLE " + tableName + " RENAME COLUMN " + oldColumnName + " TO " + newColumnName) + _, err = ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " RENAME COLUMN " + oldColumnName + " TO " + newColumnName) } if err != nil { @@ -492,9 +494,9 @@ func (ss *SqlStore) AlterColumnTypeIfExists(tableName string, columnName string, var err error if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL { - _, err = ss.GetMaster().Exec("ALTER TABLE " + tableName + " MODIFY " + columnName + " " + mySqlColType) + _, err = ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " MODIFY " + columnName + " " + mySqlColType) } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES { - _, err = ss.GetMaster().Exec("ALTER TABLE " + strings.ToLower(tableName) + " ALTER COLUMN " + strings.ToLower(columnName) + " TYPE " + postgresColType) + _, err = ss.GetMaster().ExecNoTimeout("ALTER TABLE " + strings.ToLower(tableName) + " ALTER COLUMN " + strings.ToLower(columnName) + " TYPE " + postgresColType) } if err != nil { @@ -540,7 +542,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c query = "CREATE " + uniqueStr + "INDEX " + indexName + " ON " + tableName + " (" + columnName + ")" } - _, err = ss.GetMaster().Exec(query) + _, err = ss.GetMaster().ExecNoTimeout(query) if err != nil { l4g.Critical(utils.T("store.sql.create_index.critical"), err) time.Sleep(time.Second) @@ -564,7 +566,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c fullTextIndex = " FULLTEXT " } - _, err = ss.GetMaster().Exec("CREATE " + uniqueStr + fullTextIndex + " INDEX " + indexName + " ON " + tableName + " (" + columnName + ")") + _, err = ss.GetMaster().ExecNoTimeout("CREATE " + uniqueStr + fullTextIndex + " INDEX " + indexName + " ON " + tableName + " (" + columnName + ")") if err != nil { l4g.Critical(utils.T("store.sql.create_index.critical"), err) time.Sleep(time.Second) @@ -588,7 +590,7 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool return false } - _, err = ss.GetMaster().Exec("DROP INDEX " + indexName) + _, err = ss.GetMaster().ExecNoTimeout("DROP INDEX " + indexName) if err != nil { l4g.Critical(utils.T("store.sql.remove_index.critical"), err) time.Sleep(time.Second) @@ -609,7 +611,7 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool return false } - _, err = ss.GetMaster().Exec("DROP INDEX " + indexName + " ON " + tableName) + _, err = ss.GetMaster().ExecNoTimeout("DROP INDEX " + indexName + " ON " + tableName) if err != nil { l4g.Critical(utils.T("store.sql.remove_index.critical"), err) time.Sleep(time.Second) -- cgit v1.2.3-1-g7c22