Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hailin0 committed Aug 8, 2023
1 parent 1dad465 commit 3649b3b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
8 changes: 3 additions & 5 deletions banyand/measure/tstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ import (
const (
defaultNumBufferShards = 2
defaultWriteConcurrency = 1000
defaultWriteWal = false
wal = "wal"
defaultWriteWal = true
plain = "tst"
encoded = "encoded"
)
Expand Down Expand Up @@ -74,15 +73,14 @@ func (t *tsTable) openBuffer() (err error) {
if t.encoderBuffer != nil {
return nil
}
walPath := path.Join(t.path, wal)
bufferSize := int(t.encoderBufferSize / defaultNumBufferShards)
if t.encoderBuffer, err = tsdb.NewBufferWithWal(t.l, t.position, bufferSize,
defaultWriteConcurrency, defaultNumBufferShards, t.encoderFlush, defaultWriteWal, &walPath); err != nil {
defaultWriteConcurrency, defaultNumBufferShards, t.encoderFlush, defaultWriteWal, &t.path); err != nil {
return fmt.Errorf("failed to create encoder buffer: %w", err)
}
bufferSize = int(t.bufferSize / defaultNumBufferShards)
if t.buffer, err = tsdb.NewBufferWithWal(t.l, t.position, bufferSize,
defaultWriteConcurrency, defaultNumBufferShards, t.flush, defaultWriteWal, &walPath); err != nil {
defaultWriteConcurrency, defaultNumBufferShards, t.flush, defaultWriteWal, &t.path); err != nil {
return fmt.Errorf("failed to create buffer: %w", err)
}
end := t.EndTime()
Expand Down
2 changes: 1 addition & 1 deletion banyand/tsdb/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func NewBufferWithWal(log *logger.Logger, position common.Position, flushSize, w
if walPath == nil {
return nil, errors.New("wal path is required")
}
shardWalPath := fmt.Sprintf("%s/shard-%d", *walPath, i)
shardWalPath := fmt.Sprintf("%s/buffer-%d", *walPath, i)
if err := buckets[i].startWal(shardWalPath, defaultWalSyncMode); err != nil {
return nil, errors.Wrap(err, "failed to start wal")
}
Expand Down
13 changes: 6 additions & 7 deletions banyand/tsdb/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ var _ = Describe("Buffer", func() {
writeConcurrency := 2
numShards := 2
flushSize := 1024
walPath := "wal"
baseTime := time.Now()
var walPath string
var shardWalFileHistory map[int][]string

BeforeEach(func() {
var err error
var mutex sync.Mutex

walPath, err = os.MkdirTemp("", "banyandb-test-wal-*")
Expect(err).ToNot(HaveOccurred())
shardWalFileHistory = make(map[int][]string)
buffer, err = tsdb.NewBufferWithWal(
log,
Expand All @@ -175,9 +177,7 @@ var _ = Describe("Buffer", func() {
mutex.Lock()
defer mutex.Unlock()

var shardWalDir string
shardWalDir, err = filepath.Abs(filepath.Join(walPath, "shard-"+strconv.Itoa(shardIndex)))
Expect(err).ToNot(HaveOccurred())
shardWalDir := filepath.Join(walPath, "buffer-"+strconv.Itoa(shardIndex))
var shardWalList []os.DirEntry
shardWalList, err = os.ReadDir(shardWalDir)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -223,8 +223,7 @@ var _ = Describe("Buffer", func() {
// Check wal rotate
Expect(len(shardWalFileHistory[shardIndex]) > 1).To(BeTrue())

shardWalDir, err := filepath.Abs(filepath.Join(walPath, "shard-"+strconv.Itoa(shardIndex)))
Expect(err).ToNot(HaveOccurred())
shardWalDir := filepath.Join(walPath, "buffer-"+strconv.Itoa(shardIndex))
currentShardWalFiles, err := os.ReadDir(shardWalDir)
Expect(err).ToNot(HaveOccurred())
Expect(len(currentShardWalFiles) <= 2).To(BeTrue())
Expand All @@ -233,7 +232,7 @@ var _ = Describe("Buffer", func() {
}
})

It("should recover wal file correctly", func() {
It("should recover buffer from wal file correctly", func() {
var err error
for i := 0; i < numShards; i++ {
buffer.Write(
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/envoyproxy/protoc-gen-validate v0.10.1
github.com/go-chi/chi/v5 v5.0.8
github.com/go-resty/resty/v2 v2.7.0
github.com/golang/mock v1.4.4
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0-rc.0
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down

0 comments on commit 3649b3b

Please sign in to comment.