From a813baed49e50c014fa22df81fc6bc8bc9095213 Mon Sep 17 00:00:00 2001 From: Abhinandan Prateek Date: Wed, 17 Aug 2016 16:15:15 +0530 Subject: [PATCH] CLOUDSTACK-9460: For long running transactions, if the connection is timed out by the mysql server then refresh it --- .../db/src/com/cloud/utils/db/TransactionLegacy.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/framework/db/src/com/cloud/utils/db/TransactionLegacy.java b/framework/db/src/com/cloud/utils/db/TransactionLegacy.java index af834ca115e..8f71e87a245 100644 --- a/framework/db/src/com/cloud/utils/db/TransactionLegacy.java +++ b/framework/db/src/com/cloud/utils/db/TransactionLegacy.java @@ -168,7 +168,7 @@ public class TransactionLegacy implements Closeable { isNew = true; } } - + txn.checkConnection(); txn.takeOver(name, false); if (isNew) { s_mbean.addTransaction(txn); @@ -176,6 +176,16 @@ public class TransactionLegacy implements Closeable { return txn; } + public void checkConnection() { + try { + if (_conn != null && !_conn.isValid(3)) { + _conn = null; + } + } catch (SQLException e) { + _conn = null; + } + } + protected StackElement peekInStack(Object obj) { final Iterator it = _stack.iterator(); while (it.hasNext()) {