提交 ee3c4db3 authored 作者: Thomas Mueller's avatar Thomas Mueller

MVCC: the probability of lock timeouts is now lower if multiple threads try to…

MVCC: the probability of lock timeouts is now lower if multiple threads try to update the same rows.
上级 c9c810a0
......@@ -16,6 +16,7 @@ import org.h2.expression.ParameterInterface;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.result.ResultInterface;
import org.h2.util.MathUtils;
/**
* Represents a SQL statement. This object is only used on the server side.
......@@ -256,10 +257,11 @@ public abstract class Command implements CommandInterface {
}
try {
Database database = session.getDatabase();
int sleep = 1 + MathUtils.randomInt(10);
if (database.isMultiThreaded()) {
Thread.sleep(10);
Thread.sleep(sleep);
} else {
database.wait(10);
database.wait(sleep);
}
} catch (InterruptedException e1) {
// ignore
......
......@@ -8,7 +8,6 @@ package org.h2.test.mvcc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.CountDownLatch;
import org.h2.test.TestBase;
......@@ -40,7 +39,7 @@ public class TestMvccMultiThreaded extends TestBase {
int len = 3;
final Connection[] connList = new Connection[len];
for (int i = 0; i < len; i++) {
Connection conn = getConnection("mvccMultiThreaded;MVCC=TRUE;LOCK_TIMEOUT=1000");
Connection conn = getConnection("mvccMultiThreaded;MVCC=TRUE;LOCK_TIMEOUT=100");
connList[i] = conn;
}
Connection conn = connList[0];
......@@ -51,7 +50,7 @@ public class TestMvccMultiThreaded extends TestBase {
final Connection c = connList[i];
c.setAutoCommit(false);
tasks[i] = new Task() {
public void call() throws SQLException {
public void call() throws Exception {
while (!stop) {
c.createStatement().execute("merge into test values(1, 'x')");
c.commit();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论