From a58d730e345b79ec6179db15d978e1772a3b8634 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 20 Jun 2011 11:30:14 -0700 Subject: [PATCH] bug 10368: Print out the hash code of the db connection instead of the toString(). Changed the transaction in changeToStart() method to be of a shorter interval so it won't cause so many db connection exceptions --- .../cloud/vm/VirtualMachineManagerImpl.java | 78 +++++++++---------- utils/src/com/cloud/utils/db/Transaction.java | 10 +-- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index d9d4abb80a1..ba3aaca7d6b 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -500,56 +500,54 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene Transaction txn = Transaction.currentTxn(); txn.start(); try { - try { - if (stateTransitTo(vm, Event.StartRequested, null, work.getId())) { + if (stateTransitTo(vm, Event.StartRequested, null, work.getId())) { - Journal journal = new Journal.LogJournal("Creating " + vm, s_logger); - work = _workDao.persist(work); - ReservationContextImpl context = new ReservationContextImpl(work.getId(), journal, caller, account); + Journal journal = new Journal.LogJournal("Creating " + vm, s_logger); + work = _workDao.persist(work); + ReservationContextImpl context = new ReservationContextImpl(work.getId(), journal, caller, account); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully transitioned to start state for " + vm + " reservation id = " + work.getId()); - } - return new Ternary(vmGuru.findById(vmId), context, work); - } - } catch (NoTransitionException e) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to transition into Starting state due to " + e.getMessage()); + s_logger.debug("Successfully transitioned to start state for " + vm + " reservation id = " + work.getId()); } + return new Ternary(vmGuru.findById(vmId), context, work); } - + } catch (NoTransitionException e) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Determining why we're unable to update the state to Starting for " + vm); - } - - VMInstanceVO instance = _vmDao.findById(vmId); - if (instance == null) { - throw new ConcurrentOperationException("Unable to acquire lock on " + vm); - } - - State state = instance.getState(); - if (state == State.Running) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("VM is already started: " + vm); - } - return null; - } - - if (state.isTransitional()) { - if (!checkWorkItems(vm, state)) { - throw new ConcurrentOperationException("There are concurrent operations on the VM " + vm); - } else { - continue; - } - } - - if (state != State.Stopped) { - s_logger.debug("VM " + vm + " is not in a state to be started: " + state); - return null; + s_logger.debug("Unable to transition into Starting state due to " + e.getMessage()); } } finally { txn.commit(); } + + VMInstanceVO instance = _vmDao.findById(vmId); + if (instance == null) { + throw new ConcurrentOperationException("Unable to acquire lock on " + vm); + } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Determining why we're unable to update the state to Starting for " + instance + ". Retry=" + retry); + } + + State state = instance.getState(); + if (state == State.Running) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("VM is already started: " + vm); + } + return null; + } + + if (state.isTransitional()) { + if (!checkWorkItems(vm, state)) { + throw new ConcurrentOperationException("There are concurrent operations on " + vm); + } else { + continue; + } + } + + if (state != State.Stopped) { + s_logger.debug("VM " + vm + " is not in a state to be started: " + state); + return null; + } } throw new ConcurrentOperationException("Unable to change the state of " + vm); diff --git a/utils/src/com/cloud/utils/db/Transaction.java b/utils/src/com/cloud/utils/db/Transaction.java index 714bdf94b43..b7131abbdc1 100755 --- a/utils/src/com/cloud/utils/db/Transaction.java +++ b/utils/src/com/cloud/utils/db/Transaction.java @@ -175,7 +175,7 @@ public class Transaction { public static Connection getStandaloneConnectionWithException() throws SQLException { Connection conn = s_ds.getConnection(); if (s_connLogger.isTraceEnabled()) { - s_logger.trace("Retrieving a standalone connection: " + conn); + s_logger.trace("Retrieving a standalone connection: dbconn" + System.identityHashCode(conn)); } return conn; } @@ -184,7 +184,7 @@ public class Transaction { try { Connection conn = s_ds.getConnection(); if (s_connLogger.isTraceEnabled()) { - s_logger.trace("Retrieving a standalone connection: " + conn); + s_logger.trace("Retrieving a standalone connection: dbconn" + System.identityHashCode(conn)); } return conn; } catch (SQLException e) { @@ -197,7 +197,7 @@ public class Transaction { try { Connection conn = s_usageDS.getConnection(); if (s_connLogger.isTraceEnabled()) { - s_logger.trace("Retrieving a standalone connection for usage: " + conn); + s_logger.trace("Retrieving a standalone connection for usage: dbconn" + System.identityHashCode(conn)); } return conn; } catch (SQLException e) { @@ -496,7 +496,7 @@ public class Transaction { _conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); _stack.push(new StackElement(CREATE_CONN, null)); if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Creating a DB connection with " + (_txn ? " txn: " : " no txn: ") + " for " + _dbId + ": " + _conn + buildName()); + s_connLogger.trace("Creating a DB connection with " + (_txn ? " txn: " : " no txn: ") + " for " + _dbId + ": dbconn" + System.identityHashCode(_conn) + ". Stack: " + buildName()); } } else { s_logger.trace("conn: Using existing DB connection"); @@ -665,7 +665,7 @@ public class Transaction { try { if (s_connLogger.isTraceEnabled()) { - s_logger.trace("Closing DB connection: " + _conn); + s_logger.trace("Closing DB connection: dbconn" + System.identityHashCode(_conn)); } if(this._dbId != CONNECTED_DB) { _conn.close();