1 8 9 package com.sleepycat.je.recovery; 10 11 import java.util.HashMap ; 12 import java.util.HashSet ; 13 import java.util.Iterator ; 14 import java.util.Map ; 15 import java.util.Set ; 16 17 import com.sleepycat.je.dbi.DatabaseId; 18 19 72 class LevelRecorder { 73 74 75 private Map dbLevels; 76 77 LevelRecorder() { 78 dbLevels = new HashMap (); 79 } 80 81 85 void record(DatabaseId dbId, int level) { 86 LevelInfo info =(LevelInfo) dbLevels.get(dbId); 87 if (info == null) { 88 info = new LevelInfo(); 89 dbLevels.put(dbId, info); 90 } 91 info.recordLevel(level); 92 } 93 94 98 Set getDbsWithDifferentLevels() { 99 Set reprocessDbs = new HashSet (); 100 Set entries = dbLevels.entrySet(); 101 Iterator iter = entries.iterator(); 102 while (iter.hasNext()) { 103 Map.Entry oneEntry = (Map.Entry ) iter.next(); 104 LevelInfo levelInfo = (LevelInfo)oneEntry.getValue(); 105 if (levelInfo.getDifferenceSeen()) { 106 reprocessDbs.add(oneEntry.getKey()); 107 } 108 } 109 return reprocessDbs; 110 } 111 112 115 private static class LevelInfo { 116 private int highest = Integer.MIN_VALUE; 117 private int lowest = Integer.MAX_VALUE; 118 private boolean differenceSeen = false; 119 120 void recordLevel(int level) { 121 if (!differenceSeen) { 122 if (level < lowest) { 123 lowest = level; 124 } 125 if (level > highest) { 126 highest = level; 127 } 128 differenceSeen = highest > lowest; 129 } 130 } 131 132 136 boolean getDifferenceSeen() { 137 return differenceSeen; 138 } 139 } 140 } 141 | Popular Tags |