1 8 9 package com.sleepycat.je.cleaner; 10 11 import java.nio.ByteBuffer ; 12 13 import com.sleepycat.je.DatabaseException; 14 import com.sleepycat.je.log.LogReadable; 15 import com.sleepycat.je.log.LogUtils; 16 import com.sleepycat.je.log.LogWritable; 17 18 public class FileSummary implements LogWritable, LogReadable { 19 20 21 public int totalCount; public int totalSize; public int totalINCount; public int totalINSize; public int totalLNCount; public int totalLNSize; public int obsoleteINCount; public int obsoleteLNCount; public int obsoleteLNSize; public int obsoleteLNSizeCounted; 32 35 public FileSummary() { 36 } 37 38 41 public boolean isEmpty() { 42 43 return totalCount == 0 && 44 totalSize == 0 && 45 obsoleteINCount == 0 && 46 obsoleteLNCount == 0; 47 } 48 49 53 public int getObsoleteLNSize() { 54 55 if (totalLNCount == 0) { 56 return 0; 57 } 58 59 64 int obsolete = obsoleteLNSize; 65 int notCounted = obsoleteLNCount - obsoleteLNSizeCounted; 66 if (notCounted > 0) { 67 68 long total = totalLNSize; 69 70 total <<= 8; 71 long avgSizePerLN = total / totalLNCount; 72 obsolete += (int) ((notCounted * avgSizePerLN) >> 8); 73 } 74 return obsolete; 75 } 76 77 80 public int getObsoleteINSize() { 81 82 if (totalINCount == 0) { 83 return 0; 84 } 85 86 long size = totalINSize; 87 88 size <<= 8; 89 long avgSizePerIN = size / totalINCount; 90 return (int) ((obsoleteINCount * avgSizePerIN) >> 8); 91 } 92 93 96 public int getObsoleteSize() 97 throws DatabaseException { 98 99 if (totalSize > 0) { 100 101 int leftoverSize = totalSize - (totalINSize + totalLNSize); 102 int obsoleteSize = getObsoleteLNSize() + 103 getObsoleteINSize() + 104 leftoverSize; 105 106 111 if (obsoleteSize > totalSize) { 112 obsoleteSize = totalSize; 113 } 114 return obsoleteSize; 115 } else { 116 return 0; 117 } 118 } 119 120 125 public int getEntriesCounted() { 126 return totalCount + obsoleteLNCount + obsoleteINCount; 127 } 128 129 132 public int getNonObsoleteCount() { 133 return totalLNCount + 134 totalINCount - 135 obsoleteLNCount - 136 obsoleteINCount; 137 } 138 139 142 public void reset() { 143 144 totalCount = 0; 145 totalSize = 0; 146 totalINCount = 0; 147 totalINSize = 0; 148 totalLNCount = 0; 149 totalLNSize = 0; 150 obsoleteINCount = 0; 151 obsoleteLNCount = 0; 152 obsoleteLNSize = 0; 153 obsoleteLNSizeCounted = 0; 154 } 155 156 159 public void add(FileSummary o) { 160 161 totalCount += o.totalCount; 162 totalSize += o.totalSize; 163 totalINCount += o.totalINCount; 164 totalINSize += o.totalINSize; 165 totalLNCount += o.totalLNCount; 166 totalLNSize += o.totalLNSize; 167 obsoleteINCount += o.obsoleteINCount; 168 obsoleteLNCount += o.obsoleteLNCount; 169 obsoleteLNSize += o.obsoleteLNSize; 170 obsoleteLNSizeCounted += o.obsoleteLNSizeCounted; 171 } 172 173 176 public int getLogSize() { 177 178 return 10 * LogUtils.getIntLogSize(); 179 } 180 181 184 public void writeToLog(ByteBuffer buf) { 185 186 LogUtils.writeInt(buf, totalCount); 187 LogUtils.writeInt(buf, totalSize); 188 LogUtils.writeInt(buf, totalINCount); 189 LogUtils.writeInt(buf, totalINSize); 190 LogUtils.writeInt(buf, totalLNCount); 191 LogUtils.writeInt(buf, totalLNSize); 192 LogUtils.writeInt(buf, obsoleteINCount); 193 LogUtils.writeInt(buf, obsoleteLNCount); 194 LogUtils.writeInt(buf, obsoleteLNSize); 195 LogUtils.writeInt(buf, obsoleteLNSizeCounted); 196 } 197 198 201 public void readFromLog(ByteBuffer buf, byte entryTypeVersion) { 202 203 totalCount = LogUtils.readInt(buf); 204 totalSize = LogUtils.readInt(buf); 205 totalINCount = LogUtils.readInt(buf); 206 totalINSize = LogUtils.readInt(buf); 207 totalLNCount = LogUtils.readInt(buf); 208 totalLNSize = LogUtils.readInt(buf); 209 obsoleteINCount = LogUtils.readInt(buf); 210 if (obsoleteINCount == -1) { 211 212 217 obsoleteINCount = totalINCount; 218 } 219 obsoleteLNCount = LogUtils.readInt(buf); 220 221 225 if (entryTypeVersion >= 3) { 226 obsoleteLNSize = LogUtils.readInt(buf); 227 obsoleteLNSizeCounted = LogUtils.readInt(buf); 228 } else { 229 obsoleteLNSize = 0; 230 obsoleteLNSizeCounted = 0; 231 } 232 } 233 234 237 public void dumpLog(StringBuffer buf, boolean verbose) { 238 239 buf.append("<summary totalCount=\""); 240 buf.append(totalCount); 241 buf.append("\" totalSize=\""); 242 buf.append(totalSize); 243 buf.append("\" totalINCount=\""); 244 buf.append(totalINCount); 245 buf.append("\" totalINSize=\""); 246 buf.append(totalINSize); 247 buf.append("\" totalLNCount=\""); 248 buf.append(totalLNCount); 249 buf.append("\" totalLNSize=\""); 250 buf.append(totalLNSize); 251 buf.append("\" obsoleteINCount=\""); 252 buf.append(obsoleteINCount); 253 buf.append("\" obsoleteLNCount=\""); 254 buf.append(obsoleteLNCount); 255 buf.append("\" obsoleteLNSize=\""); 256 buf.append(obsoleteLNSize); 257 buf.append("\" obsoleteLNSizeCounted=\""); 258 buf.append(obsoleteLNSizeCounted); 259 buf.append("\"/>"); 260 } 261 262 266 public long getTransactionId() { 267 return -1; 268 } 269 270 274 public boolean logEntryIsTransactional() { 275 return false; 276 } 277 278 public String toString() { 279 StringBuffer buf = new StringBuffer (); 280 dumpLog(buf, true); 281 return buf.toString(); 282 } 283 } 284 | Popular Tags |