mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-07-31 21:00:10 +08:00
fix byte counter on loading index file
fix https://github.com/chrislusf/seaweedfs/issues/441
This commit is contained in:
parent
8b15523c9d
commit
59022b6fe0
@ -39,14 +39,13 @@ func NewCompactSection(start Key) *CompactSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//return old entry size
|
//return old entry size
|
||||||
func (cs *CompactSection) Set(key Key, offset uint32, size uint32) uint32 {
|
func (cs *CompactSection) Set(key Key, offset, size uint32) (oldOffset, oldSize uint32) {
|
||||||
ret := uint32(0)
|
|
||||||
cs.Lock()
|
cs.Lock()
|
||||||
if key > cs.end {
|
if key > cs.end {
|
||||||
cs.end = key
|
cs.end = key
|
||||||
}
|
}
|
||||||
if i := cs.binarySearchValues(key); i >= 0 {
|
if i := cs.binarySearchValues(key); i >= 0 {
|
||||||
ret = cs.values[i].Size
|
oldOffset, oldSize = cs.values[i].Offset, cs.values[i].Size
|
||||||
//println("key", key, "old size", ret)
|
//println("key", key, "old size", ret)
|
||||||
cs.values[i].Offset, cs.values[i].Size = offset, size
|
cs.values[i].Offset, cs.values[i].Size = offset, size
|
||||||
} else {
|
} else {
|
||||||
@ -55,7 +54,7 @@ func (cs *CompactSection) Set(key Key, offset uint32, size uint32) uint32 {
|
|||||||
if needOverflow {
|
if needOverflow {
|
||||||
//println("start", cs.start, "counter", cs.counter, "key", key)
|
//println("start", cs.start, "counter", cs.counter, "key", key)
|
||||||
if oldValue, found := cs.overflow[key]; found {
|
if oldValue, found := cs.overflow[key]; found {
|
||||||
ret = oldValue.Size
|
oldOffset, oldSize = oldValue.Offset, oldValue.Size
|
||||||
}
|
}
|
||||||
cs.overflow[key] = NeedleValue{Key: key, Offset: offset, Size: size}
|
cs.overflow[key] = NeedleValue{Key: key, Offset: offset, Size: size}
|
||||||
} else {
|
} else {
|
||||||
@ -66,7 +65,7 @@ func (cs *CompactSection) Set(key Key, offset uint32, size uint32) uint32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cs.Unlock()
|
cs.Unlock()
|
||||||
return ret
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//return old entry size
|
//return old entry size
|
||||||
@ -129,7 +128,7 @@ func NewCompactMap() CompactMap {
|
|||||||
return CompactMap{}
|
return CompactMap{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cm *CompactMap) Set(key Key, offset uint32, size uint32) uint32 {
|
func (cm *CompactMap) Set(key Key, offset, size uint32) (oldOffset, oldSize uint32) {
|
||||||
x := cm.binarySearchCompactSection(key)
|
x := cm.binarySearchCompactSection(key)
|
||||||
if x < 0 {
|
if x < 0 {
|
||||||
//println(x, "creating", len(cm.list), "section, starting", key)
|
//println(x, "creating", len(cm.list), "section, starting", key)
|
||||||
|
@ -31,12 +31,12 @@ func LoadNeedleMap(file *os.File) (*NeedleMap, error) {
|
|||||||
if key > nm.MaximumFileKey {
|
if key > nm.MaximumFileKey {
|
||||||
nm.MaximumFileKey = key
|
nm.MaximumFileKey = key
|
||||||
}
|
}
|
||||||
nm.FileCounter++
|
|
||||||
nm.FileByteCounter = nm.FileByteCounter + uint64(size)
|
|
||||||
if offset > 0 && size != TombstoneFileSize {
|
if offset > 0 && size != TombstoneFileSize {
|
||||||
oldSize := nm.m.Set(Key(key), offset, size)
|
nm.FileCounter++
|
||||||
|
nm.FileByteCounter = nm.FileByteCounter + uint64(size)
|
||||||
|
oldOffset, oldSize := nm.m.Set(Key(key), offset, size)
|
||||||
glog.V(3).Infoln("reading key", key, "offset", offset*NeedlePaddingSize, "size", size, "oldSize", oldSize)
|
glog.V(3).Infoln("reading key", key, "offset", offset*NeedlePaddingSize, "size", size, "oldSize", oldSize)
|
||||||
if oldSize > 0 {
|
if oldOffset > 0 && oldSize != TombstoneFileSize {
|
||||||
nm.DeletionCounter++
|
nm.DeletionCounter++
|
||||||
nm.DeletionByteCounter = nm.DeletionByteCounter + uint64(oldSize)
|
nm.DeletionByteCounter = nm.DeletionByteCounter + uint64(oldSize)
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ func WalkIndexFile(r *os.File, fn func(key uint64, offset, size uint32) error) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nm *NeedleMap) Put(key uint64, offset uint32, size uint32) error {
|
func (nm *NeedleMap) Put(key uint64, offset uint32, size uint32) error {
|
||||||
oldSize := nm.m.Set(Key(key), offset, size)
|
_, oldSize := nm.m.Set(Key(key), offset, size)
|
||||||
nm.logPut(key, oldSize, size)
|
nm.logPut(key, oldSize, size)
|
||||||
return nm.appendToIndexFile(key, offset, size)
|
return nm.appendToIndexFile(key, offset, size)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user