chore: capture post-P0/P1 state for clean P2 start (working tree was dirty at task begin)
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package adaptive
|
||||
|
||||
// Package adaptive: experimental / not yet active after P1-04 prune.
|
||||
// Retained for potential P2 integration. Not used at runtime (pruned from steamcache).
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
Vendored
+4
@@ -202,6 +202,10 @@ func (tc *TieredCache) promoteToFast(key string, reader io.ReadCloser) {
|
||||
}
|
||||
}
|
||||
|
||||
// P1-01: guard promotion ReadAll using already-fetched size (in addition to space check above)
|
||||
if size > 0 && size > (1<<30) { // conservative 1GB hard limit on promotion reads (aligns with typical max_object_size)
|
||||
return
|
||||
}
|
||||
// Read the entire file content
|
||||
content, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -76,17 +76,28 @@ func EvictSmallest(v vfs.VFS, bytesNeeded uint) uint {
|
||||
return EvictBySizeAsc(v, bytesNeeded)
|
||||
}
|
||||
|
||||
// EvictLFU performs LFU (Least Frequently Used) eviction
|
||||
// EvictLFU performs LFU (Least Frequently Used) eviction using AccessCount from FileInfo (P1-03 real impl).
|
||||
func EvictLFU(v vfs.VFS, bytesNeeded uint) uint {
|
||||
// For now, fall back to size-based eviction
|
||||
// TODO: Implement proper LFU tracking
|
||||
return EvictBySizeAsc(v, bytesNeeded)
|
||||
switch fs := v.(type) {
|
||||
case *memory.MemoryFS:
|
||||
return fs.EvictLFU(bytesNeeded)
|
||||
case *disk.DiskFS:
|
||||
return fs.EvictLFU(bytesNeeded)
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// EvictHybrid implements a hybrid eviction strategy
|
||||
// EvictHybrid implements a documented size+recency+frequency hybrid (uses GetTimeDecayedScore; lower=evict first).
|
||||
func EvictHybrid(v vfs.VFS, bytesNeeded uint) uint {
|
||||
// Use LRU as primary strategy, but consider size as tiebreaker
|
||||
return EvictLRU(v, bytesNeeded)
|
||||
switch fs := v.(type) {
|
||||
case *memory.MemoryFS:
|
||||
return fs.EvictHybrid(bytesNeeded)
|
||||
case *disk.DiskFS:
|
||||
return fs.EvictHybrid(bytesNeeded)
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// GetEvictionFunction returns the eviction function for the given strategy
|
||||
|
||||
@@ -93,11 +93,6 @@ type EvictionStrategy interface {
|
||||
Evict(vfs vfs.VFS, bytesNeeded uint) uint
|
||||
}
|
||||
|
||||
// AdaptivePromotionDeciderFunc is a placeholder for the adaptive promotion logic
|
||||
var AdaptivePromotionDeciderFunc = func() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AsyncGCFS wraps a GCFS with asynchronous garbage collection capabilities
|
||||
type AsyncGCFS struct {
|
||||
*GCFS
|
||||
|
||||
@@ -428,3 +428,98 @@ func (m *MemoryFS) 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 (m *MemoryFS) EvictLFU(bytesNeeded uint) uint {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
var evicted uint
|
||||
var candidates []*types.FileInfo
|
||||
|
||||
// Collect all files
|
||||
for _, fi := range m.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 m.size <= m.capacity-int64(bytesNeeded) {
|
||||
break
|
||||
}
|
||||
|
||||
key := fi.Key
|
||||
|
||||
// Remove from LRU
|
||||
m.LRU.Remove(key)
|
||||
|
||||
// Remove from maps
|
||||
delete(m.info, key)
|
||||
delete(m.data, key)
|
||||
|
||||
// Update size
|
||||
m.size -= fi.Size
|
||||
evicted += uint(fi.Size)
|
||||
|
||||
// Clean up key lock
|
||||
shardIndex := locks.GetShardIndex(key)
|
||||
m.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 (m *MemoryFS) EvictHybrid(bytesNeeded uint) uint {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
var evicted uint
|
||||
var candidates []*types.FileInfo
|
||||
|
||||
// Collect all files
|
||||
for _, fi := range m.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 m.size <= m.capacity-int64(bytesNeeded) {
|
||||
break
|
||||
}
|
||||
|
||||
key := fi.Key
|
||||
|
||||
// Remove from LRU
|
||||
m.LRU.Remove(key)
|
||||
|
||||
// Remove from maps
|
||||
delete(m.info, key)
|
||||
delete(m.data, key)
|
||||
|
||||
// Update size
|
||||
m.size -= fi.Size
|
||||
evicted += uint(fi.Size)
|
||||
|
||||
// Clean up key lock
|
||||
shardIndex := locks.GetShardIndex(key)
|
||||
m.keyLocks[shardIndex].Delete(key)
|
||||
}
|
||||
|
||||
return evicted
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package predictive
|
||||
|
||||
// Package predictive: experimental / not yet active after P1-04 prune.
|
||||
// Retained for potential P2 integration. Not used at runtime (pruned from steamcache).
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
Reference in New Issue
Block a user