mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 10:32:34 +01:00
Manage left-over objects across management server sessions
This commit is contained in:
parent
ec98a539b4
commit
c51e68a2d5
@ -66,6 +66,11 @@ public class StackMaid {
|
|||||||
pop(msid_setby_manager, savePoint);
|
pop(msid_setby_manager, savePoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pop() {
|
||||||
|
if(currentSeq > 0)
|
||||||
|
pop(currentSeq -1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* must be called within thread context
|
* must be called within thread context
|
||||||
* @param currentMsid
|
* @param currentMsid
|
||||||
@ -78,12 +83,6 @@ public class StackMaid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void exitCleanup() {
|
public void exitCleanup() {
|
||||||
/*
|
|
||||||
assert(msid_setby_manager != 0) : "Fatal, make sure StackMaidManager is loaded";
|
|
||||||
if(msid_setby_manager == 0)
|
|
||||||
s_logger.error("Fatal, make sure StackMaidManager is loaded");
|
|
||||||
*/
|
|
||||||
|
|
||||||
exitCleanup(msid_setby_manager);
|
exitCleanup(msid_setby_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -76,7 +76,7 @@ public class StackMaidManagerImpl implements StackMaidManager {
|
|||||||
|
|
||||||
public void reallyRun() {
|
public void reallyRun() {
|
||||||
try {
|
try {
|
||||||
Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - 3600000);
|
Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - 7200000);
|
||||||
List<StackMaidVO> l = _maidDao.listLeftoversByCutTime(cutTime);
|
List<StackMaidVO> l = _maidDao.listLeftoversByCutTime(cutTime);
|
||||||
cleanupLeftovers(l);
|
cleanupLeftovers(l);
|
||||||
} catch(Throwable e) {
|
} catch(Throwable e) {
|
||||||
|
|||||||
@ -40,39 +40,55 @@ public class StackMaidDaoImpl extends GenericDaoBase<StackMaidVO, Long> implemen
|
|||||||
|
|
||||||
@DB
|
@DB
|
||||||
public void pushCleanupDelegate(long msid, int seq, String delegateClzName, Object context) {
|
public void pushCleanupDelegate(long msid, int seq, String delegateClzName, Object context) {
|
||||||
StackMaidVO delegateItem = new StackMaidVO();
|
|
||||||
delegateItem.setMsid(msid);
|
|
||||||
delegateItem.setThreadId(Thread.currentThread().getId());
|
|
||||||
delegateItem.setSeq(seq);
|
|
||||||
delegateItem.setDelegate(delegateClzName);
|
|
||||||
delegateItem.setContext(SerializerHelper.toSerializedStringOld(context));
|
|
||||||
delegateItem.setCreated(DateUtil.currentGMTTime());
|
|
||||||
|
|
||||||
super.persist(delegateItem);
|
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||||
|
try {
|
||||||
|
StackMaidVO delegateItem = new StackMaidVO();
|
||||||
|
delegateItem.setMsid(msid);
|
||||||
|
delegateItem.setThreadId(Thread.currentThread().getId());
|
||||||
|
delegateItem.setSeq(seq);
|
||||||
|
delegateItem.setDelegate(delegateClzName);
|
||||||
|
delegateItem.setContext(SerializerHelper.toSerializedStringOld(context));
|
||||||
|
delegateItem.setCreated(DateUtil.currentGMTTime());
|
||||||
|
|
||||||
|
super.persist(delegateItem);
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DB
|
@DB
|
||||||
public StackMaidVO popCleanupDelegate(long msid) {
|
public StackMaidVO popCleanupDelegate(long msid) {
|
||||||
SearchCriteria<StackMaidVO> sc = popSearch.create();
|
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||||
sc.setParameters("msid", msid);
|
try {
|
||||||
sc.setParameters("threadId", Thread.currentThread().getId());
|
SearchCriteria<StackMaidVO> sc = popSearch.create();
|
||||||
|
sc.setParameters("msid", msid);
|
||||||
|
sc.setParameters("threadId", Thread.currentThread().getId());
|
||||||
|
|
||||||
Filter filter = new Filter(StackMaidVO.class, "seq", false, 0L, (long)1);
|
Filter filter = new Filter(StackMaidVO.class, "seq", false, 0L, (long)1);
|
||||||
List<StackMaidVO> l = listIncludingRemovedBy(sc, filter);
|
List<StackMaidVO> l = listIncludingRemovedBy(sc, filter);
|
||||||
if(l != null && l.size() > 0) {
|
if(l != null && l.size() > 0) {
|
||||||
expunge(l.get(0).getId());
|
expunge(l.get(0).getId());
|
||||||
return l.get(0);
|
return l.get(0);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DB
|
@DB
|
||||||
public void clearStack(long msid) {
|
public void clearStack(long msid) {
|
||||||
SearchCriteria<StackMaidVO> sc = clearSearch.create();
|
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||||
sc.setParameters("msid", msid);
|
try {
|
||||||
|
SearchCriteria<StackMaidVO> sc = clearSearch.create();
|
||||||
|
sc.setParameters("msid", msid);
|
||||||
|
|
||||||
expunge(sc);
|
expunge(sc);
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DB
|
@DB
|
||||||
@ -80,7 +96,7 @@ public class StackMaidDaoImpl extends GenericDaoBase<StackMaidVO, Long> implemen
|
|||||||
List<StackMaidVO> l = new ArrayList<StackMaidVO>();
|
List<StackMaidVO> l = new ArrayList<StackMaidVO>();
|
||||||
String sql = "select * from stack_maid where msid=? order by msid asc, thread_id asc, seq desc";
|
String sql = "select * from stack_maid where msid=? order by msid asc, thread_id asc, seq desc";
|
||||||
|
|
||||||
Transaction txn = Transaction.currentTxn();;
|
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
try {
|
try {
|
||||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||||
@ -94,6 +110,8 @@ public class StackMaidDaoImpl extends GenericDaoBase<StackMaidVO, Long> implemen
|
|||||||
s_logger.error("unexcpected exception " + e.getMessage(), e);
|
s_logger.error("unexcpected exception " + e.getMessage(), e);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
s_logger.error("unexcpected exception " + e.getMessage(), e);
|
s_logger.error("unexcpected exception " + e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
@ -104,7 +122,7 @@ public class StackMaidDaoImpl extends GenericDaoBase<StackMaidVO, Long> implemen
|
|||||||
List<StackMaidVO> l = new ArrayList<StackMaidVO>();
|
List<StackMaidVO> l = new ArrayList<StackMaidVO>();
|
||||||
String sql = "select * from stack_maid where created < ? order by msid asc, thread_id asc, seq desc";
|
String sql = "select * from stack_maid where created < ? order by msid asc, thread_id asc, seq desc";
|
||||||
|
|
||||||
Transaction txn = Transaction.currentTxn();;
|
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
try {
|
try {
|
||||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||||
@ -119,6 +137,8 @@ public class StackMaidDaoImpl extends GenericDaoBase<StackMaidVO, Long> implemen
|
|||||||
s_logger.error("unexcpected exception " + e.getMessage(), e);
|
s_logger.error("unexcpected exception " + e.getMessage(), e);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
s_logger.error("unexcpected exception " + e.getMessage(), e);
|
s_logger.error("unexcpected exception " + e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,7 +88,9 @@ public class Transaction {
|
|||||||
public static Transaction currentTxn() {
|
public static Transaction currentTxn() {
|
||||||
Transaction txn = tls.get();
|
Transaction txn = tls.get();
|
||||||
assert txn != null : "No Transaction on stack. Did you mark the method with @DB?";
|
assert txn != null : "No Transaction on stack. Did you mark the method with @DB?";
|
||||||
assert checkAnnotation(3, txn) : "Did you even read the guide to use Transaction...IOW...other people's code? Try method can't be private. What about @DB? hmmm... could that be it? " + txn.toString();
|
|
||||||
|
// loosen the requirement to let people use explicit transaction management (i.e., in Unit tests)
|
||||||
|
// assert checkAnnotation(3, txn) : "Did you even read the guide to use Transaction...IOW...other people's code? Try method can't be private. What about @DB? hmmm... could that be it? " + txn.toString();
|
||||||
return txn;
|
return txn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user