Urgent issue with Sparksee session closing.

47 views
Skip to first unread message

Ray Neiheiser

unread,
Apr 2, 2017, 4:54:35 PM4/2/17
to Sparksee
I have the following method:

@Override
public boolean applyCreate(final RelationshipStorage storage, final long snapshotId)
{
   
final Session sess = db.newSession();
   
final Graph graph = sess.getGraph();
   
final Objects startObjs = findNode(graph, storage.getStartNode());
   
final Objects endObjs = findNode(graph, storage.getEndNode());

   
if(startObjs == null || endObjs == null)
   
{
       
if(startObjs != null)
       
{
            startObjs
.close();
       
}
       
if(endObjs != null)
       
{
            endObjs
.close();
       
}
        sess
.close();
       
return false;
   
}

   
final ObjectsIterator startIt = startObjs.iterator();
   
final ObjectsIterator endIt = endObjs.iterator();

   
while(startIt.hasNext())
   
{
       
long startNode = startIt.next();
       
while (endIt.hasNext())
       
{
           
final long endNode = endIt.next();

           
int edgeType = graph.findType(storage.getId());
           
if (Type.InvalidType == edgeType)
           
{
                edgeType
= graph.newEdgeType(storage.getId(), true, false);
           
}

           
final long relationship = graph.findOrCreateEdge(edgeType, startNode, endNode);
           
for (final Map.Entry<String, Object> entry : storage.getProperties().entrySet())
           
{
                graph
.setAttribute(relationship,
                       
SparkseeUtils.createOrFindAttributeType(entry.getKey(), entry.getValue(), Type.GlobalType, graph),
                       
SparkseeUtils.getValue(entry.getValue()));
           
}

           
int snapshotAttributeId = SparkseeUtils.createOrFindAttributeType(Constants.TAG_SNAPSHOT_ID, snapshotId, Type.GlobalType, graph);
            graph
.setAttribute(relationship, snapshotAttributeId, SparkseeUtils.getValue(snapshotId));

           
try
            {
               
int hashAttributeId = SparkseeUtils.createOrFindAttributeType(Constants.TAG_HASH, " ", Type.GlobalType, graph);
                graph
.setAttribute(relationship, hashAttributeId, SparkseeUtils.getValue(HashCreator.sha1FromRelationship(storage)));
           
}
           
catch (NoSuchAlgorithmException e)
           
{
               
Log.getLogger().warn("Couldn't execute create node transaction in server:  " + id, e);
                endObjs
.close();
                startObjs
.close();
                startIt
.close();
                endIt
.close();
                sess
.close();
               
return false;
           
}
           
Log.getLogger().warn("Successfully executed create relationship transaction in server:  " + id);
       
}
   
}

    startObjs
.close();
    endObjs
.close();
    startIt
.close();
    endIt
.close();
    sess
.close();
   
return true;
}

/**
 * Return a Objects array matching the nodeType and properties.
 * @param graph the graph.
 * @param storage the storage of the node.
 * @return Objects which match the attributes.
 */
private Objects findNode(final Graph graph, final NodeStorage storage)
{
   
Objects objects = null;

   
if(!storage.getId().isEmpty())
   
{
       
int nodeTypeId = SparkseeUtils.createOrFindNodeType(storage, graph);
        objects
= graph.select(nodeTypeId);
   
}

   
for (final Map.Entry<String, Object> entry : storage.getProperties().entrySet())
   
{
       
final int attributeId = graph.findAttribute(Type.GlobalType, entry.getKey());

       
if (objects == null || objects.isEmpty())
       
{
           
if(objects != null)
           
{
                objects
.close();
           
}
            objects
= graph.select(attributeId, Condition.Equal, SparkseeUtils.getValue(entry.getValue()));
       
}
       
else
        {
            objects
= graph.select(attributeId, Condition.Equal, SparkseeUtils.getValue(entry.getValue()), objects);
       
}
   
}
   
return objects;
}


Which always throws:

Closing sparkseejava.lang.RuntimeException: Session data still active when closing
at com.sparsity.sparkseejavawrapJNI.delete_sparksee_gdb_Session(Native Method)
at com.sparsity.sparksee.gdb.Session.delete(Session.java:32)
at com.sparsity.sparksee.gdb.Session.close(Session.java:40)
at main.java.com.bag.server.database.SparkseeDatabaseAccess.applyCreate(SparkseeDatabaseAccess.java:595)
at main.java.com.bag.main.DatabaseLoader.loadGraph(DatabaseLoader.java:97)
at main.java.com.bag.main.DatabaseLoader.main(DatabaseLoader.java:191)

on the last "sess.close" what is the problem of this?

c3po.ac

unread,
Apr 3, 2017, 3:00:11 AM4/3/17
to Sparksee

Hi,


I think that the problem may be this line in "findNode":


objects = graph.select(attributeId, Condition.Equal, SparkseeUtils.getValue(entry.getValue()), objects);



The "objects" reference that you use as a restriction argument will be replaced by the new Objects created and may have not been disposed by the garbage collector by the time the session is closed. You may want to replace it for something like this:


Objects tempObj = graph.select(attributeId, Condition.Equal, SparkseeUtils.getValue(entry.getValue()), objects);
objects
.close();
objects
= tempObj;


You may also want to close the iterators (startIt and endIt) before closing the objects (endObjs, startObjs), but I don't think that's your current issue.


Best regards


El diumenge, 2 abril de 2017 22:54:35 UTC+2, Ray Neiheiser va escriure:

Ray Neiheiser

unread,
Apr 3, 2017, 10:35:07 AM4/3/17
to Sparksee
That worked.

Thanks a lot!
Reply all
Reply to author
Forward
0 new messages