Include Name as GlobalPinInfo key and consolidate redundant keys

GlobalPinInfo objects carried redundant information (Cid, Peer) that takes
space and time to serialize.

This has been addressed by having GlobalPinInfo embed PinInfoShort rather than
PinInfo. This new types ommits redundant fields.
This commit is contained in:
Hector Sanjuan 2020-05-16 00:32:28 +02:00
parent 4a0c8195eb
commit c026299b95
11 changed files with 268 additions and 186 deletions

View File

@ -490,16 +490,12 @@ func (wait *waitService) Status(ctx context.Context, in cid.Cid, out *types.Glob
if time.Now().After(wait.pinStart.Add(5 * time.Second)) { //pinned if time.Now().After(wait.pinStart.Add(5 * time.Second)) { //pinned
*out = types.GlobalPinInfo{ *out = types.GlobalPinInfo{
Cid: in, Cid: in,
PeerMap: map[string]*types.PinInfo{ PeerMap: map[string]*types.PinInfoShort{
peer.Encode(test.PeerID1): { peer.Encode(test.PeerID1): {
Cid: in,
Peer: test.PeerID1,
Status: types.TrackerStatusPinned, Status: types.TrackerStatusPinned,
TS: wait.pinStart, TS: wait.pinStart,
}, },
peer.Encode(test.PeerID2): { peer.Encode(test.PeerID2): {
Cid: in,
Peer: test.PeerID2,
Status: types.TrackerStatusPinned, Status: types.TrackerStatusPinned,
TS: wait.pinStart, TS: wait.pinStart,
}, },
@ -508,16 +504,12 @@ func (wait *waitService) Status(ctx context.Context, in cid.Cid, out *types.Glob
} else { // pinning } else { // pinning
*out = types.GlobalPinInfo{ *out = types.GlobalPinInfo{
Cid: in, Cid: in,
PeerMap: map[string]*types.PinInfo{ PeerMap: map[string]*types.PinInfoShort{
peer.Encode(test.PeerID1): { peer.Encode(test.PeerID1): {
Cid: in,
Peer: test.PeerID1,
Status: types.TrackerStatusPinning, Status: types.TrackerStatusPinning,
TS: wait.pinStart, TS: wait.pinStart,
}, },
peer.Encode(test.PeerID2): { peer.Encode(test.PeerID2): {
Cid: in,
Peer: test.PeerID2,
Status: types.TrackerStatusPinned, Status: types.TrackerStatusPinned,
TS: wait.pinStart, TS: wait.pinStart,
}, },

View File

@ -960,7 +960,7 @@ func (api *API) statusHandler(w http.ResponseWriter, r *http.Request) {
pin.Cid, pin.Cid,
&pinInfo, &pinInfo,
) )
api.sendResponse(w, autoStatus, err, pinInfoToGlobal(&pinInfo)) api.sendResponse(w, autoStatus, err, pinInfo.ToGlobal())
} else { } else {
var pinInfo types.GlobalPinInfo var pinInfo types.GlobalPinInfo
err := api.rpcClient.CallContext( err := api.rpcClient.CallContext(
@ -1019,7 +1019,7 @@ func (api *API) recoverHandler(w http.ResponseWriter, r *http.Request) {
pin.Cid, pin.Cid,
&pinInfo, &pinInfo,
) )
api.sendResponse(w, autoStatus, err, pinInfoToGlobal(&pinInfo)) api.sendResponse(w, autoStatus, err, pinInfo.ToGlobal())
} else { } else {
var pinInfo types.GlobalPinInfo var pinInfo types.GlobalPinInfo
err := api.rpcClient.CallContext( err := api.rpcClient.CallContext(
@ -1127,19 +1127,10 @@ func (api *API) parsePidOrError(w http.ResponseWriter, r *http.Request) peer.ID
return pid return pid
} }
func pinInfoToGlobal(pInfo *types.PinInfo) *types.GlobalPinInfo {
return &types.GlobalPinInfo{
Cid: pInfo.Cid,
PeerMap: map[string]*types.PinInfo{
peer.Encode(pInfo.Peer): pInfo,
},
}
}
func pinInfosToGlobal(pInfos []*types.PinInfo) []*types.GlobalPinInfo { func pinInfosToGlobal(pInfos []*types.PinInfo) []*types.GlobalPinInfo {
gPInfos := make([]*types.GlobalPinInfo, len(pInfos)) gPInfos := make([]*types.GlobalPinInfo, len(pInfos))
for i, p := range pInfos { for i, p := range pInfos {
gPInfos[i] = pinInfoToGlobal(p) gPInfos[i] = p.ToGlobal()
} }
return gPInfos return gPInfos
} }

View File

@ -246,11 +246,12 @@ var ipfsPinStatus2TrackerStatusMap = map[IPFSPinStatus]TrackerStatus{
// GlobalPinInfo contains cluster-wide status information about a tracked Cid, // GlobalPinInfo contains cluster-wide status information about a tracked Cid,
// indexed by cluster peer. // indexed by cluster peer.
type GlobalPinInfo struct { type GlobalPinInfo struct {
Cid cid.Cid `json:"cid" codec:"c"` Cid cid.Cid `json:"cid" codec:"c"`
Name string `json:"name" codec:"n"`
// https://github.com/golang/go/issues/28827 // https://github.com/golang/go/issues/28827
// Peer IDs are of string Kind(). We can't use peer IDs here // Peer IDs are of string Kind(). We can't use peer IDs here
// as Go ignores TextMarshaler. // as Go ignores TextMarshaler.
PeerMap map[string]*PinInfo `json:"peer_map" codec:"pm,omitempty"` PeerMap map[string]*PinInfoShort `json:"peer_map" codec:"pm,omitempty"`
} }
// String returns the string representation of a GlobalPinInfo. // String returns the string representation of a GlobalPinInfo.
@ -263,17 +264,47 @@ func (gpi *GlobalPinInfo) String() string {
return str return str
} }
// PinInfo holds information about local pins. // Add adds a PinInfo object to a GlobalPinInfo
type PinInfo struct { func (gpi *GlobalPinInfo) Add(pi *PinInfo) {
Cid cid.Cid `json:"cid" codec:"c"` if !gpi.Cid.Defined() {
Name string `json:"name" codec:"n,omitempty"` gpi.Cid = pi.Cid
Peer peer.ID `json:"peer" codec:"p,omitempty"` gpi.Name = pi.Name
}
if gpi.PeerMap == nil {
gpi.PeerMap = make(map[string]*PinInfoShort)
}
gpi.PeerMap[peer.Encode(pi.Peer)] = &pi.PinInfoShort
}
// PinInfoShort is a subset of PinInfo which is embedded in GlobalPinInfo
// objects and does not carry redundant information as PinInfo would.
type PinInfoShort struct {
PeerName string `json:"peername" codec:"pn,omitempty"` PeerName string `json:"peername" codec:"pn,omitempty"`
Status TrackerStatus `json:"status" codec:"st,omitempty"` Status TrackerStatus `json:"status" codec:"st,omitempty"`
TS time.Time `json:"timestamp" codec:"ts,omitempty"` TS time.Time `json:"timestamp" codec:"ts,omitempty"`
Error string `json:"error" codec:"e,omitempty"` Error string `json:"error" codec:"e,omitempty"`
} }
// PinInfo holds information about local pins. This is used by the Pin
// Trackers.
type PinInfo struct {
Cid cid.Cid `json:"cid" codec:"c"`
Name string `json:"name" codec:"m,omitempty"`
Peer peer.ID `json:"Peer" codec:"p,omitempty"`
PinInfoShort
}
// ToGlobal converts a PinInfo object to a GlobalPinInfo with
// a single peer corresponding to the given PinInfo.
func (pi *PinInfo) ToGlobal() *GlobalPinInfo {
gpi := GlobalPinInfo{}
gpi.Add(pi)
return &gpi
}
// Version holds version information // Version holds version information
type Version struct { type Version struct {
Version string `json:"version" codec:"v"` Version string `json:"version" codec:"v"`

View File

@ -1646,15 +1646,18 @@ func (c *Cluster) getTrustedPeers(ctx context.Context) ([]peer.ID, error) {
return trustedPeers, nil return trustedPeers, nil
} }
func setTrackerStatus(gpin *api.GlobalPinInfo, h cid.Cid, peers []peer.ID, status api.TrackerStatus, t time.Time) { func setTrackerStatus(gpin *api.GlobalPinInfo, h cid.Cid, peers []peer.ID, status api.TrackerStatus, name string, t time.Time) {
for _, p := range peers { for _, p := range peers {
gpin.PeerMap[peer.Encode(p)] = &api.PinInfo{ gpin.Add(&api.PinInfo{
Cid: h, Cid: h,
Peer: p, Name: name,
PeerName: p.String(), Peer: p,
Status: status, PinInfoShort: api.PinInfoShort{
TS: t, PeerName: p.String(),
} Status: status,
TS: t,
},
})
} }
} }
@ -1662,19 +1665,54 @@ func (c *Cluster) globalPinInfoCid(ctx context.Context, comp, method string, h c
ctx, span := trace.StartSpan(ctx, "cluster/globalPinInfoCid") ctx, span := trace.StartSpan(ctx, "cluster/globalPinInfoCid")
defer span.End() defer span.End()
gpin := &api.GlobalPinInfo{ // The object we will return
Cid: h, gpin := &api.GlobalPinInfo{}
PeerMap: make(map[string]*api.PinInfo),
}
// allocated peers, we will contact them through rpc // allocated peers, we will contact them through rpc
var dests []peer.ID var dests []peer.ID
// un-allocated peers, we will set remote status // un-allocated peers, we will set remote status
var remote []peer.ID var remote []peer.ID
timeNow := time.Now() timeNow := time.Now()
// set dests and remote // If pin is not part of the pinset, mark it unpinned
pin, err := c.PinGet(ctx, h)
if err != nil && err != state.ErrNotFound {
logger.Error(err)
return nil, err
}
// When NotFound return directly with an unpinned
// status.
if err == state.ErrNotFound {
var members []peer.ID
if c.config.FollowerMode {
members = []peer.ID{c.host.ID()}
} else {
members, err = c.consensus.Peers(ctx)
if err != nil {
logger.Error(err)
return nil, err
}
}
setTrackerStatus(
gpin,
h,
members,
api.TrackerStatusUnpinned,
"",
timeNow,
)
return gpin, nil
}
// The pin exists.
gpin.Cid = h
gpin.Name = pin.Name
// Make the list of peers that will receive the request.
if c.config.FollowerMode { if c.config.FollowerMode {
// during follower mode return status only on self peer // during follower mode return only local status.
dests = []peer.ID{c.host.ID()} dests = []peer.ID{c.host.ID()}
remote = []peer.ID{} remote = []peer.ID{}
} else { } else {
@ -1684,17 +1722,6 @@ func (c *Cluster) globalPinInfoCid(ctx context.Context, comp, method string, h c
return nil, err return nil, err
} }
// If pin is not part of the pinset, mark it unpinned
pin, err := c.PinGet(ctx, h)
if err == state.ErrNotFound {
setTrackerStatus(gpin, h, members, api.TrackerStatusUnpinned, timeNow)
return gpin, nil
}
if err != nil {
logger.Error(err)
return nil, err
}
if len(pin.Allocations) > 0 { if len(pin.Allocations) > 0 {
dests = pin.Allocations dests = pin.Allocations
remote = peersSubtract(members, dests) remote = peersSubtract(members, dests)
@ -1705,7 +1732,7 @@ func (c *Cluster) globalPinInfoCid(ctx context.Context, comp, method string, h c
} }
// set status remote on un-allocated peers // set status remote on un-allocated peers
setTrackerStatus(gpin, h, remote, api.TrackerStatusRemote, timeNow) setTrackerStatus(gpin, h, remote, api.TrackerStatusRemote, pin.Name, timeNow)
lenDests := len(dests) lenDests := len(dests)
replies := make([]*api.PinInfo, lenDests) replies := make([]*api.PinInfo, lenDests)
@ -1726,7 +1753,7 @@ func (c *Cluster) globalPinInfoCid(ctx context.Context, comp, method string, h c
// No error. Parse and continue // No error. Parse and continue
if e == nil { if e == nil {
gpin.PeerMap[peer.Encode(dests[i])] = r gpin.Add(r)
continue continue
} }
@ -1737,14 +1764,17 @@ func (c *Cluster) globalPinInfoCid(ctx context.Context, comp, method string, h c
// Deal with error cases (err != nil): wrap errors in PinInfo // Deal with error cases (err != nil): wrap errors in PinInfo
logger.Errorf("%s: error in broadcast response from %s: %s ", c.id, dests[i], e) logger.Errorf("%s: error in broadcast response from %s: %s ", c.id, dests[i], e)
gpin.PeerMap[peer.Encode(dests[i])] = &api.PinInfo{ gpin.Add(&api.PinInfo{
Cid: h, Cid: h,
Peer: dests[i], Name: pin.Name,
PeerName: dests[i].String(), Peer: dests[i],
Status: api.TrackerStatusClusterError, PinInfoShort: api.PinInfoShort{
TS: timeNow, PeerName: dests[i].String(),
Error: e.Error(), Status: api.TrackerStatusClusterError,
} TS: timeNow,
Error: e.Error(),
},
})
} }
return gpin, nil return gpin, nil
@ -1784,23 +1814,16 @@ func (c *Cluster) globalPinInfoSlice(ctx context.Context, comp, method string) (
rpcutil.CopyPinInfoSliceToIfaces(replies), rpcutil.CopyPinInfoSliceToIfaces(replies),
) )
mergePins := func(pins []*api.PinInfo) { setPinInfo := func(p *api.PinInfo) {
for _, p := range pins { if p == nil {
if p == nil { return
continue
}
item, ok := fullMap[p.Cid]
if !ok {
fullMap[p.Cid] = &api.GlobalPinInfo{
Cid: p.Cid,
PeerMap: map[string]*api.PinInfo{
peer.Encode(p.Peer): p,
},
}
} else {
item.PeerMap[peer.Encode(p.Peer)] = p
}
} }
info, ok := fullMap[p.Cid]
if !ok {
info = &api.GlobalPinInfo{}
fullMap[p.Cid] = info
}
info.Add(p)
} }
erroredPeers := make(map[peer.ID]string) erroredPeers := make(map[peer.ID]string)
@ -1812,21 +1835,27 @@ func (c *Cluster) globalPinInfoSlice(ctx context.Context, comp, method string) (
} }
logger.Errorf("%s: error in broadcast response from %s: %s ", c.id, members[i], e) logger.Errorf("%s: error in broadcast response from %s: %s ", c.id, members[i], e)
erroredPeers[members[i]] = e.Error() erroredPeers[members[i]] = e.Error()
} else { continue
mergePins(r) }
for _, pin := range r {
setPinInfo(pin)
} }
} }
// Merge any errors // Merge any errors
for p, msg := range erroredPeers { for p, msg := range erroredPeers {
for c := range fullMap { for c := range fullMap {
fullMap[c].PeerMap[peer.Encode(p)] = &api.PinInfo{ setPinInfo(&api.PinInfo{
Cid: c, Cid: c,
Peer: p, Name: "",
Status: api.TrackerStatusClusterError, Peer: p,
TS: time.Now(), PinInfoShort: api.PinInfoShort{
Error: msg, Status: api.TrackerStatusClusterError,
} TS: time.Now(),
Error: msg,
},
})
} }
} }

View File

@ -142,17 +142,15 @@ func textFormatPrintID(obj *api.ID) {
func textFormatPrintGPInfo(obj *api.GlobalPinInfo) { func textFormatPrintGPInfo(obj *api.GlobalPinInfo) {
var b strings.Builder var b strings.Builder
var name string
peers := make([]string, 0, len(obj.PeerMap)) peers := make([]string, 0, len(obj.PeerMap))
for k, v := range obj.PeerMap { for k := range obj.PeerMap {
peers = append(peers, k) peers = append(peers, k)
name = v.Name // All PinInfos will have the same name
} }
sort.Strings(peers) sort.Strings(peers)
fmt.Fprintf(&b, "%s", obj.Cid) fmt.Fprintf(&b, "%s", obj.Cid)
if name != "" { if obj.Name != "" {
fmt.Fprintf(&b, " | %s", name) fmt.Fprintf(&b, " | %s", obj.Name)
} }
b.WriteString(":\n") b.WriteString(":\n")

View File

@ -458,7 +458,7 @@ func printStatusOnline(absPath, clusterName string) error {
} }
} }
pinInfo := gpi.PeerMap[pid] pinInfo := gpi.PeerMap[pid]
printPin(gpi.Cid, pinInfo.Status.String(), pinInfo.Name, pinInfo.Error) printPin(gpi.Cid, pinInfo.Status.String(), gpi.Name, pinInfo.Error)
} }
return nil return nil
} }

View File

@ -830,7 +830,7 @@ func TestClustersStatusAll(t *testing.T) {
clusters, mock := createClusters(t) clusters, mock := createClusters(t)
defer shutdownClusters(t, clusters, mock) defer shutdownClusters(t, clusters, mock)
h := test.Cid1 h := test.Cid1
clusters[0].Pin(ctx, h, api.PinOptions{}) clusters[0].Pin(ctx, h, api.PinOptions{Name: "test"})
pinDelay() pinDelay()
// Global status // Global status
f := func(t *testing.T, c *Cluster) { f := func(t *testing.T, c *Cluster) {
@ -844,6 +844,11 @@ func TestClustersStatusAll(t *testing.T) {
if !statuses[0].Cid.Equals(h) { if !statuses[0].Cid.Equals(h) {
t.Error("bad cid in status") t.Error("bad cid in status")
} }
if statuses[0].Name != "test" {
t.Error("globalPinInfo should have the name")
}
info := statuses[0].PeerMap info := statuses[0].PeerMap
if len(info) != nClusters { if len(info) != nClusters {
t.Error("bad info in status") t.Error("bad info in status")
@ -877,7 +882,7 @@ func TestClustersStatusAllWithErrors(t *testing.T) {
clusters, mock := createClusters(t) clusters, mock := createClusters(t)
defer shutdownClusters(t, clusters, mock) defer shutdownClusters(t, clusters, mock)
h := test.Cid1 h := test.Cid1
clusters[0].Pin(ctx, h, api.PinOptions{}) clusters[0].Pin(ctx, h, api.PinOptions{Name: "test"})
pinDelay() pinDelay()
// shutdown 1 cluster peer // shutdown 1 cluster peer
@ -899,6 +904,14 @@ func TestClustersStatusAllWithErrors(t *testing.T) {
t.Fatal("bad status. Expected one item") t.Fatal("bad status. Expected one item")
} }
if !statuses[0].Cid.Equals(h) {
t.Error("wrong Cid in globalPinInfo")
}
if statuses[0].Name != "test" {
t.Error("wrong Name in globalPinInfo")
}
// Raft and CRDT behave differently here // Raft and CRDT behave differently here
switch consensus { switch consensus {
case "raft": case "raft":
@ -913,10 +926,6 @@ func TestClustersStatusAllWithErrors(t *testing.T) {
pid := peer.Encode(clusters[1].id) pid := peer.Encode(clusters[1].id)
errst := stts.PeerMap[pid] errst := stts.PeerMap[pid]
if !errst.Cid.Equals(h) {
t.Error("errored pinInfo should have a good cid")
}
if errst.Status != api.TrackerStatusClusterError { if errst.Status != api.TrackerStatusClusterError {
t.Error("erroring status should be set to ClusterError:", errst.Status) t.Error("erroring status should be set to ClusterError:", errst.Status)
} }
@ -932,10 +941,6 @@ func TestClustersStatusAllWithErrors(t *testing.T) {
if pinfo.Status != api.TrackerStatusClusterError { if pinfo.Status != api.TrackerStatusClusterError {
t.Error("erroring status should be ClusterError:", pinfo.Status) t.Error("erroring status should be ClusterError:", pinfo.Status)
} }
if !pinfo.Cid.Equals(h) {
t.Error("errored status should have a good cid")
}
case "crdt": case "crdt":
// CRDT will not have contacted the offline peer because // CRDT will not have contacted the offline peer because
// its metric expired and therefore is not in the // its metric expired and therefore is not in the

View File

@ -142,21 +142,25 @@ func (opt *OperationTracker) SetError(ctx context.Context, c cid.Cid, err error)
func (opt *OperationTracker) unsafePinInfo(ctx context.Context, op *Operation) api.PinInfo { func (opt *OperationTracker) unsafePinInfo(ctx context.Context, op *Operation) api.PinInfo {
if op == nil { if op == nil {
return api.PinInfo{ return api.PinInfo{
Cid: cid.Undef, Cid: cid.Undef,
Peer: opt.pid, Peer: opt.pid,
PeerName: opt.peerName, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusUnpinned, PeerName: opt.peerName,
TS: time.Now(), Status: api.TrackerStatusUnpinned,
Error: "", TS: time.Now(),
Error: "",
},
} }
} }
return api.PinInfo{ return api.PinInfo{
Cid: op.Cid(), Cid: op.Cid(),
Peer: opt.pid, Peer: opt.pid,
PeerName: opt.peerName, PinInfoShort: api.PinInfoShort{
Status: op.ToTrackerStatus(), PeerName: opt.peerName,
TS: op.Timestamp(), Status: op.ToTrackerStatus(),
Error: op.Error(), TS: op.Timestamp(),
Error: op.Error(),
},
} }
} }

View File

@ -183,21 +183,29 @@ func TestPinTracker_StatusAll(t *testing.T) {
}, },
[]*api.PinInfo{ []*api.PinInfo{
{ {
Cid: test.Cid1, Cid: test.Cid1,
Status: api.TrackerStatusPinned, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusPinned,
},
}, },
{ {
Cid: test.Cid2, Cid: test.Cid2,
Status: api.TrackerStatusRemote, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusRemote,
},
}, },
{ {
Cid: test.Cid3, Cid: test.Cid3,
Status: api.TrackerStatusRemote, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusRemote,
},
}, },
{ {
// in state but not on IPFS // in state but not on IPFS
Cid: test.Cid4, Cid: test.Cid4,
Status: api.TrackerStatusPinError, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusPinError,
},
}, },
}, },
}, },
@ -274,8 +282,10 @@ func TestPinTracker_Status(t *testing.T) {
testStatelessPinTracker(t), testStatelessPinTracker(t),
}, },
api.PinInfo{ api.PinInfo{
Cid: test.Cid1, Cid: test.Cid1,
Status: api.TrackerStatusPinned, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusPinned,
},
}, },
}, },
{ {
@ -285,8 +295,10 @@ func TestPinTracker_Status(t *testing.T) {
testStatelessPinTracker(t), testStatelessPinTracker(t),
}, },
api.PinInfo{ api.PinInfo{
Cid: test.Cid5, Cid: test.Cid5,
Status: api.TrackerStatusUnpinned, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusUnpinned,
},
}, },
}, },
} }
@ -322,24 +334,32 @@ func TestPinTracker_RecoverAll(t *testing.T) {
}, },
[]*api.PinInfo{ []*api.PinInfo{
{ {
Cid: test.Cid1, Cid: test.Cid1,
Status: api.TrackerStatusPinned, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusPinned,
},
}, },
{ {
Cid: test.Cid2, Cid: test.Cid2,
Status: api.TrackerStatusRemote, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusRemote,
},
}, },
{ {
Cid: test.Cid3, Cid: test.Cid3,
Status: api.TrackerStatusRemote, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusRemote,
},
}, },
{ {
// This will recover and status // This will recover and status
// is ignored as it could come back as // is ignored as it could come back as
// queued, pinning or error. // queued, pinning or error.
Cid: test.Cid4, Cid: test.Cid4,
Status: api.TrackerStatusPinError, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusPinError,
},
}, },
}, },
false, false,
@ -399,8 +419,10 @@ func TestPinTracker_Recover(t *testing.T) {
testStatelessPinTracker(t), testStatelessPinTracker(t),
}, },
api.PinInfo{ api.PinInfo{
Cid: test.Cid1, Cid: test.Cid1,
Status: api.TrackerStatusPinned, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusPinned,
},
}, },
false, false,
}, },
@ -438,8 +460,10 @@ func TestUntrackTrack(t *testing.T) {
testStatelessPinTracker(t), testStatelessPinTracker(t),
}, },
api.PinInfo{ api.PinInfo{
Cid: test.Cid1, Cid: test.Cid1,
Status: api.TrackerStatusPinned, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusPinned,
},
}, },
false, false,
}, },
@ -479,8 +503,10 @@ func TestTrackUntrackWithCancel(t *testing.T) {
testStatelessPinTracker(t), testStatelessPinTracker(t),
}, },
api.PinInfo{ api.PinInfo{
Cid: test.SlowCid1, Cid: test.SlowCid1,
Status: api.TrackerStatusPinned, PinInfoShort: api.PinInfoShort{
Status: api.TrackerStatusPinned,
},
}, },
false, false,
}, },

View File

@ -305,10 +305,12 @@ func (spt *Tracker) Status(ctx context.Context, c cid.Cid) *api.PinInfo {
} }
pinInfo := &api.PinInfo{ pinInfo := &api.PinInfo{
Cid: c, Cid: c,
Peer: spt.peerID, Peer: spt.peerID,
PeerName: spt.peerName, PinInfoShort: api.PinInfoShort{
TS: time.Now(), PeerName: spt.peerName,
TS: time.Now(),
},
} }
// check global state to see if cluster should even be caring about // check global state to see if cluster should even be caring about
@ -449,12 +451,14 @@ func (spt *Tracker) ipfsStatusAll(ctx context.Context) (map[string]*api.PinInfo,
continue continue
} }
p := &api.PinInfo{ p := &api.PinInfo{
Cid: c, Cid: c,
Name: "", // to be filled later Name: "", // to be filled later
Peer: spt.peerID, Peer: spt.peerID,
PeerName: spt.peerName, PinInfoShort: api.PinInfoShort{
Status: ips.ToTrackerStatus(), PeerName: spt.peerName,
TS: time.Now(), Status: ips.ToTrackerStatus(),
TS: time.Now(),
},
} }
pins[cidstr] = p pins[cidstr] = p
} }
@ -495,11 +499,13 @@ func (spt *Tracker) localStatus(ctx context.Context, incExtra bool) (map[string]
ipfsInfo, pinnedInIpfs := localpis[pCid] ipfsInfo, pinnedInIpfs := localpis[pCid]
// base pinInfo object - status to be filled. // base pinInfo object - status to be filled.
pinInfo := api.PinInfo{ pinInfo := api.PinInfo{
Cid: p.Cid, Cid: p.Cid,
Name: p.Name, Name: p.Name,
Peer: spt.peerID, Peer: spt.peerID,
PeerName: spt.peerName, PinInfoShort: api.PinInfoShort{
TS: time.Now(), PeerName: spt.peerName,
TS: time.Now(),
},
} }
switch { switch {

View File

@ -224,10 +224,8 @@ func (mock *mockCluster) StatusAll(ctx context.Context, in struct{}, out *[]*api
*out = []*api.GlobalPinInfo{ *out = []*api.GlobalPinInfo{
{ {
Cid: Cid1, Cid: Cid1,
PeerMap: map[string]*api.PinInfo{ PeerMap: map[string]*api.PinInfoShort{
pid: { pid: {
Cid: Cid1,
Peer: PeerID1,
Status: api.TrackerStatusPinned, Status: api.TrackerStatusPinned,
TS: time.Now(), TS: time.Now(),
}, },
@ -235,10 +233,8 @@ func (mock *mockCluster) StatusAll(ctx context.Context, in struct{}, out *[]*api
}, },
{ {
Cid: Cid2, Cid: Cid2,
PeerMap: map[string]*api.PinInfo{ PeerMap: map[string]*api.PinInfoShort{
pid: { pid: {
Cid: Cid2,
Peer: PeerID1,
Status: api.TrackerStatusPinning, Status: api.TrackerStatusPinning,
TS: time.Now(), TS: time.Now(),
}, },
@ -246,10 +242,8 @@ func (mock *mockCluster) StatusAll(ctx context.Context, in struct{}, out *[]*api
}, },
{ {
Cid: Cid3, Cid: Cid3,
PeerMap: map[string]*api.PinInfo{ PeerMap: map[string]*api.PinInfoShort{
pid: { pid: {
Cid: Cid3,
Peer: PeerID1,
Status: api.TrackerStatusPinError, Status: api.TrackerStatusPinError,
TS: time.Now(), TS: time.Now(),
}, },
@ -269,10 +263,8 @@ func (mock *mockCluster) Status(ctx context.Context, in cid.Cid, out *api.Global
} }
*out = api.GlobalPinInfo{ *out = api.GlobalPinInfo{
Cid: in, Cid: in,
PeerMap: map[string]*api.PinInfo{ PeerMap: map[string]*api.PinInfoShort{
peer.Encode(PeerID1): { peer.Encode(PeerID1): {
Cid: in,
Peer: PeerID1,
Status: api.TrackerStatusPinned, Status: api.TrackerStatusPinned,
TS: time.Now(), TS: time.Now(),
}, },
@ -362,16 +354,20 @@ func (mock *mockPinTracker) Untrack(ctx context.Context, in *api.Pin, out *struc
func (mock *mockPinTracker) StatusAll(ctx context.Context, in struct{}, out *[]*api.PinInfo) error { func (mock *mockPinTracker) StatusAll(ctx context.Context, in struct{}, out *[]*api.PinInfo) error {
*out = []*api.PinInfo{ *out = []*api.PinInfo{
{ {
Cid: Cid1, Cid: Cid1,
Peer: PeerID1, Peer: PeerID1,
Status: api.TrackerStatusPinned, PinInfoShort: api.PinInfoShort{
TS: time.Now(), Status: api.TrackerStatusPinned,
TS: time.Now(),
},
}, },
{ {
Cid: Cid3, Cid: Cid3,
Peer: PeerID1, Peer: PeerID1,
Status: api.TrackerStatusPinError, PinInfoShort: api.PinInfoShort{
TS: time.Now(), Status: api.TrackerStatusPinError,
TS: time.Now(),
},
}, },
} }
return nil return nil
@ -383,10 +379,12 @@ func (mock *mockPinTracker) Status(ctx context.Context, in cid.Cid, out *api.Pin
} }
*out = api.PinInfo{ *out = api.PinInfo{
Cid: in, Cid: in,
Peer: PeerID2, Peer: PeerID2,
Status: api.TrackerStatusPinned, PinInfoShort: api.PinInfoShort{
TS: time.Now(), Status: api.TrackerStatusPinned,
TS: time.Now(),
},
} }
return nil return nil
} }
@ -398,10 +396,12 @@ func (mock *mockPinTracker) RecoverAll(ctx context.Context, in struct{}, out *[]
func (mock *mockPinTracker) Recover(ctx context.Context, in cid.Cid, out *api.PinInfo) error { func (mock *mockPinTracker) Recover(ctx context.Context, in cid.Cid, out *api.PinInfo) error {
*out = api.PinInfo{ *out = api.PinInfo{
Cid: in, Cid: in,
Peer: PeerID1, Peer: PeerID1,
Status: api.TrackerStatusPinned, PinInfoShort: api.PinInfoShort{
TS: time.Now(), Status: api.TrackerStatusPinned,
TS: time.Now(),
},
} }
return nil return nil
} }