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

Cleanup#2

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