Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database closed #3678

Closed
lvca opened this issue Mar 2, 2015 · 7 comments
Closed

Database closed #3678

lvca opened this issue Mar 2, 2015 · 7 comments
Assignees
Milestone

Comments

@lvca
Copy link
Member

lvca commented Mar 2, 2015

Issue from Riccardo Tasso:

Hi, I am migrating my application to Orient 2.0.3, from 1.7.10.

I have a UnitTest which throws an Exception, and I can't figure out why. Here is the stacktrace:

Running it.celi.cbook.temp.OrientCloseDatabaseTest
feb 24, 2015 11:36:36 AM com.orientechnologies.common.log.OLogManager log
INFORMAZIONI: OrientDB auto-config DISKCACHE=4.061MB (heap=1.748MB os=7.857MB disk=23.038MB)
feb 24, 2015 11:36:37 AM com.orientechnologies.common.log.OLogManager log
AVVERTENZA: {db=temp} Requested command 'Committing the active transaction to create the new type 'Person' as subclass of 'V'. The transaction will be reopen right after that. To avoid this behavior create the classes outside the transaction' must be executed outside active transaction: the transaction will be committed and reopen right after it. To avoid this behavior execute it outside a transaction
feb 24, 2015 11:36:37 AM com.orientechnologies.common.log.OLogManager log
AVVERTENZA: {db=temp} Requested command 'Committing the active transaction to create the new type 'City' as subclass of 'V'. The transaction will be reopen right after that. To avoid this behavior create the classes outside the transaction' must be executed outside active transaction: the transaction will be committed and reopen right after it. To avoid this behavior execute it outside a transaction
feb 24, 2015 11:36:37 AM com.orientechnologies.common.log.OLogManager log
AVVERTENZA: {db=temp} Requested command 'Committing the active transaction to create the new type 'lives' as subclass of 'E'. The transaction will be reopen right after that. To avoid this behavior create the classes outside the transaction' must be executed outside active transaction: the transaction will be committed and reopen right after it. To avoid this behavior execute it outside a transaction
Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.194 sec <<< FAILURE! - in it.celi.cbook.temp.OrientCloseDatabaseTest
test1(it.celi.cbook.temp.OrientCloseDatabaseTest)  Time elapsed: 0.027 sec  <<< ERROR!
com.orientechnologies.orient.core.exception.ODatabaseException: Database 'memory:temp' is closed
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.checkOpeness(ODatabaseDocumentTx.java:2590)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.executeReadRecord(ODatabaseDocumentTx.java:1527)
    at com.orientechnologies.orient.core.tx.OTransactionNoTx.loadRecord(OTransactionNoTx.java:80)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.load(ODatabaseDocumentTx.java:1424)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.load(ODatabaseDocumentTx.java:117)
    at com.orientechnologies.orient.core.id.ORecordId.getRecord(ORecordId.java:313)
    at com.tinkerpop.blueprints.impls.orient.OrientVertexIterator.createWrapper(OrientVertexIterator.java:52)
    at com.tinkerpop.blueprints.impls.orient.OrientVertexIterator.createWrapper(OrientVertexIterator.java:34)
    at com.orientechnologies.orient.core.iterator.OLazyWrapperIterator.hasNext(OLazyWrapperIterator.java:79)
    at com.orientechnologies.common.collection.OMultiCollectionIterator.getNextPartial(OMultiCollectionIterator.java:169)
    at com.orientechnologies.common.collection.OMultiCollectionIterator.hasNext(OMultiCollectionIterator.java:69)
    at com.orientechnologies.orient.core.sql.method.misc.OSQLMethodField.execute(OSQLMethodField.java:66)
    at com.orientechnologies.orient.core.sql.methods.OSQLMethodRuntime.execute(OSQLMethodRuntime.java:139)
    at com.orientechnologies.orient.core.sql.filter.OSQLFilterItemAbstract.transformValue(OSQLFilterItemAbstract.java:140)
    at com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime.execute(OSQLFunctionRuntime.java:128)
    at com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime.getValue(OSQLFunctionRuntime.java:142)
    at com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition.evaluate(OSQLFilterCondition.java:307)
    at com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition.evaluate(OSQLFilterCondition.java:80)
    at com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition.evaluate(OSQLFilterCondition.java:313)
    at com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition.evaluate(OSQLFilterCondition.java:79)
    at com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition.evaluate(OSQLFilterCondition.java:313)
    at com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition.evaluate(OSQLFilterCondition.java:79)
    at com.orientechnologies.orient.core.sql.filter.OSQLFilter.evaluate(OSQLFilter.java:100)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLResultsetAbstract.evaluateRecord(OCommandExecutorSQLResultsetAbstract.java:386)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLResultsetAbstract.filter(OCommandExecutorSQLResultsetAbstract.java:376)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.executeSearchRecord(OCommandExecutorSQLSelect.java:505)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.fetchFromTarget(OCommandExecutorSQLSelect.java:1315)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.executeSearch(OCommandExecutorSQLSelect.java:433)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.execute(OCommandExecutorSQLSelect.java:391)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.execute(OCommandExecutorSQLDelegate.java:64)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.executeCommand(OAbstractPaginatedStorage.java:1184)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:1173)
    at com.orientechnologies.orient.core.sql.query.OSQLQuery.run(OSQLQuery.java:71)
    at com.orientechnologies.orient.core.sql.query.OSQLSynchQuery.run(OSQLSynchQuery.java:85)
    at com.orientechnologies.orient.core.query.OQueryAbstract.execute(OQueryAbstract.java:33)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.query(ODatabaseDocumentTx.java:630)
    at it.celi.cbook.temp.OrientCloseDatabaseTest.test1(OrientCloseDatabaseTest.java:77)

The problem seems to be that I'm executing a query over a closed database. Anyway it should not be closed, since it's a pool.
The strange thing is also that with another query (test2) which doesn't involve edges, the exception is not thrown.

Am I using the API in a wrong way?
Looking at documentation ( http://www.orientechnologies.com/docs/last/orientdb.wiki/Graph-Factory.html ) everything seems ok.

@lvca lvca added the bug label Mar 2, 2015
@lvca lvca added this to the 2.0.4 milestone Mar 2, 2015
@lvca
Copy link
Member Author

lvca commented Mar 2, 2015

It seems that one of the quickest way to release a OrienDatabase from pool without releasing it it's the following:

public static void closeQuietly(ODatabaseDocument db) {
    try {
        if (isNotNull(db)) {
            OrientGraph graph = new OrientGraph(db.getURL());
            graph.shutdown();
        }
    } catch (Exception ignored) {
        log.error("Error closing db:: ", ignored);
    }
}

It sounds a bit strange but works.

@lvca
Copy link
Member Author

lvca commented Mar 2, 2015

Test Case:

package it.celi.cbook.temp;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.hamcrest.Matchers;
import org.junit.BeforeClass;
import org.junit.Test;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;

public class OrientCloseDatabaseTest {

    private static OrientGraphFactory pool;

    @BeforeClass
    public static void setup() {
        createGraph();

        pool = new OrientGraphFactory("memory:temp", "admin", "admin").setupPool(1, 10);
        try(ODatabaseDocumentTx db = pool.getDatabase()) {
            OrientGraph graph = new OrientGraph(db);
            fillTheGraph(graph);
        }
    }

    private static void createGraph() {
        OrientGraph g = new OrientGraph("memory:temp", "admin", "admin");
        g.shutdown();
    }

    private static void fillTheGraph(OrientGraph graph) {
        OrientVertex riccardo = createPerson(graph, "riccardo", 32);
        OrientVertex luca = createPerson(graph, "luca", 40);
        OrientVertex luigi = createPerson(graph, "luigi", 30);

        OrientVertex milano = createCity(graph, "milano", 1332516);
        OrientVertex roma = createCity(graph, "roma", 1332516);
        OrientVertex unknown = createCity(graph, "unknown", -1);

        riccardo.addEdge("lives", milano);
        luca.addEdge("lives", roma);
        luigi.addEdge("lives", unknown);
    }

    private static OrientVertex createPerson(OrientGraph graph, String localName, int age) {
        OrientVertex a = graph.addVertex("class:Person");
        a.setProperties(
                "localName", localName,
                "age", age
        );
        return a;
    }

    private static OrientVertex createCity(OrientGraph graph, String localName, int population) {
        OrientVertex a = graph.addVertex("class:City");
        a.setProperties(
                "localName", localName,
                "population", population
        );
        return a;
    }

    @Test
    public void test1() {
        try (ODatabaseDocumentTx db = pool.getDatabase()) {

            String queryText = "SELECT @rid as rid, localName FROM Person WHERE ( 'milano' IN out('lives').localName OR 'roma' IN out('lives').localName ) ORDER BY age ASC";
            OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(queryText);
            List<ODocument> results = db.query(query);
            assertNotNull(results);
            assertThat(results.size(), Matchers.greaterThan(0));

        }
    }

    @Test
    public void test2() {
        try (ODatabaseDocumentTx db = pool.getDatabase()) {

            String queryText = "SELECT @rid as rid, localName FROM Person WHERE age > 30";
            OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(queryText);
            List<ODocument> results = db.query(query);
            assertNotNull(results);
            assertThat(results.size(), Matchers.greaterThan(0));

        }
    }

}

@lvca lvca modified the milestones: 2.0.4, 2.0.5 Mar 4, 2015
@tglman
Copy link
Member

tglman commented Mar 4, 2015

fixed on hotfix branch, leaving open till the fix is ported to develop

@lvca
Copy link
Member Author

lvca commented Mar 4, 2015

Can you just cherry-pick it?

@tglman
Copy link
Member

tglman commented Mar 4, 2015

yes, but we have some issue with the new sql parser that i prefer will be fixed before

tglman added a commit that referenced this issue Mar 5, 2015
Conflicts:
	graphdb/src/main/java/com/orientechnologies/orient/graph/sql/OCommandExecutorSQLDeleteEdge.java
@tglman
Copy link
Member

tglman commented Mar 5, 2015

merged in develop closing

@tglman tglman closed this as completed Mar 5, 2015
@lvca
Copy link
Member Author

lvca commented Mar 5, 2015

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants