Rename to OpenHeadBlock

This commit is contained in:
Fabian Reinartz 2016-12-22 20:00:24 +01:00
parent cabd7e4ebc
commit 8aba95048a
5 changed files with 14 additions and 11 deletions

View File

@ -128,7 +128,7 @@ func findBlocks(path string) ([]*persistedBlock, *HeadBlock, error) {
if err != nil {
return nil, nil, errors.Errorf("invalid directory name")
}
head, err = NewHeadBlock(p, int64(ts))
head, err = OpenHeadBlock(p, int64(ts))
if err != nil {
return nil, nil, err
}

4
db.go
View File

@ -206,7 +206,7 @@ func OpenShard(path string, logger log.Logger) (*Shard, error) {
if head == nil {
fmt.Println("creating new head", baset)
head, err = NewHeadBlock(filepath.Join(path, fmt.Sprintf("%d", baset)), baset)
head, err = OpenHeadBlock(filepath.Join(path, fmt.Sprintf("%d", baset)), baset)
if err != nil {
return nil, err
}
@ -304,7 +304,7 @@ func (s *Shard) persist() error {
// Set new head block.
head := s.head
newHead, err := NewHeadBlock(filepath.Join(s.path, fmt.Sprintf("%d", head.stats.MaxTime)), head.stats.MaxTime)
newHead, err := OpenHeadBlock(filepath.Join(s.path, fmt.Sprintf("%d", head.stats.MaxTime)), head.stats.MaxTime)
if err != nil {
s.mtx.Unlock()
return err

View File

@ -29,8 +29,8 @@ type HeadBlock struct {
stats BlockStats
}
// NewHeadBlock creates a new empty head block.
func NewHeadBlock(dir string, baseTime int64) (*HeadBlock, error) {
// OpenHeadBlock creates a new empty head block.
func OpenHeadBlock(dir string, baseTime int64) (*HeadBlock, error) {
wal, err := OpenWAL(dir)
if err != nil {
return nil, err

13
wal.go
View File

@ -122,11 +122,14 @@ type walEncoder struct {
buf []byte
}
// walPageBytes is the alignment for flushing records to the backing Writer.
// It should be a multiple of the minimum sector size so that WAL can safely
// distinguish between torn writes and ordinary data corruption.
const minSectorSize = 512
const walPageBytes = 8 * minSectorSize
const (
minSectorSize = 512
// walPageBytes is the alignment for flushing records to the backing Writer.
// It should be a multiple of the minimum sector size so that WAL can safely
// distinguish between torn writes and ordinary data corruption.
walPageBytes = 8 * minSectorSize
)
func newWALEncoder(f *os.File) (*walEncoder, error) {
offset, err := f.Seek(0, os.SEEK_CUR)

View File

@ -178,7 +178,7 @@ func BenchmarkWALReadIntoHead(b *testing.B) {
b.ResetTimer()
head, err := NewHeadBlock(d, 0)
head, err := OpenHeadBlock(d, 0)
require.NoError(b, err)
stat, _ := head.wal.f.Stat()