Merge pull request #1675 from mattermost/replica-fix
PLT-1413 Split db channel get into two functions using master and replica
Этот коммит содержится в:
@@ -241,13 +241,27 @@ func (s SqlChannelStore) extraUpdated(channel *model.Channel) StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) Get(id string) StoreChannel {
|
func (s SqlChannelStore) Get(id string) StoreChannel {
|
||||||
|
return s.get(id, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s SqlChannelStore) GetFromMaster(id string) StoreChannel {
|
||||||
|
return s.get(id, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s SqlChannelStore) get(id string, master bool) StoreChannel {
|
||||||
storeChannel := make(StoreChannel)
|
storeChannel := make(StoreChannel)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
result := StoreResult{}
|
result := StoreResult{}
|
||||||
|
|
||||||
// reading from master due to expected race condition when creating channels
|
var db *gorp.DbMap
|
||||||
if obj, err := s.GetMaster().Get(model.Channel{}, id); err != nil {
|
if master {
|
||||||
|
db = s.GetMaster()
|
||||||
|
} else {
|
||||||
|
db = s.GetReplica()
|
||||||
|
}
|
||||||
|
|
||||||
|
if obj, err := db.Get(model.Channel{}, id); err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.Get", "We encountered an error finding the channel", "id="+id+", "+err.Error())
|
result.Err = model.NewAppError("SqlChannelStore.Get", "We encountered an error finding the channel", "id="+id+", "+err.Error())
|
||||||
} else if obj == nil {
|
} else if obj == nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.Get", "We couldn't find the existing channel", "id="+id)
|
result.Err = model.NewAppError("SqlChannelStore.Get", "We couldn't find the existing channel", "id="+id)
|
||||||
@@ -439,7 +453,7 @@ func (s SqlChannelStore) SaveMember(member *model.ChannelMember) StoreChannel {
|
|||||||
go func() {
|
go func() {
|
||||||
var result StoreResult
|
var result StoreResult
|
||||||
// Grab the channel we are saving this member to
|
// Grab the channel we are saving this member to
|
||||||
if cr := <-s.Get(member.ChannelId); cr.Err != nil {
|
if cr := <-s.GetFromMaster(member.ChannelId); cr.Err != nil {
|
||||||
result.Err = cr.Err
|
result.Err = cr.Err
|
||||||
} else {
|
} else {
|
||||||
channel := cr.Data.(*model.Channel)
|
channel := cr.Data.(*model.Channel)
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ type ChannelStore interface {
|
|||||||
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel
|
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel
|
||||||
Update(channel *model.Channel) StoreChannel
|
Update(channel *model.Channel) StoreChannel
|
||||||
Get(id string) StoreChannel
|
Get(id string) StoreChannel
|
||||||
|
GetFromMaster(id string) StoreChannel
|
||||||
Delete(channelId string, time int64) StoreChannel
|
Delete(channelId string, time int64) StoreChannel
|
||||||
PermanentDeleteByTeam(teamId string) StoreChannel
|
PermanentDeleteByTeam(teamId string) StoreChannel
|
||||||
GetByName(team_id string, domain string) StoreChannel
|
GetByName(team_id string, domain string) StoreChannel
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user