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

Cleanup#2

上级 9c1d1d29
......@@ -1040,8 +1040,6 @@ public class Database implements DataHandler {
* @param obj the object to add
*/
public void addSchemaObject(Session session, SchemaObject obj) {
//System.out.println("addSchemaObject="+obj.getName()+",sessionId="+session.getId()+",obj="+obj);
int id = obj.getId();
if (id > 0 && !starting) {
checkWritingAllowed();
......@@ -1875,7 +1873,7 @@ public class Database implements DataHandler {
* @param session the session
* @param obj the object to be removed
*/
public boolean removeSchemaObject(Session session,
public void removeSchemaObject(Session session,
SchemaObject obj) {
int type = obj.getType();
if (type == DbObject.TABLE_OR_VIEW) {
......@@ -1883,32 +1881,26 @@ public class Database implements DataHandler {
//table.setBeingDropped(true);
if (table.isTemporary() && !table.isGlobalTemporary()) {
session.removeLocalTempTable(table);
return true;
return;
}
} else if (type == DbObject.INDEX) {
Index index = (Index) obj;
Table table = index.getTable();
if (table.isTemporary() && !table.isGlobalTemporary()) {
session.removeLocalTempTableIndex(index);
return true;
return;
}
} else if (type == DbObject.CONSTRAINT) {
Constraint constraint = (Constraint) obj;
Table table = constraint.getTable();
if (table.isTemporary() && !table.isGlobalTemporary()) {
session.removeLocalTempTableConstraint(constraint);
return true;
return;
}
}
checkWritingAllowed();
/*Boolean wasLocked = */lockMeta(session);// was lockMetaNoWait
//if(wasLocked==null){
// removeSchemaObjectQueue.put(obj,session);
// System.out.println("deferred removal scheduled="+obj.getName()+",wasLocked="+wasLocked);
// return false;
//}
lockMeta(session);
synchronized (this) {
//String savedName = obj.getName();
Comment comment = findComment(obj);
if (comment != null) {
removeDatabaseObject(session, comment);
......@@ -1925,41 +1917,11 @@ public class Database implements DataHandler {
obj.removeChildrenAndResources(session);
}
else{
//System.out.println("Starting database detected");
}
//System.out.println("Removing db object id - also remove meta lock from session and session lock from meta, id="+id+",sessionId="+session.getId()+",name="+savedName+",obj="+obj);
removeMeta(session, id);
//flushDeferredRemoveSchemaObject();
return true;
return;
}
}
// public void flushDeferredRemoveSchemaObject() {
// boolean progress = true;
// while(progress){
// progress = false;
// Iterator<Entry<SchemaObject, Session>> i = removeSchemaObjectQueue.entrySet().iterator();
// while(i.hasNext()){
// Entry<SchemaObject, Session> pair = i.next();
// i.remove();
// //System.out.println("re-attempting deferred removal="+pair.getKey().getName()+",size="+removeSchemaObjectQueue.size());
// progress = removeSchemaObject(pair.getValue(),pair.getKey());
// if(progress){
// //System.out.println("completed deferred removal="+pair.getKey().getName()+",size="+removeSchemaObjectQueue.size());
// unlockMeta(pair.getValue());
// }
// }
// }
// //System.out.println("flushDeferredRemoveSchemaObject.remove_q_size="+removeSchemaObjectQueue.size());
// if(removeSchemaObjectQueue.size()!=0){
// traceLock();
// }
// }
/**
* Check if this database is disk-based.
*
......
......@@ -173,7 +173,6 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
Prepared p;
session.pushSubQueryInfo(masks, filters, filter, sortOrder);
try {
//System.out.println("ViewIndex.prepareSubQuery:"+sql);
p = session.prepare(sql, true, true);
} finally {
session.popSubQueryInfo();
......
......@@ -88,7 +88,6 @@ public class MVTable extends TableBase {
private final ArrayList<Index> indexes = New.arrayList();
private volatile long lastModificationId;
private volatile Session lockExclusiveSession;
private volatile Throwable lockExclusiveSessionStackTrace;
// using a ConcurrentHashMap as a set
private final ConcurrentHashMap<Session, Session> lockSharedSessions =
......@@ -401,21 +400,6 @@ public class MVTable extends TableBase {
traceLock.debug("{0} {1} {2} {3}", session.getId(),
exclusive ? "exclusive write lock" : "shared read lock", statusText,
getName());
// // create a stack trace when the lock is granted so we can debug where that was...
// if(statusText.equals(TRACE_LOCK_ADDED_FOR) || statusText.equals(TRACE_LOCK_ADD_UPGRADED_FOR)){
// lockExclusiveSessionStackTrace = new Throwable("trace lock - lock granted stack trace");
// }
//
// // clear the stack trace of the granted lock, on unlock
// if(statusText.equals(TRACE_LOCK_UNLOCK)){
// lockExclusiveSessionStackTrace = null;
// }
//
// // show the stack trace where the lock was granted, if a timeout happens...
// if(statusText.contains(TRACE_LOCK_TIMEOUT_AFTER) && lockExclusiveSessionStackTrace!=null){
// lockExclusiveSessionStackTrace.printStackTrace();
// }
}
}
......@@ -426,17 +410,7 @@ public class MVTable extends TableBase {
@Override
public boolean isLockedExclusivelyBy(Session session) {
Session localSession = lockExclusiveSession;
if(localSession!=null){
//System.out.println("Meta was locked by "+localSession.getId()+" tested for "+session.getId());
if(lockExclusiveSessionStackTrace!=null){
lockExclusiveSessionStackTrace.printStackTrace();
}
}
else{
//System.out.println("Meta was not locked by anyone, tested for "+session.getId());
}
return localSession == session;
return lockExclusiveSession == session;
}
@Override
......
......@@ -87,8 +87,6 @@ public abstract class Table extends SchemaObjectBase {
private boolean onCommitDrop, onCommitTruncate;
private volatile Row nullRow;
private boolean tableExpression;
// private boolean isBeingDropped;
public Table(Schema schema, int id, String name, boolean persistIndexes,
boolean persistData) {
......@@ -529,7 +527,6 @@ public abstract class Table extends SchemaObjectBase {
public void removeChildrenAndResources(Session session) {
while (dependentViews.size() > 0) {
TableView view = dependentViews.get(0);
//System.out.println("removeChildrenAndResources.dependentViews:"+view.getName());
dependentViews.remove(0);
database.removeSchemaObject(session, view);
}
......@@ -836,14 +833,12 @@ public abstract class Table extends SchemaObjectBase {
}
/**
* Remove the given view from the list.
* Remove the given view from the dependent views list.
*
* @param view the view to remove
*/
public void removeDependentView(TableView view) {
//System.out.println("removeDependentView(Before):"+dependentViews.toString());
dependentViews.remove(view);
//System.out.println("removeDependentView(Left):"+dependentViews.toString());
}
/**
......@@ -1251,13 +1246,4 @@ public abstract class Table extends SchemaObjectBase {
public boolean isTableExpression() {
return tableExpression;
}
// public boolean isBeingDropped(){
// return isBeingDropped;
// }
//
// public void setBeingDropped(boolean isBeingDropped){
// this.isBeingDropped = isBeingDropped;
// }
}
......@@ -105,7 +105,6 @@ public class TableView extends Table {
this.isRecursiveQueryDetected = false;
this.isTableExpression = isTableExpression;
this.isPersistent = isPersistent;
//this.session = session;
index = new ViewIndex(this, querySQL, params, allowRecursive);
initColumnsAndTables(session, literalsChecked);
}
......@@ -519,7 +518,6 @@ public class TableView extends Table {
private void removeCurrentViewFromOtherTables() {
if (tables != null) {
for (Table t : tables) {
//System.out.println("removeCurrentViewFromOtherTables:"+t.getName());
t.removeDependentView(this);
}
tables.clear();
......@@ -555,8 +553,9 @@ public class TableView extends Table {
Schema mainSchema = session.getDatabase().getSchema(Constants.SCHEMA_MAIN);
String querySQL = query.getPlanSQL();
TableView v = new TableView(mainSchema, 0, name,
querySQL, query.getParameters(), null, session,
false, true /* literals have already been checked when parsing original query */, false, false/* is persistent*/);
querySQL, query.getParameters(), null /* column templates */, session,
false/* allow recursive */, true /* literals have already been checked when parsing original query */,
false /* is table expression */, false/* is persistent*/);
if (v.createException != null) {
throw v.createException;
}
......@@ -714,24 +713,18 @@ public class TableView extends Table {
ArrayList<Parameter> parameters, Column[] columnTemplates, Session session,
boolean literalsChecked, boolean isTableExpression, boolean isPersistent, Database db){
//Table shadowTable = Parser.createShadowTableForRecursiveTableExpression(isPersistent, session, name, schema, Arrays.asList(columnTemplates), db);
// build with recursion turned on
TableView view = new TableView(schema, id, name, querySQL,
parameters, columnTemplates, session,
true/* try recursive */, literalsChecked, isTableExpression, isPersistent );
//System.out.println("create recursive view:"+view);
//if(shadowTable!=null){
// Parser.destroyShadowTableForRecursiveExpression(isPersistent, session, shadowTable);
//}
//System.out.println("view.isRecursiveQueryDetected()="+view.isRecursiveQueryDetected());
// is not recursion detected ? if so - recreate it without recursion flag
// is recursion really detected ? if not - recreate it without recursion flag and no recursive index
if (!view.isRecursiveQueryDetected()) {
if(isPersistent){
db.addSchemaObject(session, view);
view.lock(session, true, true);
session.getDatabase().removeSchemaObject(session, view);
// during database startup - this method does not normally get called - and it needs to be
// to correctly un-register the table which the table expression uses...
view.removeChildrenAndResources(session);
......@@ -741,7 +734,6 @@ public class TableView extends Table {
view = new TableView(schema, id, name, querySQL, parameters,
columnTemplates, session,
false/* detected not recursive */, literalsChecked, isTableExpression, isPersistent);
//System.out.println("create nr view:"+view);
}
return view;
......
......@@ -54,6 +54,7 @@ import org.h2.test.db.TestOpenClose;
import org.h2.test.db.TestOptimizations;
import org.h2.test.db.TestOptimizerHints;
import org.h2.test.db.TestOutOfMemory;
import org.h2.test.db.TestPersistentCommonTableExpressions;
import org.h2.test.db.TestPowerOff;
import org.h2.test.db.TestQueryCache;
import org.h2.test.db.TestReadOnly;
......@@ -761,9 +762,10 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestOutOfMemory());
addTest(new TestReadOnly());
addTest(new TestRecursiveQueries());
addTest(new TestGeneralCommonTableQueries());
if(!memory){
// requires persistent store for reconnection tests
addTest(new TestGeneralCommonTableQueries());
addTest(new TestPersistentCommonTableExpressions());
}
addTest(new TestRights());
addTest(new TestRunscript());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论