pintracker: avoid listing the state unless necessary

This is a follow up to #1360 which further optimizes StatusAll calls by
avoiding listing and filtering the cluster state when requesting status for
operations that should be direclty in the operation tracker because they are
ongoing (queued, pinning, unpinning, error).
This commit is contained in:
Hector Sanjuan 2021-07-08 01:01:25 +02:00
parent 493089d6d0
commit 27569bdf88

View File

@ -481,6 +481,8 @@ func (spt *Tracker) localStatus(ctx context.Context, incExtra bool, filter api.T
ctx, span := trace.StartSpan(ctx, "tracker/stateless/localStatus") ctx, span := trace.StartSpan(ctx, "tracker/stateless/localStatus")
defer span.End() defer span.End()
var statePins []*api.Pin
// get shared state // get shared state
st, err := spt.getState(ctx) st, err := spt.getState(ctx)
if err != nil { if err != nil {
@ -488,11 +490,19 @@ func (spt *Tracker) localStatus(ctx context.Context, incExtra bool, filter api.T
return nil, err return nil, err
} }
statePins, err := st.List(ctx) // Only list the full pinset if we are interested in pin types that
// require it. Otherwise said, this whole method is mostly a no-op
// when filtering for queued/error items which are all in the operation
// tracker.
if filter.Match(
api.TrackerStatusPinned | api.TrackerStatusUnexpectedlyUnpinned |
api.TrackerStatusSharded | api.TrackerStatusRemote) {
statePins, err = st.List(ctx)
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)
return nil, err return nil, err
} }
}
var localpis map[cid.Cid]*api.PinInfo var localpis map[cid.Cid]*api.PinInfo
// Only query IPFS if we want to status for pinned items // Only query IPFS if we want to status for pinned items