Граф коммитов

825 Коммитов

Автор SHA1 Сообщение Дата
Rodrigo Villablanca
7bf6565ed2 Migration of SchemeStore to return plain errors (#14836)
Automatic Merge
2020-06-23 06:56:35 +02:00
Agniva De Sarker
a1547cfac5 MM-19548: Add a deadlock retry function for SaveChannel (#14857)
* MM-19548: Add a deadlock retry function for SaveChannel

A deadlock has been seen to occur in the upsertPublicChannelT method
during bulk import.

Here is a brief excerpt:

*** (1) TRANSACTION:
TRANSACTION 3141, ACTIVE 1 sec inserting
INSERT INTO
                            PublicChannels(Id, DeleteAt, TeamId, DisplayName, Name, Header, Purpose)
                        VALUES
                            (?, ?, ?, ?, ?, ?, ?)
                        ON DUPLICATE KEY UPDATE
                            DeleteAt = ?,
                            TeamId = ?,
                            DisplayName = ?,
                            Name = ?,
                            Header = ?,
                            Purpose = ?
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 76 page no 4 n bits 104 index Name of table `mydb`.`PublicChannels` trx id 3141 lock_mode X locks gap before rec insert intention waiting
** (2) TRANSACTION:
TRANSACTION 3140, ACTIVE 1 sec inserting
mysql tables in use 1, locked 1
5 lock struct(s), heap size 1136, 3 row lock(s), undo log entries 2
MySQL thread id 50, OS thread handle 140641523848960, query id 3226 172.17.0.1 mmuser update
INSERT INTO
                            PublicChannels(Id, DeleteAt, TeamId, DisplayName, Name, Header, Purpose)
                        VALUES
                            (?, ?, ?, ?, ?, ?, ?)
                        ON DUPLICATE KEY UPDATE
                            DeleteAt = ?,
                            TeamId = ?,
                            DisplayName = ?,
                            Name = ?,
                            Header = ?,
                            Purpose = ?
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 76 page no 4 n bits 104 index Name of table `mydb`.`PublicChannels` trx id 3140 lock_mode X locks gap before rec

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 76 page no 4 n bits 104 index Name of table `mydb`.`PublicChannels` trx id 3140 lock_mode X locks gap before rec insert intention waiting

*** WE ROLL BACK TRANSACTION (1)

Following is my analysis:

From the deadlock output, it can be seen that it's due to a gap lock.
And that's clear because the index is Name which is a multi-column index using Name and TeamId.
But interestingly, both transactions seem to be inserting the same data, which is what is puzzling me.
The multi-column index on Name and TeamId will guarantee that they are always unique. And from looking at the code,
it does not seem possible to me that it will try to insert the same data from 2 different transactions.
But even if they do, why does tx 2 try to acquire the same lock again when it already has that ?

Here is what I think the order of events happening

Tx 2 gets a gap lock.
Tx 1 tries to get the same gap lock.
Tx 2 tries to again get the same gap lock ?

The last step is what is puzzling me. Why does an UPSERT statement acquire 2 gap locks ? From my reading of https://dev.mysql.com/doc/refman/8.0/en/innodb-locks-set.html:

> INSERT ... ON DUPLICATE KEY UPDATE differs from a simple INSERT in that an exclusive lock rather than a shared lock is placed on the row to be updated when a duplicate-key error occurs. An exclusive index-record lock is taken for a duplicate primary key value. An exclusive next-key lock is taken for a duplicate unique key value.

From what I understand, the expectation is that there will be one X lock and one gap lock is taken.
But that's not what the deadlock output seems to say.

The general advice on the internet seems to be that deadlocks will happen and not all of them can be understood.

For now, we add a generic deadlock retry function at the store package which can be reused by other queries too.

P.S.: This is a verbatim copy of my investigation posted at https://dba.stackexchange.com/questions/268652/mysql-deadlock-upsert-query-acquiring-gap-lock-twice

Testing:

This is ofcourse hard to test because it is impossible to reproduce this. I have tested this by manually returning an error
and confirming that it indeed retries.

WARN[2020-06-19T11:18:24.9585676+05:30] A deadlock happened. Retrying.                caller="sqlstore/channel_store.go:568" error="Error 1213: mydeadlock"
WARN[2020-06-19T11:18:24.959158+05:30] A deadlock happened. Retrying.                caller="sqlstore/channel_store.go:568" error="Error 1213: mydeadlock"
WARN[2020-06-19T11:18:24.9595072+05:30] A deadlock happened. Retrying.                caller="sqlstore/channel_store.go:568" error="Error 1213: mydeadlock"
WARN[2020-06-19T11:18:24.9595451+05:30] Deadlock happened 3 times. Giving up          caller="sqlstore/channel_store.go:579"
ERRO[2020-06-19T11:18:24.9596426+05:30] Unable to save channel.                       caller="mlog/log.go:175" err_details="Error 1213: mydeadlock" err_where=CreateChannel http_code=500 ip_addr="::1" method=POST path=/api/v4/channels request_id=745bsj13b7f6mnmsbn3t97grbw user_id=xcof1ipipbrfxpfjf6x4p6kx9e

* Fix tests

* Address review comments

* Address review comments

* Add forgotten test

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-06-23 08:44:39 +05:30
Rodrigo Villablanca
d391fd6231 Migration of ChannelStore.GetMoreChannels to return plain error (#14811)
Automatic Merge
2020-06-19 20:26:35 +02:00
Rodrigo Villablanca
2760497660 Migration of UserTermsOfServiceStore to return plain errors (#14788)
* Migration of UserTermsOfService Store

* Ordering translations file

* Fix imports

* Fix translations]

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-06-19 17:49:30 +05:30
Farhan Munshi
4d40226e02 MM-24674 Update channel members by group to look at distinct timezones correctly (#14673)
* MM-24674 Update channel members by group to look at distinct autoTimezone and manualTimezone.

Instead of just doing a blanket distinct on the column since that returns more entries than expected

* Use JSON extract instead of parsing text

* Use single quotes in mysql query too

* Dont need to prepend users on unambiguous column

* Use json extract instead of shorthand

* Dont count timezone if timezone default length

* CI

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-18 12:02:00 -04:00
Farhan Munshi
77bee1d4f1 MM-25263 Add group members to search and get users and create getGroupStats endpoint (#14733)
Add tests for SearchInGroup
2020-06-18 10:22:35 -04:00
Mario de Frutos Dieguez
f6c934d7e0 Create GetOldestEntityCreationTime method (#14515)
This method will be used by the ES index jobs in order
to get the first timestamp to be used as the starting point
when doing indexing tasks
2020-06-18 14:34:23 +02:00
Rodrigo Villablanca
8dc7c5762f Migrate GetDeletedByName from ChannelStore to return error interface (#14709)
Automatic Merge
2020-06-18 06:26:35 +02:00
Doug Lauder
b317ee5cf2 MM-25394 session expired push notifications (#14732)
* new job type created that checks for expired mobile sessions and pushes notifications.

* only send session expired notifications if ExtendSessionLengthWithActivity is enabled.

* includes schema change:  field added to Sessions table
2020-06-17 14:47:54 -04:00
Rodrigo Villablanca
e342b5a2f2 Migrate multiples methods from ChannelStore to return error interface (#14708)
Automatic Merge
2020-06-16 10:56:35 +02:00
Farhan Munshi
09a0b7db61 Clear team cache on delete team scheme (#14671)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-06-15 15:24:44 -04:00
Hossein Ahmadian-Yazdi
2c9c58ff50 [MM-25268] Implement prefix/suffix searching on teams and channel page in system console (#14698)
* Implement prefix/suffix search on teams page

* Make Channel Page prefix/suffix search as well

* address PR comments

* add tests

* fix styling

* take postgres into account

* add more api tests

* update test

* add team store test

* write store test for team and channel

* fix lint

* update description

* revert go mod

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-15 11:21:42 -04:00
Mario de Frutos Dieguez
033db51907 Remove UserStore.Get gorp usage (#14672)
We're removing the user of gorp in the most used queries
by our platform and this is one of them
2020-06-12 17:09:18 +02:00
Flavia Bastos
f912a93299 Document SqlTeamStore delete methods (#14785)
* Document SqlTeamStore delete methods

* Address feedback from code review: clarify permantDelete method
2020-06-12 13:46:35 +02:00
Rodrigo Villablanca
172eb1853f Migrate PermanentDeleteByTeam method from ChannelStore to return erro… (#14707)
Automatic Merge
2020-06-11 17:26:35 +02:00
Rodrigo Villablanca
41d9c673cf Migrate GetChannels method from ChannelStore to return error interface (#14711)
* Migrate GetChannels method from ChannelStore to return error interface

* Fix testing

* Changed error type: ErrInvalidInput -> ErrNotFound

* Added note about error migrations

* Fix en.json

* Fix i18n

Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2020-06-11 14:02:03 +05:30
Rodrigo Villablanca
9b0ae49b55 Migrate GetDeleted method from ChannelStore to return error interface (#14710)
* Migrate GetDeleted method from ChannelStore to return error interface

* Moving i18n translations to the correct place

Co-authored-by: Jesús Espino <jespinog@gmail.com>
2020-06-11 09:37:37 +05:30
Jesús Espino
9c9bdb8a90 Fix the reply count for pinned posts (#14744) 2020-06-09 18:42:59 +02:00
Rodrigo Villablanca
cac154e62b Migrate GetAllChannels and GetAllChannelsCount from ChannelStore to r… (#14765)
* Migrate GetAllChannels and GetAllChannelsCount from ChannelStore to return plain errors

* Moving i18n translations to the correct place

Co-authored-by: Jesús Espino <jespinog@gmail.com>
2020-06-09 21:48:01 +05:30
Miguel de la Cruz
6cd898fab7 [MM-25714] Keeps track of the import lines of the posts while importing to report the right line on error (#14752)
* [MM-25714] Keeps track of the import lines of the posts while importing to report the right line on error

* Adding review comments

* Reverse the order of the error and error line params
2020-06-08 12:12:07 +02:00
Flavia Bastos
ea06c291df Document sqlTeamStore search methods (#14702)
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-06 11:53:28 +02:00
Rodrigo Villablanca
6f28f3526d Migrate PermanentDelete method from ChannelStore to return error inte… (#14706)
Automatic Merge
2020-06-06 11:47:18 +02:00
Abdulkadir Poyraz
88e8f56f03 refactor cluster discovery store to use squirrel (#14560)
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-05 17:58:29 +02:00
Rodrigo Villablanca
ac32b2da41 Migrate Delete/Restore/SetDeleteAt methods from ChannelStore to return error interface (#14700)
Automatic Merge
2020-06-05 04:32:16 -07:00
Martin Kraft
18ddae2c1b MM-25737: Fix for groups list not returning results. (#14746)
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-04 11:31:07 -04:00
Carlos Tadeu Panato Junior
ca8a67c7cb database: upgrade db to 5.24 (#14749) 2020-06-04 16:14:22 +02:00
Agniva De Sarker
21b753b38d [MM-25314] Migrate AppError from channel_member_history_store.go (#14693)
* Migrate AppError from channel_member_history_store

* Migrate AppError from channel_member_history_store

* Migrate AppError from channel_member_history_store

* Migrate AppError from channel_member_history_store

* Migrating error keys

* Review fixes.

* Regenerating i18n

* Add some i18n strings

Co-authored-by: Dante Pippi <6619666+dantepippi@users.noreply.github.com>
Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-04 13:08:51 +05:30
Rodrigo Villablanca
3649d04dfa SqlLinkMetadataStore migrates to plain errors (#14674)
Automatic Merge
2020-06-03 13:32:16 -07:00
Agniva De Sarker
e3255879ba Enable gossip encryption (#14640)
* Enable gossip encryption

* Fix order

* Auto-generate key

* Update gorp fork to include BeginTx

* Add a test for InsertIfExists

And point gorp to a custom branch for now

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-03 14:16:15 +05:30
Rodrigo Villablanca
1c9891c65e Migrate all methods of SqlEmojiStore to return plain error intead of *model.AppError (#14618)
Automatic Merge
2020-06-02 11:31:30 -07:00
Rodrigo Villablanca
52cf817c8e SqlTermsOfService migrates to plain errors (#14675)
* Advances migragint TermsOfService

* Advances...

* Replaced message key

* Replaced message key

* Replaced message key

* Replaced message key

* Refactor name of errors

* Fix mixed type of error

* Fix-imports

* i18n-extract

* Rollback changes

* Rollback changes

* Rollback changes

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-02 22:47:52 +05:30
Rodrigo Villablanca
85a69d6112 Migrate Get/GetFromMaster methods from ChannelStore to return error interface (#14688)
* Advances

* Migration finished

* Rename err to normalized error

* fix imports

* Renamed key

* Renamed key

* Suggestions

* Fix i18n

* Fix tests

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2020-06-02 21:58:29 +05:30
Rodrigo Villablanca
60cc775cf6 Migrate Update method from ChannelStore to return idiomatic plain error (#14687)
* Partial advances

* Update migrated

* Fix imports

* Suggestions

* Suggestions

* Updating i18n

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-02 20:50:34 +05:30
Siyuan Liu
6a5dd550c8 migrate direct usage of lru to cache2 (#14508)
Automatic Merge
2020-06-02 06:01:30 -07:00
Jesús Espino
18cd3a1d07 Fixing reply count on new posts (#14312)
* Fixing reply count on new posts

* Fixing tests

* Fixing post reply count on getPostsAround

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-02 14:16:46 +02:00
dantepippi
c5af40988c [MM-24945] Refactor job store to use squirrel (#14559)
* Refactor job store to use squirrel

* Using multiple Set calls instead of SetMap

* Commiting suggestions.

Co-authored-by: Miguel de la Cruz <mgdelacroix@gmail.com>

* Commiting suggestions.

Co-authored-by: Miguel de la Cruz <mgdelacroix@gmail.com>

Co-authored-by: Dante Pippi <dantepippi@gmai.com>
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Miguel de la Cruz <mgdelacroix@gmail.com>
2020-06-02 11:42:31 +02:00
Flavia Bastos
54a4c10ed4 Document sqlTeamStore get methods (#14567)
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-05-30 12:02:10 +02:00
Martin Kraft
c529d5190a MM-25040: Restrict associated groups to channels when team is group-constrained. (#14619)
* MM-25040: Only return team-associated groups if the team is group-constrained.
MM-25040: Prevents associating a group to a channel if the team doesn't have the group first.

* MM-25040: Fix lints.

* MM-25040: Still add the groupteam if the team is not group-constrained.

* MM-25040: Wraps groupteam upsert in else branch for efficiency.

* MM-25040: Removes unnecessary page iteration.

* MM-25040: Fix typo.

* MM-25040: Moves filtering to SQL.

* MM-25040: Updates tests, check pagination.

* MM-25040: Fix lint error.

* MM-25040: Adds some more group store tests.

* MM-25040: Fix for wrong test parameter.
2020-05-29 10:46:52 -04:00
Mario de Frutos Dieguez
c9cdeba1a7 Move StatusStore.GetByIds away from gorp (#14685)
We're removing the usage of gorp in some of the most used
queries in our system. This is one of them
2020-05-29 11:36:41 +02:00
Jesús Espino
ae328153d5 Fixing behavior of Replicas and SearchReplicas in canary environments (#14576)
* Fixing behavior of Replicas and SearchReplicas in canary environments

* Trying to fix tests

* Revert "Trying to fix tests"

This reverts commit 3531da961844f5cb8557efcd3b570b06f362c6df.

* Revert "Fixing behavior of Replicas and SearchReplicas in canary environments"

This reverts commit 0c05901c843e4ccd60c8320fb4e0123b1bacf430.

* Revert "Disable read/search db replicas in TE/E0 (#14400)"

This reverts commit ef5ac519d9.

* Making the store aware of the license

* Readding the unit tests

* Fixing sqlstor supplier tests

* Adding mutex to ensure license write consistency and fixing tests

* Fixing tests

* Fixing tests

* Shuting down server properly during tests

* Trying to fix tests

* Trying to fix the tests

* Skipping flaky tests

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-05-27 15:42:48 +02:00
Scott Bishel
ebece6c23a MM-25014 - Default Group Name to null, until AllowGroupReference is set (#14651)
* make Group.Name a pointer to allow null

* fix unit tests

* fix build error

* fix unit test

* ensure Name field not nil

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-05-26 19:21:29 -06:00
Farhan Munshi
b0d74c4e40 [MM-25385] Add group_count_with_allow_reference telemetry (#14614)
* MM-25385 Add group_count_with_allow_reference telemetry

* Add store layers

* Fix tests

* Fix linting
2020-05-22 10:56:15 -04:00
Agniva De Sarker
aad76a13e8 MM-24170: Allow mysql to choose the right index (#14588)
We use the same optimization used in MM-23369 to prevent
mysql from using the index in the sort query.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-05-20 09:34:55 +05:30
dantepippi
83c1723bf5 [MM-24663] Refactor link metadata store to use squirrel (#14464)
* Refactor link_metadata_store to use squirrel

* Fix sql buil error string

* Fix := on second err

* Merging code to a single Where call

* Saving a line.

Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Dante Pippi <dantepippi@gmai.com>
Co-authored-by: dantepippi <dantepippi@users.noreply.github.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
2020-05-19 09:30:05 +02:00
Agniva De Sarker
53cc7a26ea MM-24133: Migrate AppError from bot_store.go (#14339)
* MM-24135: Migrate AppError from SaveChannel/channel_store.go

This is the first POC of migration of store app errors to plain error.

We create a few basic error types in the store package and use
them to return the errors from store methods. In the app layer,
we inspect the error and re-create the exact app errors. This lets
us preserve the same error content, but yet move to plain errors.

Since this is a gradual migration, this means that the error inspection
code will be duplicated across the app layer whenever a store method
is invoked. But all of that should go away once we start propagating
the errors higher up the hierarchy.

There have been a significant amount of changes in the storetest and searchtest
layer, primarily because we have to rename the err variable now that it is of
a different type.

* Addressed review comments

* MM-24132: Migrate AppError from SaveDirectChannel/channel_store.go

This PR migrates 2 new methods SaveDirectChannel and CreateDirectChannel
to return error instead of AppError.

We also need to handle the error internally in SaveMultipleMember for now
until that is migrated too.

* MM-24133: Migrate AppError from bot_store.go

* Fix errors

* Fix err

* Fix bad return

* Fix vet errors

* Fix incorrect error check

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-05-19 08:36:53 +05:30
Agniva De Sarker
21af1f49f1 MM-25238: Fix system ping check to read from master (#14580)
The code was writing to master and immediately after that reading
from a replica causing it to fail intermittently.

Since this is not a very high-traffic table, it should be safe to read
from master always.
2020-05-15 14:19:46 +05:30
Agniva De Sarker
090743de86 MM-24132: Migrate AppError from SaveDirectChannel/channel_store.go (#14318)
* MM-24135: Migrate AppError from SaveChannel/channel_store.go

This is the first POC of migration of store app errors to plain error.

We create a few basic error types in the store package and use
them to return the errors from store methods. In the app layer,
we inspect the error and re-create the exact app errors. This lets
us preserve the same error content, but yet move to plain errors.

Since this is a gradual migration, this means that the error inspection
code will be duplicated across the app layer whenever a store method
is invoked. But all of that should go away once we start propagating
the errors higher up the hierarchy.

There have been a significant amount of changes in the storetest and searchtest
layer, primarily because we have to rename the err variable now that it is of
a different type.

* Addressed review comments

* MM-24132: Migrate AppError from SaveDirectChannel/channel_store.go

This PR migrates 2 new methods SaveDirectChannel and CreateDirectChannel
to return error instead of AppError.

We also need to handle the error internally in SaveMultipleMember for now
until that is migrated too.

* Fix layers

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-05-14 23:41:05 +05:30
Flavia Bastos
e03fca5032 Document sqlTeamStore GetAll methods (#14372)
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-05-12 20:47:10 +02:00
Agniva De Sarker
729a84a3e6 MM-24135: Migrate AppError from SaveChannel/channel_store.go (#14299)
* MM-24135: Migrate AppError from SaveChannel/channel_store.go

This is the first POC of migration of store app errors to plain error.

We create a few basic error types in the store package and use
them to return the errors from store methods. In the app layer,
we inspect the error and re-create the exact app errors. This lets
us preserve the same error content, but yet move to plain errors.

Since this is a gradual migration, this means that the error inspection
code will be duplicated across the app layer whenever a store method
is invoked. But all of that should go away once we start propagating
the errors higher up the hierarchy.

There have been a significant amount of changes in the storetest and searchtest
layer, primarily because we have to rename the err variable now that it is of
a different type.

* Addressed review comments

* Made all appError origins to be CreateChannel

* Remove typed internal error

* Fix translations

* fix layer generation

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-05-12 21:23:41 +05:30
catalintomai
41e58d9769 MM-23816: Group Mentions: Add ability to rename group names (#14338)
* MM-23816: Group Mentions: Add ability to rename group names
2020-05-12 08:35:03 -07:00