Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // tiletool is a command line application to validate a tile store. | |
| 2 package main | |
| 3 | |
| 4 import ( | |
| 5 "flag" | |
| 6 "fmt" | |
| 7 "log" | |
| 8 "time" | |
| 9 ) | |
| 10 | |
| 11 import ( | |
| 12 "config" | |
| 13 "filetilestore" | |
| 14 "types" | |
| 15 ) | |
| 16 | |
| 17 // flags | |
| 18 var ( | |
| 19 tileDir = flag.String("tile_dir", "/tmp/tileStore", "What directory t o look for tiles in.") | |
| 20 verbose = flag.Bool("verbose", false, "Verbose.") | |
| 21 echoHashes = flag.Bool("echo_hashes", false, "Echo Git hashes during val idation.") | |
| 22 ) | |
| 23 | |
| 24 // validateTile validates a tile by confirming that all the commits are in | |
| 25 // ascending order. | |
| 26 // | |
| 27 // Also checks that none of the commits overlap with the following tile by | |
| 28 // making sure each commit appears before oldestTS. | |
| 29 func validateTile(tile *types.Tile, oldestTS int64) error { | |
| 30 var lastTS int64 = 0 | |
| 31 lastHash := "" | |
| 32 if *verbose { | |
| 33 fmt.Println("Number of Commits:", len(tile.Commits)) | |
| 34 } | |
| 35 for i, c := range tile.Commits { | |
| 36 if *echoHashes { | |
| 37 fmt.Println("Hash:", c.Hash, c.CommitTime) | |
| 38 } | |
| 39 if c.CommitTime > oldestTS { | |
| 40 fmt.Printf("ERROR: Tiles out of order: Commit (%s) %d ti mestamp is %d, which appears after %d\n", c.Hash, i, c.CommitTime, oldestTS) | |
|
mtklein
2014/07/14 16:18:34
return fmt.Errorf?
jcgregorio
2014/07/14 16:21:39
Maybe eventually, but for now I only print the err
| |
| 41 } | |
| 42 if c.CommitTime < lastTS { | |
| 43 return fmt.Errorf("Commits out of order: Commit (%s) %d timestamp is %d, which appears before (%s) %d\n", c.Hash, i, c.CommitTime, lastH ash, lastTS) | |
| 44 } | |
| 45 lastTS = c.CommitTime | |
| 46 lastHash = c.Hash | |
| 47 } | |
| 48 | |
| 49 if *verbose { | |
| 50 fmt.Println("Number of traces:", len(tile.Traces)) | |
| 51 } | |
| 52 | |
| 53 // Make sure each Trace is the right length. | |
| 54 numCommits := len(tile.Commits) | |
| 55 for _, trace := range tile.Traces { | |
| 56 if len(trace.Values) != numCommits { | |
| 57 return fmt.Errorf("Trace lenght incorrect: Num Commits % d != Values in trace %d for Key %s", numCommits, len(trace.Values), trace.Key) | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 return nil | |
| 62 } | |
| 63 | |
| 64 // validateDataset validates all the tiles stored in a TileStore. | |
| 65 func validateDataset(store types.TileStore) bool { | |
| 66 index := -1 | |
| 67 isValid := true | |
| 68 // If tilebuilding were instantaneous this might cause a false negative, but | |
| 69 // it's not. | |
| 70 oldestTS := time.Now().Unix() | |
| 71 | |
| 72 for { | |
| 73 tile, err := store.Get(0, index) | |
| 74 if err != nil { | |
| 75 fmt.Printf("Failed to Get(0, %d): %s\n", index, err) | |
| 76 isValid = false | |
| 77 break | |
| 78 } | |
| 79 if *verbose { | |
| 80 fmt.Println("TileIndex:", tile.TileIndex) | |
| 81 } | |
| 82 // Validate the git hashes in the tile. | |
| 83 err = validateTile(tile, oldestTS) | |
| 84 oldestTS = tile.Commits[0].CommitTime | |
| 85 if err != nil { | |
| 86 fmt.Printf("Failed to validate tile %d scale 0: %s\n", i ndex, err) | |
| 87 isValid = false | |
| 88 break | |
| 89 } | |
| 90 if index > 0 && index != tile.TileIndex { | |
| 91 fmt.Printf("Tile index inconsistent: index %d != tile.Ti leIndex %d\n", index, tile.TileIndex) | |
| 92 isValid = false | |
| 93 break | |
| 94 } | |
| 95 if tile.Scale != 0 { | |
| 96 fmt.Printf("Tile scale isn't 0: tile.Scale %d\n", tile.S cale) | |
| 97 isValid = false | |
| 98 break | |
| 99 } | |
| 100 if tile.TileIndex > 0 { | |
| 101 index = tile.TileIndex - 1 | |
| 102 } else { | |
| 103 break | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 return isValid | |
| 108 } | |
| 109 | |
| 110 func main() { | |
| 111 flag.Parse() | |
| 112 valid := true | |
| 113 for _, name := range config.ALL_DATASET_NAMES { | |
| 114 fmt.Printf("Validating dataset: %s\n", string(name)) | |
| 115 store := filetilestore.NewFileTileStore(*tileDir, string(name)) | |
| 116 valid = valid && validateDataset(store) | |
| 117 } | |
| 118 if !valid { | |
| 119 log.Fatal("FAILED Validation.") | |
| 120 } | |
| 121 } | |
| OLD | NEW |