Nodes are now inserted/updated in the database in the same order
they were marked as dirty in the transactor. This is to avoid exceptions when databases check for relational constraints in inserted objects.
This commit is contained in:
parent
77fbf7e5b4
commit
d269727524
1 changed files with 13 additions and 103 deletions
|
@ -22,6 +22,7 @@ public class Transactor extends Thread {
|
||||||
|
|
||||||
// List of nodes to be updated
|
// List of nodes to be updated
|
||||||
private HashMap nodes;
|
private HashMap nodes;
|
||||||
|
private ArrayList nodesArray;
|
||||||
// List of visited clean nodes
|
// List of visited clean nodes
|
||||||
private HashMap cleannodes;
|
private HashMap cleannodes;
|
||||||
// Is a transaction in progress?
|
// Is a transaction in progress?
|
||||||
|
@ -44,6 +45,7 @@ public class Transactor extends Thread {
|
||||||
super (group, runnable, group.getName ());
|
super (group, runnable, group.getName ());
|
||||||
this.nmgr = nmgr;
|
this.nmgr = nmgr;
|
||||||
nodes = new HashMap ();
|
nodes = new HashMap ();
|
||||||
|
nodesArray = new ArrayList ();
|
||||||
cleannodes = new HashMap ();
|
cleannodes = new HashMap ();
|
||||||
sqlCon = new HashMap ();
|
sqlCon = new HashMap ();
|
||||||
active = false;
|
active = false;
|
||||||
|
@ -56,6 +58,7 @@ public class Transactor extends Thread {
|
||||||
Key key = node.getKey ();
|
Key key = node.getKey ();
|
||||||
if (!nodes.containsKey (key)) {
|
if (!nodes.containsKey (key)) {
|
||||||
nodes.put (key, node);
|
nodes.put (key, node);
|
||||||
|
nodesArray.add (node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +67,7 @@ public class Transactor extends Thread {
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
Key key = node.getKey ();
|
Key key = node.getKey ();
|
||||||
nodes.remove (key);
|
nodes.remove (key);
|
||||||
|
nodesArray.remove (node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +114,7 @@ public class Transactor extends Thread {
|
||||||
abort ();
|
abort ();
|
||||||
|
|
||||||
nodes.clear ();
|
nodes.clear ();
|
||||||
|
nodesArray.clear ();
|
||||||
cleannodes.clear ();
|
cleannodes.clear ();
|
||||||
txn = nmgr.db.beginTransaction ();
|
txn = nmgr.db.beginTransaction ();
|
||||||
active = true;
|
active = true;
|
||||||
|
@ -125,12 +130,12 @@ public class Transactor extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ins = 0, upd = 0, dlt = 0;
|
int ins = 0, upd = 0, dlt = 0;
|
||||||
int l = nodes.size ();
|
int l = nodesArray.size ();
|
||||||
|
|
||||||
Replicator replicator = nmgr.getReplicator ();
|
Replicator replicator = nmgr.getReplicator ();
|
||||||
|
|
||||||
for (Iterator i=nodes.values().iterator(); i.hasNext (); ) {
|
for (int i=0; i<l; i++) {
|
||||||
Node node = (Node) i.next ();
|
Node node = (Node) nodesArray.get (i);
|
||||||
// update nodes in db
|
// update nodes in db
|
||||||
int nstate = node.getState ();
|
int nstate = node.getState ();
|
||||||
if (nstate == Node.NEW) {
|
if (nstate == Node.NEW) {
|
||||||
|
@ -162,6 +167,7 @@ public class Transactor extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.clear ();
|
nodes.clear ();
|
||||||
|
nodesArray.clear ();
|
||||||
cleannodes.clear ();
|
cleannodes.clear ();
|
||||||
|
|
||||||
if (nmgr.idgen.dirty) {
|
if (nmgr.idgen.dirty) {
|
||||||
|
@ -180,14 +186,16 @@ public class Transactor extends Thread {
|
||||||
|
|
||||||
public synchronized void abort () throws Exception {
|
public synchronized void abort () throws Exception {
|
||||||
|
|
||||||
for (Iterator i=nodes.values().iterator(); i.hasNext(); ) {
|
int l = nodesArray.size ();
|
||||||
Node node = (Node) i.next ();
|
for (int i=0; i<l; i++ ) {
|
||||||
|
Node node = (Node) nodesArray.get (i);
|
||||||
// Declare node as invalid, so it won't be used by other threads that want to
|
// Declare node as invalid, so it won't be used by other threads that want to
|
||||||
// write on it and remove it from cache
|
// write on it and remove it from cache
|
||||||
nmgr.evictNode (node);
|
nmgr.evictNode (node);
|
||||||
node.clearWriteLock ();
|
node.clearWriteLock ();
|
||||||
}
|
}
|
||||||
nodes.clear ();
|
nodes.clear ();
|
||||||
|
nodesArray.clear ();
|
||||||
cleannodes.clear ();
|
cleannodes.clear ();
|
||||||
// close any JDBC connections associated with this transactor thread
|
// close any JDBC connections associated with this transactor thread
|
||||||
closeConnections ();
|
closeConnections ();
|
||||||
|
@ -242,101 +250,3 @@ public class Transactor extends Thread {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue