mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
* Database isolation: Balancer
Remove naive Balancer
remove debugging lines
Thread dax.Transaction through Controller
Change role to roleType
Swap out Balancer interface with new one
Standardize InvalidTransaction error
Add some interface comments
* Remove type.Worker; replace with type.Address
* Remove database validate from Queryer
This is already being handled in the `CreateTable()` method. Prior
to doing that validation, we were getting a panic, but that's no longer
the case.
* Remove dax.TableQualifier; replace with dax.QualifiedDatabaseID
* Update IDK test to create database
(cherry picked from commit d971cfc269)
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package boltdb
|
|
|
|
import (
|
|
"encoding/binary"
|
|
|
|
"github.com/featurebasedb/featurebase/v3/dax"
|
|
"github.com/featurebasedb/featurebase/v3/errors"
|
|
)
|
|
|
|
var (
|
|
bucketDirective = Bucket("nodeDirective")
|
|
keyDirectiveVersion = []byte("directiveVersion")
|
|
)
|
|
|
|
// DirectiveBuckets defines the buckets used by this package. It can be called
|
|
// during setup to create the buckets ahead of time.
|
|
var DirectiveBuckets []Bucket = []Bucket{
|
|
bucketDirective,
|
|
}
|
|
|
|
// Ensure type implements interface.
|
|
var _ dax.DirectiveVersion = (*DirectiveVersion)(nil)
|
|
|
|
type DirectiveVersion struct {
|
|
db *DB
|
|
}
|
|
|
|
func NewDirectiveVersion(db *DB) *DirectiveVersion {
|
|
return &DirectiveVersion{
|
|
db: db,
|
|
}
|
|
}
|
|
|
|
func (d *DirectiveVersion) Increment(tx dax.Transaction, delta uint64) (uint64, error) {
|
|
txx, ok := tx.(*Tx)
|
|
if !ok {
|
|
return 0, dax.NewErrInvalidTransaction()
|
|
}
|
|
|
|
bkt := txx.Bucket(bucketDirective)
|
|
if bkt == nil {
|
|
return 0, errors.Errorf(ErrFmtBucketNotFound, bucketDirective)
|
|
}
|
|
|
|
var nextVersion uint64 = 1 // Start at 1; 0 is an invalid version.
|
|
|
|
b := bkt.Get(keyDirectiveVersion)
|
|
if b != nil {
|
|
nextVersion = binary.LittleEndian.Uint64(b) + delta
|
|
}
|
|
|
|
vsn := make([]byte, 8)
|
|
binary.LittleEndian.PutUint64(vsn, nextVersion)
|
|
|
|
if err := bkt.Put(keyDirectiveVersion, vsn); err != nil {
|
|
return 0, errors.Wrap(err, "putting next directive version")
|
|
}
|
|
|
|
return nextVersion, nil
|
|
}
|