This commit is contained in:
lash 2018-10-02 14:05:19 +00:00 committed by GitHub
commit baac864497
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View file

@ -248,7 +248,7 @@ func decodeData(addr Address, data []byte) (*chunk, error) {
} }
func (s *LDBStore) collectGarbage(ratio float32) { func (s *LDBStore) collectGarbage(ratio float32) {
log.Trace("collectGarbage", "ratio", ratio) log.Trace("collectGarbage", "ratio", ratio, "entrycnt", s.entryCnt)
metrics.GetOrRegisterCounter("ldbstore.collectgarbage", nil).Inc(1) metrics.GetOrRegisterCounter("ldbstore.collectgarbage", nil).Inc(1)
@ -258,7 +258,7 @@ func (s *LDBStore) collectGarbage(ratio float32) {
garbage := []*gcItem{} garbage := []*gcItem{}
gcnt := 0 gcnt := 0
for ok := it.Seek([]byte{keyIndex}); ok && (gcnt < maxGCitems) && (uint64(gcnt) < s.entryCnt); ok = it.Next() { for ok := it.Seek([]byte{keyIndex}); ok && (uint64(gcnt) < s.entryCnt); ok = it.Next() {
itkey := it.Key() itkey := it.Key()
if (itkey == nil) || (itkey[0] != keyIndex) { if (itkey == nil) || (itkey[0] != keyIndex) {
@ -290,7 +290,11 @@ func (s *LDBStore) collectGarbage(ratio float32) {
sort.Slice(garbage[:gcnt], func(i, j int) bool { return garbage[i].value < garbage[j].value }) sort.Slice(garbage[:gcnt], func(i, j int) bool { return garbage[i].value < garbage[j].value })
if gcnt > maxGCitems {
gcnt = maxGCitems
}
cutoff := int(float32(gcnt) * ratio) cutoff := int(float32(gcnt) * ratio)
metrics.GetOrRegisterCounter("ldbstore.collectgarbage.delete", nil).Inc(int64(cutoff)) metrics.GetOrRegisterCounter("ldbstore.collectgarbage.delete", nil).Inc(int64(cutoff))
for i := 0; i < cutoff; i++ { for i := 0; i < cutoff; i++ {
@ -727,6 +731,7 @@ func (s *LDBStore) tryAccessIdx(ikey []byte, index *dpaDBIndex) bool {
case s.batchesC <- struct{}{}: case s.batchesC <- struct{}{}:
default: default:
} }
log.Trace("tryaccessidx", "addr", fmt.Sprintf("%x", ikey[1:]), "indexdata", index, "data", idata)
return true return true
} }

View file

@ -19,6 +19,7 @@ package storage
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/binary"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -385,8 +386,10 @@ func TestLDBStoreAddRemove(t *testing.T) {
// TestLDBStoreRemoveThenCollectGarbage tests that we can delete chunks and that we can trigger garbage collection // TestLDBStoreRemoveThenCollectGarbage tests that we can delete chunks and that we can trigger garbage collection
func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) { func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) {
capacity := 11 //capacity := 11
surplus := 4 //surplus := 4
capacity := 10000
surplus := 10000
ldb, cleanup := newLDBStore(t) ldb, cleanup := newLDBStore(t)
ldb.setCapacity(uint64(capacity)) ldb.setCapacity(uint64(capacity))
@ -423,7 +426,7 @@ func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) {
cleanup() cleanup()
ldb, cleanup = newLDBStore(t) ldb, cleanup = newLDBStore(t)
capacity = 10 //capacity = 10000
ldb.setCapacity(uint64(capacity)) ldb.setCapacity(uint64(capacity))
defer cleanup() defer cleanup()