Skip to content

Commit 27809e6

Browse files
author
Alex Huang
committed
bug 10322: arrival of the next generation Merovingians
1 parent e10020e commit 27809e6

5 files changed

Lines changed: 20 additions & 16 deletions

File tree

server/src/com/cloud/cluster/ClusterManagerImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.cloud.utils.component.Inject;
7070
import com.cloud.utils.concurrency.NamedThreadFactory;
7171
import com.cloud.utils.db.DB;
72+
import com.cloud.utils.db.Merovingian2;
7273
import com.cloud.utils.db.Transaction;
7374
import com.cloud.utils.events.SubscriptionMgr;
7475
import com.cloud.utils.exception.CloudRuntimeException;
@@ -604,13 +605,14 @@ public void run() {
604605
s_logger.error("Problem with the cluster heartbeat!", e);
605606
}
606607
}
607-
};
608+
};
608609
}
609610

610611
private boolean isRootCauseConnectionRelated(Throwable e) {
611612
while (e != null) {
612-
if (e instanceof com.mysql.jdbc.CommunicationsException || e instanceof com.mysql.jdbc.exceptions.jdbc4.CommunicationsException)
613+
if (e instanceof com.mysql.jdbc.CommunicationsException || e instanceof com.mysql.jdbc.exceptions.jdbc4.CommunicationsException) {
613614
return true;
615+
}
614616

615617
e = e.getCause();
616618
}
@@ -1029,6 +1031,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
10291031

10301032

10311033
_agentLBEnabled = Boolean.valueOf(configDao.getValue(Config.AgentLbEnable.key()));
1034+
1035+
Merovingian2 m = Merovingian2.createLockMaster(this._msId);
1036+
m.clear();
10321037

10331038
checkConflicts();
10341039

setup/db/create-schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ CREATE TABLE `cloud`.`op_lock` (
312312
`thread` varchar(255) NOT NULL COMMENT 'Thread that acquired this lock',
313313
`acquired_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Time acquired',
314314
`waiters` int NOT NULL DEFAULT 0 COMMENT 'How many have waited for this',
315-
PRIMARY KEY (`key`)
315+
PRIMARY KEY (`key`),
316+
INDEX `i_op_lock__mac_ip_thread`(`mac`, `ip`, `thread`)
316317
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
317318

318319
CREATE TABLE `cloud`.`configuration` (

utils/src/com/cloud/utils/db/GenericDaoBase.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ protected void insertElementCollection(T entity, Attribute idAttribute, ID id, M
12681268
while (en.hasMoreElements()) {
12691269
pstmt = txn.prepareAutoCloseStatement(ec.insertSql);
12701270
if (ec.targetClass == Date.class) {
1271-
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), (Date)en.nextElement()));
1271+
pstmt.setString(1, DateUtil.getDateDisplayString(s_gmtTimeZone, (Date)en.nextElement()));
12721272
} else {
12731273
pstmt.setObject(1, en.nextElement());
12741274
}
@@ -1347,11 +1347,11 @@ protected void prepareAttribute(final int j, final PreparedStatement pstmt, fina
13471347
return;
13481348
}
13491349
if (attr.is(Attribute.Flag.Date)) {
1350-
pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), date));
1350+
pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, date));
13511351
} else if (attr.is(Attribute.Flag.TimeStamp)) {
1352-
pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), date));
1352+
pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, date));
13531353
} else if (attr.is(Attribute.Flag.Time)) {
1354-
pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), date));
1354+
pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, date));
13551355
}
13561356
} else if (attr.field.getType() == Calendar.class) {
13571357
final Calendar cal = (Calendar)value;
@@ -1360,11 +1360,11 @@ protected void prepareAttribute(final int j, final PreparedStatement pstmt, fina
13601360
return;
13611361
}
13621362
if (attr.is(Attribute.Flag.Date)) {
1363-
pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cal.getTime()));
1363+
pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, cal.getTime()));
13641364
} else if (attr.is(Attribute.Flag.TimeStamp)) {
1365-
pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cal.getTime()));
1365+
pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, cal.getTime()));
13661366
} else if (attr.is(Attribute.Flag.Time)) {
1367-
pstmt.setString(j, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cal.getTime()));
1367+
pstmt.setString(j, DateUtil.getDateDisplayString(s_gmtTimeZone, cal.getTime()));
13681368
}
13691369
} else if (attr.field.getType().isEnum()) {
13701370
final Enumerated enumerated = attr.field.getAnnotation(Enumerated.class);

utils/src/com/cloud/utils/db/Transaction.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public boolean dbTxnStarted() {
201201

202202
public static Connection getStandaloneConnectionWithException() throws SQLException {
203203
Connection conn = s_ds.getConnection();
204+
conn.setAutoCommit(true);
204205
if (s_connLogger.isTraceEnabled()) {
205206
s_connLogger.trace("Retrieving a standalone connection: dbconn" + System.identityHashCode(conn));
206207
}
@@ -209,13 +210,9 @@ public static Connection getStandaloneConnectionWithException() throws SQLExcept
209210

210211
public static Connection getStandaloneConnection() {
211212
try {
212-
Connection conn = s_ds.getConnection();
213-
if (s_connLogger.isTraceEnabled()) {
214-
s_connLogger.trace("Retrieving a standalone connection: dbconn" + System.identityHashCode(conn));
215-
}
216-
return conn;
213+
return getStandaloneConnectionWithException();
217214
} catch (SQLException e) {
218-
s_logger.warn("Unexpected exception: ", e);
215+
s_logger.error("Unexpected exception: ", e);
219216
return null;
220217
}
221218
}

utils/src/com/cloud/utils/time/InaccurateClock.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
public class InaccurateClock extends Thread {
2525
static final InaccurateClock s_timer = new InaccurateClock();
2626
static {
27+
time = System.currentTimeMillis();
2728
s_timer.start();
2829
}
2930

0 commit comments

Comments
 (0)