Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-522

DatasetGraphWithLock claims to support multiple readers but appears not to

    XMLWordPrintableJSON

Details

    Description

      This bug originates out of a StackOverflow question pertaining to jena-text

      http://stackoverflow.com/q/18385738/107591

      However upon investigation the culprit appears to be DatasetGraphWithLock, reproducing my analysis from my SO answer here:

      The issue is that the dataset with inference implicitly uses ARQ's standard in-memory Dataset implementation and this does not support transactions.

      However text datasets which correspond to DatasetGraphText internally (and in your stack trace) requires the wrapped dataset to support transactions and where they do not wraps them with DatasetGraphWithLock. It is this that appears to be encountering the problem with the lock, the documentation states that this should support multiple readers but having followed the logic of the code I'm not sure that it actually allows this.

      I put together the following test case which illustrates the issue:

          @Test
          public synchronized void dsg_with_lock_concurrency_02() throws InterruptedException, ExecutionException, TimeoutException {
              ExecutorService executor = Executors.newCachedThreadPool();
      
              try {
                  final DatasetGraphWithLock dsg = new DatasetGraphWithLock(DatasetGraphFactory.createMem());
      
                  Callable<Boolean> callable = new Callable<Boolean>() {
      
                      @Override
                      public Boolean call() throws Exception {
                          // Get a read lock
                          dsg.begin(ReadWrite.READ);
      
                          // Hold the lock for a short time
                          try {
                              Thread.sleep(500);
                          } catch (InterruptedException e) {
                              // Ignore error
                          }
      
                          // Release the lock
                          dsg.commit();
                          return true;
                      }
      
                  };
      
                  // Run the callable a bunch of times
                  List<Future<Boolean>> futures = new ArrayList<Future<Boolean>>();
                  for (int i = 0; i < 100; i++) {
                      futures.add(executor.submit(callable));
                  }
      
                  // Check all the futures come back OK
                  for (Future<Boolean> f : futures) {
                      Assert.assertTrue(f.get(3, TimeUnit.SECONDS));
                  }
              } finally {
                  executor.shutdownNow();
              }
          }
      

      So the problem appears to be that DatasetGraphWithLock claims multi-reader support but in reality does not allow this.

      Attachments

        1. JENA-522.patch
          5 kB
          Andy Seaborne

        Issue Links

          Activity

            People

              andy Andy Seaborne
              rvesse Rob Vesse
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: