提交 f4694669 authored 作者: Owner's avatar Owner

Fixed meta locking bug in shadow table

上级 76547b6c
...@@ -5309,6 +5309,7 @@ public class Parser { ...@@ -5309,6 +5309,7 @@ public class Parser {
}else{ }else{
targetSession.removeLocalTempTable(recursiveTable); targetSession.removeLocalTempTable(recursiveTable);
} }
targetSession.getDatabase().unlockMeta(targetSession);
} }
} }
......
...@@ -100,7 +100,7 @@ public class DropTable extends SchemaCommand { ...@@ -100,7 +100,7 @@ public class DropTable extends SchemaCommand {
Database db = session.getDatabase(); Database db = session.getDatabase();
db.lockMeta(session); db.lockMeta(session);
db.removeSchemaObject(session, table); db.removeSchemaObject(session, table);
session.getDatabase().flushDeferredRemoveSchemaObject(); //session.getDatabase().flushDeferredRemoveSchemaObject();
} }
if (next != null) { if (next != null) {
next.executeDrop(); next.executeDrop();
......
...@@ -78,7 +78,7 @@ public class DropView extends SchemaCommand { ...@@ -78,7 +78,7 @@ public class DropView extends SchemaCommand {
view.lock(session, true, true); view.lock(session, true, true);
session.getDatabase().removeSchemaObject(session, view); session.getDatabase().removeSchemaObject(session, view);
session.getDatabase().unlockMeta(session); session.getDatabase().unlockMeta(session);
session.getDatabase().flushDeferredRemoveSchemaObject(); //session.getDatabase().flushDeferredRemoveSchemaObject();
// remove dependent table expressions // remove dependent table expressions
for( Table childTable: copyOfDependencies){ for( Table childTable: copyOfDependencies){
......
...@@ -11,8 +11,8 @@ import java.util.ArrayList; ...@@ -11,8 +11,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; //import java.util.Iterator;
import java.util.Map.Entry; //import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
...@@ -204,7 +204,7 @@ public class Database implements DataHandler { ...@@ -204,7 +204,7 @@ public class Database implements DataHandler {
private int queryStatisticsMaxEntries = Constants.QUERY_STATISTICS_MAX_ENTRIES; private int queryStatisticsMaxEntries = Constants.QUERY_STATISTICS_MAX_ENTRIES;
private QueryStatisticsData queryStatisticsData; private QueryStatisticsData queryStatisticsData;
private RowFactory rowFactory = RowFactory.DEFAULT; private RowFactory rowFactory = RowFactory.DEFAULT;
private ConcurrentHashMap<SchemaObject, Session> removeSchemaObjectQueue = new ConcurrentHashMap<>(); // private ConcurrentHashMap<SchemaObject, Session> removeSchemaObjectQueue = new ConcurrentHashMap<>();
public Database(ConnectionInfo ci, String cipher) { public Database(ConnectionInfo ci, String cipher) {
String name = ci.getName(); String name = ci.getName();
...@@ -925,7 +925,8 @@ public class Database implements DataHandler { ...@@ -925,7 +925,8 @@ public class Database implements DataHandler {
final Session prev = metaLockDebugging.get(); final Session prev = metaLockDebugging.get();
if (prev == null) { if (prev == null) {
metaLockDebugging.set(session); metaLockDebugging.set(session);
metaLockDebuggingStack.set(new Throwable()); metaLockDebuggingStack.set(new Throwable("Last meta lock granted in this stack trace, "+
"this is debug information for following IllegalStateException"));
} else if (prev != session) { } else if (prev != session) {
metaLockDebuggingStack.get().printStackTrace(); metaLockDebuggingStack.get().printStackTrace();
throw new IllegalStateException("meta currently locked by " throw new IllegalStateException("meta currently locked by "
...@@ -1932,12 +1933,12 @@ public class Database implements DataHandler { ...@@ -1932,12 +1933,12 @@ public class Database implements DataHandler {
} }
} }
checkWritingAllowed(); checkWritingAllowed();
Boolean wasLocked = lockMetaNoWait(session);// was /*Boolean wasLocked = */lockMeta(session);// was lockMetaNoWait
if(wasLocked==null){ //if(wasLocked==null){
removeSchemaObjectQueue.put(obj,session); // removeSchemaObjectQueue.put(obj,session);
System.out.println("deferred removal scheduled="+obj.getName()+",wasLocked="+wasLocked); // System.out.println("deferred removal scheduled="+obj.getName()+",wasLocked="+wasLocked);
return false; // return false;
} //}
synchronized (this) { synchronized (this) {
//String savedName = obj.getName(); //String savedName = obj.getName();
Comment comment = findComment(obj); Comment comment = findComment(obj);
...@@ -1963,33 +1964,33 @@ public class Database implements DataHandler { ...@@ -1963,33 +1964,33 @@ public class Database implements DataHandler {
removeMeta(session, id); removeMeta(session, id);
flushDeferredRemoveSchemaObject(); //flushDeferredRemoveSchemaObject();
return true; return true;
} }
} }
public void flushDeferredRemoveSchemaObject() { // public void flushDeferredRemoveSchemaObject() {
boolean progress = true; // boolean progress = true;
while(progress){ // while(progress){
progress = false; // progress = false;
Iterator<Entry<SchemaObject, Session>> i = removeSchemaObjectQueue.entrySet().iterator(); // Iterator<Entry<SchemaObject, Session>> i = removeSchemaObjectQueue.entrySet().iterator();
while(i.hasNext()){ // while(i.hasNext()){
Entry<SchemaObject, Session> pair = i.next(); // Entry<SchemaObject, Session> pair = i.next();
i.remove(); // i.remove();
//System.out.println("re-attempting deferred removal="+pair.getKey().getName()+",size="+removeSchemaObjectQueue.size()); // //System.out.println("re-attempting deferred removal="+pair.getKey().getName()+",size="+removeSchemaObjectQueue.size());
progress = removeSchemaObject(pair.getValue(),pair.getKey()); // progress = removeSchemaObject(pair.getValue(),pair.getKey());
if(progress){ // if(progress){
//System.out.println("completed deferred removal="+pair.getKey().getName()+",size="+removeSchemaObjectQueue.size()); // //System.out.println("completed deferred removal="+pair.getKey().getName()+",size="+removeSchemaObjectQueue.size());
unlockMeta(pair.getValue()); // unlockMeta(pair.getValue());
} // }
} // }
} // }
//System.out.println("flushDeferredRemoveSchemaObject.remove_q_size="+removeSchemaObjectQueue.size()); // //System.out.println("flushDeferredRemoveSchemaObject.remove_q_size="+removeSchemaObjectQueue.size());
if(removeSchemaObjectQueue.size()!=0){ // if(removeSchemaObjectQueue.size()!=0){
traceLock(); // traceLock();
} // }
} // }
/** /**
* Check if this database is disk-based. * Check if this database is disk-based.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论