1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.iapi.services.context.ContextService; 25 import org.apache.derby.iapi.services.diag.Diagnosticable; 26 import org.apache.derby.iapi.services.diag.DiagnosticUtil; 27 import org.apache.derby.iapi.services.monitor.Monitor; 28 import org.apache.derby.iapi.error.StandardException; 29 import org.apache.derby.iapi.store.access.AccessFactory; 30 import org.apache.derby.iapi.store.access.ConglomerateController; 31 import org.apache.derby.iapi.store.access.TransactionController; 32 import org.apache.derby.iapi.store.raw.ContainerHandle; 33 import org.apache.derby.iapi.store.raw.ContainerKey; 34 import org.apache.derby.iapi.store.raw.Page; 35 import org.apache.derby.iapi.store.raw.Transaction; 36 import org.apache.derby.iapi.store.raw.RawStoreFactory; 37 38 39 import org.apache.derby.iapi.reference.Property; 42 43 45 47 53 54 55 public class D_DiagnosticUtil 56 { 57 58 59 60 61 64 public D_DiagnosticUtil() 65 { 66 } 67 68 69 70 80 private static Object getModuleFromDbName(String db_name) 81 throws StandardException 82 { 83 Object store_module = null; 84 85 Object db = Monitor.findService(Property.DATABASE_MODULE, db_name); 86 87 if (db == null) 90 { 91 store_module = Monitor.findService(AccessFactory.MODULE, db_name); 93 } 94 else 95 { 96 store_module = Monitor.findServiceModule(db, AccessFactory.MODULE); 98 } 99 100 return(store_module); 101 } 102 103 104 136 public static String diag_conglomid_print(String db_name, long conglomid) 137 throws StandardException 138 { 139 try 140 { 141 System.out.println(diag_conglomid(db_name, conglomid)); 142 } 143 catch (Throwable t) 144 { 145 t.printStackTrace(); 146 } 147 148 return(""); 149 } 150 151 183 public static String diag_conglomid(String db_name, long conglomid) 184 throws StandardException 185 { 186 String ret_string = null; 187 AccessFactory store_module = null; 188 189 store_module = (AccessFactory) getModuleFromDbName(db_name); 190 191 if (store_module != null) 192 { 193 194 TransactionController tc = 195 store_module.getTransaction( 196 ContextService.getFactory().getCurrentContextManager()); 197 198 ConglomerateController open_table = 199 tc.openConglomerate( 200 conglomid, false, 0, TransactionController.MODE_TABLE, 201 TransactionController.ISOLATION_SERIALIZABLE); 202 203 open_table.debugConglomerate(); 204 205 Diagnosticable diag_obj = DiagnosticUtil.findDiagnostic(open_table); 206 207 ret_string = diag_obj.diag(); 208 209 open_table.close(); 210 } 211 else 212 { 213 System.out.println( 214 "Could not find module for database: " + db_name); 215 } 216 217 return(ret_string); 218 } 219 220 232 public static void diag_dump_page( 233 String db_name, 234 long segmentid, 235 long containerid, 236 long pagenumber) 237 { 238 Transaction xact = null; 239 try 240 { 241 Object module = getModuleFromDbName(db_name); 242 243 RawStoreFactory store_module = (RawStoreFactory) 244 Monitor.findServiceModule(module, RawStoreFactory.MODULE); 245 246 xact = store_module.startInternalTransaction(ContextService.getFactory().getCurrentContextManager()); 247 248 ContainerKey id = new ContainerKey(segmentid, containerid); 249 ContainerHandle container = 250 xact.openContainer(id, 251 ContainerHandle.MODE_READONLY); 252 Page page = container.getPage(pagenumber); 253 254 if (page != null) 255 { 256 System.out.println(page.toString()); 257 page.unlatch(); 258 } 259 else 260 { 261 System.out.println("page " + pagenumber + " not found"); 262 } 263 xact.abort(); 264 xact.close(); 265 xact = null; 266 } 267 catch (StandardException se) 268 { 269 se.printStackTrace(); 270 } 271 finally 272 { 273 if (xact != null) 274 { 275 try 276 { 277 xact.abort(); 278 xact.close(); 279 } 280 catch (StandardException se) 281 { 282 } 283 } 284 } 285 } 286 287 306 public static long diag_containerid_to_conglomid( 307 String db_name, 308 long containerid) 309 throws StandardException 310 { 311 Object store_module = getModuleFromDbName(db_name); 313 314 return(diag_containerid_to_conglomid(store_module, containerid)); 315 } 316 317 public static long diag_containerid_to_conglomid( 318 Object module, 319 long containerid) 320 { 321 String ret_string = null; 322 AccessFactory store_module = null; 323 long conglom_id = Long.MIN_VALUE; 324 325 store_module = (AccessFactory) 327 Monitor.getServiceModule(module, AccessFactory.MODULE); 328 329 if (store_module != null) 330 { 331 try 332 { 333 TransactionController tc = 334 store_module.getTransaction( 335 ContextService.getFactory().getCurrentContextManager()); 336 337 conglom_id = tc.findConglomid(containerid); 338 } 339 catch (Throwable t) 340 { 341 t.printStackTrace(); 342 } 344 } 345 else 346 { 347 351 355 } 356 357 return(conglom_id); 358 } 359 360 379 public static long diag_conglomid_to_containerid( 380 String db_name, 381 long conglomid) 382 throws StandardException 383 { 384 String ret_string = null; 385 Object store_module = null; 386 long conglom_id = Long.MIN_VALUE; 387 388 store_module = getModuleFromDbName(db_name); 390 391 return(diag_conglomid_to_containerid(store_module, conglomid)); 392 } 393 394 public static long diag_conglomid_to_containerid( 395 Object module, 396 long conglomid) 397 { 398 String ret_string = null; 399 AccessFactory store_module = null; 400 long container_id = Long.MIN_VALUE; 401 402 store_module = (AccessFactory) 404 Monitor.getServiceModule(module, AccessFactory.MODULE); 405 406 if (store_module != null) 407 { 408 try 409 { 410 TransactionController tc = 411 store_module.getTransaction( 412 ContextService.getFactory().getCurrentContextManager()); 413 414 container_id = tc.findContainerid(conglomid); 415 } 416 catch (Throwable t) 417 { 418 t.printStackTrace(); 419 } 421 } 422 else 423 { 424 428 432 } 433 434 return(container_id); 435 } 436 437 } 438 | Popular Tags |