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

Jena transaction isolation not working #687

Closed
alb3rtino opened this issue Oct 19, 2017 · 10 comments
Closed

Jena transaction isolation not working #687

alb3rtino opened this issue Oct 19, 2017 · 10 comments

Comments

@alb3rtino
Copy link

I have set DefaultIsolation = 8 in the parameters section of virtuoso.ini like described here.
Following runnable class reads a value and increments it by 1 inside a transaction:

class IncrementThread implements Runnable {
  @Override
  public void run() {
    Dataset ds = new VirtDataset("localhost:1111", "dba", "dba");
    ds.begin(ReadWrite.WRITE);
    try {
      Statement s = ds.getNamedModel(GRAPH).createResource(RES).getProperty(RDFS.label);
      int i = s.getLiteral().getInt();
      System.out.println(Thread.currentThread() + " reading value: " + i + ", writing value: " + ++i);
      s.changeLiteralObject(i);
      ds.commit();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      ds.end();
    }
    ds.close();
  }
}

now when running 5 threads:

public void start() {
  // clear graph, set value initial value to 0
  Dataset ds = new VirtDataset("localhost:1111", "dba", "dba");
  Model m = ds.getNamedModel(GRAPH);
  m.removeAll();
  m.createResource(RES).addProperty(RDFS.label, m.createTypedLiteral(0));
  ds.close();
  // run threads
  for (int i = 1; i <= 5; i++) {
    Thread t = new Thread(new IncrementThread());
    t.start();
  }
}

the output is something similar to this:

Thread[Thread-2,5,main] reading value: 0, writing value: 1
Thread[Thread-3,5,main] reading value: 0, writing value: 1
Thread[Thread-1,5,main] reading value: 0, writing value: 1
Thread[Thread-4,5,main] reading value: 0, writing value: 1
Thread[Thread-5,5,main] reading value: 1, writing value: 2

when it should be something like this:

Thread[Thread-1,5,main] reading value: 0, writing value: 1
Thread[Thread-2,5,main] reading value: 1, writing value: 2
Thread[Thread-3,5,main] reading value: 2, writing value: 3
Thread[Thread-5,5,main] reading value: 3, writing value: 4
Thread[Thread-4,5,main] reading value: 4, writing value: 5
@smalinin
Copy link
Collaborator

Jena provider uses TRANSACTION_READ_COMMITTED always.
It is hardcoded in VirtTransactionHandler.java and it doesn't use the Default Isolation

@alb3rtino
Copy link
Author

and are there any plans on supporting the other transaction modes as well?

@smalinin
Copy link
Collaborator

Support for set IsolationLevel was added to VirtDataset class, it will be in Git soon.
Example:

        VirtDataset ds = new VirtDataset("localhost:1111", "dba", "dba");

        ds.setIsolationLevel(VirtIsolationLevel.SERIALIZABLE);


@H-B-Schmidt
Copy link

Will this happen really soon ?

@smalinin
Copy link
Collaborator

jena3_src.zip
Some delay with updating git, please use the attached virt_jena3.jar (in zip with sources)

@H-B-Schmidt
Copy link

So without setting ds.setIsolationLevel() the jena provider is now using the server setting for isolation ?

@alb3rtino
Copy link
Author

alb3rtino commented Dec 19, 2017

did you test this? when i'm applying the changes from the provided zip and setting

ds.setIsolationLevel(VirtIsolationLevel.SERIALIZABLE);

i keep getting a

virtuoso.jdbc4.VirtuosoException: SR172: Transaction deadlocked

exception and virtuoso keeps telling me:

12:31:24 WARNING: * Monitor: Should read for update because lock escalation from shared to exclusive fails frequently (1)
12:31:24 WARNING: * Monitor: Should read for update because lock escalation from shared to exclusive fails frequently (2)

@smalinin
Copy link
Collaborator

I didn't play with your example. I tested Jena provider, that it set properly isolation level for connection. The one update in RDF storage could change many data, it doesn't look like update in an one SQL table.
Note the next:

  1. Jena provider use mode log_enable=1 by default, if you don't use log_enable option in the URL connection string

  2. You could change Concurrency mode for SPARUL queries and graph Insert/Update/Delete operations.
    The supported concurrency modes:
    VirtGraph.CONCUR_DEFAULT
    VirtGraph.CONCUR_PESSIMISTIC
    VirtGraph.CONCUR_OPTIMISTIC

Example:

        VirtDataset ds = new VirtDataset("localhost:1111", "dba", "dba");
        ds.setConcurrencyMode(VirtGraph.CONCUR_PESSIMISTIC);

Try to use VirtGraph.CONCUR_PESSIMISTIC mode.
The default concurrency mode works better with readonly operations.

@H-B-Schmidt
Copy link

Will the provided jena3_src.zip find its way into this repository soon ?

pkleef pushed a commit that referenced this issue Jan 25, 2018
Add set/getIsolationLevel to VirtDataset
@smalinin
Copy link
Collaborator

It looks, that patch for Git was missed. The fix has been added and Git sources was updated.

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

No branches or pull requests

3 participants