mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 11:27:50 +00:00
remove old BSI upgrade code
This commit is contained in:
parent
114d74af29
commit
ebb340d83e
3 changed files with 0 additions and 96 deletions
28
field.go
28
field.go
|
|
@ -759,29 +759,11 @@ func (f *Field) openViews() error {
|
|||
}
|
||||
|
||||
for name, shardset := range view2shards {
|
||||
|
||||
view := f.newView(f.viewPath(name), name)
|
||||
if err := view.openWithShardSet(shardset); err != nil {
|
||||
return fmt.Errorf("opening view: view=%s, err=%s", view.name, err)
|
||||
}
|
||||
|
||||
if f.holder.txf.TxType() == RoaringTxn {
|
||||
// Automatically upgrade BSI v1 fragments if they exist & reopen view.
|
||||
if bsig := f.bsiGroup(f.name); bsig != nil {
|
||||
if ok, err := upgradeViewBSIv2(view, bsig.BitDepth); err != nil {
|
||||
return errors.Wrap(err, "upgrade view bsi v2")
|
||||
} else if ok {
|
||||
if err := view.close(); err != nil {
|
||||
return errors.Wrap(err, "closing upgraded view")
|
||||
}
|
||||
view = f.newView(f.viewPath(name), name)
|
||||
if err := view.openWithShardSet(shardset); err != nil {
|
||||
return fmt.Errorf("re-opening view: view=%s, err=%s", view.name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
view.rowAttrStore = f.rowAttrStore
|
||||
f.holder.Logger.Debugf("add index/field/view to field.viewMap: %s/%s/%s", f.index, f.name, view.name)
|
||||
f.viewMap[view.name] = view
|
||||
|
|
@ -825,16 +807,6 @@ func (f *Field) loadMeta() error {
|
|||
max = pql.NewDecimal(pb.OldMax, pb.Scale)
|
||||
}
|
||||
|
||||
// Initialize "base" to "min" when upgrading from v1 BSI format.
|
||||
if pb.BitDepth == 0 {
|
||||
minInt64, maxInt64 := min.ToInt64(0), max.ToInt64(0)
|
||||
pb.Base = bsiBase(minInt64, maxInt64)
|
||||
pb.BitDepth = uint64(bitDepthInt64(maxInt64 - minInt64))
|
||||
if pb.BitDepth == 0 {
|
||||
pb.BitDepth = 1
|
||||
}
|
||||
}
|
||||
|
||||
// Copy metadata fields.
|
||||
f.options.Type = pb.Type
|
||||
f.options.CacheType = pb.CacheType
|
||||
|
|
|
|||
46
fragment.go
46
fragment.go
|
|
@ -3279,52 +3279,6 @@ func (f *fragment) blockToRoaringData(block int) ([]byte, error) {
|
|||
})
|
||||
}
|
||||
|
||||
// upgradeRoaringBSIv2 upgrades a fragment that contains old BSI formatting
|
||||
// to a new BSI format (v2). The new format moves the "exists" bit to the
|
||||
// beginning & adds a negative sign bit.
|
||||
func upgradeRoaringBSIv2(f *fragment, bitDepth uint64) (string, error) {
|
||||
// If flag set, already upgraded. Exit.
|
||||
if f.storage.Flags&roaringFlagBSIv2 == 1 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
other := roaring.NewBitmap()
|
||||
other.Flags = roaringFlagBSIv2
|
||||
func() {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
|
||||
_ = f.storage.ForEach(func(i uint64) error {
|
||||
rowID, columnID := i/ShardWidth, (f.shard*ShardWidth)+(i%ShardWidth)
|
||||
if rowID == uint64(bitDepth) {
|
||||
_, _ = other.Add(pos(bsiExistsBit, columnID)) // move exists bit to beginning
|
||||
} else {
|
||||
_, _ = other.Add(pos(rowID+bsiOffsetBit, columnID)) // move other bits up
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}()
|
||||
|
||||
// Create temporary file next to existing file.
|
||||
newPath := f.path() + ".tmp"
|
||||
file, err := os.OpenFile(newPath, os.O_WRONLY|os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Write & flush to temporary file.
|
||||
if _, err := other.WriteTo(file); err != nil {
|
||||
return "", err
|
||||
} else if err := file.Sync(); err != nil {
|
||||
return "", err
|
||||
} else if err := file.Close(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return newPath, nil
|
||||
}
|
||||
|
||||
type rowIterator interface {
|
||||
// TODO(kuba) linter suggests to use io.Seeker
|
||||
// Seek(offset int64, whence int) (int64, error)
|
||||
|
|
|
|||
22
view.go
22
view.go
|
|
@ -575,28 +575,6 @@ func (v *view) rangeOp(qcx *Qcx, op pql.Token, bitDepth uint64, predicate int64)
|
|||
return r, nil
|
||||
}
|
||||
|
||||
// upgradeViewBSIv2 upgrades the fragments of v. Returns ok true if any fragment upgraded.
|
||||
func upgradeViewBSIv2(v *view, bitDepth uint64) (ok bool, _ error) {
|
||||
// If reading from an old formatted BSI roaring bitmap, upgrade and reload.
|
||||
for _, frag := range v.allFragments() {
|
||||
if frag.storage.Flags&roaringFlagBSIv2 == 1 {
|
||||
continue // already upgraded, skip
|
||||
}
|
||||
ok = true // mark as upgraded, requires reload
|
||||
|
||||
if tmpPath, err := upgradeRoaringBSIv2(frag, bitDepth); err != nil {
|
||||
return ok, errors.Wrap(err, "upgrading bsi v2")
|
||||
} else if err := frag.closeStorage(); err != nil {
|
||||
return ok, errors.Wrap(err, "closing after bsi v2 upgrade")
|
||||
} else if err := os.Rename(tmpPath, frag.path()); err != nil {
|
||||
return ok, errors.Wrap(err, "renaming after bsi v2 upgrade")
|
||||
} else if err := frag.openStorage(true); err != nil {
|
||||
return ok, errors.Wrap(err, "re-opening after bsi v2 upgrade")
|
||||
}
|
||||
}
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
// ViewInfo represents schema information for a view.
|
||||
type ViewInfo struct {
|
||||
Name string `json:"name"`
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue