📄 timeout.java
字号:
/* Derby - Class org.apache.derby.impl.services.locks.Timeout Copyright 2000, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.services.locks;import org.apache.derby.impl.services.locks.TableNameInfo;import org.apache.derby.iapi.services.context.ContextService;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.services.locks.Latch;import org.apache.derby.iapi.services.locks.Lockable;import org.apache.derby.iapi.services.locks.VirtualLockTable;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.util.CheapDateFormatter;import java.util.Enumeration;import java.util.Hashtable;/** * Code to support Timeout error output. * @author gavin */public final class Timeout{ public static final int TABLE_AND_ROWLOCK = VirtualLockTable.TABLE_AND_ROWLOCK; public static final int ALL = VirtualLockTable.ALL; public static final String newline = "\n"; //FIXME: The newline might not be truely platform independent. // We do not want to use a system call because of security reasons. // LINE_SEPARATOR returns ^M for some reason, not ^M<nl>. //public static final String newline = String.valueOf( (char)(new Byte(Character.LINE_SEPARATOR)).intValue() ); //public static final String newline = System.getProperty( "line.separator" ); private TransactionController tc; private TableNameInfo tabInfo; /* the current Latch to extract info out of */ private Latch currentLock; /* the current row output of the lockTable */ private char[] outputRow; /* the entire lockTable as a buffer */ private StringBuffer sb; /* the hashtable information of the current lock */ private Hashtable currentRow; /* the time when the exception was thrown */ private final long currentTime; /* the snapshot of the lockTable that timeout */ private final Enumeration lockTable; // column1: XID varchar(10) not null // column2: TYPE varchar(13) not null // column3: MODE varchar(4) not null // column4: LOCKCOUNT varchar(9) not null // column5: LOCKNAME varchar(80) not null // column6: STATE varchar(5) not null // column7: TABLETYPE varchar(38) not null / LOCKOBJ varchar(38) // column8: INDEXNAME varchar(50) nullable as String "NULL" / CONTAINER_ID / MODE (latch only) varchar(50) // column9: TABLENAME varchar(38) not null / CONGLOM_ID varchar(38) // Total length of this string is 10+1+13+1+6+1+9+1+80+1+5+1+38+1+48+1+38=256 private final static String[] column = new String[9]; private final static int LENGTHOFTABLE; static { column[0] = "XID "; column[1] = "TYPE "; column[2] = "MODE"; column[3] = "LOCKCOUNT"; column[4] = "LOCKNAME "; column[5] = "STATE"; column[6] = "TABLETYPE / LOCKOBJ "; column[7] = "INDEXNAME / CONTAINER_ID / (MODE for LATCH only) "; column[8] = "TABLENAME / CONGLOM_ID "; int length = 0; for( int i = 0 ; i < column.length; i++ ) { length += column[i].length(); } length += column.length; // for the separator if( SanityManager.DEBUG ) { // 256 is a good number, can be expanded or contracted if necessary SanityManager.ASSERT( length == 256, "TIMEOUT_MONITOR: length of the row is not 256" ); } LENGTHOFTABLE = length; } private final static char LINE = '-'; private final static char SEPARATOR = '|'; /** * Constructor * @param myTimeoutLock The Latch that the timeout happened on * @param myLockTable * @param time The time when the lockTable was cloned. */ private Timeout( Latch myTimeoutLock, Enumeration myLockTable, long time ) { currentLock = myTimeoutLock; lockTable = myLockTable; currentTime = time; if( SanityManager.DEBUG ) { SanityManager.ASSERT( currentTime > 0, "TIMEOUT_MONITOR: currentTime is not set correctly" ); } } /** * createException creates a StandardException based on: * currentLock * a snapshot of the lockTable * @return StandardException The exception with the lockTable snapshot in it */ private StandardException createException() { try { buildLockTableString(); } catch( StandardException se ) { return se; } StandardException se = StandardException.newException( SQLState.LOCK_TIMEOUT_LOG, sb.toString() ); se.setReport( StandardException.REPORT_ALWAYS ); return se; } /** * buildLockTableString creates a LockTable info String */ private String buildLockTableString() throws StandardException { sb = new StringBuffer(8192); outputRow = new char[ LENGTHOFTABLE ]; int i; // counter // need language here to print out tablenames LanguageConnectionContext lcc = (LanguageConnectionContext) ContextService.getContext(LanguageConnectionContext.CONTEXT_ID); if( lcc != null ) tc = lcc.getTransactionExecute(); try { tabInfo = new TableNameInfo( lcc, true ); } catch (Exception se) { //just don't do anything } sb.append( newline ); sb.append(CheapDateFormatter.formatDate(currentTime)); sb.append( newline ); for( i = 0; i < column.length; i++ ) { sb.append( column[i] ); sb.append( SEPARATOR ); } sb.append( newline ); for( i = 0; i < LENGTHOFTABLE; i++ ) sb.append( LINE ); sb.append( newline ); // get the timeout lock info if( currentLock != null ) { dumpLock( ); if( timeoutInfoHash() ) { sb.append( "*** The following row is the victim ***" ); sb.append( newline ); sb.append( outputRow ); sb.append( newline ); sb.append( "*** The above row is the victim ***" ); sb.append( newline ); } else { sb.append( "*** A victim was chosen, but it cannot be printed because the lockable object, " + currentLock + ", does not want to participate ***" ); sb.append( newline ); } } // get lock info from the rest of the table if( lockTable != null ) { while( lockTable.hasMoreElements() ) { currentLock = (Latch)lockTable.nextElement(); dumpLock( ); if( timeoutInfoHash() ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -