1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.curoverse.com/arvados.git/sdk/go/arvados"
15 // Pull is a request to retrieve a block from a remote server, and
22 // MarshalJSON formats a pull request the way keepstore wants to see
24 func (p Pull) MarshalJSON() ([]byte, error) {
25 type KeepstorePullRequest struct {
26 Locator string `json:"locator"`
27 Servers []string `json:"servers"`
29 return json.Marshal(KeepstorePullRequest{
30 Locator: string(p.SizedDigest[:32]),
31 Servers: []string{p.Source.URLBase()}})
34 // Trash is a request to delete a block.
40 // MarshalJSON formats a trash request the way keepstore wants to see
41 // it, i.e., as a bare locator with no +size hint.
42 func (t Trash) MarshalJSON() ([]byte, error) {
43 type KeepstoreTrashRequest struct {
44 Locator string `json:"locator"`
45 BlockMtime int64 `json:"block_mtime"`
47 return json.Marshal(KeepstoreTrashRequest{
48 Locator: string(t.SizedDigest[:32]),
52 // ChangeSet is a set of change requests that will be sent to a
54 type ChangeSet struct {
60 // AddPull adds a Pull operation.
61 func (cs *ChangeSet) AddPull(p Pull) {
63 cs.Pulls = append(cs.Pulls, p)
67 // AddTrash adds a Trash operation
68 func (cs *ChangeSet) AddTrash(t Trash) {
70 cs.Trashes = append(cs.Trashes, t)
74 // String implements fmt.Stringer.
75 func (cs *ChangeSet) String() string {
77 defer cs.mutex.Unlock()
78 return fmt.Sprintf("ChangeSet{Pulls:%d, Trashes:%d}", len(cs.Pulls), len(cs.Trashes))