提交 9caa3a87 authored 作者: Noel Grandin's avatar Noel Grandin

fix TestMultiThreadedKernel in pagestore mode

by essentially copying over various fixes we made, from the MVStore class, to the RegularTable class
上级 3bb5aa60
......@@ -449,7 +449,7 @@ public class MVTable extends TableBase {
}
}
synchronized (getLockSyncObject()) {
if (lockSharedSessions.size() > 0) {
if (!lockSharedSessions.isEmpty()) {
lockSharedSessions.remove(s);
if (SysProperties.THREAD_DEADLOCK_DETECTOR) {
if (SHARED_LOCKS.get() != null) {
......
......@@ -11,8 +11,8 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import org.h2.api.DatabaseEventListener;
import org.h2.api.ErrorCode;
import org.h2.command.ddl.CreateTableData;
......@@ -55,7 +55,10 @@ public class RegularTable extends TableBase {
private Index scanIndex;
private long rowCount;
private volatile Session lockExclusiveSession;
private HashSet<Session> lockSharedSessions = new HashSet<>();
// using a ConcurrentHashMap as a set
private ConcurrentHashMap<Session, Session> lockSharedSessions =
new ConcurrentHashMap<>();
/**
* The queue of sessions waiting to lock the table. It is a FIFO queue to
......@@ -434,11 +437,6 @@ public class RegularTable extends TableBase {
session.markTableForAnalyze(this);
}
@Override
public boolean isLockedExclusivelyBy(Session session) {
return lockExclusiveSession == session;
}
@Override
public boolean lock(Session session, boolean exclusive,
boolean forceLockEvenInMvcc) {
......@@ -460,10 +458,10 @@ public class RegularTable extends TableBase {
if (lockExclusiveSession == session) {
return true;
}
if (!exclusive && lockSharedSessions.containsKey(session)) {
return true;
}
synchronized (database) {
if (lockExclusiveSession == session) {
return true;
}
if (!exclusive && lockSharedSessions.contains(session)) {
return true;
}
......@@ -543,7 +541,7 @@ public class RegularTable extends TableBase {
lockExclusiveSession = session;
return true;
} else if (lockSharedSessions.size() == 1 &&
lockSharedSessions.contains(session)) {
lockSharedSessions.containsKey(session)) {
traceLock(session, exclusive, "add (upgraded) for ");
lockExclusiveSession = session;
return true;
......@@ -562,10 +560,10 @@ public class RegularTable extends TableBase {
return true;
}
}
if (!lockSharedSessions.contains(session)) {
if (!lockSharedSessions.containsKey(session)) {
traceLock(session, exclusive, "ok");
session.addLock(this);
lockSharedSessions.add(session);
lockSharedSessions.put(session, session);
}
return true;
}
......@@ -626,7 +624,7 @@ public class RegularTable extends TableBase {
}
visited.add(session);
ArrayList<Session> error = null;
for (Session s : lockSharedSessions) {
for (Session s : lockSharedSessions.keySet()) {
if (s == session) {
// it doesn't matter if we have locked the object already
continue;
......@@ -640,10 +638,13 @@ public class RegularTable extends TableBase {
}
}
}
if (error == null && lockExclusiveSession != null) {
Table t = lockExclusiveSession.getWaitForLock();
// take a local copy so we don't see inconsistent data, since we are
// not locked while checking the lockExclusiveSession value
Session copyOfLockExclusiveSession = lockExclusiveSession;
if (error == null && copyOfLockExclusiveSession != null) {
Table t = copyOfLockExclusiveSession.getWaitForLock();
if (t != null) {
error = t.checkDeadlock(lockExclusiveSession, clash, visited);
error = t.checkDeadlock(copyOfLockExclusiveSession, clash, visited);
if (error != null) {
error.add(session);
}
......@@ -665,11 +666,17 @@ public class RegularTable extends TableBase {
return lockExclusiveSession != null;
}
@Override
public boolean isLockedExclusivelyBy(Session session) {
return lockExclusiveSession == session;
}
@Override
public void unlock(Session s) {
if (database != null) {
traceLock(s, lockExclusiveSession == s, "unlock");
if (lockExclusiveSession == s) {
lockSharedSessions.remove(s);
lockExclusiveSession = null;
}
synchronized (database) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论