* Removing supplier concept from the sql store
* Removing other metions to supplier
* Fixing gofmt
* Fixing gofmt
* Renaming NewSqlStore to New
* Fixing tests
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* 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>
* 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
* 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>
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.
`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>
* 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
* 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
* 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
* 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
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