cmd/stdiscosrv: Delete records for abandoned devices (#4957)
Once a device has been missing for a long time, and noone has asked about it for a long time, delete the record.
This commit is contained in:
parent
c08024ebb8
commit
127c891526
@ -195,6 +195,7 @@ func (s *levelDBStore) statisticsServe(trigger <-chan struct{}, done chan<- stru
|
|||||||
nowNanos := t0.UnixNano()
|
nowNanos := t0.UnixNano()
|
||||||
cutoff24h := t0.Add(-24 * time.Hour).UnixNano()
|
cutoff24h := t0.Add(-24 * time.Hour).UnixNano()
|
||||||
cutoff1w := t0.Add(-7 * 24 * time.Hour).UnixNano()
|
cutoff1w := t0.Add(-7 * 24 * time.Hour).UnixNano()
|
||||||
|
cutoff2Mon := t0.Add(-60 * 24 * time.Hour).UnixNano()
|
||||||
current, last24h, last1w, inactive, errors := 0, 0, 0, 0, 0
|
current, last24h, last1w, inactive, errors := 0, 0, 0, 0, 0
|
||||||
|
|
||||||
iter := s.db.NewIterator(&util.Range{}, nil)
|
iter := s.db.NewIterator(&util.Range{}, nil)
|
||||||
@ -217,6 +218,17 @@ func (s *levelDBStore) statisticsServe(trigger <-chan struct{}, done chan<- stru
|
|||||||
last24h++
|
last24h++
|
||||||
case rec.Seen > cutoff1w:
|
case rec.Seen > cutoff1w:
|
||||||
last1w++
|
last1w++
|
||||||
|
case rec.Seen > cutoff2Mon:
|
||||||
|
inactive++
|
||||||
|
case rec.Missed < cutoff2Mon:
|
||||||
|
// It hasn't been seen lately and we haven't recorded
|
||||||
|
// someone asking for this device in a long time either;
|
||||||
|
// delete the record.
|
||||||
|
if err := s.db.Delete(iter.Key(), nil); err != nil {
|
||||||
|
databaseOperations.WithLabelValues(dbOpDelete, dbResError).Inc()
|
||||||
|
} else {
|
||||||
|
databaseOperations.WithLabelValues(dbOpDelete, dbResSuccess).Inc()
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
inactive++
|
inactive++
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,6 +95,7 @@ const (
|
|||||||
dbOpGet = "get"
|
dbOpGet = "get"
|
||||||
dbOpPut = "put"
|
dbOpPut = "put"
|
||||||
dbOpMerge = "merge"
|
dbOpMerge = "merge"
|
||||||
|
dbOpDelete = "delete"
|
||||||
dbResSuccess = "success"
|
dbResSuccess = "success"
|
||||||
dbResNotFound = "not_found"
|
dbResNotFound = "not_found"
|
||||||
dbResError = "error"
|
dbResError = "error"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user