mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-06 16:45:55 +00:00
* First pass at RetryWithTx * Refactor RetryWithTx to take a writable bool (instead of reads, writes) * Implment DirectiveMethodDiff This commit adds support for a Directive to contain only the diffs (as opposed to the full Directive). * Update controller tests to allow for DirectiveMethodDiff (over Full) * Update RetryWithTx to retry on duplicate key constraint. If two concurrent processes call IngestShard() for the same shard, both were trying to insert the same job into the jobs table. That resulted in a duplicate key error from the database. We want to include that error in the list of errors for which RetryWithTx should retry. * Remove unused method: Directive.TranslatePartitions() * Replace query in a loop with a single query We had a query which was looking to see if a job already existed. That query was inside a loop, and could potentially generate 256 queries (for example). This commit replaces that logic so that we use a single query wiht an `IN ()` clause. * Convert to directive version-by-address This commit uses a separate directive version per address. It moves the version get/increment back inside the buildDirective method so that if two concurrent processes are building a directive for the same address, one of them will get rolled back trying to commit the version update. * Migration for directive version by address * Add a comment about DirectiveVersion lock/unlock logic * Remove AddLastWins * fix linter * handle error in walkdir * fix test failures from removing AddLastWins
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package sqldb_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/featurebasedb/featurebase/v3/dax"
|
|
"github.com/featurebasedb/featurebase/v3/dax/controller/sqldb"
|
|
"github.com/featurebasedb/featurebase/v3/logger"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDirectiveVersion(t *testing.T) {
|
|
t.Run("GetAndSet", func(t *testing.T) {
|
|
trans, err := sqldb.NewTransactor(sqldb.GetTestConfigRandomDB("directive_version"), logger.StderrLogger) // TODO running migrations takes kind of a long time, consolidate w/ other SQL tests
|
|
require.NoError(t, err, "connecting")
|
|
require.NoError(t, trans.Start())
|
|
|
|
tx, err := trans.BeginTx(context.Background(), true)
|
|
require.NoError(t, err, "getting transaction")
|
|
|
|
defer func() {
|
|
err := tx.Rollback()
|
|
if err != nil {
|
|
t.Logf("rolling back: %v", err)
|
|
}
|
|
}()
|
|
|
|
addr := dax.Address("address1")
|
|
|
|
dvSvc := sqldb.NewDirectiveVersion(nil)
|
|
|
|
// Get the current version; this returns 0 because a record for addr
|
|
// didn't exist and so it was created.
|
|
n, err := dvSvc.GetCurrent(tx, addr)
|
|
require.NoError(t, err)
|
|
require.Equal(t, uint64(0), n)
|
|
|
|
// Set next version to n+1 = 1.
|
|
require.NoError(t, dvSvc.SetNext(tx, addr, n, n+1))
|
|
|
|
// Get the version again and make sure we get the 1 that was set.
|
|
n, err = dvSvc.GetCurrent(tx, addr)
|
|
require.NoError(t, err)
|
|
require.Equal(t, uint64(1), n)
|
|
|
|
// Try to set next version with an incorrect current version (999) and
|
|
// ensure we get an error.
|
|
require.Error(t, dvSvc.SetNext(tx, addr, 999, n+1))
|
|
})
|
|
}
|