github.com/turingchain2020/turingchain@v1.1.21/system/store/mavl/db/tool/main.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build go1.8 6 7 // package main 用于测试数据库中的MAVL节点数目 8 package main 9 10 import ( 11 "flag" 12 "fmt" 13 "os" 14 "path/filepath" 15 16 "github.com/turingchain2020/turingchain/common" 17 dbm "github.com/turingchain2020/turingchain/common/db" 18 clog "github.com/turingchain2020/turingchain/common/log" 19 log "github.com/turingchain2020/turingchain/common/log/log15" 20 mavl "github.com/turingchain2020/turingchain/system/store/mavl/db" 21 "github.com/turingchain2020/turingchain/types" 22 ) 23 24 var ( 25 queryHashCount = flag.Bool("qh", false, "查询hash节点计数") 26 queryLeafCount = flag.Bool("ql", false, "查询叶子节点计数") 27 queryAllCount = flag.Bool("qa", false, "查询全部节点计数") 28 29 queryLeafCountCount = flag.Bool("qlc", false, "查询叶子节点索引计数") 30 queryOldLeafCountCount = flag.Bool("qolc", false, "查询叶子节点二级索引计数") 31 pruneTreeHeight = flag.Int64("pth", 0, "裁剪树高度") 32 33 querySameLeafCountKeyPri = flag.String("qslc", "", "查询所有相同前缀的key的索引节点") 34 queryHashNode = flag.String("qhn", "", "查询hash节点是否存在且list左右子节点") 35 36 //queryLeafNodeParent 37 key = flag.String("k", "", "查询叶子节点父节点所需要:key") 38 hash = flag.String("h", "", "查询叶子节点父节点所需要:hash") 39 height = flag.Int64("hei", 0, "查询叶子节点父节点所需要:height") 40 ) 41 42 func main() { 43 flag.Parse() 44 dir, err := filepath.Abs(filepath.Dir(os.Args[0])) 45 if err != nil { 46 fmt.Println(err) 47 return 48 } 49 fmt.Println(dir) 50 str := "dbug" 51 52 log1 := &types.Log{ 53 Loglevel: str, 54 LogConsoleLevel: "info", 55 LogFile: "logs/syc.log", 56 MaxFileSize: 400, 57 MaxBackups: 100, 58 MaxAge: 28, 59 LocalTime: true, 60 Compress: false, 61 } 62 clog.SetFileLog(log1) 63 64 log.Info("dir", "test", dir) 65 db := dbm.NewDB("store", "leveldb", dir, 100) 66 67 if *queryHashCount { 68 mavl.PruningTreePrintDB(db, []byte("_mh_")) 69 } 70 71 if *queryLeafCount { 72 mavl.PruningTreePrintDB(db, []byte("_mb_")) 73 } 74 75 if *queryAllCount { 76 mavl.PruningTreePrintDB(db, nil) 77 } 78 79 if *queryLeafCountCount { 80 mavl.PruningTreePrintDB(db, []byte("..mk..")) 81 } 82 83 if *queryOldLeafCountCount { 84 mavl.PruningTreePrintDB(db, []byte("..mok..")) 85 } 86 87 if *pruneTreeHeight > 0 { 88 treeCfg := &mavl.TreeConfig{ 89 PruneHeight: mavl.DefaultPruneHeight, 90 } 91 mavl.PruningTree(db, *pruneTreeHeight, treeCfg) 92 } 93 94 if len(*querySameLeafCountKeyPri) > 0 { 95 mavl.PrintSameLeafKey(db, *querySameLeafCountKeyPri) 96 } 97 98 if len(*key) > 0 && len(*hash) > 0 && *height > 0 { 99 hashb, err := common.FromHex(*hash) 100 if err != nil { 101 fmt.Println("common.FromHex err", *hash) 102 return 103 } 104 mavl.PrintLeafNodeParent(db, []byte(*key), hashb, *height) 105 } 106 107 if len(*queryHashNode) > 0 { 108 key, err := common.FromHex(*queryHashNode) 109 if err == nil { 110 mavl.PrintNodeDb(db, key) 111 } 112 } 113 }