From cbee5a60443ed4c6f76e6a4ec6cf746ef0272c11 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Wed, 29 Jun 2011 11:49:50 -0700 Subject: [PATCH] bug 10322: arrival of the next generation Merovingians --- .../src/com/cloud/cluster/ClusterManagerImpl.java | 9 +++++++-- setup/db/create-schema.sql | 3 ++- utils/src/com/cloud/utils/db/GenericDaoBase.java | 14 +++++++------- utils/src/com/cloud/utils/db/Transaction.java | 9 +++------ .../src/com/cloud/utils/time/InaccurateClock.java | 1 + 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/server/src/com/cloud/cluster/ClusterManagerImpl.java b/server/src/com/cloud/cluster/ClusterManagerImpl.java index abbdc23e1cc..9f77b1f8d84 100644 --- a/server/src/com/cloud/cluster/ClusterManagerImpl.java +++ b/server/src/com/cloud/cluster/ClusterManagerImpl.java @@ -69,6 +69,7 @@ import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.Inject; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.DB; +import com.cloud.utils.db.Merovingian2; import com.cloud.utils.db.Transaction; import com.cloud.utils.events.SubscriptionMgr; import com.cloud.utils.exception.CloudRuntimeException; @@ -604,13 +605,14 @@ public class ClusterManagerImpl implements ClusterManager { s_logger.error("Problem with the cluster heartbeat!", e); } } - }; + }; } private boolean isRootCauseConnectionRelated(Throwable e) { while (e != null) { - if (e instanceof com.mysql.jdbc.CommunicationsException || e instanceof com.mysql.jdbc.exceptions.jdbc4.CommunicationsException) + if (e instanceof com.mysql.jdbc.CommunicationsException || e instanceof com.mysql.jdbc.exceptions.jdbc4.CommunicationsException) { return true; + } e = e.getCause(); } @@ -1029,6 +1031,9 @@ public class ClusterManagerImpl implements ClusterManager { _agentLBEnabled = Boolean.valueOf(configDao.getValue(Config.AgentLbEnable.key())); + + Merovingian2 m = Merovingian2.createLockMaster(this._msId); + m.clear(); checkConflicts(); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 9aada203e83..de8132e4212 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -311,7 +311,8 @@ CREATE TABLE `cloud`.`op_lock` ( `thread` varchar(255) NOT NULL COMMENT 'Thread that acquired this lock', `acquired_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Time acquired', `waiters` int NOT NULL DEFAULT 0 COMMENT 'How many have waited for this', - PRIMARY KEY (`key`) + PRIMARY KEY (`key`), + INDEX `i_op_lock__mac_ip_thread`(`mac`, `ip`, `thread`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`configuration` ( diff --git a/utils/src/com/cloud/utils/db/GenericDaoBase.java b/utils/src/com/cloud/utils/db/GenericDaoBase.java index 6daf72b5dba..b1c5fa0dac0 100755 --- a/utils/src/com/cloud/utils/db/GenericDaoBase.java +++ b/utils/src/com/cloud/utils/db/GenericDaoBase.java @@ -1268,7 +1268,7 @@ public abstract class GenericDaoBase implements Gene while (en.hasMoreElements()) { pstmt = txn.prepareAutoCloseStatement(ec.insertSql); if (ec.targetClass == Date.class) { - pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), (Date)en.nextElement())); + pstmt.setString(1, DateUtil.getDateDisplayString(s_gmtTimeZone, (Date)en.nextElement())); } else { pstmt.setObject(1, en.nextElement()); } @@ -1347,11 +1347,11 @@ public abstract class GenericDaoBase implements Gene return; } if (attr.is(Attribute.Flag.Date)) { - pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), date)); + pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, date)); } else if (attr.is(Attribute.Flag.TimeStamp)) { - pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), date)); + pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, date)); } else if (attr.is(Attribute.Flag.Time)) { - pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), date)); + pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, date)); } } else if (attr.field.getType() == Calendar.class) { final Calendar cal = (Calendar)value; @@ -1360,11 +1360,11 @@ public abstract class GenericDaoBase implements Gene return; } if (attr.is(Attribute.Flag.Date)) { - pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cal.getTime())); + pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, cal.getTime())); } else if (attr.is(Attribute.Flag.TimeStamp)) { - pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cal.getTime())); + pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, cal.getTime())); } else if (attr.is(Attribute.Flag.Time)) { - pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cal.getTime())); + pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, cal.getTime())); } } else if (attr.field.getType().isEnum()) { final Enumerated enumerated = attr.field.getAnnotation(Enumerated.class); diff --git a/utils/src/com/cloud/utils/db/Transaction.java b/utils/src/com/cloud/utils/db/Transaction.java index 120c804a398..1b8cc0d0373 100755 --- a/utils/src/com/cloud/utils/db/Transaction.java +++ b/utils/src/com/cloud/utils/db/Transaction.java @@ -201,6 +201,7 @@ public class Transaction { public static Connection getStandaloneConnectionWithException() throws SQLException { Connection conn = s_ds.getConnection(); + conn.setAutoCommit(true); if (s_connLogger.isTraceEnabled()) { s_connLogger.trace("Retrieving a standalone connection: dbconn" + System.identityHashCode(conn)); } @@ -209,13 +210,9 @@ public class Transaction { public static Connection getStandaloneConnection() { try { - Connection conn = s_ds.getConnection(); - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Retrieving a standalone connection: dbconn" + System.identityHashCode(conn)); - } - return conn; + return getStandaloneConnectionWithException(); } catch (SQLException e) { - s_logger.warn("Unexpected exception: ", e); + s_logger.error("Unexpected exception: ", e); return null; } } diff --git a/utils/src/com/cloud/utils/time/InaccurateClock.java b/utils/src/com/cloud/utils/time/InaccurateClock.java index 3e61db3b847..d9b2ad7aca6 100644 --- a/utils/src/com/cloud/utils/time/InaccurateClock.java +++ b/utils/src/com/cloud/utils/time/InaccurateClock.java @@ -24,6 +24,7 @@ package com.cloud.utils.time; public class InaccurateClock extends Thread { static final InaccurateClock s_timer = new InaccurateClock(); static { + time = System.currentTimeMillis(); s_timer.start(); }