Commit Graph

26 Commits

Author SHA1 Message Date
Joshua Bezaleel Abednego
4ba6c35813 [MM-24664] Plugin_store queries squirrel refactor (#14523)
* Use squirrel to build query for plugin store

* Typo of PluginkeyValueStore to PluginKeyValueStore

* wrong parameter of queryBuilder in Get method

* Use casting to int for comparison on ExpireAt

* Revert query for CompareAndSet and CompareAndDelete temporarily

* Delete query of expired value

* Update query when oldValue is not nil

* Check count query when there is no row affected

* Delete query on CompareAndDelete

* Put squirrel in separate import group

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2020-07-15 22:22:35 +05:30
Mario de Frutos Dieguez
6107660483 [MM-24088] Use Raw SQL query for PluginStore.Get instead of GORP (#14650)
* Use Raw SQL query instead of GORP

As part of performance improvements we're moving the top
used queries to avoid using gorp and get rid of the overhead
caused by the reflection usage
2020-07-15 09:19:51 +02:00
Jesús Espino
2a5d30f8f3 Making private some sqlstore methods (#13895)
* Making private some sqlstore methods

* Calling for create indexes on missing stores

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-03-03 11:45:49 +01:00
Jesse Hallam
17f2cd665d MM-21672: KVCompareAndSet improvements (#13858)
* allow ExpireInSeconds < 0

Allow `ExpireInSeconds < 0` for use with `KVSetWithOptions`. While this has no practical use in reality, it's much easier to thoroughly unit tests the underlying functionality if we can match the semantics of CompareAndSet. Strictly speaking, this is a breaking change, but not relative to the advertised semantics. Anyway, it's also not entirely unreasonable to treat a negative `ExpireInSeconds` as having already expired vs. marking it as never expired.

* updated tests, to break apart

* honour expiry in CompareAndSet

* honour expiry in CompareAndDelete

* honour expiry in List

* fail unique constraint exception for SaveOrUpdate

A unique constraint error on a `SaveOrUpdate` should not be ignored: we did not save or update the requested value, as someone else managed to write the record first.

Note this is handled differently in `CompareAndSet`, where we correctly swallow the error and return `false` to indicate we did not successfully save the value.

* unexport DEFAULT_PLUGIN_KEY_FETCH_LIMIT

* s/InternalServerError/BadRequest/ for failed SaveOrUpdate

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-02-18 16:32:46 -04:00
Jesús Espino
7afafd7767 Fixing key value duplication race condition in postgres (#13753)
Automatic Merge
2020-02-04 14:05:08 -05:00
Jesse Hallam
918307e4fa delete kv on setting nil (#13769)
Setting a `nil` value should actually delete the row instead of preserve it with a `nil` value.

The existing tests passed because they only checked the return value of `nil`. When running the tests on Postgres, this value is returned as an empty `[]byte{}` instead of `nil`, so update the test to reflect this semantically equivalent behaviour.
2020-01-31 09:58:48 -04:00
Jesse Hallam
4314a0427f MM-21328: Fix KVCompareAndSet when new==old (#13612)
`KVCompareAndSet(key, sameValue, sameValue)` can fail spuriously on MySQL if the underlying `UPDATE` requires no actual changes. As per the [MySQL documentation](https://dev.mysql.com/doc/refman/8.0/en/mysql-affected-rows.html), we can't rely on rows affected in this case:

> For UPDATE statements, the affected-rows value by default is the number of rows actually changed. If you specify the CLIENT_FOUND_ROWS flag to mysql_real_connect() when connecting to mysqld, the affected-rows value is the number of rows “found”; that is, matched by the WHERE clause.

It's not tenable to change `CLIENT_FOUND_ROWS` for the all connection, so handle this case in the code instead by running a `SELECT` after the fact. Note that `KVCompareAndSet` has no guarantee of atomicity in this case, but neither would `CompareAndSwap` on which this is method was inspired.

Finally, note that no changes are required for Postgres, which has sane semantics as the default.

Fixes: https://mattermost.atlassian.net/browse/MM-21328

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-01-16 15:29:10 -04:00
Ben Schumacher
d0d6ce0a70 [MM-20353] Change KVSetWithOptions to accept a byte slice (#13213)
* Drop EncodeJSON from PluginKVSetOptions

* Add unit tests for KVSetWithOptions with nil values
2019-12-03 10:46:15 +01:00
Jesús Espino
a63684fcb5 Consistent license message for all the go files (#13235)
* Consistent license message for all the go files

* Fixing the last set of unconsistencies with the license headers

* Addressing PR review comments

* Fixing busy.go and busy_test.go license header
2019-11-29 12:59:40 +01:00
Miguel de la Cruz
2259b7f2a8 [MM-19948] Set version on module file and internal paths (#13186)
* [MM-19948] Set version on module file and internal paths

* Fixes after merge

* Fix i18n checker error
2019-11-28 14:39:38 +01:00
Gervasio Marchand
1db045bce3 MM-16822 - Implement KVSetWithOptions (#11818)
* Add SetWithOptions

* Avoid passing two structs to the functions

* Rename ExpiryInSeconds -> ExpireInSeconds

* Use t.Run for the tests

* Fix build

* Address feedback

* Update log message

* Update docs and use KVSetWithOptions in KVCompareAndSetJSON

* Improve code style

* Use struct instead of pointer to struct

* Fix minimum server versions

* Update documentation

* Address feedback

* Revert new implemention of kv helpers

* Adress feedback
2019-11-04 13:49:54 +01:00
Gervasio Marchand
11b0a20d7d MM-16821 - Add a KVCompareAndDelete to the plugin API (#11804)
* Implement KVCompareAndDelete and KVCompareAndDeleteJSON

* Add tests for KVCompareAndDelete

* Update minimum server version

* Handle nil value on CompareAndSet so that it deletes it

* Fix comments

* Tweaks from PR comments

* Go back to deleted, err
2019-08-21 23:25:38 -03:00
Phillip Ahereza
1cb32b2331 [MM-16791] Migrate Plugin.Delete to Sync by default (#11580)
* Migrate Plugin.Delete to Sync by default

* remove unused import
2019-07-16 09:10:17 -04:00
Phillip Ahereza
e9b82bc1ce Migrate Plugin.DeleteAllForPlugin to Sync by default (#11597) 2019-07-10 14:54:38 -04:00
Phillip Ahereza
eb0268f108 Migrate Plugin.DeleteAllExpired to Sync by default (#11583) 2019-07-09 17:15:35 +02:00
Rodrigo Villablanca Vásquez
ce61681c92 Migrate Plugin.SaveOrUpdate to sync by default (#11592) 2019-07-09 15:08:28 +02:00
Phillip Ahereza
ff5b221598 Migrate Plugin.List to Sync by default (#11582) 2019-07-08 23:35:33 +08:00
Phillip Ahereza
17b49e4538 [MM-16790] Migrate Plugin.Get to Sync by default (#11581)
* Migrate Plugin.Get to Sync by default

* remove unnecessary else branch

* remove unnecesary blank line
2019-07-08 13:13:10 +02:00
Ali F
6f8577b4c1 MM-14246 - Plugin framework: support transactional semantics with KV Store (#10634)
* MM-14246 - Plugin framework: support transactional semantics with KV Store

Rename old, new variable names

Moving New function to the bottom

* Made CompareAndUpdate sync, updated tests

* Removed going through channel in CompareAndSetPluginKey

* Inserting new key when oldValue is nil to KVCompareAndSet

* Updated error text to include CompareAndSet
2019-04-23 10:35:17 -07:00
Daniel Schalla
c36e85c912 DeleteAll for KV (#9431)
Expire K/V Values

Regenerate Code

pathfix

Update Expiry on Update

Check for Exit Signal

gofmt

Rewrote Go Routine

Remove tempoarily cleanup loop

fix expiretime

TEST: Expired Watchdog as GoRoutine

Check if Srv is nil

Use Scheduler/Worker for Expired Key CleanUp

add license

fix scheduler job type; DoJob Restructuring

Remove unused imports and constants

move db migration from 5.4 to 5.5
2018-10-10 10:55:12 -07:00
Shobhit Gupta
8c03e584c1 MM-11863 Add KVList method (#9467)
* Add KVList method

* Add KVList method

Add KVList method

* Add pagination support

* Change offset, limit to page, perPage

* Rename constant
2018-10-03 16:04:37 -04:00
Joram Wilander
7cefef6d21 Hash key for plugin store and limit id length (#7933) 2017-12-05 15:19:33 -08:00
Christopher Speller
81c1fad4d4 Revert "Hash key for plugin store table and limit plugin ID length (#7915)" (#7931)
This reverts commit c3af878573.
2017-12-01 23:20:11 -08:00
Joram Wilander
c3af878573 Hash key for plugin store table and limit plugin ID length (#7915)
* Hash plugin store keys and update column limits

* Limit plugin ID length on install

* Add note to manifest id and allow zero length keys
2017-12-01 15:20:08 -05:00
Joram Wilander
785a410936 Decrease plugin key value store table index name size (#7910) 2017-11-27 18:49:28 -05:00
Joram Wilander
6176bcff69 PLT-8131 (part2) Add plugin key value store support (#7902)
* Add plugin key value store support

* Add localization strings

* Updates per feedback
2017-11-27 17:23:35 -05:00