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

Unified Diff: cipd/client/cipd/client.go

Issue 2317633002: Add counter-write and counter-read commands. (Closed)
Patch Set: CL comments Created 4 years, 3 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 | « no previous file | cipd/client/cipd/remote.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cipd/client/cipd/client.go
diff --git a/cipd/client/cipd/client.go b/cipd/client/cipd/client.go
index f97983ae7bf9aaa82858c5e76a1b3c4e2cd93671..170dbf007fefde973db383c1b88f74264ee3add0 100644
--- a/cipd/client/cipd/client.go
+++ b/cipd/client/cipd/client.go
@@ -120,8 +120,16 @@ func (t UnixTime) Before(t2 UnixTime) bool {
return time.Time(t).Before(time.Time(t2))
}
+// IsZero reports whether t represents the zero time instant.
+func (t UnixTime) IsZero() bool {
+ return time.Time(t).IsZero()
+}
+
// MarshalJSON is used by JSON encoder.
func (t UnixTime) MarshalJSON() ([]byte, error) {
+ if t.IsZero() {
+ return []byte("0"), nil
+ }
return []byte(fmt.Sprintf("%d", time.Time(t).Unix())), nil
}
@@ -199,6 +207,18 @@ type RefInfo struct {
ModifiedTs UnixTime `json:"modified_ts"`
}
+// Counter is returned by ReadCounter.
+type Counter struct {
+ // Name is the counter's name.
+ Name string `json:"name"`
+ // Value is the counter's value.
+ Value int64 `json:"value"`
+ // CreatedTS is the first time the counter was written.
+ CreatedTS UnixTime `json:"created_ts"`
+ // UpdatedTS is the most recent time the counter was written.
+ UpdatedTS UnixTime `json:"updated_ts"`
+}
+
// Actions is returned by EnsurePackages.
//
// It lists pins that were attempted to be installed, updated or removed, as
@@ -321,6 +341,15 @@ type Client interface {
//
// If the update was only partially applied, returns both Actions and error.
EnsurePackages(ctx context.Context, pins []common.Pin, dryRun bool) (Actions, error)
+
+ // IncrementCounter adds delta to the counter's value and updates its last
+ // updated timestamp.
+ //
+ // delta must be 0 or 1.
+ IncrementCounter(ctx context.Context, pin common.Pin, counterName string, delta int) error
+
+ // ReadCounter returns the current value of the counter.
+ ReadCounter(ctx context.Context, pin common.Pin, counterName string) (Counter, error)
}
// ClientOptions is passed to NewClient factory function.
@@ -651,6 +680,14 @@ func (client *clientImpl) DeletePackage(ctx context.Context, packageName string)
return client.remote.deletePackage(ctx, packageName)
}
+func (client *clientImpl) IncrementCounter(ctx context.Context, pin common.Pin, counter string, delta int) error {
+ return client.remote.incrementCounter(ctx, pin, counter, delta)
+}
+
+func (client *clientImpl) ReadCounter(ctx context.Context, pin common.Pin, counter string) (Counter, error) {
+ return client.remote.readCounter(ctx, pin, counter)
+}
+
func (client *clientImpl) SetRefWhenReady(ctx context.Context, ref string, pin common.Pin) error {
if err := common.ValidatePackageRef(ref); err != nil {
return err
@@ -1047,6 +1084,9 @@ type remote interface {
listPackages(ctx context.Context, path string, recursive, showHidden bool) ([]string, []string, error)
searchInstances(ctx context.Context, tag, packageName string) ([]common.Pin, error)
+
+ incrementCounter(ctx context.Context, pin common.Pin, counter string, delta int) error
+ readCounter(ctx context.Context, pin common.Pin, counter string) (Counter, error)
}
type storage interface {
« no previous file with comments | « no previous file | cipd/client/cipd/remote.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698