adding file count and deletion count

This commit is contained in:
Chris Lu 2012-10-09 20:53:31 -07:00
parent 8e25cc74d1
commit 6b1e60582c
5 changed files with 28 additions and 18 deletions

View File

@ -9,7 +9,11 @@ import (
type NeedleMap struct { type NeedleMap struct {
indexFile *os.File indexFile *os.File
m CompactMap m CompactMap
//transient
bytes []byte bytes []byte
deletionCounter int
fileCounter int
} }
func NewNeedleMap(file *os.File) *NeedleMap { func NewNeedleMap(file *os.File) *NeedleMap {
@ -40,8 +44,10 @@ func LoadNeedleMap(file *os.File) *NeedleMap {
size := util.BytesToUint32(bytes[i+12 : i+16]) size := util.BytesToUint32(bytes[i+12 : i+16])
if offset > 0 { if offset > 0 {
nm.m.Set(Key(key), offset, size) nm.m.Set(Key(key), offset, size)
nm.fileCounter++
} else { } else {
nm.m.Delete(Key(key)) nm.m.Delete(Key(key))
nm.deletionCounter++
} }
} }
@ -55,6 +61,7 @@ func (nm *NeedleMap) Put(key uint64, offset uint32, size uint32) (int, error) {
util.Uint64toBytes(nm.bytes[0:8], key) util.Uint64toBytes(nm.bytes[0:8], key)
util.Uint32toBytes(nm.bytes[8:12], offset) util.Uint32toBytes(nm.bytes[8:12], offset)
util.Uint32toBytes(nm.bytes[12:16], size) util.Uint32toBytes(nm.bytes[12:16], size)
nm.fileCounter++
return nm.indexFile.Write(nm.bytes) return nm.indexFile.Write(nm.bytes)
} }
func (nm *NeedleMap) Get(key uint64) (element *NeedleValue, ok bool) { func (nm *NeedleMap) Get(key uint64) (element *NeedleValue, ok bool) {
@ -67,6 +74,7 @@ func (nm *NeedleMap) Delete(key uint64) {
util.Uint32toBytes(nm.bytes[8:12], 0) util.Uint32toBytes(nm.bytes[8:12], 0)
util.Uint32toBytes(nm.bytes[12:16], 0) util.Uint32toBytes(nm.bytes[12:16], 0)
nm.indexFile.Write(nm.bytes) nm.indexFile.Write(nm.bytes)
nm.deletionCounter++
} }
func (nm *NeedleMap) Close() { func (nm *NeedleMap) Close() {
nm.indexFile.Close() nm.indexFile.Close()

View File

@ -89,7 +89,7 @@ func (s *Store) Status() []*VolumeInfo {
var stats []*VolumeInfo var stats []*VolumeInfo
for k, v := range s.volumes { for k, v := range s.volumes {
s := new(VolumeInfo) s := new(VolumeInfo)
s.Id, s.Size, s.RepType = VolumeId(k), v.Size(), v.replicaType s.Id, s.Size, s.RepType, s.FileCount, s.DeleteCount = VolumeId(k), v.Size(), v.replicaType, v.nm.fileCounter, v.nm.deletionCounter
stats = append(stats, s) stats = append(stats, s)
} }
return stats return stats
@ -98,7 +98,7 @@ func (s *Store) Join(mserver string) error {
stats := new([]*VolumeInfo) stats := new([]*VolumeInfo)
for k, v := range s.volumes { for k, v := range s.volumes {
s := new(VolumeInfo) s := new(VolumeInfo)
s.Id, s.Size, s.RepType = VolumeId(k), v.Size(), v.replicaType s.Id, s.Size, s.RepType, s.FileCount, s.DeleteCount = VolumeId(k), v.Size(), v.replicaType, v.nm.fileCounter, v.nm.deletionCounter
*stats = append(*stats, s) *stats = append(*stats, s)
} }
bytes, _ := json.Marshal(stats) bytes, _ := json.Marshal(stats)

View File

@ -8,6 +8,8 @@ type VolumeInfo struct {
Id VolumeId Id VolumeId
Size int64 Size int64
RepType ReplicationType RepType ReplicationType
FileCount int
DeleteCount int
} }
type ReplicationType string type ReplicationType string

View File

@ -14,6 +14,7 @@ type Node interface {
UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int) UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int)
UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int) UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int)
UpAdjustMaxVolumeId(vid storage.VolumeId) UpAdjustMaxVolumeId(vid storage.VolumeId)
GetActiveVolumeCount() int GetActiveVolumeCount() int
GetMaxVolumeCount() int GetMaxVolumeCount() int
GetMaxVolumeId() storage.VolumeId GetMaxVolumeId() storage.VolumeId
@ -26,7 +27,7 @@ type Node interface {
Children() map[NodeId]Node Children() map[NodeId]Node
Parent() Node Parent() Node
GetValue()interface{} //get reference to the topology,dc,rack,datanode GetValue() interface{} //get reference to the topology,dc,rack,datanode
} }
type NodeImpl struct { type NodeImpl struct {
id NodeId id NodeId
@ -71,7 +72,7 @@ func (n *NodeImpl) Children() map[NodeId]Node {
func (n *NodeImpl) Parent() Node { func (n *NodeImpl) Parent() Node {
return n.parent return n.parent
} }
func (n *NodeImpl) GetValue()interface{}{ func (n *NodeImpl) GetValue() interface{} {
return n.value return n.value
} }
func (n *NodeImpl) ReserveOneVolume(r int, vid storage.VolumeId) (bool, *DataNode) { func (n *NodeImpl) ReserveOneVolume(r int, vid storage.VolumeId) (bool, *DataNode) {
@ -119,7 +120,6 @@ func (n *NodeImpl) UpAdjustMaxVolumeId(vid storage.VolumeId) { //can be negative
} }
} }
} }
func (n *NodeImpl) GetMaxVolumeId() storage.VolumeId { func (n *NodeImpl) GetMaxVolumeId() storage.VolumeId {
return n.maxVolumeId return n.maxVolumeId
} }
@ -175,7 +175,7 @@ func (n *NodeImpl) CollectDeadNodeAndFullVolumes(freshThreshHold int64, volumeSi
} }
} }
func (n *NodeImpl) GetTopology() *Topology{ func (n *NodeImpl) GetTopology() *Topology {
var p Node var p Node
p = n p = n
for p.Parent() != nil { for p.Parent() != nil {