Runs through all TSMeta objects in the UID table and passes them through each of the Trees configured in the system. First, the method loads all trees in the system, compiles them into TreeBuilders, then scans the UID table, passing each TSMeta through each of the TreeBuilder objects. @param tsdb Th
(final TSDB tsdb)
| 1100 | * @return 0 if completed successfully, something else if an error occurred |
| 1101 | */ |
| 1102 | private static int treeSync(final TSDB tsdb) throws Exception { |
| 1103 | final long start_time = System.currentTimeMillis() / 1000; |
| 1104 | final long max_id = CliUtils.getMaxMetricID(tsdb); |
| 1105 | |
| 1106 | // now figure out how many IDs to divy up between the workers |
| 1107 | final int workers = Runtime.getRuntime().availableProcessors() * 2; |
| 1108 | final double quotient = (double)max_id / (double)workers; |
| 1109 | |
| 1110 | long index = 1; |
| 1111 | |
| 1112 | LOG.info("Max metric ID is [" + max_id + "]"); |
| 1113 | LOG.info("Spooling up [" + workers + "] worker threads"); |
| 1114 | final Thread[] threads = new Thread[workers]; |
| 1115 | for (int i = 0; i < workers; i++) { |
| 1116 | threads[i] = new TreeSync(tsdb, index, quotient, i); |
| 1117 | threads[i].setName("TreeSync # " + i); |
| 1118 | threads[i].start(); |
| 1119 | index += quotient; |
| 1120 | if (index < max_id) { |
| 1121 | index++; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | // wait till we're all done |
| 1126 | for (int i = 0; i < workers; i++) { |
| 1127 | threads[i].join(); |
| 1128 | LOG.info("[" + i + "] Finished"); |
| 1129 | } |
| 1130 | |
| 1131 | // make sure buffered data is flushed to storage before exiting |
| 1132 | tsdb.flush().joinUninterruptibly(); |
| 1133 | |
| 1134 | final long duration = (System.currentTimeMillis() / 1000) - start_time; |
| 1135 | LOG.info("Completed meta data synchronization in [" + |
| 1136 | duration + "] seconds"); |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * Attempts to delete the branches, leaves, collisions and not-matched entries |
no test coverage detected