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
@@ -459,6 +459,16 @@ type API interface {
|
||||
// KVSet will store a key-value pair, unique per plugin.
|
||||
KVSet(key string, value []byte) *model.AppError
|
||||
|
||||
// KVCompareAndSet will update a key-value pair,
|
||||
// unique per plugin, to the given new value if the current value == the old value.
|
||||
// Inserts a new key if oldValue == nil.
|
||||
// Returns (false, err) if DB error occurred
|
||||
// Returns (false, nil) if current value != old value or key already exists when inserting
|
||||
// Returns (true, nil) if current value == old value or new key is inserted
|
||||
//
|
||||
// Minimum server version: 5.12
|
||||
KVCompareAndSet(key string, oldValue, newValue []byte) (bool, *model.AppError)
|
||||
|
||||
// KVSet will store a key-value pair, unique per plugin with an expiry time
|
||||
//
|
||||
// Minimum server version: 5.6
|
||||
|
||||
@@ -3490,6 +3490,37 @@ func (s *apiRPCServer) KVSet(args *Z_KVSetArgs, returns *Z_KVSetReturns) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_KVCompareAndSetArgs struct {
|
||||
A string
|
||||
B []byte
|
||||
C []byte
|
||||
}
|
||||
|
||||
type Z_KVCompareAndSetReturns struct {
|
||||
A bool
|
||||
B *model.AppError
|
||||
}
|
||||
|
||||
func (g *apiRPCClient) KVCompareAndSet(key string, oldValue, newValue []byte) (bool, *model.AppError) {
|
||||
_args := &Z_KVCompareAndSetArgs{key, oldValue, newValue}
|
||||
_returns := &Z_KVCompareAndSetReturns{}
|
||||
if err := g.client.Call("Plugin.KVCompareAndSet", _args, _returns); err != nil {
|
||||
log.Printf("RPC call to KVCompareAndSet API failed: %s", err.Error())
|
||||
}
|
||||
return _returns.A, _returns.B
|
||||
}
|
||||
|
||||
func (s *apiRPCServer) KVCompareAndSet(args *Z_KVCompareAndSetArgs, returns *Z_KVCompareAndSetReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
KVCompareAndSet(key string, oldValue, newValue []byte) (bool, *model.AppError)
|
||||
}); ok {
|
||||
returns.A, returns.B = hook.KVCompareAndSet(args.A, args.B, args.C)
|
||||
} else {
|
||||
return encodableError(fmt.Errorf("API KVCompareAndSet called but not implemented."))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_KVSetWithExpiryArgs struct {
|
||||
A string
|
||||
B []byte
|
||||
|
||||
@@ -1862,6 +1862,29 @@ func (_m *API) HasPermissionToTeam(userId string, teamId string, permission *mod
|
||||
return r0
|
||||
}
|
||||
|
||||
// KVCompareAndSet provides a mock function with given fields: key, oldValue, newValue
|
||||
func (_m *API) KVCompareAndSet(key string, oldValue []byte, newValue []byte) (bool, *model.AppError) {
|
||||
ret := _m.Called(key, oldValue, newValue)
|
||||
|
||||
var r0 bool
|
||||
if rf, ok := ret.Get(0).(func(string, []byte, []byte) bool); ok {
|
||||
r0 = rf(key, oldValue, newValue)
|
||||
} else {
|
||||
r0 = ret.Get(0).(bool)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, []byte, []byte) *model.AppError); ok {
|
||||
r1 = rf(key, oldValue, newValue)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// KVDelete provides a mock function with given fields: key
|
||||
func (_m *API) KVDelete(key string) *model.AppError {
|
||||
ret := _m.Called(key)
|
||||
|
||||
Ссылка в новой задаче
Block a user