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
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
446c6d452e
Коммит
6f8577b4c1
@@ -47,6 +47,27 @@ func (a *App) SetPluginKeyWithExpiry(pluginId string, key string, value []byte,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) CompareAndSetPluginKey(pluginId string, key string, oldValue, newValue []byte) (bool, *model.AppError) {
|
||||
kv := &model.PluginKeyValue{
|
||||
PluginId: pluginId,
|
||||
Key: key,
|
||||
Value: newValue,
|
||||
}
|
||||
|
||||
updated, err := a.Srv.Store.Plugin().CompareAndSet(kv, oldValue)
|
||||
if err != nil {
|
||||
mlog.Error("Failed to compare and set plugin key value", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(err))
|
||||
return updated, err
|
||||
}
|
||||
|
||||
// Clean up a previous entry using the hashed key, if it exists.
|
||||
if result := <-a.Srv.Store.Plugin().Delete(pluginId, getKeyHash(key)); result.Err != nil {
|
||||
mlog.Error("Failed to clean up previously hashed plugin key value", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(result.Err))
|
||||
}
|
||||
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPluginKey(pluginId string, key string) ([]byte, *model.AppError) {
|
||||
if result := <-a.Srv.Store.Plugin().Get(pluginId, key); result.Err == nil {
|
||||
return result.Data.(*model.PluginKeyValue).Value, nil
|
||||
|
||||
Ссылка в новой задаче
Block a user