Adding initial retry layer version (#14954)
* Adding initial retry layer version * Some simplification around the generated code * Generating retry layer again * Improving naming generation in store generated layers * Address PR review comments * Updating store layers * Addressing PR review comments * fixing lint errors * Updating store layers * Adding license header * Applying the retry layer to the reaction_store * Regenerating retry layer
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c89c56ab2e
Коммит
1b141678fe
@@ -736,28 +736,25 @@ func (s SqlChannelStore) Save(channel *model.Channel, maxChannelsPerTeam int64)
|
||||
}
|
||||
|
||||
var newChannel *model.Channel
|
||||
err := store.WithDeadlockRetry(func() error {
|
||||
transaction, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
transaction, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
|
||||
newChannel, err = s.saveChannelT(transaction, channel, maxChannelsPerTeam)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newChannel, err = s.saveChannelT(transaction, channel, maxChannelsPerTeam)
|
||||
if err != nil {
|
||||
return newChannel, err
|
||||
}
|
||||
|
||||
// Additionally propagate the write to the PublicChannels table.
|
||||
if err := s.upsertPublicChannelT(transaction, newChannel); err != nil {
|
||||
return errors.Wrap(err, "upsert_public_channel")
|
||||
}
|
||||
// Additionally propagate the write to the PublicChannels table.
|
||||
if err = s.upsertPublicChannelT(transaction, newChannel); err != nil {
|
||||
return nil, errors.Wrap(err, "upsert_public_channel")
|
||||
}
|
||||
|
||||
if err := transaction.Commit(); err != nil {
|
||||
return errors.Wrap(err, "commit_transaction")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err = transaction.Commit(); err != nil {
|
||||
return nil, errors.Wrap(err, "commit_transaction")
|
||||
}
|
||||
// There are cases when in case of conflict, the original channel value is returned.
|
||||
// So we return both and let the caller do the checks.
|
||||
return newChannel, err
|
||||
|
||||
@@ -56,24 +56,18 @@ func (s *SqlReactionStore) Save(reaction *model.Reaction) (*model.Reaction, erro
|
||||
}
|
||||
|
||||
func (s *SqlReactionStore) Delete(reaction *model.Reaction) (*model.Reaction, error) {
|
||||
err := store.WithDeadlockRetry(func() error {
|
||||
transaction, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
|
||||
if err := deleteReactionAndUpdatePost(transaction, reaction); err != nil {
|
||||
return errors.Wrap(err, "deleteReactionAndUpdatePost")
|
||||
}
|
||||
|
||||
if err := transaction.Commit(); err != nil {
|
||||
return errors.Wrap(err, "commit_transaction")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
transaction, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to delete reaction")
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
|
||||
if err := deleteReactionAndUpdatePost(transaction, reaction); err != nil {
|
||||
return nil, errors.Wrap(err, "deleteReactionAndUpdatePost")
|
||||
}
|
||||
|
||||
if err := transaction.Commit(); err != nil {
|
||||
return nil, errors.Wrap(err, "commit_transaction")
|
||||
}
|
||||
|
||||
return reaction, nil
|
||||
@@ -127,28 +121,22 @@ func (s *SqlReactionStore) DeleteAllWithEmojiName(emojiName string) error {
|
||||
return errors.Wrapf(err, "failed to get Reactions with emojiName=%s", emojiName)
|
||||
}
|
||||
|
||||
err := store.WithDeadlockRetry(func() error {
|
||||
_, err := s.GetMaster().Exec(
|
||||
`DELETE FROM
|
||||
Reactions
|
||||
WHERE
|
||||
EmojiName = :EmojiName`, map[string]interface{}{"EmojiName": emojiName})
|
||||
return err
|
||||
})
|
||||
_, err := s.GetMaster().Exec(
|
||||
`DELETE FROM
|
||||
Reactions
|
||||
WHERE
|
||||
EmojiName = :EmojiName`, map[string]interface{}{"EmojiName": emojiName})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Reactions with emojiName=%s", emojiName)
|
||||
}
|
||||
|
||||
for _, reaction := range reactions {
|
||||
reaction := reaction
|
||||
err := store.WithDeadlockRetry(func() error {
|
||||
_, err := s.GetMaster().Exec(UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY,
|
||||
map[string]interface{}{
|
||||
"PostId": reaction.PostId,
|
||||
"UpdateAt": model.GetMillis(),
|
||||
})
|
||||
return err
|
||||
})
|
||||
_, err := s.GetMaster().Exec(UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY,
|
||||
map[string]interface{}{
|
||||
"PostId": reaction.PostId,
|
||||
"UpdateAt": model.GetMillis(),
|
||||
})
|
||||
if err != nil {
|
||||
mlog.Warn("Unable to update Post.HasReactions while removing reactions",
|
||||
mlog.String("post_id", reaction.PostId),
|
||||
|
||||
Ссылка в новой задаче
Block a user