1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.arvados.org/arvados.git/sdk/go/arvados"
13 "git.arvados.org/arvados.git/services/keepstore"
16 // Pull is a request to retrieve a block from a remote server, and
24 // MarshalJSON formats a pull request the way keepstore wants to see
26 func (p Pull) MarshalJSON() ([]byte, error) {
27 return json.Marshal(keepstore.PullListItem{
28 Locator: string(p.SizedDigest),
29 Servers: []string{p.From.URLBase()},
30 MountUUID: p.To.KeepMount.UUID,
34 // Trash is a request to delete a block.
41 // MarshalJSON formats a trash request the way keepstore wants to see
42 // it, i.e., as a bare locator with no +size hint.
43 func (t Trash) MarshalJSON() ([]byte, error) {
44 return json.Marshal(keepstore.TrashListItem{
45 Locator: string(t.SizedDigest),
47 MountUUID: t.From.KeepMount.UUID,
51 // ChangeSet is a set of change requests that will be sent to a
53 type ChangeSet struct {
58 PullsDeferred int // number that weren't added because of PullLimit
60 TrashesDeferred int // number that weren't added because of TrashLimit
64 // AddPull adds a Pull operation.
65 func (cs *ChangeSet) AddPull(p Pull) {
67 if len(cs.Pulls) < cs.PullLimit {
68 cs.Pulls = append(cs.Pulls, p)
75 // AddTrash adds a Trash operation
76 func (cs *ChangeSet) AddTrash(t Trash) {
78 if len(cs.Trashes) < cs.TrashLimit {
79 cs.Trashes = append(cs.Trashes, t)
86 // String implements fmt.Stringer.
87 func (cs *ChangeSet) String() string {
89 defer cs.mutex.Unlock()
90 return fmt.Sprintf("ChangeSet{Pulls:%d, Trashes:%d} Deferred{Pulls:%d Trashes:%d}", len(cs.Pulls), len(cs.Trashes), cs.PullsDeferred, cs.TrashesDeferred)