1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.iapi.store.raw.ContainerKey; 25 import org.apache.derby.iapi.store.raw.RecordHandle; 26 import org.apache.derby.iapi.store.raw.PageTimeStamp; 27 import org.apache.derby.iapi.store.raw.PageKey; 28 29 import org.apache.derby.iapi.services.context.ContextManager; 30 import org.apache.derby.iapi.services.daemon.Serviceable; 31 import org.apache.derby.iapi.services.sanity.SanityManager; 32 33 import org.apache.derby.iapi.error.StandardException; 34 import org.apache.derby.iapi.store.raw.data.DataFactory; 35 import org.apache.derby.iapi.store.raw.ContainerHandle; 36 37 38 43 public final class ReclaimSpace implements Serviceable 44 { 45 private boolean serviceASAP; 46 47 private ContainerKey containerId; 48 private PageKey pageId; private RecordHandle headRowHandle; 52 private int columnId; private long columnPageId; private int columnRecordId; private PageTimeStamp timeStamp; 60 private int attempts; 61 62 private DataFactory processor; 64 private int reclaim; public static final int CONTAINER = 1; public static final int PAGE = 2; public static final int ROW_RESERVE = 3; public static final int COLUMN_CHAIN = 4; 70 71 private void initContainerInfo(ContainerKey containerId, int reclaim, 72 DataFactory processor, boolean serviceASAP) 73 { 74 this.containerId = containerId; 75 this.reclaim = reclaim; 76 this.attempts = 0; 77 78 this.processor = processor; 79 this.serviceASAP = serviceASAP; 80 } 81 82 public ReclaimSpace(int reclaim, ContainerKey containerId, 84 DataFactory processor, boolean serviceASAP) 85 { 86 if (SanityManager.DEBUG) 87 SanityManager.ASSERT(reclaim == CONTAINER); 88 initContainerInfo(containerId, reclaim, processor, serviceASAP); 89 } 90 91 public ReclaimSpace(int reclaim, PageKey pageId, 93 DataFactory processor, boolean serviceASAP) 94 { 95 if (SanityManager.DEBUG) 96 SanityManager.ASSERT(reclaim == PAGE); 97 initContainerInfo(pageId.getContainerId(), reclaim, processor, serviceASAP); 98 99 this.pageId = pageId; 100 } 101 102 public ReclaimSpace(int reclaim, RecordHandle headRowHandle, 104 DataFactory processor, boolean serviceASAP) 105 { 106 if (SanityManager.DEBUG) 107 SanityManager.ASSERT(reclaim == ROW_RESERVE); 108 109 initContainerInfo(headRowHandle.getContainerId(), reclaim, processor, serviceASAP); 110 111 this.headRowHandle = headRowHandle; 112 } 113 114 public ReclaimSpace(int reclaim, RecordHandle headRowHandle, 116 int columnId, long ovPageId, int ovRecordId, 117 PageTimeStamp timeStamp, 118 DataFactory processor, boolean serviceASAP) 119 { 120 if (SanityManager.DEBUG) 121 SanityManager.ASSERT(reclaim == COLUMN_CHAIN); 122 initContainerInfo(headRowHandle.getContainerId(), reclaim, processor, serviceASAP); 123 124 this.headRowHandle = headRowHandle; 125 this.columnId = columnId; 126 this.columnPageId = ovPageId; 127 this.columnRecordId = ovRecordId; 128 this.timeStamp = timeStamp; 129 } 130 131 134 135 public boolean serviceASAP() 136 { 137 return serviceASAP; 138 } 139 140 public int performWork(ContextManager context) throws StandardException 141 { 142 if (SanityManager.DEBUG) 143 { 144 SanityManager.ASSERT(context != null, "context is null"); 145 SanityManager.ASSERT(processor != null, "processor is null"); 146 } 147 148 return processor.reclaimSpace(this, context); 149 } 150 151 152 public boolean serviceImmediately() 154 { 155 156 return true; 165 } 166 167 168 171 172 public final ContainerKey getContainerId() 173 { 174 return containerId; 175 } 176 177 public final PageKey getPageId() 178 { 179 return pageId; 180 } 181 182 public final RecordHandle getHeadRowHandle() 183 { 184 return headRowHandle; 185 } 186 187 public final int getColumnId() 188 { 189 return columnId; 190 } 191 192 public final long getColumnPageId() 193 { 194 return columnPageId; 195 } 196 197 public final int getColumnRecordId() 198 { 199 return columnRecordId; 200 } 201 202 public final PageTimeStamp getPageTimeStamp() 203 { 204 return timeStamp; 205 } 206 207 public final int reclaimWhat() 208 { 209 return reclaim; 210 } 211 212 public final int incrAttempts() 213 { 214 return ++attempts; 215 } 216 217 public String toString() 219 { 220 if (SanityManager.DEBUG) 221 { 222 if (reclaim == CONTAINER) 223 return "Reclaim CONTAINER (" + containerId + ")"; 224 225 if (reclaim == PAGE) 226 return "Reclaim PAGE (" + pageId + ") head row at " + headRowHandle; 227 228 if (reclaim == ROW_RESERVE) 229 return "Reclaim ROW_RESERVE (" + pageId + ")." + headRowHandle + ")"; 230 231 if (reclaim == COLUMN_CHAIN) 232 return "Reclaim COLUMN_CHAIN ("+ pageId + ").(" + headRowHandle 233 + "," + columnId + ") at (" + columnPageId + 234 "," + columnRecordId + ")"; 235 } 236 return null; 237 238 } 239 240 } 241 | Popular Tags |