avoid cache.put() where theyre not really needed.
This commit is contained in:
parent
63cf63499d
commit
9fa2d5154f
1 changed files with 7 additions and 17 deletions
|
@ -184,7 +184,6 @@ public final class NodeManager {
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Transactor tx = (Transactor) Thread.currentThread ();
|
Transactor tx = (Transactor) Thread.currentThread ();
|
||||||
// tx.timer.beginEvent ("getNode "+kstr);
|
|
||||||
|
|
||||||
Key key = null;
|
Key key = null;
|
||||||
// If what we want is a virtual node create a "synthetic" key
|
// If what we want is a virtual node create a "synthetic" key
|
||||||
|
@ -198,20 +197,10 @@ public final class NodeManager {
|
||||||
Node node = tx.getVisitedNode (key);
|
Node node = tx.getVisitedNode (key);
|
||||||
|
|
||||||
if (node != null && node.getState() != Node.INVALID) {
|
if (node != null && node.getState() != Node.INVALID) {
|
||||||
// tx.timer.endEvent ("getNode "+kstr);
|
// we used to refresh the node in the main cache here to avoid the primary key entry being
|
||||||
|
// flushed from cache before the secondary one (risking duplicate nodes in cache) but
|
||||||
// if we didn't fetch the node via its primary key, refresh the primary key in the cache.
|
// we don't need to since we fetched the node from the threadlocal transactor cache and
|
||||||
// otherwise we risk cache corroption (duplicate node creation) if the node is fetched by its primary key
|
// didn't refresh it in the main cache.
|
||||||
if (!rel.usesPrimaryKey ()) {
|
|
||||||
synchronized (cache) {
|
|
||||||
Node oldnode = (Node) cache.put (node.getKey (), node);
|
|
||||||
if (oldnode != null && oldnode.getState () != Node.INVALID) {
|
|
||||||
cache.put (node.getKey (), oldnode);
|
|
||||||
cache.put (key, oldnode);
|
|
||||||
node = oldnode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,6 +221,7 @@ public final class NodeManager {
|
||||||
synchronized (cache) {
|
synchronized (cache) {
|
||||||
// check if node is already in cache with primary key
|
// check if node is already in cache with primary key
|
||||||
Node oldnode = (Node) cache.put (primKey, node);
|
Node oldnode = (Node) cache.put (primKey, node);
|
||||||
|
// no need to check for oldnode != node because we fetched a new node from db
|
||||||
if (oldnode != null && oldnode.getState () != Node.INVALID) {
|
if (oldnode != null && oldnode.getState () != Node.INVALID) {
|
||||||
cache.put (primKey, oldnode);
|
cache.put (primKey, oldnode);
|
||||||
if (!keyIsPrimary)
|
if (!keyIsPrimary)
|
||||||
|
@ -242,11 +232,11 @@ public final class NodeManager {
|
||||||
} // synchronized
|
} // synchronized
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// update primary key in cache, see above
|
// update primary key in cache to keep it from being flushed, see above
|
||||||
if (!rel.usesPrimaryKey ()) {
|
if (!rel.usesPrimaryKey ()) {
|
||||||
synchronized (cache) {
|
synchronized (cache) {
|
||||||
Node oldnode = (Node) cache.put (node.getKey (), node);
|
Node oldnode = (Node) cache.put (node.getKey (), node);
|
||||||
if (oldnode != null && oldnode.getState () != Node.INVALID) {
|
if (oldnode != node && oldnode != null && oldnode.getState () != Node.INVALID) {
|
||||||
cache.put (node.getKey (), oldnode);
|
cache.put (node.getKey (), oldnode);
|
||||||
cache.put (key, oldnode);
|
cache.put (key, oldnode);
|
||||||
node = oldnode;
|
node = oldnode;
|
||||||
|
|
Loading…
Add table
Reference in a new issue