fix some issues with test suite

This commit is contained in:
Jeffrey Picard 2022-02-28 16:09:54 -05:00
parent 3c99296f8b
commit cff780bc74
4 changed files with 57 additions and 22 deletions

View file

@ -249,10 +249,17 @@ func (ps *PathSegment) String() string {
return ps.name
}
// // BisectRight returns the index of the first element in the list that is greater than or equal to the value.
// // https://stackoverflow.com/questions/29959506/is-there-a-go-analog-of-pythons-bisect-module
// func BisectRight(arr []uint32, val uint32) uint32 {
// i := sort.Search(len(arr), func(i int) bool { return arr[i] >= val })
// return uint32(i)
// }
// BisectRight returns the index of the first element in the list that is greater than or equal to the value.
// https://stackoverflow.com/questions/29959506/is-there-a-go-analog-of-pythons-bisect-module
func BisectRight(arr []uint32, val uint32) uint32 {
i := sort.Search(len(arr), func(i int) bool { return arr[i] >= val })
func BisectRight(arr []interface{}, val uint32) uint32 {
i := sort.Search(len(arr), func(i int) bool { return arr[i].(uint32) >= val })
return uint32(i)
}
@ -509,19 +516,18 @@ func GetDBColumnFamlies(name string, cfNames []string) (*ReadOnlyDBColumnFamily,
}
func Advance(db *ReadOnlyDBColumnFamily, height uint32) {
/*
def advance(self, height: int):
tx_count = self.db.prefix_db.tx_count.get(height).tx_count
assert len(self.db.tx_counts) == height, f"{len(self.db.tx_counts)} != {height}"
self.db.tx_counts.append(tx_count)
self.db.headers.append(self.db.prefix_db.header.get(height, deserialize_value=False))
*/
// TODO: assert tx_count not in self.db.tx_counts, f'boom {tx_count} in {len(self.db.tx_counts)} tx counts'
if db.TxCounts.Len() >= 0 && db.TxCounts.Len() != height {
if db.TxCounts.Len() != height {
log.Println("Error: tx count len:", db.TxCounts.Len(), "height:", height)
return
}
headerObj, err := GetHeader(db, height)
if err != nil {
log.Println("Error getting header:", err)
return
}
txCountObj, err := GetTxCount(db, height)
if err != nil {
log.Println("Error getting tx count:", err)
@ -529,7 +535,7 @@ func Advance(db *ReadOnlyDBColumnFamily, height uint32) {
}
txCount := txCountObj.TxCount
db.TxCounts.Push(txCount)
db.Headers.Push(headerObj)
}
func Unwind(db *ReadOnlyDBColumnFamily) {
@ -611,12 +617,13 @@ func DetectChanges(db *ReadOnlyDBColumnFamily) error {
//TODO: ClearCache
db.LastState = state
//TODO: block count metric
// self.last_state = state ???:w
//TODO: update blocked streams
//TODO: update filtered streams
}
}
return nil
/*
if self.last_state:
while True:
@ -645,8 +652,6 @@ func DetectChanges(db *ReadOnlyDBColumnFamily) error {
self.db.filtering_channel_hashes
)
*/
return nil
}
/*

View file

@ -37,9 +37,9 @@ func PrepareResolveResult(
return nil, err
}
var txCounts []uint32
txCounts = db.TxCounts.GetSlice().([]uint32)
txCounts = txCounts[db.TxCounts.Len()-1:]
var txCounts []interface{}
txCounts = db.TxCounts.GetSlice()
txCounts = txCounts[:db.TxCounts.Len()]
height := BisectRight(txCounts, txNum)
createdHeight := BisectRight(txCounts, rootTxNum)
lastTakeoverHeight := controllingClaim.Height

View file

@ -51,6 +51,6 @@ func (s *SliceBackedStack) Size() int {
return len(s.slice)
}
func (s *SliceBackedStack) GetSlice() interface{} {
func (s *SliceBackedStack) GetSlice() []interface{} {
return s.slice
}

View file

@ -6,6 +6,7 @@ import (
"encoding/hex"
"log"
"os"
"strings"
"testing"
dbpkg "github.com/lbryio/hub/db"
@ -41,7 +42,13 @@ func OpenAndFillTmpDBColumnFamlies(filePath string) (*dbpkg.ReadOnlyDBColumnFami
}
var handleMap map[string]*grocksdb.ColumnFamilyHandle = make(map[string]*grocksdb.ColumnFamilyHandle)
for _, cfNameRune := range records[0][0] {
// Make sure we always create the TxCounts column family
var cfNameRunes string = records[0][0]
txCountPrefix := string(prefixes.TxCount)
if !strings.Contains(cfNameRunes, txCountPrefix) {
cfNameRunes = cfNameRunes + txCountPrefix
}
for _, cfNameRune := range cfNameRunes {
cfName := string(cfNameRune)
log.Println(cfName)
handle, err := db.CreateColumnFamily(opts, cfName)
@ -75,11 +82,34 @@ func OpenAndFillTmpDBColumnFamlies(filePath string) (*dbpkg.ReadOnlyDBColumnFami
}
myDB := &dbpkg.ReadOnlyDBColumnFamily{
DB: db,
Handles: handleMap,
Opts: grocksdb.NewDefaultReadOptions(),
DB: db,
Handles: handleMap,
Opts: grocksdb.NewDefaultReadOptions(),
BlockedStreams: make(map[string][]byte),
BlockedChannels: make(map[string][]byte),
FilteredStreams: make(map[string][]byte),
FilteredChannels: make(map[string][]byte),
TxCounts: nil,
LastState: nil,
Height: 0,
Headers: nil,
}
// err = dbpkg.ReadDBState(myDB) //TODO: Figure out right place for this
// if err != nil {
// return nil, nil, nil, err
// }
err = dbpkg.InitTxCounts(myDB)
if err != nil {
return nil, nil, nil, err
}
// err = dbpkg.InitHeaders(myDB)
// if err != nil {
// return nil, nil, nil, err
// }
return myDB, records, toDefer, nil
}