mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
We switch everything to use QueryContext/QueryRead/etc instead of Qcx/Tx. We drop the short_txkey subpackage (it's now handled by either keys or querycontext). We drop all the dbshard stuff, and all the tx/txfactory stuff. We remove all the things that related to the old "Block" concept, which was mostly used by the anti-entropy code, but had one fragmentary usage left in the ImportRoaringOverwrite case of ImportRoaring. That's replaced by using a rewriter that deletes all bits (not just bits in specific columns) from an existing thing, but writes in new bits. Actually we could probably do that better with a custom "eradicate-rewriter" that doesn't try to be clever, and just eliminates things. This includes a number of minor bug fixes that were exposed by getting the testing to work. For example: * When checking whether an operation "requires write", we now consider a Delete a kind of a Write, because it is. * Several tests were relying on the fact that writes through Qcx were being committed whether or not the Qcx was ever told to finish. With QueryContext, you actually have to reach a Commit() or the writes don't happen (except for special cases in Delete). * Replaced a lot of panics with t.Fatalf in tests. There's also some minor staticcheck fixes, like deleting the unused "db" member of a boltdb transaction wrapper.
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
// Copyright 2021 Molecula Corp. All rights reserved.
|
|
package pilosa
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
// mustOpenView returns a new instance of View with a temporary path.
|
|
func mustOpenView(tb testing.TB) *view {
|
|
_, _, _, v := newTestView(tb)
|
|
if err := v.openEmpty(); err != nil {
|
|
tb.Fatalf("opening empty test view: %v", err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Ensure that simultaneous attempts to grab a new fragment don't clash even
|
|
// if the broadcast operation takes a bit of time.
|
|
func TestView_CreateFragmentRace(t *testing.T) {
|
|
var creates errgroup.Group
|
|
v := mustOpenView(t)
|
|
|
|
// Use a broadcaster which intentionally fails.
|
|
v.broadcaster = delayBroadcaster{delay: 10 * time.Millisecond}
|
|
|
|
shard := uint64(0)
|
|
|
|
creates.Go(func() error {
|
|
_, err := v.CreateFragmentIfNotExists(shard)
|
|
return err
|
|
})
|
|
creates.Go(func() error {
|
|
_, err := v.CreateFragmentIfNotExists(shard)
|
|
return err
|
|
})
|
|
err := creates.Wait()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
// delayBroadcaster is a nopBroadcaster with a configurable delay.
|
|
type delayBroadcaster struct {
|
|
nopBroadcaster
|
|
delay time.Duration
|
|
}
|
|
|
|
// SendSync is an implementation of Broadcaster SendSync which delays for a
|
|
// specified interval before succeeding.
|
|
func (d delayBroadcaster) SendSync(Message) error {
|
|
time.Sleep(d.delay)
|
|
return nil
|
|
}
|