diff --git a/datatree/load_recover_test.go b/datatree/load_recover_test.go index 3ba4f0f..c6c8a39 100644 --- a/datatree/load_recover_test.go +++ b/datatree/load_recover_test.go @@ -16,6 +16,12 @@ func compareNodes(t *testing.T, nodesA, nodesB map[NodePos]*[32]byte) { } func compareTwigs(t *testing.T, twigMapA, twigMapB map[int64]*Twig) { + //for k := range twigMapA { + // fmt.Printf("A %d\n", k) + //} + //for k := range twigMapB { + // fmt.Printf("B %d\n", k) + //} assert.Equal(t, len(twigMapA), len(twigMapB)) for id, twigA := range twigMapA { twigB := twigMapB[id] @@ -29,12 +35,18 @@ func compareTwigs(t *testing.T, twigMapA, twigMapB map[int64]*Twig) { } } -func TestLoadTree(t *testing.T) { +func TestLoadRecover(t *testing.T) { + testLoadRecover(t, TwigMask, 6) + testLoadRecover(t, LeafCountInTwig*2-10, 10) + testLoadRecover(t, LeafCountInTwig*4-3, 3) +} + +func testLoadRecover(t *testing.T, countBefore, countAfter int) { dirName := "./DataTree" _ = os.RemoveAll(dirName) _ = os.Mkdir(dirName, 0700) deactSNList := []int64{101, 999, 1002} - tree0, _, _ := buildTestTree(dirName, deactSNList, TwigMask, 6) + tree0, _, _ := buildTestTree(dirName, deactSNList, countBefore, countAfter) tree0.EndBlock() tree0.WaitForFlushing() nodes0 := tree0.nodes @@ -59,3 +71,4 @@ func TestLoadTree(t *testing.T) { os.RemoveAll(dirName) } + diff --git a/datatree/recover.go b/datatree/recover.go index 17b467b..6a634bd 100644 --- a/datatree/recover.go +++ b/datatree/recover.go @@ -75,6 +75,7 @@ func (tree *Tree) RecoverEntry(pos int64, entry *Entry, deactivedSNList []int64, tree.youngestTwigID++ tree.activeTwigs[tree.youngestTwigID] = CopyNullTwig() tree.mtree4YoungestTwig = NullMT4Twig + tree.touchedPosOf512b[(entry.SerialNum + 1)/512] = struct{}{} } } diff --git a/datatree/tree.go b/datatree/tree.go index de41a47..99271bb 100644 --- a/datatree/tree.go +++ b/datatree/tree.go @@ -263,6 +263,17 @@ func (tree *Tree) Close() { tree.deactivedSNList = nil } +func (tree *Tree) printNodes() { + nList := make([]NodePos, 0, len(tree.nodes)) + for pos := range tree.nodes { + nList = append(nList, pos) + } + sort.Slice(nList, func(i, j int) bool { return nList[i] < nList[j] }) + for i, pos := range nList { + fmt.Printf("NODE#%d %d-%d %#v\n", i, pos.Level(), pos.Nth(), tree.nodes[pos]) + } +} + func calcMaxLevel(youngestTwigID int64) int { return FirstLevelAboveTwig + 63 - bits.LeadingZeros64(uint64(youngestTwigID)) }