1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.iapi.services.diag.Diagnosticable; 25 import org.apache.derby.iapi.services.diag.DiagnosticableGeneric; 26 import org.apache.derby.iapi.services.sanity.SanityManager; 27 import org.apache.derby.iapi.error.StandardException; 28 29 import org.apache.derby.iapi.store.access.Qualifier; 30 31 import org.apache.derby.iapi.store.raw.FetchDescriptor; 32 import org.apache.derby.iapi.store.raw.Page; 33 import org.apache.derby.iapi.store.raw.RecordHandle; 34 35 import org.apache.derby.iapi.types.DataValueDescriptor; 36 37 import java.util.Properties ; 38 import java.io.PrintStream ; 39 import java.io.IOException ; 40 41 import org.apache.derby.iapi.services.io.FormatableBitSet; 42 import org.apache.derby.iapi.services.io.CounterOutputStream; 43 import org.apache.derby.iapi.services.io.NullOutputStream; 44 45 55 56 public class D_StoredPage implements Diagnosticable 57 { 58 protected StoredPage page; 59 60 public D_StoredPage() 61 { 62 } 63 64 65 66 69 public void init(Object obj) 70 { 71 if (SanityManager.DEBUG) 72 SanityManager.ASSERT(obj instanceof StoredPage); 73 74 page = (StoredPage) obj; 75 } 76 77 89 public String diag() 90 throws StandardException 91 { 92 return(page.toString()); 93 } 94 95 106 public void diag_detail(Properties prop) 107 throws StandardException 108 { 109 String prop_value = null; 110 111 if (prop.getProperty(Page.DIAG_PAGE_SIZE) != null) 113 { 114 prop.put(Page.DIAG_PAGE_SIZE, Integer.toString(page.getPageSize())); 116 } 117 118 if (prop.getProperty(Page.DIAG_BYTES_FREE) != null) 119 { 120 int space_available = page.freeSpace; 121 122 prop.put(Page.DIAG_BYTES_FREE, Integer.toString(space_available)); 124 } 125 126 if (prop.getProperty(Page.DIAG_BYTES_RESERVED) != null) 127 { 128 int reservedSpace = (page.totalSpace * page.spareSpace / 100); 129 reservedSpace = Math.min(reservedSpace, page.freeSpace); 130 131 prop.put( 133 Page.DIAG_BYTES_RESERVED, Integer.toString(reservedSpace)); 134 } 135 136 if (prop.getProperty(Page.DIAG_RESERVED_SPACE) != null) 137 { 138 141 prop.put( 142 Page.DIAG_RESERVED_SPACE, Integer.toString(page.spareSpace)); 143 } 144 145 if (prop.getProperty(Page.DIAG_MINIMUM_REC_SIZE) != null) 146 { 147 150 prop.put( 151 Page.DIAG_MINIMUM_REC_SIZE, 152 Integer.toString(page.minimumRecordSize)); 153 } 154 155 if (prop.getProperty(Page.DIAG_PAGEOVERHEAD) != null) 156 { 157 160 prop.put( 161 Page.DIAG_PAGEOVERHEAD, 162 Integer.toString(page.getPageSize() - page.getMaxFreeSpace())); 163 } 164 165 if (prop.getProperty(Page.DIAG_SLOTTABLE_SIZE) != null) 166 { 167 170 int slotEntrySize = page.getSlotsInUse() * 3 * 173 ((page.getPageSize() >= 65536) ? 174 StoredPage.LARGE_SLOT_SIZE : StoredPage.SMALL_SLOT_SIZE); 175 176 prop.put(Page.DIAG_SLOTTABLE_SIZE, Integer.toString(slotEntrySize)); 177 } 178 179 int overflow_count = 0; 181 int row_size = 0; 182 long min_rowsize = 0; 183 long max_rowsize = 0; 184 long record_size = 0; 185 186 if (page.getSlotsInUse() > 0) 187 { 188 min_rowsize = Long.MAX_VALUE; 189 max_rowsize = Long.MIN_VALUE; 190 191 for (int slot = 0; slot < page.getSlotsInUse(); slot++) 192 { 193 try 194 { 195 if (page.getIsOverflow(slot)) 196 { 197 if (SanityManager.DEBUG) 198 SanityManager.DEBUG_PRINT("OVER", 199 "Slot (" + slot + ") is overflow record of page:" + 200 page); 201 overflow_count++; 202 } 203 record_size = page.getRecordLength(slot); 204 row_size += record_size; 205 206 min_rowsize = Math.min(min_rowsize, record_size); 207 max_rowsize = Math.max(max_rowsize, record_size); 208 } 209 catch (Throwable t) 210 { 211 System.out.println("Got error from getIsOverflow()."); 212 } 213 214 } 215 } 216 217 if (prop.getProperty(Page.DIAG_NUMOVERFLOWED) != null) 218 { 219 221 prop.put(Page.DIAG_NUMOVERFLOWED, Integer.toString(overflow_count)); 222 } 223 224 if (prop.getProperty(Page.DIAG_ROWSIZE) != null) 225 { 226 228 prop.put(Page.DIAG_ROWSIZE, Integer.toString(row_size)); 229 } 230 231 if (prop.getProperty(Page.DIAG_MINROWSIZE) != null) 232 { 233 235 prop.put(Page.DIAG_MINROWSIZE, Long.toString(min_rowsize)); 236 } 237 238 if (prop.getProperty(Page.DIAG_MAXROWSIZE) != null) 239 { 240 242 prop.put(Page.DIAG_MAXROWSIZE, Long.toString(max_rowsize)); 243 } 244 } 245 246 247 248 257 public boolean checkSlotTable(PrintStream out) throws StandardException, IOException { 258 259 boolean ok = true; 260 261 int slotCount = page.getSlotsInUse(); 262 int recordCount = page.recordCount(); 263 264 if (slotCount != recordCount) { 265 out.println("CORRUPT PAGE: slot count mismatch: slot count " + slotCount 266 + " record count " + recordCount); 267 ok = false; 268 } 269 270 for (int slot = 0; slot < slotCount; slot++) { 271 272 int recordLength = page.getRecordPortionLength(slot); 273 274 275 CounterOutputStream counter = new CounterOutputStream(); 276 counter.setOutputStream(new NullOutputStream()); 277 278 int recordId = 279 page.fetchFromSlot( 280 null, 281 slot, 282 new DataValueDescriptor[0], 283 (FetchDescriptor) null, true).getId(); 284 285 page.logRecord(slot, page.LOG_RECORD_DEFAULT, recordId, 286 (FormatableBitSet) null, counter, (RecordHandle)null); 287 288 int actualLength = counter.getCount(); 289 290 if (actualLength != recordLength) { 291 out.println( 292 "CORRUPT PAGE: record length mismatch at slot " + slot); 293 out.println(" slot entry length " + recordLength); 294 out.println(" actual length " + actualLength); 295 ok = false; 296 } 297 298 } 299 300 301 return ok; 302 303 } 304 305 public String pageHeaderToString() 306 { 307 return "page id " + page.getIdentity() + 308 " Overflow: " + page.isOverflowPage() + 309 " PageVersion: " + page.getPageVersion() + 310 " SlotsInUse: " + page.getSlotsInUse() + 311 " PageStatus: " + page.getPageStatus() + 312 " NextId: " + page.newRecordId() + "\n"; 313 } 314 315 } 316 | Popular Tags |