mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
This is a unification of a number of bug fixes, feature additions, and so on. Features include: * Dropping the "New" from NewWrite/NewRead. * IndexName->keys.Index, etc. * Add a new "Flush" operation which is necessary to get the intended behavior of Delete, which allows us to commit/flush changes without letting go of a write lock. * Some additional wrapping and locking in rbfTxWrappers to support that. rbfQueryRead/Write now forward their calls to the parent rbfTxWrappers, so it can lock around the reference to its underlying tx, so the flush operation can replace that tx safely. * AddIndexShards now treats no shards as "all shards", to simplify call sites. * Added parameters to NewRBFTxStore to let it interact with executor's logger and worker pool. * Internally, support explicit closes of parts of the database which can also check for errors and fail if it's in use. * Add ability to request a map of fields and views in use for a given index/shard pair. This is probably deprecated but we need it for the way backup/restore work. * Add ability to request a complete map of the database showing which shards exist for which index/field/view tuples. This is backwards from how we store things on disk, but we need it to allow creating the right in-memory data structures on database open. * Add "Backend()" method to let us distinguish backends in case we some day have them again. * Support deleting indexes, fields, or fragments. * Support Backup (returning a ReadCloser that dumps the RBF file, implicitly merging any current WAL) and Restore (create a new RBF file). * Change directory structure and fragment keys to match existing databases, so we should in theory be able to open an existing data directory. * Fragment delete probably doesn't lock correctly and this should be reviewed. * Export the DOT-format Dump so we can hook it up to a debug endpoint. This wants to be explored more; ideally the front-end UI should be able to display this. * Create a NopTxStore which can be used like a TxStore but everything that can error errors out. This is then used to let a holder that hasn't had a txstore initialized work anyway. There's at least a couple of open issues that need to be revisited here.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package querycontext
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/molecula/featurebase/v3/roaring"
|
|
)
|
|
|
|
func TestRbfWrite(t *testing.T) {
|
|
ctx := context.Background()
|
|
txs := testTxStore(t, "foo", nil)
|
|
q, _ := txs.NewWriteQueryContext(ctx, txs.Scope().AddIndex("i"))
|
|
wr, _ := q.Write("i", "f", "v", 0)
|
|
_, _ = wr.Add(23, 25)
|
|
_, _ = wr.Remove(25)
|
|
// putting nil and removing a missing container are no-ops
|
|
_ = wr.PutContainer(2, nil)
|
|
_ = wr.RemoveContainer(3)
|
|
citer, _, _ := wr.ContainerIterator(3)
|
|
if citer != nil {
|
|
citer.Close()
|
|
}
|
|
_, _ = wr.Container(7)
|
|
_, _ = wr.Count()
|
|
_, _ = wr.Max()
|
|
_, _, _ = wr.Min()
|
|
_, _ = wr.CountRange(0, 65535)
|
|
_, _ = wr.RoaringBitmap()
|
|
_, _ = wr.OffsetRange(0, 0, 0)
|
|
filter := roaring.NewBitmapColumnFilter(23)
|
|
_ = wr.ApplyFilter(0, filter)
|
|
// we're not testing ApplyRewriter and ImportRoaringBits because
|
|
// they have a lot more setup to be testable, and in practice
|
|
// they're all one-line functions anyway.
|
|
_ = q.Commit()
|
|
q, _ = txs.NewQueryContext(ctx)
|
|
rd, _ := q.Read("i", "f", "v", 0)
|
|
ok, _ := rd.Contains(23)
|
|
if !ok {
|
|
t.Fatalf("no 23")
|
|
}
|
|
txs.expect(1)
|
|
err := txs.Close()
|
|
if err == nil {
|
|
t.Fatalf("shouldn't close a database while still open")
|
|
}
|
|
q.Release()
|
|
}
|