提交 df154436 authored 作者: noelgrandin@gmail.com's avatar noelgrandin@gmail.com

since we have removed the synchronization from Database#lockMeta,

it now makes more sense to return a boolean for isLockedExclusivelyBy() from the lock()
method, to make it easier to reason about the atomic-ness of the operation
上级 0c8ca6e6
......@@ -884,8 +884,7 @@ public class Database implements DataHandler {
if (meta == null) {
return true;
}
boolean wasLocked = meta.isLockedExclusivelyBy(session);
meta.lock(session, true, true);
boolean wasLocked = meta.lock(session, true, true);
return wasLocked;
}
......
......@@ -94,11 +94,11 @@ public class MVTable extends TableBase {
}
@Override
public void lock(Session session, boolean exclusive,
public boolean lock(Session session, boolean exclusive,
boolean forceLockEvenInMvcc) {
int lockMode = database.getLockMode();
if (lockMode == Constants.LOCK_MODE_OFF) {
return;
return false;
}
if (!forceLockEvenInMvcc && database.isMultiVersion()) {
// MVCC: update, delete, and insert use a shared lock.
......@@ -109,12 +109,12 @@ public class MVTable extends TableBase {
exclusive = false;
} else {
if (lockExclusiveSession == null) {
return;
return false;
}
}
}
if (lockExclusiveSession == session) {
return;
return true;
}
synchronized (getLockSyncObject()) {
session.setWaitForLock(this, Thread.currentThread());
......@@ -126,6 +126,7 @@ public class MVTable extends TableBase {
waitingSessions.remove(session);
}
}
return false;
}
/**
......
......@@ -87,8 +87,9 @@ public class FunctionTable extends Table {
}
@Override
public void lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
public boolean lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
// nothing to do
return false;
}
@Override
......
......@@ -591,8 +591,9 @@ public class MetaTable extends Table {
}
@Override
public void lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
public boolean lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
// nothing to do
return false;
}
@Override
......
......@@ -64,8 +64,9 @@ public class RangeTable extends Table {
}
@Override
public void lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
public boolean lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
// nothing to do
return false;
}
@Override
......
......@@ -439,11 +439,11 @@ public class RegularTable extends TableBase {
}
@Override
public void lock(Session session, boolean exclusive,
public boolean lock(Session session, boolean exclusive,
boolean forceLockEvenInMvcc) {
int lockMode = database.getLockMode();
if (lockMode == Constants.LOCK_MODE_OFF) {
return;
return lockExclusiveSession != null;
}
if (!forceLockEvenInMvcc && database.isMultiVersion()) {
// MVCC: update, delete, and insert use a shared lock.
......@@ -452,16 +452,16 @@ public class RegularTable extends TableBase {
exclusive = false;
} else {
if (lockExclusiveSession == null) {
return;
return false;
}
}
}
if (lockExclusiveSession == session) {
return;
return true;
}
synchronized (database) {
if (lockExclusiveSession == session) {
return;
return true;
}
session.setWaitForLock(this, Thread.currentThread());
waitingSessions.addLast(session);
......@@ -472,6 +472,7 @@ public class RegularTable extends TableBase {
waitingSessions.remove(session);
}
}
return false;
}
private void doLock1(Session session, int lockMode, boolean exclusive) {
......
......@@ -134,9 +134,10 @@ public abstract class Table extends SchemaObjectBase {
* @param session the session
* @param exclusive true for write locks, false for read locks
* @param forceLockEvenInMvcc lock even in the MVCC mode
* @return true if the table was already exclusively locked by this session.
* @throws DbException if a lock timeout occurred
*/
public abstract void lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc);
public abstract boolean lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc);
/**
* Close the table object and flush changes.
......
......@@ -390,8 +390,9 @@ public class TableLink extends Table {
}
@Override
public void lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
public boolean lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
// nothing to do
return false;
}
@Override
......
......@@ -320,8 +320,9 @@ public class TableView extends Table {
}
@Override
public void lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
public boolean lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
// exclusive lock means: the view will be dropped
return false;
}
@Override
......
......@@ -341,8 +341,9 @@ public class TestTableEngines extends TestBase {
}
@Override
public void lock(Session session, boolean exclusive, boolean force) {
public boolean lock(Session session, boolean exclusive, boolean force) {
// do nothing
return false;
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论