提交 e9400e3b authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Remove MVCC code from PageDataIndex

上级 b02190d5
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
*/ */
package org.h2.index; package org.h2.index;
import java.util.Iterator;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.Row; import org.h2.result.Row;
...@@ -22,7 +21,6 @@ class PageDataCursor implements Cursor { ...@@ -22,7 +21,6 @@ class PageDataCursor implements Cursor {
private Row row; private Row row;
private final boolean multiVersion; private final boolean multiVersion;
private final Session session; private final Session session;
private Iterator<Row> delta;
PageDataCursor(Session session, PageDataLeaf current, int idx, long maxKey, PageDataCursor(Session session, PageDataLeaf current, int idx, long maxKey,
boolean multiVersion) { boolean multiVersion) {
...@@ -31,9 +29,6 @@ class PageDataCursor implements Cursor { ...@@ -31,9 +29,6 @@ class PageDataCursor implements Cursor {
this.maxKey = maxKey; this.maxKey = maxKey;
this.multiVersion = multiVersion; this.multiVersion = multiVersion;
this.session = session; this.session = session;
if (multiVersion) {
delta = current.index.getDelta();
}
} }
@Override @Override
...@@ -53,22 +48,10 @@ class PageDataCursor implements Cursor { ...@@ -53,22 +48,10 @@ class PageDataCursor implements Cursor {
return checkMax(); return checkMax();
} }
while (true) { while (true) {
if (delta != null) { nextRow();
if (!delta.hasNext()) { if (row != null && row.getSessionId() != 0 &&
delta = null; row.getSessionId() != session.getId()) {
row = null; continue;
continue;
}
row = delta.next();
if (!row.isDeleted() || row.getSessionId() == session.getId()) {
continue;
}
} else {
nextRow();
if (row != null && row.getSessionId() != 0 &&
row.getSessionId() != session.getId()) {
continue;
}
} }
break; break;
} }
......
...@@ -5,16 +5,11 @@ ...@@ -5,16 +5,11 @@
*/ */
package org.h2.index; package org.h2.index;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.dml.AllColumnsForPlan; import org.h2.command.dml.AllColumnsForPlan;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
import org.h2.engine.UndoLogRecord;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
...@@ -40,9 +35,6 @@ public class PageDataIndex extends PageIndex { ...@@ -40,9 +35,6 @@ public class PageDataIndex extends PageIndex {
private final RegularTable tableData; private final RegularTable tableData;
private long lastKey; private long lastKey;
private long rowCount; private long rowCount;
private HashSet<Row> delta;
private int rowCountDiff;
private final HashMap<Integer, Integer> sessionRowCount;
private int mainIndexColumn = -1; private int mainIndexColumn = -1;
private DbException fastDuplicateKeyException; private DbException fastDuplicateKeyException;
...@@ -53,21 +45,12 @@ public class PageDataIndex extends PageIndex { ...@@ -53,21 +45,12 @@ public class PageDataIndex extends PageIndex {
private int memoryPerPage; private int memoryPerPage;
private int memoryCount; private int memoryCount;
private final boolean multiVersion;
public PageDataIndex(RegularTable table, int id, IndexColumn[] columns, public PageDataIndex(RegularTable table, int id, IndexColumn[] columns,
IndexType indexType, boolean create, Session session) { IndexType indexType, boolean create, Session session) {
initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType); initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType);
this.multiVersion = database.isMVStore();
// trace = database.getTrace(Trace.PAGE_STORE + "_di"); // trace = database.getTrace(Trace.PAGE_STORE + "_di");
// trace.setLevel(TraceSystem.DEBUG); // trace.setLevel(TraceSystem.DEBUG);
if (multiVersion) {
sessionRowCount = new HashMap<>();
isMultiVersion = true;
} else {
sessionRowCount = null;
}
tableData = table; tableData = table;
this.store = database.getPageStore(); this.store = database.getPageStore();
store.addIndex(this); store.addIndex(this);
...@@ -190,16 +173,6 @@ public class PageDataIndex extends PageIndex { ...@@ -190,16 +173,6 @@ public class PageDataIndex extends PageIndex {
root = newRoot; root = newRoot;
} }
row.setDeleted(false); row.setDeleted(false);
if (multiVersion) {
if (delta == null) {
delta = new HashSet<>();
}
boolean wasDeleted = delta.remove(row);
if (!wasDeleted) {
delta.add(row);
}
incrementRowCount(session.getId(), 1);
}
invalidateRowCount(); invalidateRowCount();
rowCount++; rowCount++;
store.logAddOrRemoveRow(session, tableData.getId(), row, true); store.logAddOrRemoveRow(session, tableData.getId(), row, true);
...@@ -350,18 +323,6 @@ public class PageDataIndex extends PageIndex { ...@@ -350,18 +323,6 @@ public class PageDataIndex extends PageIndex {
store.incrementChangeCount(); store.incrementChangeCount();
} }
} }
if (multiVersion) {
// if storage is null, the delete flag is not yet set
row.setDeleted(true);
if (delta == null) {
delta = new HashSet<>();
}
boolean wasAdded = delta.remove(row);
if (!wasAdded) {
delta.add(row);
}
incrementRowCount(session.getId(), -1);
}
store.logAddOrRemoveRow(session, tableData.getId(), row, false); store.logAddOrRemoveRow(session, tableData.getId(), row, false);
} }
...@@ -387,9 +348,6 @@ public class PageDataIndex extends PageIndex { ...@@ -387,9 +348,6 @@ public class PageDataIndex extends PageIndex {
session.commit(false); session.commit(false);
database.getLobStorage().removeAllForTable(table.getId()); database.getLobStorage().removeAllForTable(table.getId());
} }
if (multiVersion) {
sessionRowCount.clear();
}
tableData.setRowCount(0); tableData.setRowCount(0);
} }
...@@ -439,13 +397,6 @@ public class PageDataIndex extends PageIndex { ...@@ -439,13 +397,6 @@ public class PageDataIndex extends PageIndex {
@Override @Override
public long getRowCount(Session session) { public long getRowCount(Session session) {
if (multiVersion) {
Integer i = sessionRowCount.get(session.getId());
long count = i == null ? 0 : i.intValue();
count += rowCount;
count -= rowCountDiff;
return count;
}
return rowCount; return rowCount;
} }
...@@ -476,46 +427,11 @@ public class PageDataIndex extends PageIndex { ...@@ -476,46 +427,11 @@ public class PageDataIndex extends PageIndex {
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
trace.debug("{0} close", this); trace.debug("{0} close", this);
} }
if (delta != null) {
delta.clear();
}
rowCountDiff = 0;
if (sessionRowCount != null) {
sessionRowCount.clear();
}
// can not close the index because it might get used afterwards, // can not close the index because it might get used afterwards,
// for example after running recovery // for example after running recovery
writeRowCount(); writeRowCount();
} }
Iterator<Row> getDelta() {
if (delta == null) {
return Collections.emptyIterator();
}
return delta.iterator();
}
private void incrementRowCount(int sessionId, int count) {
if (multiVersion) {
Integer id = sessionId;
Integer c = sessionRowCount.get(id);
int current = c == null ? 0 : c.intValue();
sessionRowCount.put(id, current + count);
rowCountDiff += count;
}
}
@Override
public void commit(int operation, Row row) {
if (multiVersion) {
if (delta != null) {
delta.remove(row);
}
incrementRowCount(row.getSessionId(),
operation == UndoLogRecord.DELETE ? 1 : -1);
}
}
/** /**
* The root page has changed. * The root page has changed.
* *
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论