diff --git a/banyand/measure/tstable.go b/banyand/measure/tstable.go index d69047f37..689d43f74 100644 --- a/banyand/measure/tstable.go +++ b/banyand/measure/tstable.go @@ -41,8 +41,7 @@ import ( const ( defaultNumBufferShards = 2 defaultWriteConcurrency = 1000 - defaultWriteWal = false - wal = "wal" + defaultWriteWal = true plain = "tst" encoded = "encoded" ) @@ -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() diff --git a/banyand/tsdb/buffer.go b/banyand/tsdb/buffer.go index a1cbf9e71..d555b304c 100644 --- a/banyand/tsdb/buffer.go +++ b/banyand/tsdb/buffer.go @@ -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") } diff --git a/banyand/tsdb/buffer_test.go b/banyand/tsdb/buffer_test.go index 57029df13..4b500c189 100644 --- a/banyand/tsdb/buffer_test.go +++ b/banyand/tsdb/buffer_test.go @@ -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, @@ -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()) @@ -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()) @@ -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( diff --git a/go.mod b/go.mod index 77259d00c..7cf870650 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 55cfc2421..eb7ac7e64 100644 --- a/go.sum +++ b/go.sum @@ -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=