Skip to content

Commit 1386e98

Browse files
refactor: remove provider status command (#1157)
* remove: provider status command * fix: use structured logging for provider records use Debugw with count field first, calculate len once * fix: log successful provides with prefix and keys add batchProvide entry log with prefix and count log sent records after successful sendProviderRecords put prefix first in all provider logs --------- Co-authored-by: Marcin Rataj <[email protected]>
1 parent 0114a72 commit 1386e98

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

provider/provider.go

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ func (s *SweepingProvider) getAvgPrefixLenNoLock() (int, error) {
551551
// (typically 1 or 2), because exploring the keyspace would add too much
552552
// overhead for a small number of keys.
553553
func (s *SweepingProvider) vanillaProvide(k mh.Multihash) (bitstr.Key, error) {
554+
keys := []mh.Multihash{k}
554555
// Add provider record to local provider store.
555556
s.addLocalRecord(k)
556557
// Get peers to which the record will be allocated.
@@ -562,9 +563,13 @@ func (s *SweepingProvider) vanillaProvide(k mh.Multihash) (bitstr.Key, error) {
562563
addrInfo := peer.AddrInfo{ID: s.peerid, Addrs: s.getSelfAddrs()}
563564
keysAllocations := make(map[peer.ID][]mh.Multihash)
564565
for _, p := range peers {
565-
keysAllocations[p] = []mh.Multihash{k}
566+
keysAllocations[p] = keys
566567
}
567-
return coveredPrefix, s.sendProviderRecords(keysAllocations, addrInfo)
568+
err = s.sendProviderRecords(keysAllocations, addrInfo)
569+
if err == nil {
570+
logger.Debugw("sent provider record", "prefix", coveredPrefix, "count", 1, "keys", keys)
571+
}
572+
return coveredPrefix, err
568573
}
569574

570575
// exploreSwarm finds all peers whose kademlia identifier matches `prefix` in
@@ -1100,6 +1105,7 @@ func (s *SweepingProvider) batchProvide(prefix bitstr.Key, keys []mh.Multihash)
11001105
if len(keys) == 0 {
11011106
return
11021107
}
1108+
logger.Debugw("batchProvide called", "prefix", prefix, "count", len(keys))
11031109
addrInfo, ok := s.selfAddrInfo()
11041110
if !ok {
11051111
// Don't provide if the node doesn't have a valid address to include in the
@@ -1325,7 +1331,9 @@ func (s *SweepingProvider) provideRegions(regions []keyspace.Region, addrInfo pe
13251331
}
13261332
continue
13271333
}
1328-
s.provideCounter.Add(s.ctx, int64(len(allKeys)))
1334+
keyCount := len(allKeys)
1335+
s.provideCounter.Add(s.ctx, int64(keyCount))
1336+
logger.Debugw("sent provider records", "prefix", r.Prefix, "count", keyCount, "keys", allKeys)
13291337
}
13301338
// If at least 1 regions was provided, we don't consider it a failure.
13311339
return errCount < len(regions)
@@ -1417,25 +1425,6 @@ func (s *SweepingProvider) Clear() int {
14171425
return s.provideQueue.Clear()
14181426
}
14191427

1420-
// ProvideState encodes the current relationship between this node and `key`.
1421-
type ProvideState uint8
1422-
1423-
const (
1424-
StateUnknown ProvideState = iota // we have no record of the key
1425-
StateQueued // key is queued to be provided
1426-
StateProvided // key was provided at least once
1427-
)
1428-
1429-
// ProvideStatus reports the provider’s view of a key.
1430-
//
1431-
// When `state == StateProvided`, `lastProvide` is the wall‑clock time of the
1432-
// most recent successful provide operation (UTC).
1433-
// For `StateQueued` or `StateUnknown`, `lastProvide` is the zero `time.Time`.
1434-
func (s *SweepingProvider) ProvideStatus(key mh.Multihash) (state ProvideState, lastProvide time.Time) {
1435-
// TODO: implement me
1436-
return StateUnknown, time.Time{}
1437-
}
1438-
14391428
// AddToSchedule makes sure the prefixes associated with the supplied keys are
14401429
// scheduled to be reprovided.
14411430
//

0 commit comments

Comments
 (0)