use of org.apache.derby.shared.common.error.ShutdownException in project derby by apache.
the class InterruptStatus method setInterrupted.
/**
* Make a note that this thread saw an interrupt. Thread's intr
* status flag is presumably off already, but we reset it here
* also. Use lcc if available, else thread local variable.
*/
public static void setInterrupted() {
LanguageConnectionContext lcc = null;
try {
lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
} catch (ShutdownException e) {
// Ignore. Can happen when: a) background thread (RawStoreDaemon)
// is performing checkpointing and b) a user thread starts shutdown
// and interrupts the background thread. During recovery of the
// container we get here. DERBY-4920.
}
Thread.interrupted();
StandardException e = StandardException.newException(SQLState.CONN_INTERRUPT);
if (lcc != null) {
lcc.setInterruptedException(e);
} else {
exception.set(e);
}
}
use of org.apache.derby.shared.common.error.ShutdownException in project derby by apache.
the class ContextService method getFactory.
public static ContextService getFactory() {
// Verify that we have permission to execute this method.
SecurityUtil.checkDerbyInternalsPrivilege();
ContextService csf = factory;
if (csf == null)
throw new ShutdownException();
return csf;
}
use of org.apache.derby.shared.common.error.ShutdownException in project derby by apache.
the class IndexStatisticsDaemonImpl method processingLoop.
/**
* Main processing loop which will compute statistics until the queue
* of scheduled work units has been drained.
*/
private void processingLoop() {
// If we don't have a connection to the database, create one.
if (daemonLCC == null) {
try {
daemonLCC = db.setupConnection(ctxMgr, dbOwner, null, databaseName);
// Initialize the lcc/transaction.
// TODO: Would be nice to name the transaction.
daemonLCC.setIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED);
// Don't wait for any locks.
daemonLCC.getTransactionExecute().setNoLockWait(true);
} catch (StandardException se) {
log(AS_BACKGROUND_TASK, null, se, "failed to initialize index statistics updater");
return;
}
}
TransactionController tc = null;
try {
tc = daemonLCC.getTransactionExecute();
trace(0, "worker thread started (xid=" + tc.getTransactionIdString() + ")");
TableDescriptor td = null;
long start = 0;
while (true) {
synchronized (queue) {
if (daemonDisabled) {
// Clean the lcc and exit.
try {
tc.destroy();
} catch (ShutdownException se) {
// Ignore
}
tc = null;
daemonLCC = null;
queue.clear();
trace(1, "daemon disabled");
break;
}
if (queue.isEmpty()) {
trace(1, "queue empty");
break;
}
td = queue.get(0);
}
try {
start = System.currentTimeMillis();
generateStatistics(daemonLCC, td);
wuProcessed++;
// Reset consecutive error counter.
errorsConsecutive = 0;
log(AS_BACKGROUND_TASK, td, "generation complete (" + ((System.currentTimeMillis() - start)) + " ms)");
} catch (StandardException se) {
errorsConsecutive++;
// For less severe errors, rollback tx to clean up.
if (!handleFatalErrors(ctxMgr, se)) {
boolean handled = handleExpectedErrors(td, se);
if (!handled) {
handled = handleUnexpectedErrors(td, se);
}
daemonLCC.internalRollback();
if (SanityManager.DEBUG) {
SanityManager.ASSERT(handled);
}
}
} finally {
// Whatever happened, discard the unit of work.
synchronized (queue) {
// Queue may have been cleared due to shutdown.
if (!queue.isEmpty()) {
queue.remove(0);
}
}
// Create an exception to force logging of the message.
if (errorsConsecutive >= 50) {
log(AS_BACKGROUND_TASK, null, new IllegalStateException("degraded state"), "shutting down daemon, " + errorsConsecutive + " consecutive errors seen");
stop();
}
}
}
} catch (StandardException se) {
log(AS_BACKGROUND_TASK, null, se, "thread died");
// Do nothing, just let the thread die.
} finally {
synchronized (queue) {
runningThread = null;
}
if (daemonLCC != null && !daemonLCC.isTransactionPristine()) {
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("transaction not pristine");
}
log(AS_BACKGROUND_TASK, null, "transaction not pristine - forcing rollback");
try {
daemonLCC.internalRollback();
} catch (StandardException se) {
// Log, then continue.
log(AS_BACKGROUND_TASK, null, se, "forced rollback failed");
}
}
}
}
use of org.apache.derby.shared.common.error.ShutdownException in project derby by apache.
the class LogToFile method performWork.
public int performWork(ContextManager context) {
synchronized (this) {
if (corrupt != null)
// don't do this again.
return Serviceable.DONE;
}
// check to see if checkpointInterval and logSwitchInterval has changed
AccessFactory af = (AccessFactory) getServiceModule(this, AccessFactory.MODULE);
try {
if (af != null) {
TransactionController tc = null;
try {
tc = af.getAndNameTransaction(context, AccessFactoryGlobals.SYS_TRANS_NAME);
getLogFactoryProperties(tc);
} finally {
if (tc != null)
tc.commit();
}
}
// checkpoint will start its own internal transaction on the current
// context.
rawStoreFactory.checkpoint();
} catch (StandardException se) {
Monitor.logTextMessage(MessageId.LOG_CHECKPOINT_EXCEPTION);
logErrMsg(se);
} catch (ShutdownException shutdown) {
// If we are shutting down, just ignore the error and let the
// system go down without printing errors to the log.
}
checkpointDaemonCalled = false;
return Serviceable.DONE;
}
use of org.apache.derby.shared.common.error.ShutdownException in project derby by apache.
the class InterruptStatus method restoreIntrFlagIfSeen.
/**
* Same purpose as {@code restoreIntrFlagIfSeen()}. This variant presumes
* we are sure we have a {@code lcc != null}, i.e. {@code
* setupContextStack} has been called and not yet restored. Note that we
* cannot merge this code with {@code restoreContextStack}, since that is
* typically called in a {@code finally} block, at which point in time, the
* {@code lcc} may be gone due to errors of severity {@code
* SESSION_SEVERITY} or {@code DATABASE_SEVERITY}.
* <p/>
* If no {@code lcc} is available, use the zero-arg variant. We only need
* this variant for performance reasons.
*
* @param lcc the language connection context for this session
*/
public static void restoreIntrFlagIfSeen(LanguageConnectionContext lcc) {
if (SanityManager.DEBUG) {
LanguageConnectionContext ctxLcc = null;
try {
ctxLcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
SanityManager.ASSERT(lcc == ctxLcc, "lcc=" + lcc + " getContextOrNull=" + ctxLcc);
} catch (ShutdownException e) {
// ignore
}
}
if (lcc.getInterruptedException() != null) {
lcc.setInterruptedException(null);
// Set thread's interrupt status flag back on.
Thread.currentThread().interrupt();
}
}
Aggregations