mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-05 08:10:50 +00:00
- all tests green on RoaringTx
- RoaringTx on by default
- blueGreenTx testing framework available for A-vs-B comparison
of Tx implementations
- flag -tx added to server command line but not wired to
change NewIndex() selection yet.
- 918 green tests, 14 tests red on BadgerTx.
A full list of the 14 red tests on BadgerTx follows.
Note that these red tests represent not defects in BadgerDB
or BadgerTx but rather failures of the pre-existing pilosa infrastructure to yet
be fully adapted from files to using a transactional storage engine.
As such these are tests that RBF should not be expected to
pass yet either.
Fixing the pilosa infrastructure to allow these tests
to go green under Badger is the next and highest priority
order of business, but RBF can get much testing benefit
from the 918 green tests we do have, and hence we merge
as much as we have today.
The 14 red tests when NewIndex() is set to use
BadgerTx are as follows. Note in particular
that pilosa cluster resizing is not working yet under a
transactional store.
TestCluster_ResizeStates/Multiple_nodes,_with_data
TestImportClearRestart/0MaxOpN10000
TestImportClearRestart/1MaxOpN10000
TestImportClearRestart/2MaxOpN10000
TestImportClearRestart/3MaxOpN10000
TestExecutor_Execute_Existence/Row
TestExecutor_ForeignIndex
TestExecutor_Execute_CountDistinct/Distinct
TestExecutor_Execute_CountDistinct/Count(Distinct)
TestExecutor_Execute_CountDistinct/GroupBy(Distinct)
TestExecutor_BareDistinct
TestExecutor_Execute_TopNDistinct/TopN
TestHolderSyncer_IntField/BasicSync
TestHolderSyncer_IntField/MultiShard
259 lines
7.2 KiB
Go
259 lines
7.2 KiB
Go
// Copyright 2017 Pilosa Corp.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"math"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/pilosa/pilosa/v2"
|
|
"github.com/pilosa/pilosa/v2/boltdb"
|
|
"github.com/pilosa/pilosa/v2/pql"
|
|
)
|
|
|
|
var panicOn = pilosa.PanicOn
|
|
|
|
// Holder is a test wrapper for pilosa.Holder.
|
|
type Holder struct {
|
|
*pilosa.Holder
|
|
}
|
|
|
|
// NewHolder returns a new instance of Holder with a temporary path.
|
|
func NewHolder() *Holder {
|
|
path, err := ioutil.TempDir("", "pilosa-")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
h := &Holder{Holder: pilosa.NewHolder(pilosa.DefaultPartitionN)}
|
|
h.Path = path
|
|
h.Holder.NewAttrStore = boltdb.NewAttrStore
|
|
|
|
return h
|
|
}
|
|
|
|
// MustOpenHolder creates and opens a holder at a temporary path. Panic on error.
|
|
func MustOpenHolder() *Holder {
|
|
h := NewHolder()
|
|
if err := h.Open(); err != nil {
|
|
panic(err)
|
|
}
|
|
return h
|
|
}
|
|
|
|
// Close closes the holder and removes all underlying data.
|
|
func (h *Holder) Close() error {
|
|
defer os.RemoveAll(h.Path)
|
|
return h.Holder.Close()
|
|
}
|
|
|
|
// Reopen instantiates and opens a new holder.
|
|
// Note that the holder must be Closed first.
|
|
func (h *Holder) Reopen() error {
|
|
path, logger := h.Path, h.Holder.Logger
|
|
h.Holder = pilosa.NewHolder(pilosa.DefaultPartitionN)
|
|
h.Holder.Path = path
|
|
h.Holder.Logger = logger
|
|
h.Holder.NewAttrStore = boltdb.NewAttrStore
|
|
return h.Holder.Open()
|
|
}
|
|
|
|
// MustCreateIndexIfNotExists returns a given index. Panic on error.
|
|
func (h *Holder) MustCreateIndexIfNotExists(index string, opt pilosa.IndexOptions) *Index {
|
|
idx, err := h.Holder.CreateIndexIfNotExists(index, opt)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return &Index{Index: idx}
|
|
}
|
|
|
|
// Row returns a Row for a given field.
|
|
func (h *Holder) Row(index, field string, rowID uint64) *pilosa.Row {
|
|
idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{})
|
|
f, err := idx.CreateFieldIfNotExists(field, pilosa.OptFieldTypeDefault())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
tx := idx.Index.Txf.NewTx(pilosa.Txo{Write: false, Index: idx.Index})
|
|
defer tx.Rollback()
|
|
|
|
row, err := f.Row(tx, rowID)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
// clone it so that mmapped storage doesn't disappear from under it
|
|
// once the tx goes away.
|
|
return row.Clone()
|
|
}
|
|
|
|
// ReadRow returns a Row for a given field. If the field does not exist,
|
|
// it panics rather than creating the field.
|
|
func (h *Holder) ReadRow(index, field string, rowID uint64) *pilosa.Row {
|
|
idx := h.Holder.Index(index)
|
|
if idx == nil {
|
|
panic(pilosa.ErrIndexNotFound)
|
|
}
|
|
f := idx.Field(field)
|
|
if f == nil {
|
|
panic(pilosa.ErrFieldNotFound)
|
|
}
|
|
tx := idx.Txf.NewTx(pilosa.Txo{Write: false, Field: f})
|
|
defer tx.Rollback()
|
|
|
|
row, err := f.Row(tx, rowID)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// clone it so that mmapped storage doesn't disappear from under it
|
|
// once the tx goes away.
|
|
return row.Clone()
|
|
}
|
|
|
|
func (h *Holder) RowAttrStore(index, field string) pilosa.AttrStore {
|
|
idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{})
|
|
f, err := idx.CreateFieldIfNotExists(field, pilosa.OptFieldTypeDefault())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return f.RowAttrStore()
|
|
}
|
|
|
|
func (h *Holder) RowTime(index, field string, rowID uint64, t time.Time, quantum string) *pilosa.Row {
|
|
idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{})
|
|
f, err := idx.CreateFieldIfNotExists(field, pilosa.OptFieldTypeDefault())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
tx := idx.Index.Txf.NewTx(pilosa.Txo{Write: false, Index: idx.Index})
|
|
defer tx.Rollback()
|
|
|
|
row, err := f.RowTime(tx, rowID, t, quantum)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// clone it so that mmapped storage doesn't disappear from under it
|
|
// once the tx goes away.
|
|
return row.Clone()
|
|
}
|
|
|
|
// SetBit sets a bit on the given field.
|
|
func (h *Holder) SetBit(index, field string, rowID, columnID uint64) {
|
|
h.SetBitTime(index, field, rowID, columnID, nil)
|
|
}
|
|
|
|
// SetBitTime sets a bit with timestamp on the given field.
|
|
func (h *Holder) SetBitTime(index, field string, rowID, columnID uint64, t *time.Time) {
|
|
idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{})
|
|
f, err := idx.CreateFieldIfNotExists(field, pilosa.OptFieldTypeDefault())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
tx := idx.Index.Txf.NewTx(pilosa.Txo{Write: true, Index: idx.Index})
|
|
defer tx.Rollback()
|
|
|
|
_, err = f.SetBit(tx, rowID, columnID, t)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
panicOn(tx.Commit())
|
|
}
|
|
|
|
// ClearBit clears a bit on the given field.
|
|
func (h *Holder) ClearBit(index, field string, rowID, columnID uint64) {
|
|
idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{})
|
|
f, err := idx.CreateFieldIfNotExists(field, pilosa.OptFieldTypeDefault())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
tx := idx.Index.Txf.NewTx(pilosa.Txo{Write: true, Index: idx.Index})
|
|
defer tx.Rollback()
|
|
|
|
_, err = f.ClearBit(tx, rowID, columnID)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
panicOn(tx.Commit())
|
|
}
|
|
|
|
// MustSetBits sets columns on a row. Panic on error.
|
|
// This function does not accept a timestamp or quantum.
|
|
func (h *Holder) MustSetBits(index, field string, rowID uint64, columnIDs ...uint64) {
|
|
for _, columnID := range columnIDs {
|
|
h.SetBit(index, field, rowID, columnID)
|
|
}
|
|
}
|
|
|
|
// SetValue sets an integer value on the given field.
|
|
func (h *Holder) SetValue(index, field string, columnID uint64, value int64) *Index {
|
|
idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{})
|
|
f, err := idx.CreateFieldIfNotExists(field, pilosa.OptFieldTypeInt(math.MinInt64, math.MaxInt64))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
tx := idx.Index.Txf.NewTx(pilosa.Txo{Write: true, Index: idx.Index})
|
|
defer tx.Rollback()
|
|
|
|
_, err = f.SetValue(tx, columnID, value)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if err := tx.Commit(); err != nil {
|
|
panic(err)
|
|
}
|
|
return idx
|
|
}
|
|
|
|
// Value returns the integer value for a given column.
|
|
func (h *Holder) Value(index, field string, columnID uint64) (int64, bool) {
|
|
idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{})
|
|
f, err := idx.CreateFieldIfNotExists(field, pilosa.OptFieldTypeInt(math.MinInt64, math.MaxInt64))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
tx := idx.Index.Txf.NewTx(pilosa.Txo{Write: false, Index: idx.Index})
|
|
defer tx.Rollback()
|
|
|
|
val, exists, err := f.Value(tx, columnID)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return val, exists
|
|
}
|
|
|
|
// Range returns a Row (of column IDs) for a field based
|
|
// on the given range.
|
|
func (h *Holder) Range(index, field string, op pql.Token, predicate int64) *pilosa.Row {
|
|
idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{})
|
|
f, err := idx.CreateFieldIfNotExists(field, pilosa.OptFieldTypeInt(math.MinInt64, math.MaxInt64))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
tx := idx.Index.Txf.NewTx(pilosa.Txo{Write: false, Index: idx.Index})
|
|
defer tx.Rollback()
|
|
|
|
row, err := f.Range(tx, field, op, predicate)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// clone it so that mmapped storage doesn't disappear from under it
|
|
// once the tx goes away.
|
|
return row.Clone()
|
|
}
|