github.com/bartle-stripe/trillian@v1.2.1/storage/tools/dump_tree/main.go (about)

     1  // Copyright 2017 Google Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // The dump_tree program uses the in memory storage implementation to create a sequenced
    16  // log tree of a particular size using known leaf data and then dumps out the resulting
    17  // SubTree protos for examination and debugging. It does not require any actual storage
    18  // to be configured.
    19  //
    20  // Examples of some usages:
    21  //
    22  // Print a summary of the storage protos in a tree of size 1044, rebuilding internal nodes:
    23  // dump_tree -tree_size 1044 -summary
    24  //
    25  // Print all versions of all raw subtree protos for a tree of size 58:
    26  // dump_tree -tree_size 58 -latest_version=false
    27  //
    28  // Print the latest revision of each subtree proto for a tree of size 127 with hex keys:
    29  // dump_tree -tree_size 127
    30  //
    31  // Print out the nodes by level using the NodeReader API for a tree of size 11:
    32  // dump_tree -tree_size 11 -traverse
    33  //
    34  // The format for recordio output is as defined in:
    35  // https://github.com/google/or-tools/blob/master/ortools/base/recordio.h
    36  // This program always outputs uncompressed records.
    37  package main
    38  
    39  import (
    40  	"flag"
    41  	"fmt"
    42  
    43  	"github.com/golang/glog"
    44  	"github.com/google/trillian/storage/tools/dump_tree/dumplib"
    45  )
    46  
    47  var (
    48  	treeSizeFlag        = flag.Int("tree_size", 871, "The number of leaves to be added to the tree")
    49  	batchSizeFlag       = flag.Int("batch_size", 50, "The batch size for sequencing")
    50  	leafDataFormatFlag  = flag.String("leaf_format", "Leaf %d", "The format string for leaf data")
    51  	latestRevisionFlag  = flag.Bool("latest_version", true, "If true outputs only the latest revision per subtree")
    52  	summaryFlag         = flag.Bool("summary", false, "If true outputs a brief summary per subtree, false dumps the whole proto")
    53  	hexKeysFlag         = flag.Bool("hex_keys", false, "If true shows proto keys as hex rather than base64")
    54  	leafHashesFlag      = flag.Bool("leaf_hashes", false, "If true the summary output includes leaf hashes")
    55  	recordIOFlag        = flag.Bool("recordio", false, "If true outputs in recordio format")
    56  	rebuildInternalFlag = flag.Bool("rebuild", true, "If true rebuilds internal nodes + root hash from leaves")
    57  	traverseFlag        = flag.Bool("traverse", false, "If true dumps a tree traversal via coord space, else raw subtrees")
    58  	dumpLeavesFlag      = flag.Bool("dump_leaves", false, "If true dumps the leaf data from the tree via the API")
    59  )
    60  
    61  func main() {
    62  	flag.Parse()
    63  	defer glog.Flush()
    64  
    65  	fmt.Print(dumplib.Main(dumplib.Options{
    66  		TreeSize:       *treeSizeFlag,
    67  		BatchSize:      *batchSizeFlag,
    68  		LeafFormat:     *leafDataFormatFlag,
    69  		LatestRevision: *latestRevisionFlag,
    70  		Summary:        *summaryFlag,
    71  		HexKeys:        *hexKeysFlag,
    72  		LeafHashes:     *leafHashesFlag,
    73  		RecordIO:       *recordIOFlag,
    74  		Rebuild:        *rebuildInternalFlag,
    75  		Traverse:       *traverseFlag,
    76  		DumpLeaves:     *dumpLeavesFlag,
    77  	}))
    78  }