diff --git a/rbf/cursor_test.go b/rbf/cursor_test.go index f4f16cf08..9e98fafb3 100644 --- a/rbf/cursor_test.go +++ b/rbf/cursor_test.go @@ -80,7 +80,7 @@ func TestCursor_FirstNext_Quick(t *testing.T) { t.Skip("race detection enabled, skipping") } - const n = 100000 + const n = 10000 QuickCheck(t, func(t *testing.T, rand *rand.Rand) { t.Parallel() @@ -202,7 +202,7 @@ func TestCursor_LastPrev_Quick(t *testing.T) { t.Skip("race detection enabled, skipping") } - const n = 100000 + const n = 10000 QuickCheck(t, func(t *testing.T, rand *rand.Rand) { t.Parallel() @@ -323,7 +323,7 @@ func TestCursor_Union(t *testing.T) { defer MustCloseDB(t, db) tx := MustBegin(t, db, true) defer MustRollback(t, tx) - values := GenerateValues(rand, 100000) + values := GenerateValues(rand, 10000) rows := ToRows(values) if err := tx.CreateBitmap("x"); err != nil { @@ -404,7 +404,7 @@ func TestCursor_Intersect(t *testing.T) { defer MustCloseDB(t, db) tx := MustBegin(t, db, true) defer MustRollback(t, tx) - values := GenerateValues(rand, rand.Intn(100000)) + values := GenerateValues(rand, rand.Intn(10000)) rows := ToRows(values) if err := tx.CreateBitmap("x"); err != nil { diff --git a/rbf/helpers_test.go b/rbf/helpers_test.go new file mode 100644 index 000000000..51167a28a --- /dev/null +++ b/rbf/helpers_test.go @@ -0,0 +1,93 @@ +package rbf_test + +/* +func itohex(v int) string { return fmt.Sprintf("0x%x", v) } + +func hexdump(b []byte) { println(hex.Dump(b)) } + +// treedump recursively writes the tree representation starting from a given page to STDERR. +func treedump(tx *rbf.Tx, pgno uint32, indent string, writer io.Writer) { + page, err := tx.readPage(pgno) + if err != nil { + panic(err) + } + + if rbf.IsMetaPage(page) { + fmt.Fprintf(writer, "META(%d)\n", pgno) + fmt.Fprintf(writer, "└── \n") + //treedump(tx, readMetaFreelistPageNo(page), indent+" ") + + visitor := func(pgno uint32, records []*rbf.RootRecord) { + fmt.Fprintf(writer, "└── ROOT RECORD(%d): n=%d\n", pgno, len(records)) + for _, record := range records { + fmt.Fprintf(writer, "└── ROOT(%q) %d\n", record.Name, record.Pgno) + treedump(tx, record.Pgno, indent+" ", writer) + + } + } + rrdump(tx, readMetaRootRecordPageNo(page), visitor) + + return + } + + // Handle + switch typ := readFlags(page); typ { + case PageTypeBranch: + fmt.Fprintf(writer, "%s BRANCH(%d) n=%d\n", fmtindent(indent), pgno, readCellN(page)) + + for i, n := 0, readCellN(page); i < n; i++ { + cell := readBranchCell(page, i) + treedump(tx, cell.Pgno, " "+indent, writer) + } + case PageTypeLeaf: + fmt.Fprintf(writer, "%s LEAF(%d) n=%d\n", fmtindent(indent), pgno, readCellN(page)) + pagedumpi(page, fmtindent(" "+indent), writer) + default: + panic(err) + } +} + +func rrdump(tx *Tx, pgno uint32, v func(uint32, []*RootRecord)) { + for pgno := readMetaRootRecordPageNo(tx.meta[:]); pgno != 0; { + page, err := tx.readPage(pgno) + if err != nil { + panic(err) + } + + // Read all records on the page. + a, err := readRootRecords(page) + if err != nil { + panic(err) + } + v(pgno, a) + // Read next overflow page number. + pgno = WalkRootRecordPages(page) + } +} + +func fmtindent(s string) string { + if s == "" { + return "" + } + return s + "└──" +} + +// RowValues returns a list of integer values from a row bitmap. +func RowValues(b []uint64) []uint64 { + a := make([]uint64, 0) + for i, v := range b { + for j := uint(0); j < 64; j++ { + if v&(1<\n") - //treedump(tx, readMetaFreelistPageNo(page), indent+" ") - - visitor := func(pgno uint32, records []*RootRecord) { - fmt.Fprintf(writer, "└── ROOT RECORD(%d): n=%d\n", pgno, len(records)) - for _, record := range records { - fmt.Fprintf(writer, "└── ROOT(%q) %d\n", record.Name, record.Pgno) - treedump(tx, record.Pgno, indent+" ", writer) - - } - } - rrdump(tx, readMetaRootRecordPageNo(page), visitor) - - return - } - - // Handle - switch typ := readFlags(page); typ { - case PageTypeBranch: - fmt.Fprintf(writer, "%s BRANCH(%d) n=%d\n", fmtindent(indent), pgno, readCellN(page)) - - for i, n := 0, readCellN(page); i < n; i++ { - cell := readBranchCell(page, i) - treedump(tx, cell.Pgno, " "+indent, writer) - } - case PageTypeLeaf: - fmt.Fprintf(writer, "%s LEAF(%d) n=%d\n", fmtindent(indent), pgno, readCellN(page)) - pagedumpi(page, fmtindent(" "+indent), writer) - default: - panic(err) - } -} - -func rrdump(tx *Tx, pgno uint32, v func(uint32, []*RootRecord)) { - for pgno := readMetaRootRecordPageNo(tx.meta[:]); pgno != 0; { - page, err := tx.readPage(pgno) - if err != nil { - panic(err) - } - - // Read all records on the page. - a, err := readRootRecords(page) - if err != nil { - panic(err) - } - v(pgno, a) - // Read next overflow page number. - pgno = WalkRootRecordPages(page) - } -} - -func fmtindent(s string) string { - if s == "" { - return "" - } - return s + "└──" } // RowValues returns a list of integer values from a row bitmap. @@ -623,15 +563,3 @@ func RowValues(b []uint64) []uint64 { } return a } - -func onpanic(fn func()) { - if r := recover(); r != nil { - fn() - } -} - -func assert(condition bool) { - if !condition { - panic("assertion failed") - } -} diff --git a/rbf/tx.go b/rbf/tx.go index 6c0adfcce..8740697dc 100644 --- a/rbf/tx.go +++ b/rbf/tx.go @@ -79,9 +79,12 @@ func (tx *Tx) Rollback() error { // Disconnect transaction from DB. err := tx.db.removeTx(tx) - if err != nil { - //TODO need to fix this error - } + _ = err + /* + if err != nil { + //TODO need to fix this error + } + */ return nil } @@ -149,12 +152,15 @@ func (tx *Tx) CreateBitmap(name string) error { return nil } + +/* func dump(r []*RootRecord) { for _, i := range r { fmt.Println("RECORD", i.Name, i.Pgno) } } +*/ // DeleteBitmap removes a bitmap with the given name. // Returns an error if the bitmap does not exist. diff --git a/rbf/tx_test.go b/rbf/tx_test.go index fa758309c..e9ceb05ac 100644 --- a/rbf/tx_test.go +++ b/rbf/tx_test.go @@ -226,7 +226,7 @@ func TestTx_Add_Quick(t *testing.T) { defer MustCloseDB(t, db) tx := MustBegin(t, db, true) defer MustRollback(t, tx) - values := GenerateValues(rand, 100000) + values := GenerateValues(rand, 10000) if err := tx.CreateBitmap("x"); err != nil { t.Fatal(err) @@ -265,7 +265,7 @@ func TestTx_AddRemove_Quick(t *testing.T) { defer MustCloseDB(t, db) tx := MustBegin(t, db, true) defer MustRollback(t, tx) - values := GenerateValues(rand, 100000) + values := GenerateValues(rand, 10000) if err := tx.CreateBitmap("x"); err != nil { t.Fatal(err) diff --git a/rbf/wal_test.go b/rbf/wal_test.go index 0e201b01a..4511578c8 100644 --- a/rbf/wal_test.go +++ b/rbf/wal_test.go @@ -16,8 +16,7 @@ package rbf_test import ( "bytes" - "encoding/hex" - "fmt" + "encoding/hex" "io/ioutil" "math/rand" "os" @@ -27,9 +26,6 @@ import ( "github.com/pilosa/pilosa/v2/rbf" ) -func itohex(v int) string { return fmt.Sprintf("0x%x", v) } - -func hexdump(b []byte) { println(hex.Dump(b)) } func TestWALSegment_Open(t *testing.T) { t.Run("OK", func(t *testing.T) {