Commit Graph

1735 Commits

Author SHA1 Message Date
Doug Lauder
02196e04fa MM-27493 Shared channels (MVP) (#17301)
Remote Cluster Service
- provides ability for multiple Mattermost cluster instances to create a trusted connection with each other and exchange messages
- trusted connections are managed via slash commands (for now)
- facilitates features requiring inter-cluster communication, such as Shared Channels
Shared Channels Service
- provides ability to shared channels between one or more Mattermost cluster instances (using trusted connection)
- sharing/unsharing of channels is managed via slash commands (for now)
2021-04-01 13:44:56 -04:00
Eli Yukelzon
480796a1df MM-33708 - Add MentionCountRoot column to ChannelMembers (#17099)
* added new column for root-only mentions

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-04-01 14:43:09 +03:00
Eli Yukelzon
3c21eef110 MM-33746 hotfix (#17320)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-04-01 13:56:39 +03:00
Eli Yukelzon
ab5925c4de MM-33746 Add TotalMsgCountRoot and MsgCountRoot columns (#17150) 2021-03-31 16:51:02 +03:00
Claudio Costa
ee3f986da0 [MM-32622] Remove app.WaitForChannelMembership() (#17048)
* Remove app.WaitForChannelMembership

* Fix tests

* Fix test

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-31 09:40:35 +02:00
catalintomai
ca9f4c9ed8 MM-32882: Add an unread badge/marker to the Main Menu icon and the ‘Plugin Marketplace’ Menu Item (#16992) 2021-03-29 22:55:44 -07:00
Agniva De Sarker
7b1dee4936 MM-33818: Add replica lag metric (#17148)
* MM-33818: Add replica lag metric

We add two new metrics for monitoring replica lag:
- Monitor absolute lag based on binlog distance/transaction queue length.
- Monitor time taken for the replica to catch up.

To achieve this, we add a config setting to run a user defined SQL query
on the database.

We need to specify a separate datasource field as part of the config because
in some databases, querying the replica lag value requires elevated credentials
which are not needed for usual running of the application, and can even be a security risk.

Arguably, a peculiar part of the design is the requirement of the query output to be in a (node, value)
format. But since from the application, the SQL query is a black box and the user can set any query
they want, we cannot, in any way templatize this.

And as an extra note, freno also does it in a similar way.

The last bit is because we need to have a separate datasources, now we consume one extra connection
rather than sharing it with the pool. This is an unfortunate result of the design, and while one extra
connection doesn't make much of a difference in a single-tenant scenario. It does make so, in a multi-tenant scenario.
But in a multi-tenant scenario, the expectation would already be to use a connection pool. So this
is not a big concern.

https://mattermost.atlassian.net/browse/MM-33818

```release-note
Two new gauge metrics were added:
mattermost_db_replica_lag_abs and mattermost_db_replica_lag_time, both
containing a label of "node", signifying which db host is the metric from.

These metrics signify the replica lag in absolute terms and in the time dimension
capturing the whole picture of replica lag.

To use these metrics, a separate config section ReplicaLagSettings was added
under SqlSettings. This is an array of maps which contain three keys: DataSource,
QueryAbsoluteLag, and QueryTimeLag. Each map entry is for a single replica instance.

DataSource contains the DB credentials to connect to the replica instance.

QueryAbsoluteLag is a plain SQL query that must return a single row of which the first column
must be the node value of the Prometheus metric, and the second column must be the value of the lag.

QueryTimeLag is the same as above, but used to measure the time lag.

As an example, for AWS Aurora instances, the QueryAbsoluteLag can be:

select server_id, highest_lsn_rcvd-durable_lsn as bindiff from aurora_global_db_instance_status() where server_id=<>

and QueryTimeLag can be:

select server_id, visibility_lag_in_msec from aurora_global_db_instance_status() where server_id=<>

For MySQL Group Replication, the absolute lag can be measured from the number of pending transactions
in the applier queue:

select member_id, count_transaction_remote_in_applier_queue FROM performance_schema.replication_group_member_stats where member_id=<>

Overall, what query to choose is left to the administrator, and depending on the database and need, an appropriate
query can be chosen.
```

* Trigger CI

* Fix tests

* address review comments

* Remove t.Parallel

It was spawning too many connections,
and overloading the docker container.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-29 21:35:24 +05:30
Harrison Healey
b3e0db012b MM-27380 Move collapsed categories to server (#17194) 2021-03-26 17:46:56 -04:00
Ibrahim Serdar Acikgoz
85bc354680 [MM-33640] storetest/team_store: use NewTestId for fields like names etc. (#17204)
* storetest/team_store: use NewTestId for fields like names etc.

* reflect review comments

* fix tests

* we love good old C

* remove rand
2021-03-26 10:02:52 +03:00
Elisabeth Kulzer
5329eac020 Upgrade db and version (#17230) 2021-03-25 15:42:27 +01:00
Eli Yukelzon
0cc72342de MM-33544 is_following prop in getPosts API methods (#17093)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-23 13:31:54 +02:00
Ibrahim Serdar Acikgoz
35cfab33fc store/post: fix searching for phrases in postgres (#17042)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-22 11:03:26 +03:00
Agniva De Sarker
33e319366c MM-34080: Removing sqlite entirely (#17188)
* MM-34080: Removing sqlite entirely

The initial commit missed removing this blank import.
So the library still remained in our vendor directory.
Removing it for good now.

Bye bye sqlite.

https://mattermost.atlassian.net/browse/MM-34080

* fix go.mod
2021-03-19 20:23:23 +05:30
Claudio Costa
d3a003dcb2 Address outstanding merging issues with cloud branch (#17160) 2021-03-17 10:39:46 +01:00
Jesús Espino
c5e1b36dd3 Making the posts tests a bit more robust (#17151) 2021-03-16 15:55:55 +01:00
Jesús Espino
7208952010 Improve file search results with postgres (#17112)
* Improve file search results with postgres

* Adding channel id to search results

* Fixing file info saves
2021-03-16 11:19:13 +01:00
Agniva De Sarker
23dd4a5946 MM-31396: Fix a possible deadlock with SidebarCategories (#17109)
This is a deadlock due to reversed locking order of the SidebarChannels
and SidebarCategories table.

I could not find the exact culprit query from the deadlock output
because it only shows the last query a transaction is running. And from looking
at the code, the only query that runs "UPDATE SidebarCategories SET DisplayName = ?, Sorting = ? WHERE Id = ?"
is UpdateSidebarCategories. But for the deadlock to happen, it has to lock
SidebarChannels _first_, and then _then_ lock SidebarCategories.

Looking a bit more throughly, I found that DeleteSidebarCategory does indeed
lock the tables in an inverse way and if DeleteSidebarCategory runs concurrently with
UpdateSidebarCategories, they will deadlock.

Here's how it will happen.

```
tx1
DELETE FROM SidebarChannels WHERE CategoryId = 'xx';

tx2
UPDATE SidebarCategories SET DisplayName='dn' WHERE Id='xx';

tx2
DELETE FROM SidebarChannels WHERE (ChannelId IN ('yy') AND CategoryId = 'xx');

tx1
DELETE FROM SidebarCategories WHERE Id = 'xx';
```

And then we see:
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction

To fix this, we simply reorder the Delete query to lock the SidebarCategories first,
and then SidebarChannels.

In fact, any transaction updating/deleting rows from those two tables should always operate on that order
if possible.

https://mattermost.atlassian.net/browse/MM-31396

```release-note
Fixed a database deadlock that can happen if a sidebar category is updated and deleted at the same time.
```
2021-03-16 15:07:30 +05:30
Mahmudul Haque
62fa7b9350 unparam lint (#16927)
* fix "always receives ..." lint err

* add unparam lint check

* fix failed test

* rm details param

* ignore unparam lint

* magic string replaced with model.NewRandomString

* rm unused enableComplianceFeatures param

* generate random message inside createPost

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-16 12:48:20 +05:30
Agniva De Sarker
936540ea58 MM-33789: Revert fallback to master for GetAllProfilesInChannel (#17119)
* MM-33789: Revert fallback to master for GetAllProfilesInChannel

This fixes a regression introduced in https://github.com/mattermost/mattermost-server/pull/16911.

It was causing problems with too many invalidations and overloading the writer instance for big installations.
Reverting this does not affect correctness at all because it was done out of abundance of caution and the
idea at that point was it was to be done for all caches.

https://mattermost.atlassian.net/browse/MM-33789

```release-note
NONE
```

* fix gofmt issues
2021-03-15 19:51:49 +05:30
Anurag Shivarathri
145fa97069 MM-31054 demote user (#16990)
* changing SchemeAdmin to false on demotion

* Added test

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-15 18:33:54 +05:30
Martin Raymond Kraft
58dce5930e [MM-31094] Replication Lag (#16888)
* MM-31094: Adds tooling to develop and test using a MySQL instance with replication lag. Adds some lazy lookups to fallback to master if results are not found.

* MM-31094: Removes mysql-read-replica from default docker services.

* MM-31094: Switches (store..SessionStore).Get and (store.TeamStore).GetMember to using context.Context.

* MM-31094: Updates (store.UsersStore).Get to use context.

* MM-31094: Updates (store.PostStore).Get to use context.

* MM-31094: Removes feature flag and config setting.

* MM-31094: Rolls back some master reads.

* MM-31094: Rolls a non-cache read.

* MM-31094: Removes feature flag from the store.

* MM-31094: Removes unused constant and struct field.

* MM-31094: Removes some old feature flag references.

* MM-31094: Fixes some tests.

* MM-31094: App layers fix.

* MM-31094: Fixes mocks.

* MM-31094: Don't reparse flag.

* MM-31094: No reparse.

* MM-31094: Removed unused FeatureFlags field.

* MM-31094: Removes unnecessary feature flags variable declarations.

* MM-31094: Fixes copy-paste error.

* MM-31094: Fixes logical error.

* MM-30194: Removes test method from store.

* Revert "MM-30194: Removes test method from store."

This reverts commit d5a6e8529b.

* MM-31094: Conforming to make's strange syntax.

* MM-31094: Configures helper for read replica with option.

* MM-31094: Adds some missing ctx's.

* MM-31094: WIP

* MM-31094: Updates test names.

* MM-31094: WIP

* MM-31094: Removes unnecessary master reads.

* MM-31094: ID case changes out of scope.

* MM-31094: Removes unused context.

* MM-31094: Switches to a helper. Removes some var naming changes. Fixes a merge error.

* MM-31094: Removes SQLITE db driver ref.

* MM-31094: Layer generate fix.

* MM-31094: Removes unnecessary changes.

* MM-31094: Moves test method.

* MM-31094: Re-add previous fix.

* MM-31094: Removes make command for dev.

* MM-31094: Fix for login.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-12 12:37:30 -05:00
Miguel de la Cruz
8248477319 [MM-33655] Add db upgrade step for version v5.29.1 (#17096) 2021-03-10 10:07:56 +01:00
Eli Yukelzon
90e7c5a852 MM-33359 corrected unread replies update (#17068)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-09 16:10:47 +02:00
Mahmudul Haque
5a89208944 remove redundant transaction (#16928)
Automatic Merge
2021-03-09 09:08:32 +01:00
Jesús Espino
9cc5089af8 Moving mlog to corelibs (#16915)
* Moving mlog to corelibs

* Regenerating app layers

* Fix golangci-lint problem

* Fixing golangci-lint errors

* Renaming from corelibs to shared

* Renaming from corelibs to shared

* Fixing import

* Fixing merge problems

* Fixing build
2021-03-05 09:18:37 +01:00
Eli Yukelzon
4aa6c863c3 MM-30304 - Handle collapsed threads in page apis (#17064) 2021-03-05 09:46:36 +02:00
Claudio Costa
4ad29c3a8d Bring schema versions up-to-date (#17053)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-04 17:17:27 +01:00
jingkai
22853628b2 Refactor term_of_service_store to use squirrel (#16923)
* refactor: replace select statement with squirell

* fix: fixed sqlquery for GetLatest

* fix: gofmt

* fix: replaced old AppError with errors.Wrap

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-01 15:43:56 +01:00
Claudio Costa
cc86ec9f50 [MM-33333] Fix GetSidebarCategories() failing on db replicas (#17031)
* Fix GetSidebarCategories failing on replicas

* Simplify further

* Add comment
2021-02-27 07:54:13 -05:00
Agniva De Sarker
6dcbad049c MM-32693: Use master when emoji_layer is invalidated (#16951)
We add a map which tracks invalidations to the emoji caches
and use master whenever a fresh item is fetched from DB.

https://mattermost.atlassian.net/browse/MM-32693

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-02-26 17:47:51 +01:00
Claudio Costa
33c8b0ad73 Remove waitForSidebarCategories (#17004) 2021-02-26 09:42:19 +01:00
Jesús Espino
5dd2e75c10 Extracting i18n functionality to i18n core library (#16914)
* extracting i18n functionality to i18n core library

* Removing utils.T

* Adding documentation and changing one function name for better explanation

* Changing other missing utils.T

* Adding license string

* Renaming corelibs to pkg

* Renaming corelibs to pkg (moving directory)

* Renaming from pkg to shared

* Fixing bodyPage.Html casing

* Fixing merges

* Fixing merge problem

* Fixing tests
2021-02-26 08:12:49 +01:00
John Tzikas
809affd6d1 Create basic make commands for configuring golang-migrate (#16938)
* Create basic make commands for configuring golang-migrate

* Showcase full flow with new migrations

* Apply PR suggestions

* Migrate over team members

* Update mocks

* Fix specs

* Move columns that added after table creation onto separate stmts

* Put back gorp table definitions

* Fix issues with golang-migrate that not tracks underlying db driver

* Help prompt after new migration and consistent checksum for bindata

* Put gorp mapping back

* Apply PR suggestiong

* Close migrations after they run

* Add migration file to bindata check

* Updates needed

* Reset store_test

* Add copyright

* Apply PR suggestions

* Fix new circleci check

* Put back upgrade step for backwards comp

* Add store test to test migration directions

* Apply PR suggestions

* Add go-bindata to tools

* Apply PR suggestios

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-02-23 16:22:31 +02:00
Atanas Alexandrov
e44190f4cc NO-TCIKET fix bad smells - error strings should not be capitalized (#16930)
Automatic Merge
2021-02-23 06:22:27 +01:00
Jesús Espino
2b6c0e9746 Adding bulk-indexing and improving a bit the name indexing for bleve and elasticsearch (#16704)
* Adding bulk-indexing and improving a bit the name indexing for bleve and elasticsearch

* Update services/searchengine/bleveengine/bleve.go

Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org>

* Update store/sqlstore/file_info_store.go

Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org>

* Update store/sqlstore/file_info_store.go

Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org>

* Adding tests requested in the PR review

* fixing tests

* Adding a feature flag to avoid indexing files before the feature is released

* Fixing i18n

Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-02-22 14:28:52 +01:00
John Tzikas
813f60649f Close search replicas on store close (#16985) 2021-02-19 16:30:23 +02:00
John Tzikas
8d6dd195e1 Remote any references to sqlite (#16980)
* Remote any references to sqlite

* Fix specs
2021-02-19 11:09:52 +02:00
Haardik Dharma
6356e906e0 [Partial Fix - #16623]: Fix initialism errors in codebase. (#16877)
* Update files in /app

* Update files in /plugin

* Update files in /store

* Update files in /utils

* Update files in /web

* Update store.go

* Update command_response.go

* check-mocks and check-store-layer checks

* Fix build errors

* Revert "Fix build errors"

This reverts commit 4ee38c3d0b.

* Update .golangci.yml

* make i18n-extract and make i18n-check

* Commit suggestions

* check-mocks and check-store-layers

* Update en.json

* Update product_notices.go

* Update main.go

* Fix translations

* Regenerate mocks

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Claudio Costa <cstcld91@gmail.com>
2021-02-18 15:36:56 +01:00
Agniva De Sarker
9992a27a90 Revert "MM-24530-Add support for search terms with underscore using postgresql engine (#16618)" (#16950)
This reverts commit ba3b788e46.
2021-02-17 13:52:15 +05:30
Agniva De Sarker
2596a9e630 MM-32893: Refactor the getting of DB handle (#16943)
* MM-32893: Refactor the getting of DB handle

We add a method in *SqlStore that returns the correct DB handle
depending on the context.

https://mattermost.atlassian.net/browse/MM-32893

```release-note
NONE
```

* fix receiver name
2021-02-16 14:00:03 +05:30
Jesús Espino
59d33b9002 Migrate channel to waitgroup for access the store in parallel (#16926)
* Migrate channel to waitgroup for access the store in parallel

* Addressing PR review comments

* Using a cleanest way of group errors

* Reverting go.mod change
2021-02-15 19:32:45 +01:00
Eli Yukelzon
830594004b MM-32652 /threads?unread=true returns null threads and no counts if there are no unread threads (#16885)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-02-15 15:42:05 +02:00
Agniva De Sarker
021c90f29f MM-30882: Fix read-after-write issue for demoting user (#16911)
* MM-30882: Fix read-after-write issue for demoting user

In (*App).DemoteUserToGuest, we would demote a user, and then immediately
read it back to do future operations from the user. This reading back
of the user had the effect of sticking the old value into the cache
after which it would never be updated.

There was another issue along with this, which was when the invalidation
message would broadcast across the cluster, it would hit the cache invalidation
problem where an unrelated store call would miss the cache because
it was invalidated, and then again read from replica and stick the old value.

To fix all these, we return the new value directly from the store method
to avoid having the app to read it again.

And we add a map in the localcache layer which tracks invalidations made,
and then switch to use master if it's true.

The core change is fairly limited, but due to changing the store method signatures,
a lot of code needed to be updated to pass "context.Background". Therefore the PR
just "appears" to be big, but the main changes are limited to app/user.go,
sqlstore/user_store.go and user_layer.go

https://mattermost.atlassian.net/browse/MM-30882

```release-note
Fix an issue where demoting a user to guest would not take effect in
an environment with read replicas.
```

* Fix concurrent map access

* Fixing mistakes

* fix tests
2021-02-12 19:04:05 +05:30
Mahmudul Haque
2b038db6ad unparam lint (#16901)
Automatic Merge
2021-02-12 10:22:27 +01:00
Claudio Costa
6b35b933a8 Revert "MM-27312 Allow uploading 10 files per post (#16235)" (#16908)
This reverts commit 8e2986e5ed.
2021-02-10 20:19:05 +01:00
John Tzikas
1e3b6b56a6 Optimise creation of DM (#16819)
* Optimise creation of dm

* Handle direct channels with the same user

* Cover GetMany with specs and add it on tha cache layer as well

* Fix specs by handling user dming themselves

* Apply PR suggestions

* Apply PR suggestions

* Use require.NoError instead of require.Nil on userstore test

* Improve readability of GetOrCreateDirectChannel

* Apply PR suggestions

* Update layers

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-02-10 15:51:04 +02:00
Jesús Espino
0e9ad9f7f8 Replacing {require,assert}.{Nil,NotNil} with {require,assert}.{NoError,Error} in the store tests (when comparing errors) (#16886)
* Replacing require.Nil with require.NoError

* More replacements

* More Nil/NotNill to NoError/Error

* Other detected errors

* renaming apperr to err

* Removed not needed line

* Rename old appErr variables that are no longer model.AppError values

* Fixing tiny typo

* Reverting changes outside the store (accidentally added)

* Apply suggestions from code review

Co-authored-by: Doug Lauder <wiggin77@warpmail.net>

Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
2021-02-10 11:34:41 +01:00
Eli Yukelzon
9a33c3706a MM-32525 Incorrect number of mentions for channels when threads are enabled (#16853) 2021-02-09 12:03:32 +02:00
John Tzikas
4a60cdaf4f Avoid possible false possitives when generating team names (#16856) 2021-02-08 11:06:40 +02:00
Mahmudul Haque
a63dea6c55 unparam lint (#16771)
* fixed: `identifier` is unused lint error

* make saveMultipleMembersT method saveMultipleMembers

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-02-04 11:08:05 +05:30