orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

Issues with OrientVertex#addEdge after OrientEdge#remove

Open Vannav opened this issue 10 years ago • 2 comments

OrientDB Version, operating system, or hardware.

  • v2.2.9

Operating System

  • [x] Windows

Expected behavior and actual behavior

Steps to reproduce the problem

I'm trying to update the connection of vertices by removing the edge and then adding a new edge via java graph api. Multiple issues arise which are described in the following test.

[3] and [4] are working without errrors or warnings but shouldn't this be achived with the reload() call?

[5] is weird because the document state is valid (i.e. only one edge) after commit but is not persited to the db.

@Test
   public void testDeleteAndAddNewEdge()
   {
      OrientGraph graph = factory.getTx();

      OrientVertex v1 = graph.addTemporaryVertex( "Test1V" );
      v1.getRecord().field( "name", "v1" );
      v1.save();

      OrientVertex v2 = graph.addTemporaryVertex( "Test2V" );
      v2.getRecord().field( "name", "v2" );
      v2.save();

      graph.commit();

      System.out.println( v1.getRecord().toJSON() );
      System.out.println( v2.getRecord().toJSON() );

      Assert.assertTrue( v1.getIdentity().isPersistent() );
      Assert.assertTrue( v2.getIdentity().isPersistent() );

      for( int i = 0; i < 5; i++ )
      {
         System.out.println( i );

         // Remove all edges
         List<Edge> edges = new ArrayList<>();
         v1.getEdges( Direction.OUT, "TestE" ).forEach( edges::add );
         edges.forEach( Edge::remove );


         // -------------------------
         // [1] WITHOUT RELOAD
         // ==> java.lang.NullPointerException on commit
         // at com.tinkerpop.blueprints.impls.orient.OrientElement.checkClass(OrientElement.java:606)
         // at com.tinkerpop.blueprints.impls.orient.OrientEdge.remove(OrientEdge.java:384)
         // at java.util.ArrayList.forEach(Unknown Source)


         // -------------------------
         // [2] WITH RELOAD
         // ==> WARNING: Found record in transaction with the same RID #152:4 but different instance. Probably the record has been loaded from another transaction and reused on the current one: reload it from current transaction before to update or delete it

         // v1.reload();
         // v2.reload();


         // -------------------------
         // [3] WITH NEW INSTANCE
         // ==> No warnings! But not always feasible because more tracking and vertex management required

         // v1 = new OrientVertex( null, v1.getIdentity() );
         // v2 = new OrientVertex( null, v2.getIdentity() );


         // -------------------------
         // [4] WITH rawElement REFLECTION TO 'RELOAD'
         // ==> No warnings! Same as above

         // try
         // {
         //    Field field = OrientElement.class.getDeclaredField( "rawElement" );
         //    field.setAccessible( true );
         //    field.set( v1, v1.getIdentity() );
         //    field.set( v2, v2.getIdentity() );
         // }
         // catch( Exception e )
         // {
         //    throw new IllegalStateException( e );
         // }

         // Add new edge
         v1.addEdge( "TestE", v2 );

         graph.commit();

         // -------------------------
         // [5] WITH RELOAD AFTER COMMIT
         // ==> WARNING: Record (#138:84) is null
         // Edges are deleted but but the links in both vertices are not updated
         // "out_TestE":["#140:82","#137:89","#138:84","#139:89","#140:83"]
         // "in_TestE":["#140:82","#137:89","#138:84","#139:89","#140:83"]

         // v1.reload();
         // v2.reload();



         System.out.println( v1.getRecord().toJSON() );
         System.out.println( v2.getRecord().toJSON() );

         Assert.assertEquals( v2.getId(), v1.getVertices( Direction.OUT, "TestE" ).iterator().next().getId() );
         Assert.assertEquals( v1.getId(), v2.getVertices( Direction.IN, "TestE" ).iterator().next().getId() );
      }
   }

Vannav avatar Oct 04 '16 14:10 Vannav

Hi! Any news on this problem? Or suggestions how to work around it? Thanks!

Vannav avatar Dec 01 '16 15:12 Vannav

hi,

There was a bug on the refresh of the local cache, i fixed it and added the relative test, is going to be relelased in 2.2.14

bye

tglman avatar Dec 14 '16 18:12 tglman