// Copyright 2021 Molecula Corp. All rights reserved. package pilosa import ( "math/rand" "runtime" "testing" "github.com/molecula/featurebase/v3/logger" ) type cv struct { cols []uint64 vals []int64 } func forceSnapshotsCheckMapping(t *testing.T) { depth := uint64(6) f, idx, tx := mustOpenBSIFragment(t, "i", "f", viewStandard, 0) tx.Rollback() f.Logger = logger.NewLogfLogger(t) defer f.Clean(t) tx = idx.holder.txf.NewTx(Txo{Write: writable, Index: idx, Fragment: f, Shard: f.shard}) defer tx.Rollback() for i := 0; i < f.MaxOpN; i++ { _, _ = f.setBit(tx, 0, uint64(32*i)) } // force snapshot so we get a mmapped row... err := f.Snapshot() if err != nil { t.Fatalf("initial snapshot error: %v", err) } values := make([]cv, 1024) for i := range values { cols := make([]uint64, 128) vals := make([]int64, 128) for j := range cols { // pick values in the first 16 cols of each of the 16 // shards in a default shardwidth, so each set will // probably change some values from the previous one. cols[j] = uint64(((rand.Int63n(16) & int64(i>>2)) << 16) + rand.Int63n(16)) vals[j] = int64(rand.Int63n(1 << depth)) } values[i] = cv{cols, vals} } // modify the original bitmap, until it causes a snapshot, which // then invalidates the other map... for i := 0; i < 32; i++ { cv := values[i%len(values)] // periodically force gc, so if we have a small pool of maps // we'll go in and out of mapping mode if i%5 == 0 { runtime.GC() } err := f.importValue(tx, cv.cols, cv.vals, depth, (i%3 == 1)) if err != nil { t.Fatalf("importValue[%d]: %v", i, err) } err = f.Snapshot() if err != nil { t.Fatalf("snapshot[%d]: %v", i, err) } } }