Skip to content

Commit

Permalink
删除Index接口中不再使用的commit方法
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Jan 10, 2015
1 parent 12d1473 commit 6d00a81
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 227 deletions.
Expand Up @@ -376,11 +376,6 @@ public Table getTable() {
return table; return table;
} }


@Override
public void commit(int operation, Row row) {
// nothing to do
}

void setMultiVersion(boolean multiVersion) { void setMultiVersion(boolean multiVersion) {
this.isMultiVersion = multiVersion; this.isMultiVersion = multiVersion;
} }
Expand Down
Expand Up @@ -211,15 +211,6 @@ public interface Index extends SchemaObject {
*/ */
Table getTable(); Table getTable();


/**
* Commit the operation for a row. This is only important for multi-version
* indexes. The method is only called if multi-version is enabled.
*
* @param operation the operation type
* @param row the row
*/
void commit(int operation, Row row);

/** /**
* Get the row with the given key. * Get the row with the given key.
* *
Expand Down
10 changes: 0 additions & 10 deletions lealone-sql/src/main/java/org/lealone/dbobject/table/Table.java
Expand Up @@ -199,16 +199,6 @@ public void removeRow(final Session session, final Row row, boolean isUndo) {
*/ */
public abstract void addRow(Session session, Row row); public abstract void addRow(Session session, Row row);


/**
* Commit an operation (when using multi-version concurrency).
*
* @param operation the operation
* @param row the row
*/
public void commit(short operation, Row row) {
// nothing to do
}

/** /**
* Check if this table supports ALTER TABLE. * Check if this table supports ALTER TABLE.
* *
Expand Down
172 changes: 0 additions & 172 deletions lealone-sql/src/main/java/org/lealone/dbobject/table/TableBase.java
Expand Up @@ -7,24 +7,15 @@
package org.lealone.dbobject.table; package org.lealone.dbobject.table;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;


import org.lealone.api.DatabaseEventListener;
import org.lealone.api.ErrorCode;
import org.lealone.command.ddl.Analyze; import org.lealone.command.ddl.Analyze;
import org.lealone.command.ddl.CreateTableData; import org.lealone.command.ddl.CreateTableData;
import org.lealone.dbobject.constraint.Constraint;
import org.lealone.dbobject.constraint.ConstraintReferential;
import org.lealone.dbobject.index.Cursor;
import org.lealone.dbobject.index.Index; import org.lealone.dbobject.index.Index;
import org.lealone.dbobject.index.IndexType; import org.lealone.dbobject.index.IndexType;
import org.lealone.engine.Constants;
import org.lealone.engine.Session; import org.lealone.engine.Session;
import org.lealone.engine.SysProperties; import org.lealone.engine.SysProperties;
import org.lealone.message.DbException; import org.lealone.message.DbException;
import org.lealone.result.Row; import org.lealone.result.Row;
import org.lealone.util.MathUtils;
import org.lealone.util.New; import org.lealone.util.New;
import org.lealone.util.StatementBuilder; import org.lealone.util.StatementBuilder;
import org.lealone.util.StringUtils; import org.lealone.util.StringUtils;
Expand Down Expand Up @@ -163,56 +154,6 @@ public Row getRow(Session session, long key) {


@Override @Override
public void addRow(Session session, Row row) { public void addRow(Session session, Row row) {
lastModificationId = database.getNextModificationDataId();
if (database.isMultiVersion()) {
row.setSessionId(session.getId());
}
int i = 0;
try {
for (int size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
index.add(session, row);
checkRowCount(session, index, 1);
}
rowCount++;
} catch (Throwable e) {
try {
while (--i >= 0) {
Index index = indexes.get(i);
index.remove(session, row);
checkRowCount(session, index, 0);
}
} catch (DbException e2) {
// this could happen, for example on failure in the storage
// but if that is not the case it means there is something wrong
// with the database
trace.error(e2, "could not undo operation");
throw e2;
}
DbException de = DbException.convert(e);
// if (de.getErrorCode() == ErrorCode.DUPLICATE_KEY_1) {
// for (int j = 0; j < indexes.size(); j++) {
// Index index = indexes.get(j);
// if (index.getIndexType().isUnique() && index instanceof MultiVersionIndex) {
// MultiVersionIndex mv = (MultiVersionIndex) index;
// if (mv.isUncommittedFromOtherSession(session, row)) {
// throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, index.getName());
// }
// }
// }
// }
throw de;
}
analyzeIfRequired(session);
}

@Override
public void commit(short operation, Row row) {
lastModificationId = database.getNextModificationDataId();
for (int i = 0, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
index.commit(operation, row);
}
} }


public void checkRowCount(Session session, Index index, int offset) { public void checkRowCount(Session session, Index index, int offset) {
Expand Down Expand Up @@ -269,44 +210,6 @@ public long getRowCount(Session session) {


@Override @Override
public void removeRow(Session session, Row row) { public void removeRow(Session session, Row row) {
if (database.isMultiVersion()) {
if (row.isDeleted()) {
throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, getName());
}
int old = row.getSessionId();
int newId = session.getId();
if (old == 0) {
row.setSessionId(newId);
} else if (old != newId) {
throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, getName());
}
}
lastModificationId = database.getNextModificationDataId();
int i = indexes.size() - 1;
try {
for (; i >= 0; i--) {
Index index = indexes.get(i);
index.remove(session, row);
checkRowCount(session, index, -1);
}
rowCount--;
} catch (Throwable e) {
try {
while (++i < indexes.size()) {
Index index = indexes.get(i);
index.add(session, row);
checkRowCount(session, index, 0);
}
} catch (DbException e2) {
// this could happen, for example on failure in the storage
// but if that is not the case it means there is something wrong
// with the database
trace.error(e2, "could not undo operation");
throw e2;
}
throw DbException.convert(e);
}
analyzeIfRequired(session);
} }


@Override @Override
Expand Down Expand Up @@ -373,26 +276,6 @@ public void checkSupportAlter() {
// ok // ok
} }


@Override
public boolean canTruncate() {
if (getCheckForeignKeyConstraints() && database.getReferentialIntegrity()) {
ArrayList<Constraint> constraints = getConstraints();
if (constraints != null) {
for (int i = 0, size = constraints.size(); i < size; i++) {
Constraint c = constraints.get(i);
if (!(c.getConstraintType().equals(Constraint.REFERENTIAL))) {
continue;
}
ConstraintReferential ref = (ConstraintReferential) c;
if (ref.getRefTable() == this) {
return false;
}
}
}
}
return true;
}

@Override @Override
public String getTableType() { public String getTableType() {
return Table.TABLE; return Table.TABLE;
Expand Down Expand Up @@ -431,59 +314,4 @@ public Column getRowIdColumn() {
return rowIdColumn; return rowIdColumn;
} }


protected void rebuildIfNeed(Session session, Index index, String indexName) {
if (index.needRebuild() && rowCount > 0) {
try {
Index scan = getScanIndex(session);
long remaining = scan.getRowCount(session);
long total = remaining;
Cursor cursor = scan.find(session, null, null);
long i = 0;
int bufferSize = (int) Math.min(rowCount, Constants.DEFAULT_MAX_MEMORY_ROWS);
ArrayList<Row> buffer = New.arrayList(bufferSize);
String n = getName() + ":" + index.getName();
int t = MathUtils.convertLongToInt(total);
while (cursor.next()) {
database.setProgress(DatabaseEventListener.STATE_CREATE_INDEX, n, MathUtils.convertLongToInt(i++), t);
Row row = cursor.get();
buffer.add(row);
if (buffer.size() >= bufferSize) {
addRowsToIndex(session, buffer, index);
}
remaining--;
}
addRowsToIndex(session, buffer, index);
if (SysProperties.CHECK && remaining != 0) {
DbException.throwInternalError("rowcount remaining=" + remaining + " " + getName());
}
} catch (DbException e) {
getSchema().freeUniqueName(indexName);
try {
index.remove(session);
} catch (DbException e2) {
// this could happen, for example on failure in the storage
// but if that is not the case it means
// there is something wrong with the database
trace.error(e2, "could not remove index");
throw e2;
}
throw e;
}
}
}

private static void addRowsToIndex(Session session, ArrayList<Row> list, Index index) {
final Index idx = index;
Collections.sort(list, new Comparator<Row>() {
@Override
public int compare(Row r1, Row r2) {
return idx.compareRows(r1, r2);
}
});
for (Row row : list) {
index.add(session, row);
}
list.clear();
}

} }
18 changes: 9 additions & 9 deletions lealone-sql/src/main/java/org/lealone/engine/Session.java
Expand Up @@ -643,15 +643,15 @@ public void log(Table table, short operation, Row row) {
// } // }
// undoLog.add(log); // undoLog.add(log);
// } else { // } else {
if (database.isMultiVersion()) { // if (database.isMultiVersion()) {
// see also UndoLogRecord.commit // // see also UndoLogRecord.commit
ArrayList<Index> indexes = table.getIndexes(); // ArrayList<Index> indexes = table.getIndexes();
for (int i = 0, size = indexes.size(); i < size; i++) { // for (int i = 0, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i); // Index index = indexes.get(i);
index.commit(operation, row); // index.commit(operation, row);
} // }
row.commit(); // row.commit();
} // }
} }


/** /**
Expand Down
26 changes: 7 additions & 19 deletions lealone-sql/src/main/java/org/lealone/result/Row.java
Expand Up @@ -27,7 +27,6 @@ public class Row implements SearchRow {
private int memory; private int memory;
private int version; private int version;
private boolean deleted; private boolean deleted;
private int sessionId;
private Value rowKey; private Value rowKey;
private Table table; private Table table;


Expand All @@ -48,8 +47,9 @@ public long getTransactionId() {
return transactionId; return transactionId;
} }


public void setTransactionId(long transactionId) { public Row setTransactionId(long transactionId) {
this.transactionId = transactionId; this.transactionId = transactionId;
return this;
} }


public Row(Value[] data, int memory) { public Row(Value[] data, int memory) {
Expand All @@ -75,7 +75,6 @@ public Row getCopy() {
Row r2 = new Row(d2, memory); Row r2 = new Row(d2, memory);
r2.key = key; r2.key = key;
r2.version = version + 1; r2.version = version + 1;
r2.sessionId = sessionId;
return r2; return r2;
} }


Expand Down Expand Up @@ -208,21 +207,6 @@ public void setDeleted(boolean deleted) {
this.deleted = deleted; this.deleted = deleted;
} }


public void setSessionId(int sessionId) {
this.sessionId = sessionId;
}

public int getSessionId() {
return sessionId;
}

/**
* This record has been committed. The session id is reset.
*/
public void commit() {
this.sessionId = 0;
}

public boolean isDeleted() { public boolean isDeleted() {
return deleted; return deleted;
} }
Expand Down Expand Up @@ -253,8 +237,12 @@ public void merge(Row newRow) {
} }
} }


//TODO
public Table getTable() { public Table getTable() {
return table; return table;
} }

public Row setTable(Table table) {
this.table = table;
return this;
}
} }
3 changes: 0 additions & 3 deletions lealone-sql/src/main/java/org/lealone/result/RowList.java
Expand Up @@ -57,7 +57,6 @@ private void writeRow(Data buff, Row r) {
buff.writeLong(r.getKey()); buff.writeLong(r.getKey());
buff.writeInt(r.getVersion()); buff.writeInt(r.getVersion());
buff.writeInt(r.isDeleted() ? 1 : 0); buff.writeInt(r.isDeleted() ? 1 : 0);
buff.writeInt(r.getSessionId());
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
Value v = r.getValue(i); Value v = r.getValue(i);
buff.checkCapacity(1); buff.checkCapacity(1);
Expand Down Expand Up @@ -175,7 +174,6 @@ private Row readRow(Data buff) {
key = 0; key = 0;
} }
boolean deleted = buff.readInt() == 1; boolean deleted = buff.readInt() == 1;
int sessionId = buff.readInt();
Value[] values = new Value[columnCount]; Value[] values = new Value[columnCount];
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
Value v; Value v;
Expand All @@ -197,7 +195,6 @@ private Row readRow(Data buff) {
row.setKey(key); row.setKey(key);
row.setVersion(version); row.setVersion(version);
row.setDeleted(deleted); row.setDeleted(deleted);
row.setSessionId(sessionId);
return row; return row;
} }


Expand Down

0 comments on commit 6d00a81

Please sign in to comment.