Remove plans/ directory (P0/P1/P2 work complete)

This commit is contained in:
2026-05-27 02:12:21 -05:00
parent 0c1840d223
commit 0dbb2e02ed
33 changed files with 1906 additions and 990 deletions
+13 -5
View File
@@ -77,11 +77,19 @@ func (fi *FileInfo) UpdateAccessBatched(btu *BatchedTimeUpdate) {
fi.AccessCount++
}
// GetTimeDecayedScore calculates a score based on access time and frequency
// More recent and frequent accesses get higher scores
func (fi *FileInfo) GetTimeDecayedScore() float64 {
timeSinceAccess := time.Since(fi.ATime).Hours()
// DecayedScore computes the time-decayed eviction score from scalar snapshot values (aTime, accessCount).
// This is the canonical implementation of the decay formula (shared to eliminate duplication).
// Used by FileInfo.GetTimeDecayedScore and by EvictHybrid (memory/disk) for race-free scoring
// on values captured under RLock.
func DecayedScore(aTime time.Time, accessCount int) float64 {
timeSinceAccess := time.Since(aTime).Hours()
decayFactor := 1.0 / (1.0 + timeSinceAccess/24.0) // Decay over days
frequencyBonus := float64(fi.AccessCount) * 0.1
frequencyBonus := float64(accessCount) * 0.1
return decayFactor + frequencyBonus
}
// GetTimeDecayedScore calculates a score based on access time and frequency
// More recent and frequent accesses get higher scores.
func (fi *FileInfo) GetTimeDecayedScore() float64 {
return DecayedScore(fi.ATime, fi.AccessCount)
}
+54
View File
@@ -0,0 +1,54 @@
package types
import (
"testing"
"time"
)
func TestNewFileInfo(t *testing.T) {
t.Parallel()
fi := NewFileInfo("k", 42)
if fi.Key != "k" || fi.Size != 42 || fi.AccessCount != 1 {
t.Errorf("bad NewFileInfo: %+v", fi)
}
if time.Since(fi.ATime) > time.Second || time.Since(fi.CTime) > time.Second {
t.Error("timestamps not recent")
}
}
func TestUpdateAccess(t *testing.T) {
t.Parallel()
fi := NewFileInfo("k", 1)
oldCount := fi.AccessCount
oldAT := fi.ATime
time.Sleep(2 * time.Millisecond)
fi.UpdateAccess()
if fi.AccessCount != oldCount+1 {
t.Error("access count not inc")
}
if !fi.ATime.After(oldAT) {
t.Error("ATime not updated")
}
}
func TestBatchedTimeUpdate(t *testing.T) {
t.Parallel()
b := NewBatchedTimeUpdate(50 * time.Millisecond)
t1 := b.GetTime()
time.Sleep(10 * time.Millisecond)
t2 := b.GetTime()
// within interval, same
if t1 != t2 {
t.Log("batched may have ticked, ok")
}
}
func TestGetTimeDecayedScore(t *testing.T) {
t.Parallel()
fi := NewFileInfo("k", 100)
fi.AccessCount = 5
score := fi.GetTimeDecayedScore()
if score <= 0 {
t.Errorf("score = %f, want >0", score)
}
}