db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kristian Waagan (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-4171) Connections to on-disk db go to in-memory db if in-memory db with same name is booted
Date Tue, 21 Apr 2009 08:25:47 GMT

    [ https://issues.apache.org/jira/browse/DERBY-4171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12701099#action_12701099
] 

Kristian Waagan commented on DERBY-4171:
----------------------------------------

I'm not sure yet, but there seems to be a problem in StorageFactoryService.getCanonicalServiceName:
	String protocolLeadIn = getType() + ":";
        int colon = name.indexOf( ':');
        if( colon > 1) // Subsubprotocols must be at least 2 characters long
        {
            if( ! name.startsWith( protocolLeadIn))
                return null; // It is not our database
            name = name.substring( colon + 1);
        }
        if( getType().equals( PersistentService.DIRECTORY)) // The default subsubprototcol
            protocolLeadIn = "";
        final String nm = name;

If there is no subsubprotocol present in the name, the code above will use the one from the
storage factory being checked. In the case of VFMemoryStorageFactory, getType() returns 'memory'.
If you connect to the on-disk db first, than in-memory and finally on-disk again, the order
of the services will be different and you'll (correctly) get a connection to the on-disk db.

Adding the following lines of code after 'int colon = ...' fixes the original repro:
        // Add the default subsubprotocol if there is none present.
        if (colon == -1) {
            name = PersistentService.DIRECTORY + ":" + name;
        }

The regression tests ran cleanly with the change, but I'm not yet sure if it is the correct
thing to do.
Also note that the problem will only happen when the databases have equal names and are "stored"
in the same canonical path (determined by java.io.File).

> Connections to on-disk db go to in-memory db if in-memory db with same name is booted
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4171
>                 URL: https://issues.apache.org/jira/browse/DERBY-4171
>             Project: Derby
>          Issue Type: Bug
>          Components: Store
>    Affects Versions: 10.5.1.1
>            Reporter: Knut Anders Hatlen
>
> When an in-memory database has been booted, subsequent attempts to connect to an ordinary
(on-disk) database with the same name as the in-memory database will connect to the in-memory
db.
> ij version 10.5
> ij> connect 'jdbc:derby:memory:MyDB;create=true'; -- with subprotocol memory
> ij> create table t (x varchar(30));
> 0 rows inserted/updated/deleted
> ij> insert into t values 'This is the in-memory backend';
> 1 row inserted/updated/deleted
> ij> connect 'jdbc:derby:MyDB;create=true'; --without subprotocol memory, should create
disk db
> WARNING 01J01: Database 'MyDB' not created, connection made to existing database instead.
> ij(CONNECTION1)> select * from t;
> X                             
> ------------------------------
> This is the in-memory backend 
> 1 row selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message