1 8 9 package com.sleepycat.je.cleaner; 10 11 import com.sleepycat.je.dbi.MemoryBudget; 12 13 23 public class TrackedFileSummary extends FileSummary { 24 25 private UtilizationTracker tracker; 26 private long fileNum; 27 private OffsetList obsoleteOffsets; 28 private int memSize; 29 private boolean trackDetail; 30 private boolean allowFlush = true; 31 32 35 TrackedFileSummary(UtilizationTracker tracker, 36 long fileNum, 37 boolean trackDetail) { 38 this.tracker = tracker; 39 this.fileNum = fileNum; 40 this.trackDetail = trackDetail; 41 } 42 43 47 public boolean getAllowFlush() { 48 return allowFlush; 49 } 50 51 55 void setAllowFlush(boolean allowFlush) { 56 this.allowFlush = allowFlush; 57 } 58 59 62 public long getFileNumber() { 63 return fileNum; 64 } 65 66 72 int getMemorySize() { 73 return memSize; 74 } 75 76 82 public void reset() { 83 84 obsoleteOffsets = null; 85 86 tracker.resetFile(this); 87 88 if (memSize > 0) { 89 updateMemoryBudget(0 - memSize); 90 } 91 92 super.reset(); 93 } 94 95 100 void trackObsolete(long offset) { 101 102 if (!trackDetail) { 103 return; 104 } 105 int adjustMem = 0; 106 if (obsoleteOffsets == null) { 107 obsoleteOffsets = new OffsetList(); 108 adjustMem += MemoryBudget.TFS_LIST_INITIAL_OVERHEAD; 109 } 110 if (obsoleteOffsets.add(offset, tracker.getEnvironment().isOpen())) { 111 adjustMem += MemoryBudget.TFS_LIST_SEGMENT_OVERHEAD; 112 } 113 if (adjustMem != 0) { 114 updateMemoryBudget(adjustMem); 115 } 116 } 117 118 121 void addTrackedSummary(TrackedFileSummary other) { 122 123 124 add(other); 125 126 131 if (other.obsoleteOffsets != null) { 132 if (obsoleteOffsets != null) { 133 134 if (obsoleteOffsets.merge(other.obsoleteOffsets)) { 135 136 updateMemoryBudget 137 (- MemoryBudget.TFS_LIST_SEGMENT_OVERHEAD); 138 } 139 } else { 140 141 obsoleteOffsets = other.obsoleteOffsets; 142 } 143 } 144 } 145 146 149 public long[] getObsoleteOffsets() { 150 151 if (obsoleteOffsets != null) { 152 return obsoleteOffsets.toArray(); 153 } else { 154 return null; 155 } 156 } 157 158 164 boolean containsObsoleteOffset(long offset) { 165 166 if (obsoleteOffsets != null) { 167 return obsoleteOffsets.contains(offset); 168 } else { 169 return false; 170 } 171 } 172 173 private void updateMemoryBudget(int delta) { 174 memSize += delta; 175 tracker.getEnvironment(). 176 getMemoryBudget(). 177 updateMiscMemoryUsage(delta); 178 } 179 } 180 | Popular Tags |