提交 2bc448b8 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Create UndoLog only when necessary

上级 9f4ea2c5
...@@ -85,7 +85,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -85,7 +85,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
private final User user; private final User user;
private final int id; private final int id;
private final ArrayList<Table> locks = Utils.newSmallArrayList(); private final ArrayList<Table> locks = Utils.newSmallArrayList();
private final UndoLog undoLog; private UndoLog undoLog;
private boolean autoCommit = true; private boolean autoCommit = true;
private Random random; private Random random;
private int lockTimeout; private int lockTimeout;
...@@ -168,7 +168,6 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -168,7 +168,6 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
this.database = database; this.database = database;
this.queryTimeout = database.getSettings().maxQueryTimeout; this.queryTimeout = database.getSettings().maxQueryTimeout;
this.queryCacheSize = database.getSettings().queryCacheSize; this.queryCacheSize = database.getSettings().queryCacheSize;
this.undoLog = new UndoLog(this);
this.user = user; this.user = user;
this.id = id; this.id = id;
this.lockTimeout = database.getLockTimeout(); this.lockTimeout = database.getLockTimeout();
...@@ -691,7 +690,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -691,7 +690,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
database.commit(this); database.commit(this);
} }
removeTemporaryLobs(true); removeTemporaryLobs(true);
if (undoLog.size() > 0) { if (undoLog != null && undoLog.size() > 0) {
undoLog.clear(); undoLog.clear();
} }
if (!ddl) { if (!ddl) {
...@@ -761,7 +760,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -761,7 +760,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
checkCommitRollback(); checkCommitRollback();
currentTransactionName = null; currentTransactionName = null;
transactionStart = null; transactionStart = null;
boolean needCommit = undoLog.size() > 0 || transaction != null; boolean needCommit = undoLog != null && undoLog.size() > 0 || transaction != null;
if(needCommit) { if(needCommit) {
rollbackTo(null, false); rollbackTo(null, false);
} }
...@@ -784,10 +783,12 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -784,10 +783,12 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
*/ */
public void rollbackTo(Savepoint savepoint, boolean trimToSize) { public void rollbackTo(Savepoint savepoint, boolean trimToSize) {
int index = savepoint == null ? 0 : savepoint.logIndex; int index = savepoint == null ? 0 : savepoint.logIndex;
while (undoLog.size() > index) { if (undoLog != null) {
UndoLogRecord entry = undoLog.getLast(); while (undoLog.size() > index) {
entry.undo(this); UndoLogRecord entry = undoLog.getLast();
undoLog.removeLast(trimToSize); entry.undo(this);
undoLog.removeLast(trimToSize);
}
} }
if (transaction != null) { if (transaction != null) {
if (savepoint == null) { if (savepoint == null) {
...@@ -818,7 +819,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -818,7 +819,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
@Override @Override
public boolean hasPendingTransaction() { public boolean hasPendingTransaction() {
return undoLog.size() > 0; return undoLog != null && undoLog.size() > 0;
} }
/** /**
...@@ -828,7 +829,9 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -828,7 +829,9 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
*/ */
public Savepoint setSavepoint() { public Savepoint setSavepoint() {
Savepoint sp = new Savepoint(); Savepoint sp = new Savepoint();
sp.logIndex = undoLog.size(); if (undoLog != null) {
sp.logIndex = undoLog.size();
}
if (database.getMvStore() != null) { if (database.getMvStore() != null) {
sp.transactionSavepoint = getStatementSavepoint(); sp.transactionSavepoint = getStatementSavepoint();
} }
...@@ -856,7 +859,9 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -856,7 +859,9 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
removeTemporaryLobs(false); removeTemporaryLobs(false);
cleanTempTables(true); cleanTempTables(true);
undoLog.clear(); if (undoLog != null) {
undoLog.clear();
}
// Table#removeChildrenAndResources can take the meta lock, // Table#removeChildrenAndResources can take the meta lock,
// and we need to unlock before we call removeSession(), which might // and we need to unlock before we call removeSession(), which might
// want to take the meta lock using the system session. // want to take the meta lock using the system session.
...@@ -910,6 +915,9 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -910,6 +915,9 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
} }
} }
} }
if (undoLog == null) {
undoLog = new UndoLog(this);
}
undoLog.add(log); undoLog.add(log);
} }
} }
...@@ -942,7 +950,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -942,7 +950,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
private void unlockAll() { private void unlockAll() {
if (SysProperties.CHECK) { if (SysProperties.CHECK) {
if (undoLog.size() > 0) { if (undoLog != null && undoLog.size() > 0) {
DbException.throwInternalError(); DbException.throwInternalError();
} }
} }
...@@ -1086,7 +1094,9 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -1086,7 +1094,9 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
savepoints = database.newStringMap(); savepoints = database.newStringMap();
} }
Savepoint sp = new Savepoint(); Savepoint sp = new Savepoint();
sp.logIndex = undoLog.size(); if (undoLog != null) {
sp.logIndex = undoLog.size();
}
if (database.getMvStore() != null) { if (database.getMvStore() != null) {
sp.transactionSavepoint = getStatementSavepoint(); sp.transactionSavepoint = getStatementSavepoint();
} }
...@@ -1619,7 +1629,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -1619,7 +1629,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
if (!database.isPersistent()) { if (!database.isPersistent()) {
return ValueNull.INSTANCE; return ValueNull.INSTANCE;
} }
if (undoLog.size() == 0) { if (undoLog == null || undoLog.size() == 0) {
return ValueNull.INSTANCE; return ValueNull.INSTANCE;
} }
return ValueString.get(firstUncommittedLog + "-" + firstUncommittedPos + return ValueString.get(firstUncommittedLog + "-" + firstUncommittedPos +
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论