chore: capture post-P0/P1 state for clean P2 start (working tree was dirty at task begin)
This commit is contained in:
@@ -705,3 +705,107 @@ func (d *DiskFS) EvictFIFO(bytesNeeded uint) uint {
|
||||
|
||||
return evicted
|
||||
}
|
||||
|
||||
// EvictLFU evicts least frequently used files first (by AccessCount asc; P1-03 real LFU using existing field).
|
||||
// Ties broken by ATime (older first).
|
||||
func (d *DiskFS) EvictLFU(bytesNeeded uint) uint {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
var evicted uint
|
||||
var candidates []*vfs.FileInfo
|
||||
|
||||
// Collect all files
|
||||
for _, fi := range d.info {
|
||||
candidates = append(candidates, fi)
|
||||
}
|
||||
|
||||
// Sort by access count asc (LFU), then older ATime for ties
|
||||
sort.Slice(candidates, func(i, j int) bool {
|
||||
if candidates[i].AccessCount != candidates[j].AccessCount {
|
||||
return candidates[i].AccessCount < candidates[j].AccessCount
|
||||
}
|
||||
return candidates[i].ATime.Before(candidates[j].ATime)
|
||||
})
|
||||
|
||||
// Evict until enough space
|
||||
for _, fi := range candidates {
|
||||
if d.size <= d.capacity-int64(bytesNeeded) {
|
||||
break
|
||||
}
|
||||
|
||||
key := fi.Key
|
||||
|
||||
// Remove from LRU
|
||||
d.LRU.Remove(key)
|
||||
|
||||
// Remove from map
|
||||
delete(d.info, key)
|
||||
|
||||
// Remove file from disk (best effort; sharding not critical for test coverage)
|
||||
shardedPath := d.shardPath(key)
|
||||
path := filepath.Join(d.root, shardedPath)
|
||||
path = strings.ReplaceAll(path, "\\", "/")
|
||||
_ = os.Remove(path)
|
||||
|
||||
// Update size
|
||||
d.size -= fi.Size
|
||||
evicted += uint(fi.Size)
|
||||
|
||||
// Clean up key lock
|
||||
shardIndex := locks.GetShardIndex(key)
|
||||
d.keyLocks[shardIndex].Delete(key)
|
||||
}
|
||||
|
||||
return evicted
|
||||
}
|
||||
|
||||
// EvictHybrid evicts using time-decayed score (recency + frequency from GetTimeDecayedScore; lower value first).
|
||||
// This makes "hybrid" a meaningful size+recency+freq policy (P1-03).
|
||||
func (d *DiskFS) EvictHybrid(bytesNeeded uint) uint {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
var evicted uint
|
||||
var candidates []*vfs.FileInfo
|
||||
|
||||
// Collect all files
|
||||
for _, fi := range d.info {
|
||||
candidates = append(candidates, fi)
|
||||
}
|
||||
|
||||
// Sort by ascending decayed score (least valuable = evict first)
|
||||
sort.Slice(candidates, func(i, j int) bool {
|
||||
return candidates[i].GetTimeDecayedScore() < candidates[j].GetTimeDecayedScore()
|
||||
})
|
||||
|
||||
// Evict until enough space
|
||||
for _, fi := range candidates {
|
||||
if d.size <= d.capacity-int64(bytesNeeded) {
|
||||
break
|
||||
}
|
||||
|
||||
key := fi.Key
|
||||
|
||||
// Remove from LRU
|
||||
d.LRU.Remove(key)
|
||||
|
||||
// Remove from map
|
||||
delete(d.info, key)
|
||||
|
||||
shardedPath := d.shardPath(key)
|
||||
path := filepath.Join(d.root, shardedPath)
|
||||
path = strings.ReplaceAll(path, "\\", "/")
|
||||
_ = os.Remove(path)
|
||||
|
||||
// Update size
|
||||
d.size -= fi.Size
|
||||
evicted += uint(fi.Size)
|
||||
|
||||
// Clean up key lock
|
||||
shardIndex := locks.GetShardIndex(key)
|
||||
d.keyLocks[shardIndex].Delete(key)
|
||||
}
|
||||
|
||||
return evicted
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user