(Application zeze)
| 19 | private static final @NotNull Logger logger = LogManager.getLogger(Verify.class); |
| 20 | |
| 21 | public static void run(Application zeze) throws Exception { |
| 22 | var applyDb = new ApplyDatabaseMemory(); |
| 23 | var defaultDb = zeze.getDatabase(""); |
| 24 | var applyTables = new ConcurrentHashMap<Integer, ApplyTable<?, ?>>(); |
| 25 | zeze.checkpointRun(); // 【注意】如果存在多个app,需要所有app都checkpoint,这里只保证当前app提交。 |
| 26 | var counter = new AtomicLong(); |
| 27 | var total = new AtomicLong(); |
| 28 | var lastK = new OutObject<>(new Id128()); |
| 29 | zeze.getHistoryModule().getHistoryTable().walkDatabase((key, value) -> { |
| 30 | if (lastK.value.compareTo(key) >= 0) { |
| 31 | logger.error("out of Id128 order: {}, {}", lastK.value, key); |
| 32 | assert false; // XXX 这里会出现断言失败。 |
| 33 | } |
| 34 | lastK.value = key; |
| 35 | |
| 36 | for (var r : value.getChanges().entrySet()) { |
| 37 | var applyTable = applyTables.computeIfAbsent(r.getKey().getTableId(), __ -> { |
| 38 | var tableName = TableKey.tables.get(r.getKey().getTableId()); |
| 39 | if (tableName == null) |
| 40 | throw new RuntimeException("table id not found. id=" + r.getKey().getTableId()); |
| 41 | logger.info("history apply table {}", tableName); |
| 42 | var originTable = defaultDb.getTable(tableName); |
| 43 | if (originTable == null) |
| 44 | throw new RuntimeException("table not found. name=" + tableName); |
| 45 | return originTable.createApplyTable(applyDb); |
| 46 | }); |
| 47 | try { |
| 48 | applyTable.apply(r.getKey(), r.getValue()); |
| 49 | } catch (Exception e) { |
| 50 | throw new RuntimeException(String.format("apply(%d-%d:%s) exception", key.getHigh(), key.getLow(), |
| 51 | applyTable.getOriginTable().decodeKey(ByteBuffer.Wrap(r.getKey().getKeyEncoded()))), e); |
| 52 | } |
| 53 | } |
| 54 | var process = counter.incrementAndGet(); |
| 55 | if (process >= 50000) { |
| 56 | logger.info("history applying ................. {}", total.addAndGet(process)); |
| 57 | counter.set(0); |
| 58 | } |
| 59 | return true; |
| 60 | }); |
| 61 | var process = counter.incrementAndGet(); |
| 62 | logger.info("history apply end! +++++++++++++++++ {}", total.addAndGet(process)); |
| 63 | for (var applyTable : applyTables.values()) |
| 64 | applyTable.verifyAndClear(); |
| 65 | logger.info("history verify success!!!!!!!!!!!!!!!!!!!!!!"); |
| 66 | } |
| 67 | |
| 68 | public static @NotNull String toString(@NotNull BLogChanges.Data b) { |
| 69 | var sb = new StringBuilder(); |
nothing calls this directly
no test coverage detected