Lock bulk importing to master database node (#9012)

Этот коммит содержится в:
Joram Wilander
2018-06-27 05:08:40 -04:00
коммит произвёл George Goldberg
родитель f17c15c9d8
Коммит 0d91bf323e
9 изменённых файлов: 57 добавлений и 1 удалений

Просмотреть файл

@@ -209,6 +209,9 @@ func (a *App) BulkImport(fileReader io.Reader, dryRun bool, workers int) (*model
scanner := bufio.NewScanner(fileReader) scanner := bufio.NewScanner(fileReader)
lineNumber := 0 lineNumber := 0
a.Srv.Store.LockToMaster()
defer a.Srv.Store.UnlockFromMaster()
errorsChan := make(chan LineImportWorkerError, (2*workers)+1) // size chosen to ensure it never gets filled up completely. errorsChan := make(chan LineImportWorkerError, (2*workers)+1) // size chosen to ensure it never gets filled up completely.
var wg sync.WaitGroup var wg sync.WaitGroup
var linesChan chan LineImportWorkerData var linesChan chan LineImportWorkerData

Просмотреть файл

@@ -181,6 +181,14 @@ func (s *LayeredStore) Close() {
s.DatabaseLayer.Close() s.DatabaseLayer.Close()
} }
func (s *LayeredStore) LockToMaster() {
s.DatabaseLayer.LockToMaster()
}
func (s *LayeredStore) UnlockFromMaster() {
s.DatabaseLayer.UnlockFromMaster()
}
func (s *LayeredStore) DropAllTables() { func (s *LayeredStore) DropAllTables() {
s.DatabaseLayer.DropAllTables() s.DatabaseLayer.DropAllTables()
} }

Просмотреть файл

@@ -65,6 +65,8 @@ type SqlStore interface {
RemoveIndexIfExists(indexName string, tableName string) bool RemoveIndexIfExists(indexName string, tableName string) bool
GetAllConns() []*gorp.DbMap GetAllConns() []*gorp.DbMap
Close() Close()
LockToMaster()
UnlockFromMaster()
Team() store.TeamStore Team() store.TeamStore
Channel() store.ChannelStore Channel() store.ChannelStore
Post() store.PostStore Post() store.PostStore

Просмотреть файл

@@ -105,6 +105,7 @@ type SqlSupplier struct {
searchReplicas []*gorp.DbMap searchReplicas []*gorp.DbMap
oldStores SqlSupplierOldStores oldStores SqlSupplierOldStores
settings *model.SqlSettings settings *model.SqlSettings
lockedToMaster bool
} }
func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlSupplier { func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlSupplier {
@@ -283,7 +284,7 @@ func (ss *SqlSupplier) GetSearchReplica() *gorp.DbMap {
} }
func (ss *SqlSupplier) GetReplica() *gorp.DbMap { func (ss *SqlSupplier) GetReplica() *gorp.DbMap {
if len(ss.settings.DataSourceReplicas) == 0 { if len(ss.settings.DataSourceReplicas) == 0 || ss.lockedToMaster {
return ss.GetMaster() return ss.GetMaster()
} }
@@ -801,6 +802,14 @@ func (ss *SqlSupplier) Close() {
} }
} }
func (ss *SqlSupplier) LockToMaster() {
ss.lockedToMaster = true
}
func (ss *SqlSupplier) UnlockFromMaster() {
ss.lockedToMaster = false
}
func (ss *SqlSupplier) Team() store.TeamStore { func (ss *SqlSupplier) Team() store.TeamStore {
return ss.oldStores.team return ss.oldStores.team
} }

Просмотреть файл

@@ -67,6 +67,8 @@ type Store interface {
Plugin() PluginStore Plugin() PluginStore
MarkSystemRanUnitTests() MarkSystemRanUnitTests()
Close() Close()
LockToMaster()
UnlockFromMaster()
DropAllTables() DropAllTables()
TotalMasterDbConnections() int TotalMasterDbConnections() int
TotalReadDbConnections() int TotalReadDbConnections() int

Просмотреть файл

@@ -200,6 +200,11 @@ func (_m *LayeredStoreDatabaseLayer) License() store.LicenseStore {
return r0 return r0
} }
// LockToMaster provides a mock function with given fields:
func (_m *LayeredStoreDatabaseLayer) LockToMaster() {
_m.Called()
}
// MarkSystemRanUnitTests provides a mock function with given fields: // MarkSystemRanUnitTests provides a mock function with given fields:
func (_m *LayeredStoreDatabaseLayer) MarkSystemRanUnitTests() { func (_m *LayeredStoreDatabaseLayer) MarkSystemRanUnitTests() {
_m.Called() _m.Called()
@@ -851,6 +856,11 @@ func (_m *LayeredStoreDatabaseLayer) TotalSearchDbConnections() int {
return r0 return r0
} }
// UnlockFromMaster provides a mock function with given fields:
func (_m *LayeredStoreDatabaseLayer) UnlockFromMaster() {
_m.Called()
}
// User provides a mock function with given fields: // User provides a mock function with given fields:
func (_m *LayeredStoreDatabaseLayer) User() store.UserStore { func (_m *LayeredStoreDatabaseLayer) User() store.UserStore {
ret := _m.Called() ret := _m.Called()

Просмотреть файл

@@ -411,6 +411,11 @@ func (_m *SqlStore) License() store.LicenseStore {
return r0 return r0
} }
// LockToMaster provides a mock function with given fields:
func (_m *SqlStore) LockToMaster() {
_m.Called()
}
// MarkSystemRanUnitTests provides a mock function with given fields: // MarkSystemRanUnitTests provides a mock function with given fields:
func (_m *SqlStore) MarkSystemRanUnitTests() { func (_m *SqlStore) MarkSystemRanUnitTests() {
_m.Called() _m.Called()
@@ -706,6 +711,11 @@ func (_m *SqlStore) TotalSearchDbConnections() int {
return r0 return r0
} }
// UnlockFromMaster provides a mock function with given fields:
func (_m *SqlStore) UnlockFromMaster() {
_m.Called()
}
// User provides a mock function with given fields: // User provides a mock function with given fields:
func (_m *SqlStore) User() store.UserStore { func (_m *SqlStore) User() store.UserStore {
ret := _m.Called() ret := _m.Called()

Просмотреть файл

@@ -198,6 +198,11 @@ func (_m *Store) License() store.LicenseStore {
return r0 return r0
} }
// LockToMaster provides a mock function with given fields:
func (_m *Store) LockToMaster() {
_m.Called()
}
// MarkSystemRanUnitTests provides a mock function with given fields: // MarkSystemRanUnitTests provides a mock function with given fields:
func (_m *Store) MarkSystemRanUnitTests() { func (_m *Store) MarkSystemRanUnitTests() {
_m.Called() _m.Called()
@@ -437,6 +442,11 @@ func (_m *Store) TotalSearchDbConnections() int {
return r0 return r0
} }
// UnlockFromMaster provides a mock function with given fields:
func (_m *Store) UnlockFromMaster() {
_m.Called()
}
// User provides a mock function with given fields: // User provides a mock function with given fields:
func (_m *Store) User() store.UserStore { func (_m *Store) User() store.UserStore {
ret := _m.Called() ret := _m.Called()

Просмотреть файл

@@ -77,6 +77,8 @@ func (s *Store) ChannelMemberHistory() store.ChannelMemberHistoryStore {
} }
func (s *Store) MarkSystemRanUnitTests() { /* do nothing */ } func (s *Store) MarkSystemRanUnitTests() { /* do nothing */ }
func (s *Store) Close() { /* do nothing */ } func (s *Store) Close() { /* do nothing */ }
func (s *Store) LockToMaster() { /* do nothing */ }
func (s *Store) UnlockFromMaster() { /* do nothing */ }
func (s *Store) DropAllTables() { /* do nothing */ } func (s *Store) DropAllTables() { /* do nothing */ }
func (s *Store) TotalMasterDbConnections() int { return 1 } func (s *Store) TotalMasterDbConnections() int { return 1 }
func (s *Store) TotalReadDbConnections() int { return 1 } func (s *Store) TotalReadDbConnections() int { return 1 }