Fix issue with Aurora read replica (#5448)

This commit is contained in:
Corey Hulen
2017-02-17 08:20:29 -05:00
committed by Joram Wilander
parent 48b785aded
commit da448cedc8

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"strings"
"time"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
@@ -153,6 +154,8 @@ func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *mo
} else {
channel := result.Data.(*model.Channel)
WaitForChannelMembership(channel.Id, userId)
InvalidateCacheForUser(userId)
InvalidateCacheForUser(otherUserId)
@@ -164,6 +167,31 @@ func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *mo
}
}
func WaitForChannelMembership(channelId string, userId string) {
if len(utils.Cfg.SqlSettings.DataSourceReplicas) > 0 {
now := model.GetMillis()
for model.GetMillis()-now < 12000 {
time.Sleep(100 * time.Millisecond)
result := <-Srv.Store.Channel().GetMember(channelId, userId)
// If the membership was found then return
if result.Err == nil {
return
}
// If we recieved a error but it wasn't a missing channel member then return
if result.Err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
return
}
}
l4g.Error("WaitForChannelMembership giving up channelId=%v userId=%v", channelId, userId)
}
}
func UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
if result := <-Srv.Store.Channel().Update(channel); result.Err != nil {
return nil, result.Err
@@ -327,6 +355,8 @@ func addUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelM
return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "")
}
WaitForChannelMembership(channel.Id, user.Id)
InvalidateCacheForUser(user.Id)
InvalidateCacheForChannelMembers(channel.Id)