Skip to content

Commit

Permalink
make a copy of KVs coming from boltdb which are only valid until the …
Browse files Browse the repository at this point in the history
…transaction is valid (grafana#2971)

* make a copy of KVs coming from boltdb which are only valid until the transaction is valid

Signed-off-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com>

* update changelog

Signed-off-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com>
  • Loading branch information
sandeepsukhani authored Aug 3, 2020
1 parent d3724c7 commit d68fc89
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions local/boltdb_index_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,14 @@ func (b *BoltIndexClient) QueryDB(ctx context.Context, db *bbolt.DB, query chunk
break
}

batch.rangeValue = k[len(rowPrefix):]
batch.value = v
// make a copy since k, v are only valid for the life of the transaction.
// See: https://godoc.org/github.com/boltdb/bolt#Cursor.Seek
batch.rangeValue = make([]byte, len(k)-len(rowPrefix))
copy(batch.rangeValue, k[len(rowPrefix):])

batch.value = make([]byte, len(v))
copy(batch.value, v)

if !callback(query, &batch) {
break
}
Expand Down

0 comments on commit d68fc89

Please sign in to comment.