Forum Stats

  • 3,770,000 Users
  • 2,253,045 Discussions
  • 7,875,263 Comments

Discussions

How to delete Database which is opened by JEConnection.openDatabase()

527078
527078 Member Posts: 33
edited Sep 11, 2006 8:17AM in Berkeley DB Java Edition
How can i delete (or drop) a Database which is opened by JEConnection.openDatabase().


/*
* Use JEConnection.openDatabase() to obtain a cached Database
* handle. Do not call close() on Database handles obtained
* using this method.
*/

But without closing a Database handle how can i remove the Database?

Thanks,

Katta.

Comments

  • Bogdan Coman-Oracle
    Bogdan Coman-Oracle Member Posts: 676
    edited Sep 7, 2006 12:03PM
    Hi Katta,

    If you want to remove the database, you should use removeDatabase ( http://www.sleepycat.com/jedocs/java/com/sleepycat/je/Environment.html#removeDatabase(com.sleepycat.je.Transaction,%20java.lang.String) ) - but you'll not be able to use the handle after that, because the database must be closed when you perform this action on it.

    If you want to empty the database, discarding all records it contains, you should use truncateDatabase ( http://www.sleepycat.com/jedocs/java/com/sleepycat/je/Environment.html#truncateDatabase(com.sleepycat.je.Transaction,%20java.lang.String,%20boolean) ). It deletes every record in the database and optionally returns the number of records that were deleted. Note that it is much less expensive to truncate a database without counting the number of records deleted than it is to truncate and count.

    JE Administrative Methods: http://www.sleepycat.com/jedocs/GettingStartedGuide/DBAdmin.html


    Hope this helps,
    Bogdan Coman
  • Charles Lamb
    Charles Lamb Member Posts: 836
    edited Sep 7, 2006 1:35PM
    Hi Katta,

    JEConnection.openDatabase does return a com.sleepycat.je.Database object, but as the documentation says, you should not close it (and by implication you should not delete it). The reason is that the Database object is cached in a Map so that it's shared across connections (and also to save the overhead of re-opening it each time a connection is made to the database using JCA).

    Although I have not tried it, I believe it will be ok to call Environment.removeDatabase on that database (after calling JEConnection.close() on the connection and close on the Database object) as long as you never use it after removing it.

    Please let me know if that works out ok.

    Charles Lamb

    Message was edited by:
    Charles Lamb
  • 527078
    527078 Member Posts: 33
    Hi Charles,

    I have done what your suggested way.(after calling JEConnection.close() on the connection and close on the Database object). But when i call the Environment.removeDatabase i got the below exception.

    11:32:51,316 ERROR [BerkelyDBConfig] Caught Exception and message is::(JE 3.0.12) Lock expired. Locker 63_http-0.0.0.0-8080-1_Txn: waited for lock on database=_jeNameMap node=14 type=WRITE grant=WAIT_PROMOTION timeoutMillis=500 startTime=1157695370318 endTime=1157695371316
    Owners: [<LockInfo locker="-1_http-0.0.0.0-8080-2_BasicLocker" type="READ"/>, <LockInfo locker="-1_http-0.0.0.0-8080-1_BasicLocker" type="READ"/>, <LockInfo locker="63_http-0.0.0.0-8080-1_Txn" type="READ"/>]
    Waiters: []
    Transaction 63_http-0.0.0.0-8080-1_Txn owns 14 <LockInfo locker="63_http-0.0.0.0-8080-1_Txn" type="READ"/>
    Transaction 63_http-0.0.0.0-8080-1_Txn waits for node 14

    11:32:51,316 ERROR [STDERR] com.sleepycat.je.DeadlockException: (JE 3.0.12) Lock expired. Locker 63_http-0.0.0.0-8080-1_Txn: waited for lock on database=_jeNameMap node=14 type=WRITE grant=WAIT_PROMOTION timeoutMillis=500 startTime=1157695370318 endTime=1157695371316
    Owners: [<LockInfo locker="-1_http-0.0.0.0-8080-2_BasicLocker" type="READ"/>, <LockInfo locker="-1_http-0.0.0.0-8080-1_BasicLocker" type="READ"/>, <LockInfo locker="63_http-0.0.0.0-8080-1_Txn" type="READ"/>]
    Waiters: []
    Transaction 63_http-0.0.0.0-8080-1_Txn owns 14 <LockInfo locker="63_http-0.0.0.0-8080-1_Txn" type="READ"/>
    Transaction 63_http-0.0.0.0-8080-1_Txn waits for node 14
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.txn.LockManager.lock(LockManager.java:267)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.txn.Txn.lockInternal(Txn.java:288)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.txn.Locker.lock(Locker.java:258)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.CursorImpl.lockLNDeletedAllowed(CursorImpl.java:2321)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.CursorImpl.lockLN(CursorImpl.java:2249)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.CursorImpl.searchAndPosition(CursorImpl.java:1941)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.DbTree.lockNameLN(DbTree.java:358)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.DbTree.dbRemove(DbTree.java:448)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.EnvironmentImpl.dbRemove(EnvironmentImpl.java:1220)


    Once more question is how can i release the lock on myDbEnv folder which is locked by Environment ?

    Thanks,
    Katta.
  • 527078
    527078 Member Posts: 33
    Hi Bogdan Coman,

    The above methods working fine without using JCA. But i'm accessing the myDbEnv using JCA. When i did the the above methods i got the following exception.

    11:32:51,316 ERROR [BerkelyDBConfig] Caught Exception and message is::(JE 3.0.12) Lock expired. Locker 63_http-0.0.0.0-8080-1_Txn: waited for lock on database=_jeNameMap node=14 type=WRITE grant=WAIT_PROMOTION timeoutMillis=500 startTime=1157695370318 endTime=1157695371316
    Owners: [<LockInfo locker="-1_http-0.0.0.0-8080-2_BasicLocker" type="READ"/>, <LockInfo locker="-1_http-0.0.0.0-8080-1_BasicLocker" type="READ"/>, <LockInfo locker="63_http-0.0.0.0-8080-1_Txn" type="READ"/>]
    Waiters: []
    Transaction 63_http-0.0.0.0-8080-1_Txn owns 14 <LockInfo locker="63_http-0.0.0.0-8080-1_Txn" type="READ"/>
    Transaction 63_http-0.0.0.0-8080-1_Txn waits for node 14

    11:32:51,316 ERROR [STDERR] com.sleepycat.je.DeadlockException: (JE 3.0.12) Lock expired. Locker 63_http-0.0.0.0-8080-1_Txn: waited for lock on database=_jeNameMap node=14 type=WRITE grant=WAIT_PROMOTION timeoutMillis=500 startTime=1157695370318 endTime=1157695371316
    Owners: [<LockInfo locker="-1_http-0.0.0.0-8080-2_BasicLocker" type="READ"/>, <LockInfo locker="-1_http-0.0.0.0-8080-1_BasicLocker" type="READ"/>, <LockInfo locker="63_http-0.0.0.0-8080-1_Txn" type="READ"/>]
    Waiters: []
    Transaction 63_http-0.0.0.0-8080-1_Txn owns 14 <LockInfo locker="63_http-0.0.0.0-8080-1_Txn" type="READ"/>
    Transaction 63_http-0.0.0.0-8080-1_Txn waits for node 14
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.txn.LockManager.lock(LockManager.java:267)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.txn.Txn.lockInternal(Txn.java:288)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.txn.Locker.lock(Locker.java:258)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.CursorImpl.lockLNDeletedAllowed(CursorImpl.java:2321)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.CursorImpl.lockLN(CursorImpl.java:2249)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.CursorImpl.searchAndPosition(CursorImpl.java:1941)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.DbTree.lockNameLN(DbTree.java:358)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.DbTree.dbRemove(DbTree.java:448)
    11:32:51,316 ERROR [STDERR] at com.sleepycat.je.dbi.EnvironmentImpl.dbRemove(EnvironmentImpl.java:1220)

    Thanks,
    Katta.
  • Charles Lamb
    Charles Lamb Member Posts: 836
    Hi Katta,

    I think what is happening is that the other Database instances in the pool are still "open" and are holding locks to the _jeNameMap database (an internal JE database). I suspect that what has to happen is that the connection pool has to be cleaned up and all databases closed before this operation will work. So, please add the following method to JEConnection.java:

    public void destroy()
    throws ResourceException {
    mc.destroy();
    }

    and then call it when you know that there are no in-use Database handles on that database. Calling this method should close up all Database handles and clear the connection pool. However, this will also close your Environment so may have to call your method BerkelyDBConfig.getConnection() again in order to get a new connection manager.

    Please try that and let me know how it goes.

    Thanks.

    Charles Lamb
  • 527078
    527078 Member Posts: 33
    Hi Charles ,

    I added the destroy() method to JEConnection.java and rebuild the jejca.jar. I got the following exception.

    (JE 3.0.12) Can't call Database.get: Database state can't be DbState.CLOSED must be DbState.OPEN
    at org.apache.lucene.store.je.File.exists(File.java:129)
    at org.apache.lucene.store.je.File.<init>(File.java:61)
    at org.apache.lucene.store.je.JEIndexOutput.<init>(JEIndexOutput.java:55)
    at org.apache.lucene.store.je.JEDirectory.createOutput(JEDirectory.java:114)
    at org.apache.lucene.index.FieldInfos.write(FieldInfos.java:255)
    at org.apache.lucene.index.SegmentMerger.mergeFields(SegmentMerger.java:176)
    at org.apache.lucene.index.SegmentMerger.merge(SegmentMerger.java:88)
    at org.apache.lucene.index.IndexWriter.mergeSegments(IndexWriter.java:709)
    at org.apache.lucene.index.IndexWriter.mergeSegments(IndexWriter.java:686)
    at org.apache.lucene.index.IndexWriter.maybeMergeSegments(IndexWriter.java:674)
    at org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:479)
    at org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:462)

    Thanks,

    Katta.
  • Charles Lamb
    Charles Lamb Member Posts: 836
    Katta,

    Are you calling destroy() before you call Environment.removeDatabase()? Are there any threads that are accessing the Database that you're deleting after you call destroy()? Is it possible that the stack trace below is from a thread that is accessing the old database destroy() has been called?

    Please email me at charles.lamb !-ATSIGN-! oracle.com. Perhaps we can reduce the latency of this forum.

    Thanks.

    Charles Lamb
This discussion has been closed.