bug 10322: Transaction is using the new Merovingian

This commit is contained in:
Alex Huang 2011-06-29 15:15:52 -07:00
parent 7a4af21f72
commit 43252dd4de
2 changed files with 22 additions and 5 deletions

View File

@ -94,6 +94,7 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean {
Connection conn = null;
try {
conn = Transaction.getStandaloneConnectionWithException();
conn.setAutoCommit(true);
while ((InaccurateClock.getTime() - startTime) < (timeInSeconds * 1000)) {
int count = owns(conn, key);
if (count == -1) {
@ -227,6 +228,7 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean {
Connection conn = null;
try {
conn = Transaction.getStandaloneConnectionWithException();
conn.setAutoCommit(true);
cleanup(conn, msId);
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to clear the locks", e);
@ -244,6 +246,7 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean {
PreparedStatement pstmt = null;
try {
conn = Transaction.getStandaloneConnectionWithException();
conn.setAutoCommit(true);
pstmt = conn.prepareStatement(CLEANUP_MGMT_LOCKS_SQL);
pstmt.setLong(1, _msId);
pstmt.executeUpdate();
@ -267,6 +270,7 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean {
int threadId = System.identityHashCode(th);
try {
conn = Transaction.getStandaloneConnectionWithException();
conn.setAutoCommit(true);
pstmt = conn.prepareStatement(DECREMENT_SQL);
pstmt.setString(1, key);
pstmt.setLong(2, _msId);
@ -330,6 +334,7 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean {
ResultSet rs = null;
try {
conn = Transaction.getStandaloneConnectionWithException();
conn.setAutoCommit(true);
pstmt = conn.prepareStatement(sql);
if (msId != null) {
pstmt.setLong(1, msId);
@ -381,6 +386,7 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean {
Connection conn = null;
try {
conn = Transaction.getStandaloneConnectionWithException();
conn.setAutoCommit(true);
return owns(conn, key);
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to retrieve locks ", e);
@ -400,6 +406,7 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean {
ResultSet rs = null;
try {
conn = Transaction.getStandaloneConnectionWithException();
conn.setAutoCommit(true);
pstmt = conn.prepareStatement(SELECT_THREAD_LOCKS_SQL);
pstmt.setLong(1, msId);
pstmt.setString(2, threadName);
@ -432,6 +439,7 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean {
PreparedStatement pstmt = null;
try {
conn = Transaction.getStandaloneConnectionWithException();
conn.setAutoCommit(true);
pstmt = conn.prepareStatement(CLEANUP_THREAD_LOCKS_SQL);
pstmt.setLong(1, _msId);
pstmt.setString(2, threadName);

View File

@ -79,7 +79,6 @@ public class Transaction {
public static final short USAGE_DB = 1;
public static final short CONNECTED_DB = -1;
private static final Merovingian2 s_lockMaster = Merovingian2.getLockMaster();
private static AtomicLong s_id = new AtomicLong();
private static final TransactionMBeanImpl s_mbean = new TransactionMBeanImpl();
static {
@ -197,7 +196,6 @@ 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));
}
@ -342,11 +340,19 @@ public class Transaction {
}
public boolean lock(final String name, final int timeoutSeconds) {
return s_lockMaster.acquire(name, timeoutSeconds);
Merovingian2 lockMaster = Merovingian2.getLockMaster();
if (lockMaster == null) {
throw new CloudRuntimeException("There's no support for locking yet");
}
return lockMaster.acquire(name, timeoutSeconds);
}
public boolean release(final String name) {
return s_lockMaster.release(name);
Merovingian2 lockMaster = Merovingian2.getLockMaster();
if (lockMaster == null) {
throw new CloudRuntimeException("There's no support for locking yet");
}
return lockMaster.release(name);
}
public void start() {
@ -588,7 +594,10 @@ public class Transaction {
closeConnection();
_stack.clear();
s_lockMaster.cleanupThread();
Merovingian2 lockMaster = Merovingian2.getLockMaster();
if (lockMaster != null) {
lockMaster.cleanupThread();
}
}
public void close() {