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

Remove MVCC code from PageDataIndex

上级 b02190d5
......@@ -5,7 +5,6 @@
*/
package org.h2.index;
import java.util.Iterator;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.result.Row;
......@@ -22,7 +21,6 @@ class PageDataCursor implements Cursor {
private Row row;
private final boolean multiVersion;
private final Session session;
private Iterator<Row> delta;
PageDataCursor(Session session, PageDataLeaf current, int idx, long maxKey,
boolean multiVersion) {
......@@ -31,9 +29,6 @@ class PageDataCursor implements Cursor {
this.maxKey = maxKey;
this.multiVersion = multiVersion;
this.session = session;
if (multiVersion) {
delta = current.index.getDelta();
}
}
@Override
......@@ -53,22 +48,10 @@ class PageDataCursor implements Cursor {
return checkMax();
}
while (true) {
if (delta != null) {
if (!delta.hasNext()) {
delta = null;
row = null;
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;
}
nextRow();
if (row != null && row.getSessionId() != 0 &&
row.getSessionId() != session.getId()) {
continue;
}
break;
}
......
......@@ -5,16 +5,11 @@
*/
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.command.dml.AllColumnsForPlan;
import org.h2.engine.Constants;
import org.h2.engine.Session;
import org.h2.engine.SysProperties;
import org.h2.engine.UndoLogRecord;
import org.h2.message.DbException;
import org.h2.result.Row;
import org.h2.result.SearchRow;
......@@ -40,9 +35,6 @@ public class PageDataIndex extends PageIndex {
private final RegularTable tableData;
private long lastKey;
private long rowCount;
private HashSet<Row> delta;
private int rowCountDiff;
private final HashMap<Integer, Integer> sessionRowCount;
private int mainIndexColumn = -1;
private DbException fastDuplicateKeyException;
......@@ -53,21 +45,12 @@ public class PageDataIndex extends PageIndex {
private int memoryPerPage;
private int memoryCount;
private final boolean multiVersion;
public PageDataIndex(RegularTable table, int id, IndexColumn[] columns,
IndexType indexType, boolean create, Session session) {
initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType);
this.multiVersion = database.isMVStore();
// trace = database.getTrace(Trace.PAGE_STORE + "_di");
// trace.setLevel(TraceSystem.DEBUG);
if (multiVersion) {
sessionRowCount = new HashMap<>();
isMultiVersion = true;
} else {
sessionRowCount = null;
}
tableData = table;
this.store = database.getPageStore();
store.addIndex(this);
......@@ -190,16 +173,6 @@ public class PageDataIndex extends PageIndex {
root = newRoot;
}
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();
rowCount++;
store.logAddOrRemoveRow(session, tableData.getId(), row, true);
......@@ -350,18 +323,6 @@ public class PageDataIndex extends PageIndex {
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);
}
......@@ -387,9 +348,6 @@ public class PageDataIndex extends PageIndex {
session.commit(false);
database.getLobStorage().removeAllForTable(table.getId());
}
if (multiVersion) {
sessionRowCount.clear();
}
tableData.setRowCount(0);
}
......@@ -439,13 +397,6 @@ public class PageDataIndex extends PageIndex {
@Override
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;
}
......@@ -476,46 +427,11 @@ public class PageDataIndex extends PageIndex {
if (trace.isDebugEnabled()) {
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,
// for example after running recovery
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.
*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论