/** add session to the end of queue when a transaction starts (depending on isolation mode) */ public void beginAction(Session session, Statement cs) { synchronized (liveTransactionTimestamps) { session.actionTimestamp = nextChangeTimestamp(); if (!session.isTransaction) { session.transactionTimestamp = session.actionTimestamp; session.isTransaction = true; liveTransactionTimestamps.addLast(session.actionTimestamp); } } if (session.hasLocks()) { return; } try { writeLock.lock(); boolean canProceed = beginActionTPL(session, cs); if (!canProceed) { session.abortTransaction = true; } } finally { writeLock.unlock(); } }
public boolean commitTransaction(Session session) { if (session.abortTransaction) { return false; } int limit = session.rowActionList.size(); Object[] list = session.rowActionList.getArray(); writeLock.lock(); try { // new actionTimestamp used for commitTimestamp session.actionTimestamp = nextChangeTimestamp(); session.transactionEndTimestamp = session.actionTimestamp; endTransaction(session); for (int i = 0; i < limit; i++) { RowAction action = (RowAction) list[i]; action.commit(session); } persistCommit(session, list, limit); int newLimit = session.rowActionList.size(); if (newLimit > limit) { list = session.rowActionList.getArray(); mergeTransaction(session, list, limit, newLimit, session.actionTimestamp); finaliseRows(session, list, limit, newLimit, true); session.rowActionList.setSize(limit); } // session.actionTimestamp is the committed tx timestamp if (getFirstLiveTransactionTimestamp() > session.actionTimestamp || session == lobSession) { mergeTransaction(session, list, 0, limit, session.actionTimestamp); finaliseRows(session, list, 0, limit, true); } else { list = session.rowActionList.toArray(); addToCommittedQueue(session, list); } endTransactionTPL(session); } finally { writeLock.unlock(); } session.tempSet.clear(); return true; }
public void beginTransaction(Session session) { synchronized (liveTransactionTimestamps) { session.actionTimestamp = nextChangeTimestamp(); session.transactionTimestamp = session.actionTimestamp; session.isTransaction = true; liveTransactionTimestamps.addLast(session.transactionTimestamp); } }
public void rollback(Session session) { session.abortTransaction = false; session.actionTimestamp = nextChangeTimestamp(); rollbackPartial(session, 0, session.transactionTimestamp); endTransaction(session); try { writeLock.lock(); endTransactionTPL(session); } finally { writeLock.unlock(); } }
public boolean prepareCommitActions(Session session) { Object[] list = session.rowActionList.getArray(); int limit = session.rowActionList.size(); if (session.abortTransaction) { // System.out.println("cascade fail " + session + " " + session.actionTimestamp); return false; } try { writeLock.lock(); for (int i = 0; i < limit; i++) { RowAction rowact = (RowAction) list[i]; if (!rowact.canCommit(session, session.tempSet)) { // System.out.println("commit conflicts " + session + " " + // session.actionTimestamp); return false; } } session.actionTimestamp = nextChangeTimestamp(); for (int i = 0; i < limit; i++) { RowAction action = (RowAction) list[i]; action.prepareCommit(session); } for (int i = 0; i < session.tempSet.size(); i++) { Session current = (Session) session.tempSet.get(i); current.abortTransaction = true; } return true; } finally { writeLock.unlock(); session.tempSet.clear(); } }
public void beginTransaction(Session session) { writeLock.lock(); try { if (!session.isTransaction) { session.actionTimestamp = nextChangeTimestamp(); session.transactionTimestamp = session.actionTimestamp; session.isTransaction = true; transactionCount++; liveTransactionTimestamps.addLast(session.transactionTimestamp); } } finally { writeLock.unlock(); } }
public boolean prepareCommitActions(Session session) { Object[] list = session.rowActionList.getArray(); int limit = session.rowActionList.size(); writeLock.lock(); try { session.actionTimestamp = nextChangeTimestamp(); for (int i = 0; i < limit; i++) { RowAction action = (RowAction) list[i]; action.prepareCommit(session); } return true; } finally { writeLock.unlock(); } }
public boolean commitTransaction(Session session) { if (session.abortTransaction) { return false; } int limit = session.rowActionList.size(); Object[] list = limit == 0 ? ValuePool.emptyObjectArray : session.rowActionList.getArray(); try { writeLock.lock(); endTransaction(session); if (limit == 0) { endTransactionTPL(session); try { session.logSequences(); } catch (HsqlException e) { } return true; } // new actionTimestamp used for commitTimestamp // already set in prepareCommitActions(); session.actionTimestamp = nextChangeTimestamp(); for (int i = 0; i < limit; i++) { RowAction action = (RowAction) list[i]; action.commit(session); } for (int i = 0; i < limit; i++) { RowAction action = (RowAction) list[i]; if (action.type == RowActionBase.ACTION_NONE) { continue; } int type = action.getCommitType(session.actionTimestamp); PersistentStore store = session.sessionData.getRowStore(action.table); Row row = action.memoryRow; if (row == null) { row = (Row) store.get(action.getPos(), false); } if (action.table.hasLobColumn) { switch (type) { case RowActionBase.ACTION_INSERT: session.sessionData.addLobUsageCount(action.table, row.getData()); break; default: } } if (action.table.tableType == TableBase.TEXT_TABLE) { switch (type) { case RowActionBase.ACTION_DELETE: store.removePersistence(action.getPos()); break; case RowActionBase.ACTION_INSERT: store.commitPersistence(row); break; default: } } } // session.actionTimestamp is the committed tx timestamp if (getFirstLiveTransactionTimestamp() > session.actionTimestamp) { mergeTransaction(session, list, 0, limit, session.actionTimestamp); rowActionMapRemoveTransaction(list, 0, limit, true); } else { list = session.rowActionList.toArray(); addToCommittedQueue(session, list); } try { session.logSequences(); database.logger.writeCommitStatement(session); } catch (HsqlException e) { } endTransactionTPL(session); return true; } finally { writeLock.unlock(); session.tempSet.clear(); } }