Unverified 提交 04564b6e authored 作者: Andrei Tokar's avatar Andrei Tokar 提交者: GitHub

Merge pull request #1137 from h2database/txcommit-atomic

Step toward making transaction commit atomic.
......@@ -379,9 +379,19 @@ public class MVMap<K, V> extends AbstractMap<K, V>
* @return the value, or null if not found
*/
@Override
public final V get(Object key) {
return get(getRootPage(), key);
}
/**
* Get the value for the given key from a snapshot, or null if not found.
*
* @param p the root of a snapshot
* @param key the key
* @return the value, or null if not found
*/
@SuppressWarnings("unchecked")
public V get(Object key) {
Page p = getRootPage();
public V get(Page p, Object key) {
return (V) Page.get(p, key);
}
......
......@@ -183,7 +183,7 @@ public abstract class Page implements Cloneable
* @param p the root page
* @return the value, or null if not found
*/
public static Object get(Page p, Object key) {
static Object get(Page p, Object key) {
while (true) {
int index = p.binarySearch(key);
if (p.isLeaf()) {
......
......@@ -210,7 +210,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
}
if (unique != null) {
// This code expects that mayHaveDuplicates(row) == false
Iterator<Value> it = map.keyIterator(unique, true);
Iterator<Value> it = map.keyIterator(unique, null, true);
while (it.hasNext()) {
ValueArray k = (ValueArray) it.next();
if (compareRows(row, convertToSearchRow(k)) != 0) {
......
......@@ -48,12 +48,6 @@ public final class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
return new MVRTreeMap<>(this);
}
@Override
public V get(Object key) {
V result = get(getRootPage(), key);
return result;
}
/**
* Iterate over all keys that have an intersection with the given rectangle.
*
......@@ -102,6 +96,7 @@ public final class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
* @return the value, or null if not found
*/
@SuppressWarnings("unchecked")
@Override
public V get(Page p, Object key) {
int keyCount = p.getKeyCount();
if (!p.isLeaf()) {
......
......@@ -374,7 +374,7 @@ public class TransactionStore {
* @param key the key
* @param oldValue the old value
*/
void log(Transaction t, long logId, int mapId,
long log(Transaction t, long logId, int mapId,
Object key, Object oldValue) {
Long undoKey = getOperationId(t.getId(), logId);
Object[] log = { mapId, key, oldValue };
......@@ -393,6 +393,7 @@ public class TransactionStore {
} finally {
rwLock.writeLock().unlock();
}
return undoKey;
}
/**
......
......@@ -31,6 +31,10 @@ public class VersionedValue {
this.value = value;
}
public long getOperationId() {
return operationId;
}
@Override
public String toString() {
return value + (operationId == 0 ? "" : (
......
......@@ -102,7 +102,7 @@ public class TestMvccMultiThreaded2 extends TestBase {
}
if (DISPLAY_STATS) {
System.out.println(String.format(
println(String.format(
"+ INFO: TestMvccMultiThreaded2 RUN STATS threads=%d, minProcessed=%d, maxProcessed=%d, "
+ "totalProcessed=%d, averagePerThread=%d, averagePerThreadPerSecond=%d\n",
TEST_THREAD_COUNT, minProcessed, maxProcessed, totalProcessed, totalProcessed / TEST_THREAD_COUNT,
......@@ -139,10 +139,10 @@ public class TestMvccMultiThreaded2 extends TestBase {
// give the other threads a chance to start up before going into our work loop
Thread.yield();
PreparedStatement ps = conn.prepareStatement(
"SELECT * FROM test WHERE entity_id = ? FOR UPDATE");
while (!done) {
try {
PreparedStatement ps = conn.prepareStatement(
"SELECT * FROM test WHERE entity_id = ? FOR UPDATE");
String id;
int value;
if ((iterationsProcessed & 1) == 0) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论