2011-12-16 14:51:26 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2013-02-10 22:00:06 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2014-10-26 18:34:55 +00:00
|
|
|
|
|
|
|
"github.com/chrislusf/weed-fs/go/util"
|
2011-12-16 14:51:26 +00:00
|
|
|
)
|
|
|
|
|
2013-04-18 07:23:14 +00:00
|
|
|
type NeedleMapper interface {
|
2015-03-27 23:34:58 +00:00
|
|
|
Put(key uint64, offset uint32, size uint32) error
|
2013-04-18 07:23:14 +00:00
|
|
|
Get(key uint64) (element *NeedleValue, ok bool)
|
|
|
|
Delete(key uint64) error
|
|
|
|
Close()
|
2014-03-10 18:43:54 +00:00
|
|
|
Destroy() error
|
2013-04-18 07:23:14 +00:00
|
|
|
ContentSize() uint64
|
|
|
|
DeletedSize() uint64
|
|
|
|
FileCount() int
|
|
|
|
DeletedCount() int
|
2014-04-17 06:43:27 +00:00
|
|
|
MaxFileKey() uint64
|
2013-04-18 07:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type mapMetric struct {
|
|
|
|
DeletionCounter int `json:"DeletionCounter"`
|
|
|
|
FileCounter int `json:"FileCounter"`
|
|
|
|
DeletionByteCounter uint64 `json:"DeletionByteCounter"`
|
|
|
|
FileByteCounter uint64 `json:"FileByteCounter"`
|
2013-09-02 06:58:21 +00:00
|
|
|
MaximumFileKey uint64 `json:"MaxFileKey"`
|
2013-04-18 07:23:14 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 23:34:58 +00:00
|
|
|
func appendToIndexFile(indexFile *os.File,
|
|
|
|
key uint64, offset uint32, size uint32) error {
|
2014-03-19 11:38:10 +00:00
|
|
|
bytes := make([]byte, 16)
|
|
|
|
util.Uint64toBytes(bytes[0:8], key)
|
|
|
|
util.Uint32toBytes(bytes[8:12], offset)
|
|
|
|
util.Uint32toBytes(bytes[12:16], size)
|
2015-03-27 23:34:58 +00:00
|
|
|
if _, err := indexFile.Seek(0, 2); err != nil {
|
|
|
|
return fmt.Errorf("cannot seek end of indexfile %s: %v",
|
|
|
|
indexFile.Name(), err)
|
2014-05-30 02:19:03 +00:00
|
|
|
}
|
2015-03-27 23:34:58 +00:00
|
|
|
_, err := indexFile.Write(bytes)
|
|
|
|
return err
|
2011-12-19 05:59:37 +00:00
|
|
|
}
|
2015-03-27 23:34:58 +00:00
|
|
|
|
|
|
|
func (mm *mapMetric) logDelete(deletedByteCount uint32) {
|
|
|
|
mm.DeletionByteCounter = mm.DeletionByteCounter + uint64(deletedByteCount)
|
|
|
|
mm.DeletionCounter++
|
2011-12-16 14:51:26 +00:00
|
|
|
}
|
2015-03-27 23:34:58 +00:00
|
|
|
|
|
|
|
func (mm *mapMetric) logPut(key uint64, oldSize uint32, newSize uint32) {
|
|
|
|
if key > mm.MaximumFileKey {
|
|
|
|
mm.MaximumFileKey = key
|
2014-05-30 02:19:03 +00:00
|
|
|
}
|
2015-03-27 23:34:58 +00:00
|
|
|
mm.FileCounter++
|
|
|
|
mm.FileByteCounter = mm.FileByteCounter + uint64(newSize)
|
|
|
|
if oldSize > 0 {
|
|
|
|
mm.DeletionCounter++
|
|
|
|
mm.DeletionByteCounter = mm.DeletionByteCounter + uint64(oldSize)
|
2013-02-10 22:00:06 +00:00
|
|
|
}
|
2013-09-02 06:58:21 +00:00
|
|
|
}
|