Unify variable naming between GuaranteedUpdate and Delete in storage

This commit is contained in:
wojtekt 2020-12-16 09:28:44 +01:00
parent c995039d62
commit d0726e4b13
4 changed files with 20 additions and 18 deletions

View File

@ -78,7 +78,7 @@ func (s *DryRunnableStorage) List(ctx context.Context, key string, opts storage.
func (s *DryRunnableStorage) GuaranteedUpdate( func (s *DryRunnableStorage) GuaranteedUpdate(
ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool, ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool,
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, dryRun bool, suggestion runtime.Object) error { preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, dryRun bool, cachedExistingObject runtime.Object) error {
if dryRun { if dryRun {
err := s.Storage.Get(ctx, key, storage.GetOptions{IgnoreNotFound: ignoreNotFound}, ptrToType) err := s.Storage.Get(ctx, key, storage.GetOptions{IgnoreNotFound: ignoreNotFound}, ptrToType)
if err != nil { if err != nil {
@ -98,7 +98,7 @@ func (s *DryRunnableStorage) GuaranteedUpdate(
} }
return s.copyInto(out, ptrToType) return s.copyInto(out, ptrToType)
} }
return s.Storage.GuaranteedUpdate(ctx, key, ptrToType, ignoreNotFound, preconditions, tryUpdate, suggestion) return s.Storage.GuaranteedUpdate(ctx, key, ptrToType, ignoreNotFound, preconditions, tryUpdate, cachedExistingObject)
} }
func (s *DryRunnableStorage) Count(key string) (int64, error) { func (s *DryRunnableStorage) Count(key string) (int64, error) {

View File

@ -752,6 +752,8 @@ func (c *Cacher) GuaranteedUpdate(
if elem, exists, err := c.watchCache.GetByKey(key); err != nil { if elem, exists, err := c.watchCache.GetByKey(key); err != nil {
klog.Errorf("GetByKey returned error: %v", err) klog.Errorf("GetByKey returned error: %v", err)
} else if exists { } else if exists {
// DeepCopy the object since we modify resource version when serializing the
// current object.
currObj := elem.(*storeElement).Object.DeepCopyObject() currObj := elem.(*storeElement).Object.DeepCopyObject()
return c.storage.GuaranteedUpdate(ctx, key, ptrToType, ignoreNotFound, preconditions, tryUpdate, currObj) return c.storage.GuaranteedUpdate(ctx, key, ptrToType, ignoreNotFound, preconditions, tryUpdate, currObj)
} }

View File

@ -285,7 +285,7 @@ func (s *store) conditionalDelete(
// GuaranteedUpdate implements storage.Interface.GuaranteedUpdate. // GuaranteedUpdate implements storage.Interface.GuaranteedUpdate.
func (s *store) GuaranteedUpdate( func (s *store) GuaranteedUpdate(
ctx context.Context, key string, out runtime.Object, ignoreNotFound bool, ctx context.Context, key string, out runtime.Object, ignoreNotFound bool,
preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, suggestion runtime.Object) error { preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, cachedExistingObject runtime.Object) error {
trace := utiltrace.New("GuaranteedUpdate etcd3", utiltrace.Field{"type", getTypeName(out)}) trace := utiltrace.New("GuaranteedUpdate etcd3", utiltrace.Field{"type", getTypeName(out)})
defer trace.LogIfLong(500 * time.Millisecond) defer trace.LogIfLong(500 * time.Millisecond)
@ -306,12 +306,12 @@ func (s *store) GuaranteedUpdate(
} }
var origState *objState var origState *objState
var mustCheckData bool var origStateIsCurrent bool
if suggestion != nil { if cachedExistingObject != nil {
origState, err = s.getStateFromObject(suggestion) origState, err = s.getStateFromObject(cachedExistingObject)
mustCheckData = true
} else { } else {
origState, err = getCurrentState() origState, err = getCurrentState()
origStateIsCurrent = true
} }
if err != nil { if err != nil {
return err return err
@ -322,7 +322,7 @@ func (s *store) GuaranteedUpdate(
for { for {
if err := preconditions.Check(key, origState.obj); err != nil { if err := preconditions.Check(key, origState.obj); err != nil {
// If our data is already up to date, return the error // If our data is already up to date, return the error
if !mustCheckData { if origStateIsCurrent {
return err return err
} }
@ -332,7 +332,7 @@ func (s *store) GuaranteedUpdate(
if err != nil { if err != nil {
return err return err
} }
mustCheckData = false origStateIsCurrent = true
// Retry // Retry
continue continue
} }
@ -340,7 +340,7 @@ func (s *store) GuaranteedUpdate(
ret, ttl, err := s.updateState(origState, tryUpdate) ret, ttl, err := s.updateState(origState, tryUpdate)
if err != nil { if err != nil {
// If our data is already up to date, return the error // If our data is already up to date, return the error
if !mustCheckData { if origStateIsCurrent {
return err return err
} }
@ -350,7 +350,7 @@ func (s *store) GuaranteedUpdate(
if err != nil { if err != nil {
return err return err
} }
mustCheckData = false origStateIsCurrent = true
// Retry // Retry
continue continue
} }
@ -363,12 +363,12 @@ func (s *store) GuaranteedUpdate(
// if we skipped the original Get in this loop, we must refresh from // if we skipped the original Get in this loop, we must refresh from
// etcd in order to be sure the data in the store is equivalent to // etcd in order to be sure the data in the store is equivalent to
// our desired serialization // our desired serialization
if mustCheckData { if !origStateIsCurrent {
origState, err = getCurrentState() origState, err = getCurrentState()
if err != nil { if err != nil {
return err return err
} }
mustCheckData = false origStateIsCurrent = true
if !bytes.Equal(data, origState.data) { if !bytes.Equal(data, origState.data) {
// original data changed, restart loop // original data changed, restart loop
continue continue
@ -412,7 +412,7 @@ func (s *store) GuaranteedUpdate(
return err return err
} }
trace.Step("Retry value restored") trace.Step("Retry value restored")
mustCheckData = false origStateIsCurrent = true
continue continue
} }
putResp := txnResp.Responses[0].GetResponsePut() putResp := txnResp.Responses[0].GetResponsePut()

View File

@ -220,9 +220,9 @@ type Interface interface {
// or zero value in 'ptrToType' parameter otherwise. // or zero value in 'ptrToType' parameter otherwise.
// If the object to update has the same value as previous, it won't do any update // If the object to update has the same value as previous, it won't do any update
// but will return the object in 'ptrToType' parameter. // but will return the object in 'ptrToType' parameter.
// If 'suggestion' is non-nil, it can be used as a suggestion about the current version // If 'cachedExistingObject' is non-nil, it can be used as a suggestion about the
// of the object to avoid read operation from storage to get it. However, the // current version of the object to avoid read operation from storage to get it.
// implementations have to retry in case suggestion is stale. // However, the implementations have to retry in case suggestion is stale.
// //
// Example: // Example:
// //
@ -244,7 +244,7 @@ type Interface interface {
// ) // )
GuaranteedUpdate( GuaranteedUpdate(
ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool, ctx context.Context, key string, ptrToType runtime.Object, ignoreNotFound bool,
precondtions *Preconditions, tryUpdate UpdateFunc, suggestion runtime.Object) error precondtions *Preconditions, tryUpdate UpdateFunc, cachedExistingObject runtime.Object) error
// Count returns number of different entries under the key (generally being path prefix). // Count returns number of different entries under the key (generally being path prefix).
Count(key string) (int64, error) Count(key string) (int64, error)