Transaction support of InMemoryStoreManager?


christian...@...
 

Hi.

I am doing some experiments with the InMemoryStoreManager and facing some issue with transactions in that case. When I produce vertices in one thread and commit them in bulk, that commit seems to be not atomic for other threads. I wrote the following test to reproduce the issue:

  @Test
  void testTxAtomicity () throws InterruptedException {
    final int ITERATIONS = 100;
    final int CHUNK_SIZE = 10;

    final JanusGraph graph = JanusGraphFactory.open (GraphDatabaseConfiguration.buildGraphConfiguration ()
                                                                               .set (GraphDatabaseConfiguration.STORAGE_BACKEND,
                                                                                     StandardStoreManager.IN_MEMORY.getManagerClass ())
                                                                               .getConfiguration ());

    final Thread producer = new Thread ( () -> {
      for (int i = 0; i < ITERATIONS; i++) {
        for (int j = 0; j < CHUNK_SIZE; j++) {
          graph.addVertex ("id", i * CHUNK_SIZE + j);
          Thread.yield ();
        }
        graph.tx ().commit ();
      }
    });
    producer.start ();

    try {
      final GraphTraversalSource g = graph.traversal ();
      for (int i = 0; i < ITERATIONS; i++) {
        final int count = g.V ().toList ().size ();
        assertTrue ("Expecting a multitude of " + CHUNK_SIZE + " but received " + count, count % CHUNK_SIZE == 0);
        Thread.sleep (10);
      }
      cache.rollback ();
    } finally {
      producer.join ();
    }
  }

The producer creates vertices and commits them in chunks of 10. Hence, I would expect that other threads will see all of these 10 or none of them. Unfortunately, there seems to be no such atomicity, at least the reading thread sometimes sees only a few of the commited vertices. Am I doing something wrong here or does the InMemoryStoreManager not offer any atomicity guarantees?

Regards
Christian

Join janusgraph-users@lists.lfaidata.foundation to automatically receive all group messages.