提交 204ff2d9 authored 作者: Thomas Mueller's avatar Thomas Mueller

When using SELECT_FOR_UPDATE_MVCC (lock only the selected rows when using MVCC),…

When using SELECT_FOR_UPDATE_MVCC (lock only the selected rows when using MVCC), the selected rows were sometimes not locked correctly.
上级 526ec3e3
...@@ -504,7 +504,7 @@ public class Select extends Query { ...@@ -504,7 +504,7 @@ public class Select extends Query {
row[i] = expr.getValue(session); row[i] = expr.getValue(session);
} }
if (isForUpdateMvcc) { if (isForUpdateMvcc) {
topTableFilter.lockRow(forUpdateRows); topTableFilter.lockRowAdd(forUpdateRows);
} }
result.addRow(row); result.addRow(row);
rowNumber++; rowNumber++;
......
...@@ -31,6 +31,22 @@ public class Row implements SearchRow { ...@@ -31,6 +31,22 @@ public class Row implements SearchRow {
this.memory = memory; this.memory = memory;
} }
/**
* Get a copy of the row that is distinct from (not equal to) this row.
* This is used for FOR UPDATE to allow pseudo-updating a row.
*
* @return a new row with the same data
*/
public Row getCopy() {
Value[] d2 = new Value[data.length];
System.arraycopy(data, 0, d2, 0, data.length);
Row r2 = new Row(d2, memory);
r2.key = key;
r2.version = version + 1;
r2.sessionId = sessionId;
return r2;
}
public void setKeyAndVersion(SearchRow row) { public void setKeyAndVersion(SearchRow row) {
setKey(row.getKey()); setKey(row.getKey());
setVersion(row.getVersion()); setVersion(row.getVersion());
......
...@@ -898,7 +898,7 @@ public class TableFilter implements ColumnResolver { ...@@ -898,7 +898,7 @@ public class TableFilter implements ColumnResolver {
* *
* @param rows the rows to lock * @param rows the rows to lock
*/ */
public void lockRow(ArrayList<Row> rows) { public void lockRowAdd(ArrayList<Row> rows) {
if (state == FOUND) { if (state == FOUND) {
rows.add(get()); rows.add(get());
} }
...@@ -912,7 +912,8 @@ public class TableFilter implements ColumnResolver { ...@@ -912,7 +912,8 @@ public class TableFilter implements ColumnResolver {
public void lockRows(ArrayList<Row> forUpdateRows) { public void lockRows(ArrayList<Row> forUpdateRows) {
for (Row row : forUpdateRows) { for (Row row : forUpdateRows) {
table.removeRow(session, row); table.removeRow(session, row);
table.addRow(session, row); Row r2 = row.getCopy();
table.addRow(session, r2);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论