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.dbi.DatabaseImpl; 15 import com.sleepycat.je.dbi.MemoryBudget; 16 import com.sleepycat.je.log.LogEntryType; 17 import com.sleepycat.je.log.LogException; 18 import com.sleepycat.je.log.LogUtils; 19 20 23 public final class MapLN extends LN { 24 25 private static final String BEGIN_TAG = "<mapLN>"; 26 private static final String END_TAG = "</mapLN>"; 27 28 private DatabaseImpl databaseImpl; 29 private boolean deleted; 30 31 37 public MapLN(DatabaseImpl db) { 38 super(new byte[0]); 39 databaseImpl = db; 40 deleted = false; 41 } 42 43 46 public MapLN() 47 throws DatabaseException { 48 49 super(); 50 databaseImpl = new DatabaseImpl(); 51 } 52 53 public boolean isDeleted() { 54 return deleted; 55 } 56 57 void makeDeleted() { 58 deleted = true; 59 60 61 databaseImpl.getTree().setRoot(null, true); 62 } 63 64 public DatabaseImpl getDatabase() { 65 return databaseImpl; 66 } 67 68 71 public void postFetchInit(DatabaseImpl db, long sourceLsn) 72 throws DatabaseException { 73 74 databaseImpl.setEnvironmentImpl(db.getDbEnvironment()); 75 } 76 77 81 public long getMemorySizeIncludedByParent() { 82 return MemoryBudget.MAPLN_OVERHEAD + 83 databaseImpl.getAdditionalMemorySize(); 84 } 85 86 89 90 public String toString() { 91 return dumpString(0, true); 92 } 93 94 public String beginTag() { 95 return BEGIN_TAG; 96 } 97 98 public String endTag() { 99 return END_TAG; 100 } 101 102 public String dumpString(int nSpaces, boolean dumpTags) { 103 StringBuffer sb = new StringBuffer (); 104 sb.append(super.dumpString(nSpaces, dumpTags)); 105 sb.append('\n'); 106 sb.append(TreeUtils.indent(nSpaces)); 107 sb.append("<deleted val=\"").append(Boolean.toString(deleted)); 108 sb.append("\">"); 109 sb.append('\n'); 110 sb.append(databaseImpl.dumpString(nSpaces)); 111 return sb.toString(); 112 } 113 114 117 118 121 protected LogEntryType getTransactionalLogType() { 122 return LogEntryType.LOG_MAPLN_TRANSACTIONAL; 123 } 124 125 128 public LogEntryType getLogType() { 129 return LogEntryType.LOG_MAPLN; 130 } 131 132 139 public int getLastLoggedSize() { 140 return getLogSizeInternal(true); 141 } 142 143 146 public int getLogSize() { 147 return getLogSizeInternal(false); 148 } 149 150 private int getLogSizeInternal(boolean lastLogged) { 151 return super.getLogSize() + 152 (lastLogged ? databaseImpl.getLastLoggedSize() 153 : databaseImpl.getLogSize()) + 154 LogUtils.getBooleanLogSize(); 155 } 156 157 160 public void writeToLog(ByteBuffer logBuffer) { 161 162 super.writeToLog(logBuffer); 163 databaseImpl.writeToLog(logBuffer); 164 LogUtils.writeBoolean(logBuffer, deleted); 165 } 166 167 170 public void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion) 171 throws LogException { 172 173 super.readFromLog(itemBuffer, entryTypeVersion); 174 databaseImpl.readFromLog(itemBuffer, entryTypeVersion); 175 deleted = LogUtils.readBoolean(itemBuffer); 176 } 177 178 182 protected void dumpLogAdditional(StringBuffer sb, boolean verbose) { 183 databaseImpl.dumpLog(sb, true); 184 } 185 } 186 | Popular Tags |