Browse Source

adding file count and deletion count

pull/2/head
Chris Lu 12 years ago
parent
commit
6b1e60582c
  1. 8
      weed-fs/src/pkg/storage/needle_map.go
  2. 4
      weed-fs/src/pkg/storage/store.go
  3. 2
      weed-fs/src/pkg/storage/volume_info.go
  4. 2
      weed-fs/src/pkg/topology/node.go

8
weed-fs/src/pkg/storage/needle_map.go

@ -9,7 +9,11 @@ import (
type NeedleMap struct {
indexFile *os.File
m CompactMap
//transient
bytes []byte
deletionCounter int
fileCounter int
}
func NewNeedleMap(file *os.File) *NeedleMap {
@ -40,8 +44,10 @@ func LoadNeedleMap(file *os.File) *NeedleMap {
size := util.BytesToUint32(bytes[i+12 : i+16])
if offset > 0 {
nm.m.Set(Key(key), offset, size)
nm.fileCounter++
} else {
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.Uint32toBytes(nm.bytes[8:12], offset)
util.Uint32toBytes(nm.bytes[12:16], size)
nm.fileCounter++
return nm.indexFile.Write(nm.bytes)
}
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[12:16], 0)
nm.indexFile.Write(nm.bytes)
nm.deletionCounter++
}
func (nm *NeedleMap) Close() {
nm.indexFile.Close()

4
weed-fs/src/pkg/storage/store.go

@ -89,7 +89,7 @@ func (s *Store) Status() []*VolumeInfo {
var stats []*VolumeInfo
for k, v := range s.volumes {
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)
}
return stats
@ -98,7 +98,7 @@ func (s *Store) Join(mserver string) error {
stats := new([]*VolumeInfo)
for k, v := range s.volumes {
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)
}
bytes, _ := json.Marshal(stats)

2
weed-fs/src/pkg/storage/volume_info.go

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

2
weed-fs/src/pkg/topology/node.go

@ -14,6 +14,7 @@ type Node interface {
UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int)
UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int)
UpAdjustMaxVolumeId(vid storage.VolumeId)
GetActiveVolumeCount() int
GetMaxVolumeCount() int
GetMaxVolumeId() storage.VolumeId
@ -119,7 +120,6 @@ func (n *NodeImpl) UpAdjustMaxVolumeId(vid storage.VolumeId) { //can be negative
}
}
}
func (n *NodeImpl) GetMaxVolumeId() storage.VolumeId {
return n.maxVolumeId
}

Loading…
Cancel
Save