Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: go/src/infra/gae/libs/memlock/memlock.go

Issue 1230303003: Revert "Refactor current GAE abstraction library to be free of the SDK*" (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/gae/libs/gae/upstream_types.go ('k') | go/src/infra/gae/libs/memlock/memlock_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/memlock/memlock.go
diff --git a/go/src/infra/gae/libs/memlock/memlock.go b/go/src/infra/gae/libs/memlock/memlock.go
index fee7dcd2374ddd9690f0325b29c06f8321001e77..0665f0d60d14aa1c6eb1f22302b1b3f8f61079c2 100644
--- a/go/src/infra/gae/libs/memlock/memlock.go
+++ b/go/src/infra/gae/libs/memlock/memlock.go
@@ -11,14 +11,15 @@ package memlock
import (
"bytes"
"errors"
- "golang.org/x/net/context"
+ "infra/gae/libs/wrapper"
+ "infra/libs/clock"
"sync/atomic"
"time"
- "infra/gae/libs/gae"
-
- "github.com/luci/luci-go/common/clock"
"github.com/luci/luci-go/common/logging"
+ "golang.org/x/net/context"
+
+ "appengine/memcache"
)
// ErrFailedToLock is returned from TryWithLock when it fails to obtain a lock
@@ -66,7 +67,7 @@ func TryWithLock(ctx context.Context, key, clientID string, f func(check func()
ctx = logging.SetField(ctx, "key", key)
ctx = logging.SetField(ctx, "clientID", clientID)
log := logging.Get(ctx)
- mc := gae.GetMC(ctx)
+ mc := wrapper.GetMC(ctx)
key = memlockKeyPrefix + key
cid := []byte(clientID)
@@ -89,20 +90,22 @@ func TryWithLock(ctx context.Context, key, clientID string, f func(check func()
return false
}
- if len(itm.Value()) > 0 && !bytes.Equal(itm.Value(), cid) {
- log.Infof("lock owned by %q", string(itm.Value()))
+ if len(itm.Value) > 0 && !bytes.Equal(itm.Value, cid) {
+ log.Infof("lock owned by %q", string(itm.Value))
return false
}
if op == refresh {
- itm.SetValue(cid).SetExpiration(memcacheLockTime)
+ itm.Value = cid
+ itm.Expiration = memcacheLockTime
} else {
- if len(itm.Value()) == 0 {
+ if len(itm.Value) == 0 {
// it's already unlocked, no need to CAS
log.Infof("lock already released")
return true
}
- itm.SetValue([]byte{}).SetExpiration(delay)
+ itm.Value = []byte{}
+ itm.Expiration = delay
}
err = mc.CompareAndSwap(itm)
@@ -116,10 +119,10 @@ func TryWithLock(ctx context.Context, key, clientID string, f func(check func()
// Now the actual logic begins. First we 'Add' the item, which will set it if
// it's not present in the memcache, otherwise leaves it alone.
-
- err := mc.Add(mc.NewItem(key).SetValue(cid).SetExpiration(memcacheLockTime))
+ err := mc.Add(&memcache.Item{
+ Key: key, Value: cid, Expiration: memcacheLockTime})
if err != nil {
- if err != gae.ErrMCNotStored {
+ if err != memcache.ErrNotStored {
log.Warningf("error adding: %s", err)
}
if !checkAnd(refresh) {
« no previous file with comments | « go/src/infra/gae/libs/gae/upstream_types.go ('k') | go/src/infra/gae/libs/memlock/memlock_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698