fixed potential bug in quota calculation
This commit is contained in:
parent
711f020c18
commit
23528fe28e
1 changed files with 17 additions and 7 deletions
|
|
@ -126,12 +126,16 @@ func (mh *MetadataHandler) DeleteOldest() (s int64) {
|
|||
if m != nil {
|
||||
log := mh.log.WithValues("file", m.name)
|
||||
log.Info("deleting oldest file")
|
||||
cs := m.Size
|
||||
if !m.FullyCached() {
|
||||
cs = m.ChunkSize()
|
||||
}
|
||||
err := m.Delete()
|
||||
if err != nil {
|
||||
log.Error(err, "error deleting oldest file")
|
||||
return
|
||||
}
|
||||
s = m.Size
|
||||
s = cs
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -140,7 +144,7 @@ func (mh *MetadataHandler) Size() (s int64) {
|
|||
mh.mu.RLock()
|
||||
defer mh.mu.RUnlock()
|
||||
for _, md := range mh.md {
|
||||
s += md.Chunks.Size()
|
||||
s += md.ChunkSize()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -152,7 +156,10 @@ func (mh *MetadataHandler) CacheStatus(name string) int {
|
|||
if !ok {
|
||||
return -1
|
||||
}
|
||||
size := md.Chunks.Size()
|
||||
if md.FullyCached() {
|
||||
return 100
|
||||
}
|
||||
size := md.ChunkSize()
|
||||
if size == 0 {
|
||||
return -1
|
||||
}
|
||||
|
|
@ -321,10 +328,7 @@ func (md *Metadata) Delete() error {
|
|||
func (md *Metadata) FullyCached() bool {
|
||||
md.mu.RLock()
|
||||
defer md.mu.RUnlock()
|
||||
if len(md.Chunks) == 0 {
|
||||
return false
|
||||
}
|
||||
return md.Size == md.Chunks[0][1]
|
||||
return len(md.Chunks) == 1 && md.Size == md.Chunks[0][1]
|
||||
}
|
||||
|
||||
func (md *Metadata) HasChunk(off int64, n int) bool {
|
||||
|
|
@ -333,6 +337,12 @@ func (md *Metadata) HasChunk(off int64, n int) bool {
|
|||
return md.Chunks.Exists(off, n, md.Size)
|
||||
}
|
||||
|
||||
func (md *Metadata) ChunkSize() int64 {
|
||||
md.mu.RLock()
|
||||
defer md.mu.RUnlock()
|
||||
return md.Chunks.Size()
|
||||
}
|
||||
|
||||
func (md *Metadata) AddChunk(off int64, n int) {
|
||||
md.mu.Lock()
|
||||
defer md.mu.Unlock()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue