From 8aba95048a819fbbeeb325837731cbde170b1179 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 22 Dec 2016 20:00:24 +0100 Subject: [PATCH] Rename to OpenHeadBlock --- block.go | 2 +- db.go | 4 ++-- head.go | 4 ++-- wal.go | 13 ++++++++----- wal_test.go | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/block.go b/block.go index f237ba095..e8985a7f2 100644 --- a/block.go +++ b/block.go @@ -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 } diff --git a/db.go b/db.go index 58dc195b9..bfc7f1f96 100644 --- a/db.go +++ b/db.go @@ -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 diff --git a/head.go b/head.go index b7a3b8432..c09bf92e4 100644 --- a/head.go +++ b/head.go @@ -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 diff --git a/wal.go b/wal.go index f037fe0ed..18f66edb9 100644 --- a/wal.go +++ b/wal.go @@ -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) diff --git a/wal_test.go b/wal_test.go index 8849c08a3..0131d0230 100644 --- a/wal_test.go +++ b/wal_test.go @@ -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()