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"
15 // Pull is a request to retrieve a block from a remote server, and
23 // MarshalJSON formats a pull request the way keepstore wants to see
25 func (p Pull) MarshalJSON() ([]byte, error) {
26 type KeepstorePullRequest struct {
27 Locator string `json:"locator"`
28 Servers []string `json:"servers"`
29 MountUUID string `json:"mount_uuid"`
31 return json.Marshal(KeepstorePullRequest{
32 Locator: string(p.SizedDigest[:32]),
33 Servers: []string{p.From.URLBase()},
34 MountUUID: p.To.KeepMount.UUID,
38 // Trash is a request to delete a block.
45 // MarshalJSON formats a trash request the way keepstore wants to see
46 // it, i.e., as a bare locator with no +size hint.
47 func (t Trash) MarshalJSON() ([]byte, error) {
48 type KeepstoreTrashRequest struct {
49 Locator string `json:"locator"`
50 BlockMtime int64 `json:"block_mtime"`
51 MountUUID string `json:"mount_uuid"`
53 return json.Marshal(KeepstoreTrashRequest{
54 Locator: string(t.SizedDigest[:32]),
56 MountUUID: t.From.KeepMount.UUID,
60 // ChangeSet is a set of change requests that will be sent to a
62 type ChangeSet struct {
67 PullsDeferred int // number that weren't added because of PullLimit
69 TrashesDeferred int // number that weren't added because of TrashLimit
73 // AddPull adds a Pull operation.
74 func (cs *ChangeSet) AddPull(p Pull) {
76 if len(cs.Pulls) < cs.PullLimit {
77 cs.Pulls = append(cs.Pulls, p)
84 // AddTrash adds a Trash operation
85 func (cs *ChangeSet) AddTrash(t Trash) {
87 if len(cs.Trashes) < cs.TrashLimit {
88 cs.Trashes = append(cs.Trashes, t)
95 // String implements fmt.Stringer.
96 func (cs *ChangeSet) String() string {
98 defer cs.mutex.Unlock()
99 return fmt.Sprintf("ChangeSet{Pulls:%d, Trashes:%d} Deferred{Pulls:%d Trashes:%d}", len(cs.Pulls), len(cs.Trashes), cs.PullsDeferred, cs.TrashesDeferred)