提交 359dfbce authored 作者: Owner's avatar Owner

Reconnecting shows persistance problem

上级 e7d335f2
......@@ -5222,6 +5222,9 @@ public class Parser {
String[] cols = null;
Database db = targetSession.getDatabase();
System.out.println("systemSessionId="+database.getSystemSession().getId());
System.out.println("sessionId="+session.getId());
// column names are now optional - they can be inferred from the named
// query, if not supplied by user
if (readIf("(")) {
......
......@@ -130,7 +130,9 @@ public class CreateView extends SchemaCommand {
view.setComment(comment);
}
if (old == null) {
System.out.println("addSchemaObject="+view.getName()+",sessionId="+session.getId());
db.addSchemaObject(session, view);
db.unlockMeta(session);
} else {
db.updateMeta(session, view);
}
......
......@@ -69,10 +69,11 @@ public class DropView extends SchemaCommand {
}
// TODO: Where is the ConstraintReferential.CASCADE style drop processing ? It's
// supported from imported keys - but not for dependant
// supported from imported keys - but not for dependent db objects
view.lock(session, true, true);
session.getDatabase().removeSchemaObject(session, view);
session.getDatabase().unlockMeta(session);
session.getDatabase().flushDeferredRemoveSchemaObject();
}
return 0;
......
......@@ -927,14 +927,20 @@ public class Database implements DataHandler {
} else if (prev != session) {
metaLockDebuggingStack.get().printStackTrace();
throw new IllegalStateException("meta currently locked by "
+ prev
+ prev +", sessionid="+ prev.getId()
+ " and trying to be locked by different session, "
+ session + " on same thread");
+ session +", sessionid="+ session.getId() + " on same thread");
}
}
boolean wasLocked = meta.lock(session, true, true);
return wasLocked;
}
public void traceLock(){
if(metaLockDebuggingStack.get()!=null && metaLockDebugging.get() !=null){
System.out.println("traceLock: Meta locked by sessionId="+metaLockDebugging.get().getId());
metaLockDebuggingStack.get().printStackTrace();
}
}
/**
* Lock the metadata table for updates - but don't wait if it's already locked...
......@@ -1890,7 +1896,7 @@ public class Database implements DataHandler {
* @param session the session
* @param obj the object to be removed
*/
public void removeSchemaObject(Session session,
public boolean removeSchemaObject(Session session,
SchemaObject obj) {
int type = obj.getType();
if (type == DbObject.TABLE_OR_VIEW) {
......@@ -1898,31 +1904,32 @@ public class Database implements DataHandler {
table.setBeingDropped(true);
if (table.isTemporary() && !table.isGlobalTemporary()) {
session.removeLocalTempTable(table);
return;
return true;
}
} else if (type == DbObject.INDEX) {
Index index = (Index) obj;
Table table = index.getTable();
if (table.isTemporary() && !table.isGlobalTemporary()) {
session.removeLocalTempTableIndex(index);
return;
return true;
}
} else if (type == DbObject.CONSTRAINT) {
Constraint constraint = (Constraint) obj;
Table table = constraint.getTable();
if (table.isTemporary() && !table.isGlobalTemporary()) {
session.removeLocalTempTableConstraint(constraint);
return;
return true;
}
}
checkWritingAllowed();
Boolean wasLocked = lockMetaNoWait(session);
Boolean wasLocked = lockMetaNoWait(session);// was
if(wasLocked==null){
removeSchemaObjectQueue.put(obj,session);
System.out.println("deferred removal scheduled="+obj.getName()+",wasLocked="+wasLocked);
return;
return false;
}
synchronized (this) {
String savedName = obj.getName();
Comment comment = findComment(obj);
if (comment != null) {
removeDatabaseObject(session, comment);
......@@ -1937,30 +1944,41 @@ public class Database implements DataHandler {
t.getSQL());
}
obj.removeChildrenAndResources(session);
}
System.out.println("Removing meta lock");
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);
removeMeta(session, id);
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());
removeSchemaObject(pair.getValue(),pair.getKey());
if(!removeSchemaObjectQueue.contains(pair.getKey())){
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 disk-based.
* Check if this database is disk-based.
*
* @return true if it is disk-based, false it it is in-memory only.
*/
......
......@@ -23,7 +23,7 @@ org.h2.tools.Console=Starts the H2 Console (web-) server, as well as the TCP and
org.h2.tools.Console.main=When running without options, -tcp, -web, -browser and -pg are started.\nOptions are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-url] Start a browser and connect to this URL\n[-driver] Used together with -url\: the driver\n[-user] Used together with -url\: the user name\n[-password] Used together with -url\: the password\n[-web] Start the web server with the H2 Console\n[-tool] Start the icon or window that allows to start a browser\n[-browser] Start a browser connecting to the web server\n[-tcp] Start the TCP server\n[-pg] Start the PG server\nFor each Server, additional options are available;\n for details, see the Server tool.\nIf a service can not be started, the program\n terminates with an exit code of 1.
org.h2.tools.ConvertTraceFile=Converts a .trace.db file to a SQL script and Java source code.\nSQL statement statistics are listed as well.
org.h2.tools.ConvertTraceFile.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-traceFile <file>] The trace file name (default\: test.trace.db)\n[-script <file>] The script file name (default\: test.sql)\n[-javaClass <file>] The Java directory and class file name (default\: Test)
org.h2.tools.CreateCluster=Creates a cluster from a standalone database.\nCopies a database to another location if required.
org.h2.tools.CreateCluster=Creates a cluster from a stand-alone database.\nCopies a database to another location if required.
org.h2.tools.CreateCluster.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-urlSource "<url>"] The database URL of the source database (jdbc\:h2\:...)\n[-urlTarget "<url>"] The database URL of the target database (jdbc\:h2\:...)\n[-user <user>] The user name (default\: sa)\n[-password <pwd>] The password\n[-serverList <list>] The comma separated list of host names or IP addresses
org.h2.tools.DeleteDbFiles=Deletes all files belonging to a database.\nThe database must be closed before calling this tool.
org.h2.tools.DeleteDbFiles.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-dir <dir>] The directory (default\: .)\n[-db <database>] The database name\n[-quiet] Do not print progress information
......
......@@ -701,9 +701,10 @@ public class TableView extends Table {
super.removeView(view);
// if this is a table expression and the last view to use it is
// being dropped - then remove itself from the schema
if(isTableExpression() && getViews()!=null && view.isBeingDropped()){
if(isTableExpression() && getViews()!=null){
// check if any database objects are left using this view
if(getViews().size()==0){
if(getViews().size()==0 && !isBeingDropped()){
System.out.println("Detected unused CTE: Trying to remove="+this.getName()+",session="+session.toString()+",sessionId="+session.getId());
session.getDatabase().removeSchemaObject(session,this);
}
}
......
......@@ -29,20 +29,23 @@ public class TestGeneralCommonTableQueries extends TestBase {
@Override
public void test() throws Exception {
testSimpleSelect();
testImpliedColumnNames();
testChainedQuery();
testParameterizedQuery();
testNumberedParameterizedQuery();
testColumnNames();
testInsert();
testUpdate();
testDelete();
testMerge();
testCreateTable();
testNestedSQL();
testRecursiveTable();
// testSimpleSelect();
// testImpliedColumnNames();
// testChainedQuery();
// testParameterizedQuery();
// testNumberedParameterizedQuery();
// testColumnNames();
//
// testInsert();
// testUpdate();
// testDelete();
// testMerge();
// testCreateTable();
// testNestedSQL();
// testRecursiveTable();
// turn on special locking debug
System.setProperty("h2.check2", "true");
// persistent cte tests
testPersistentNonRecursiveTableInCreateView();
......@@ -568,7 +571,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
String[] expectedColumnNames =new String[]{"SUB_TREE_ROOT_ID","TREE_LEVEL","PARENT_FK","CHILD_FK"};
int expectedNumberOfRows = 11;
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, SETUP_SQL,
WITH_QUERY, maxRetries-1);
WITH_QUERY, 0/*maxRetries-1*/);
}
private void testPersistentNonRecursiveTableInCreateView() throws Exception {
String SETUP_SQL = ""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论