Skip to content

Commit

Permalink
beginTransaction时保存对session的引用
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Jan 14, 2015
1 parent 4683dea commit c36ed7c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
Expand Up @@ -773,7 +773,7 @@ public void checkRename() {
@Override
public LocalTransaction getTransaction(Session session) {
if (session.getTransaction() == null) {
LocalTransaction t = store.begin();
LocalTransaction t = store.beginTransaction(session);
session.setTransaction(t);
t.setSession(session);
return t;
Expand Down
Expand Up @@ -248,7 +248,7 @@ public void initTransactions() {
*
* @param objectIds the ids of the objects to keep
*/
public void removeTemporaryMaps(BitField objectIds) {
public void removeTemporaryMaps(Session session, BitField objectIds) {
for (String mapName : store.getMapNames()) {
if (mapName.startsWith("temp.")) {
MVMap<?, ?> map = store.openMap(mapName);
Expand All @@ -258,7 +258,7 @@ public void removeTemporaryMaps(BitField objectIds) {
if (!objectIds.get(id)) {
ValueDataType keyType = new ValueDataType(null, null, null);
ValueDataType valueType = new ValueDataType(null, null, null);
LocalTransaction t = transactionStore.begin();
LocalTransaction t = transactionStore.beginTransaction(session);
TransactionMap<?, ?> m = t.openMap(mapName, keyType, valueType);
transactionStore.removeMap(m);
t.commit();
Expand Down
Expand Up @@ -69,11 +69,7 @@ public class LocalTransaction extends TransactionBase {
}

LocalTransaction(Session session, TransactionStore store, int transactionId, int status, String name, long logId) {
this.store = store;
this.transactionId = transactionId;
this.status = status;
this.name = name;
this.logId = logId;
this(store, transactionId, status, name, logId);
this.session = session;
}

Expand Down
Expand Up @@ -17,7 +17,6 @@
import org.lealone.mvstore.MVStore;
import org.lealone.mvstore.type.DataType;
import org.lealone.mvstore.type.ObjectDataType;
import org.lealone.transaction.TransactionInterface;
import org.lealone.util.New;

/**
Expand Down Expand Up @@ -224,7 +223,8 @@ public synchronized void close() {
*
* @return the transaction
*/
public synchronized LocalTransaction begin() {
@Override
public synchronized LocalTransaction beginTransaction(Session session) {
if (!init) {
throw DataUtils.newIllegalStateException(DataUtils.ERROR_TRANSACTION_ILLEGAL_STATE, "Not initialized");
}
Expand All @@ -233,7 +233,7 @@ public synchronized LocalTransaction begin() {
lastTransactionId = 0;
}
int status = LocalTransaction.STATUS_OPEN;
return new LocalTransaction(this, transactionId, status, null, 0);
return new LocalTransaction(session, this, transactionId, status, null, 0);
}

/**
Expand Down Expand Up @@ -561,17 +561,4 @@ synchronized void commitTransactionStatusTable(LocalTransaction t, String allLoc
Object[] v = { allLocalTransactionNames, ++lastTransactionId };
transactionStatusTable.put(t.getId(), v);
}

@Override
public synchronized TransactionInterface beginTransaction(Session session) {
if (!init) {
throw DataUtils.newIllegalStateException(DataUtils.ERROR_TRANSACTION_ILLEGAL_STATE, "Not initialized");
}
int transactionId = ++lastTransactionId;
if (lastTransactionId >= maxTransactionId) {
lastTransactionId = 0;
}
int status = LocalTransaction.STATUS_OPEN;
return new LocalTransaction(session, this, transactionId, status, null, 0);
}
}

0 comments on commit c36ed7c

Please sign in to comment.