1 8 9 package com.sleepycat.je.tree; 10 11 import java.nio.ByteBuffer ; 12 13 import com.sleepycat.je.DatabaseException; 14 import com.sleepycat.je.cleaner.UtilizationTracker; 15 import com.sleepycat.je.dbi.DatabaseImpl; 16 import com.sleepycat.je.dbi.INList; 17 import com.sleepycat.je.latch.LatchNotHeldException; 18 import com.sleepycat.je.log.LogEntryType; 19 import com.sleepycat.je.log.LogException; 20 import com.sleepycat.je.log.LogReadable; 21 import com.sleepycat.je.log.LogUtils; 22 import com.sleepycat.je.log.LogWritable; 23 import com.sleepycat.je.log.LoggableObject; 24 25 28 public abstract class Node 29 implements LoggableObject, LogReadable, LogWritable { 30 31 36 public synchronized static void setLastNodeId(long id) { 37 if (lastAllocatedId < id) { 38 lastAllocatedId = id; 39 } 40 } 41 42 private static long lastAllocatedId = 0; 43 44 private static final String BEGIN_TAG = "<node>"; 45 private static final String END_TAG = "</node>"; 46 47 private long nodeId; 49 50 53 private Node() { 54 } 55 56 59 protected Node(boolean init) { 60 if (init) { 61 nodeId = getNextNodeId(); 62 } 63 } 64 65 68 public static synchronized long getNextNodeId() { 69 return ++lastAllocatedId; 70 } 71 72 75 public static synchronized long getLastId() { 76 return lastAllocatedId; 77 } 78 79 82 public void postFetchInit(DatabaseImpl db, long sourceLsn) 83 throws DatabaseException { 84 85 86 } 87 88 public long getNodeId() { 89 return nodeId; 90 } 91 92 93 void setNodeId(long nid) { 94 nodeId = nid; 95 } 96 97 public void latchShared() 98 throws DatabaseException { 99 100 } 101 102 public void releaseLatch() 103 throws LatchNotHeldException { 104 105 } 106 107 public void verify(byte[] maxKey) 108 throws DatabaseException { 109 } 110 111 115 public boolean containsDuplicates() { 116 return false; 117 } 118 119 123 int getLevel() { 124 return 0; 125 } 126 127 134 boolean matchLNByNodeId(TreeLocation location, long nodeId) 135 throws DatabaseException { 136 137 throw new DatabaseException("matchLNByNodeId called on non DIN/DBIN"); 138 } 139 140 144 abstract void rebuildINList(INList inList) 145 throws DatabaseException; 146 147 151 abstract void accountForSubtreeRemoval(INList inList, 152 UtilizationTracker tracker) 153 throws DatabaseException; 154 155 158 abstract boolean isValidForDelete() 159 throws DatabaseException; 160 161 164 abstract protected boolean isSoughtNode(long nid, boolean updateGeneration) 165 throws DatabaseException; 166 167 172 abstract protected boolean canBeAncestor(boolean targetContainsDuplicates); 173 174 181 protected long getMemorySizeIncludedByParent() { 182 return 0; 183 } 184 185 188 189 192 public String toString() { 193 return this.dumpString(0, true); 194 } 195 196 private String beginTag() { 197 return BEGIN_TAG; 198 } 199 200 private String endTag() { 201 return END_TAG; 202 } 203 204 public void dump(int nSpaces) { 205 System.out.print(dumpString(nSpaces, true)); 206 } 207 208 String dumpString(int nSpaces, boolean dumpTags) { 209 StringBuffer self = new StringBuffer (); 210 self.append(TreeUtils.indent(nSpaces)); 211 if (dumpTags) { 212 self.append(beginTag()); 213 } 214 self.append(nodeId); 215 if (dumpTags) { 216 self.append(endTag()); 217 } 218 return self.toString(); 219 } 220 221 public String shortDescription() { 222 return "<" + getType() + "/" + getNodeId(); 223 } 224 225 public String getType() { 226 return getClass().getName(); 227 } 228 229 232 233 236 public abstract LogEntryType getLogType(); 237 238 242 public boolean marshallOutsideWriteLatch() { 243 return true; 244 } 245 246 249 public boolean countAsObsoleteWhenLogged() { 250 return false; 251 } 252 253 256 public void postLogWork(long justLoggedLsn) 257 throws DatabaseException { 258 259 } 260 261 264 public int getLogSize() { 265 return LogUtils.LONG_BYTES; 266 } 267 268 271 public void writeToLog(ByteBuffer logBuffer) { 272 LogUtils.writeLong(logBuffer, nodeId); 273 } 274 275 278 public void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion) 279 throws LogException { 280 281 nodeId = LogUtils.readLong(itemBuffer); 282 } 283 284 287 public void dumpLog(StringBuffer sb, boolean verbose) { 288 sb.append(BEGIN_TAG); 289 sb.append(nodeId); 290 sb.append(END_TAG); 291 } 292 } 293 | Popular Tags |