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 {
68 // AddPull adds a Pull operation.
69 func (cs *ChangeSet) AddPull(p Pull) {
71 cs.Pulls = append(cs.Pulls, p)
75 // AddTrash adds a Trash operation
76 func (cs *ChangeSet) AddTrash(t Trash) {
78 cs.Trashes = append(cs.Trashes, t)
82 // String implements fmt.Stringer.
83 func (cs *ChangeSet) String() string {
85 defer cs.mutex.Unlock()
86 return fmt.Sprintf("ChangeSet{Pulls:%d, Trashes:%d}", len(cs.Pulls), len(cs.Trashes))