Skip to content

Commit

Permalink
use shardwidth package
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Nov 20, 2024
1 parent 0a3eaa4 commit f847b87
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions internal/timeseries/timeseries_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import (
"fmt"

"github.com/cockroachdb/pebble"
"github.com/gernest/roaring/shardwidth"
"github.com/vinceanalytics/vince/internal/encoding"
"github.com/vinceanalytics/vince/internal/models"
"github.com/vinceanalytics/vince/internal/ro2"
"github.com/vinceanalytics/vince/internal/shards"
"github.com/vinceanalytics/vince/internal/util/oracle"
)

const ShardWidth = 1 << 20

type batch struct {
db *shards.DB
translate *translation
Expand All @@ -32,7 +31,7 @@ func newbatch(db *shards.DB, tr *translation) *batch {
b := &batch{
translate: tr,
id: tr.id,
shard: tr.id / ShardWidth,
shard: tr.id / shardwidth.ShardWidth,
db: db,
}
for i := range b.mutex {
Expand Down Expand Up @@ -151,7 +150,7 @@ func (b *batch) add(m *models.Model) error {
// Skip events without timestamp, id
return nil
}
shard := (b.id + 1) / ShardWidth
shard := (b.id + 1) / shardwidth.ShardWidth
if shard != b.shard {
err := b.save()
if err != nil {
Expand Down Expand Up @@ -209,7 +208,7 @@ func (b *batch) set(field models.Field, id uint64, value []byte) {
}
idx := field.Mutex()
ro2.WriteMutex(b.mutex[idx], id, b.tr(field, value))
b.mutexExistence[idx].DirectAdd(id % ShardWidth)
b.mutexExistence[idx].DirectAdd(id % shardwidth.ShardWidth)
}

func (b *batch) tr(field models.Field, value []byte) uint64 {
Expand Down

0 comments on commit f847b87

Please sign in to comment.