Commit 21946ca3 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

More cache locking fixes. ENT-425

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10139 b35dd754-fafc-0310-a699-88a17e54d16e
parent b67badf7
...@@ -69,7 +69,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -69,7 +69,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
*/ */
private Cache<String, ClientRoute> usersCache; private Cache<String, ClientRoute> usersCache;
/** /**
* Cache (unlimited, never expire) that holds sessions of anoymous user that have authenticated with the server. * Cache (unlimited, never expire) that holds sessions of anonymous user that have authenticated with the server.
* Key: full JID, Value: {nodeID, available/unavailable} * Key: full JID, Value: {nodeID, available/unavailable}
*/ */
private Cache<String, ClientRoute> anonymousUsersCache; private Cache<String, ClientRoute> anonymousUsersCache;
...@@ -102,7 +102,14 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -102,7 +102,14 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
public void addServerRoute(JID route, LocalOutgoingServerSession destination) { public void addServerRoute(JID route, LocalOutgoingServerSession destination) {
String address = route.getDomain(); String address = route.getDomain();
localRoutingTable.addRoute(address, destination); localRoutingTable.addRoute(address, destination);
serversCache.put(address, server.getNodeID().toByteArray()); Lock lock = CacheFactory.getLock(address, serversCache);
try {
lock.lock();
serversCache.put(address, server.getNodeID().toByteArray());
}
finally {
lock.unlock();
}
} }
public void addComponentRoute(JID route, RoutableChannelHandler destination) { public void addComponentRoute(JID route, RoutableChannelHandler destination) {
...@@ -127,7 +134,15 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -127,7 +134,15 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
boolean available = destination.getPresence().isAvailable(); boolean available = destination.getPresence().isAvailable();
localRoutingTable.addRoute(route.toString(), destination); localRoutingTable.addRoute(route.toString(), destination);
if (destination.getAuthToken().isAnonymous()) { if (destination.getAuthToken().isAnonymous()) {
added = anonymousUsersCache.put(route.toString(), new ClientRoute(server.getNodeID(), available)) == null; Lock lockAn = CacheFactory.getLock(route.toString(), anonymousUsersCache);
try {
lockAn.lock();
added = anonymousUsersCache.put(route.toString(), new ClientRoute(server.getNodeID(), available)) ==
null;
}
finally {
lockAn.unlock();
}
// Add the session to the list of user sessions // Add the session to the list of user sessions
if (route.getResource() != null && (!available || added)) { if (route.getResource() != null && (!available || added)) {
Lock lock = CacheFactory.getLock(route.toBareJID(), usersSessions); Lock lock = CacheFactory.getLock(route.toBareJID(), usersSessions);
...@@ -141,7 +156,14 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -141,7 +156,14 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
} }
} }
else { else {
added = usersCache.put(route.toString(), new ClientRoute(server.getNodeID(), available)) == null; Lock lockU = CacheFactory.getLock(route.toString(), usersCache);
try {
lockU.lock();
added = usersCache.put(route.toString(), new ClientRoute(server.getNodeID(), available)) == null;
}
finally {
lockU.unlock();
}
// Add the session to the list of user sessions // Add the session to the list of user sessions
if (route.getResource() != null && (!available || added)) { if (route.getResource() != null && (!available || added)) {
Lock lock = CacheFactory.getLock(route.toBareJID(), usersSessions); Lock lock = CacheFactory.getLock(route.toBareJID(), usersSessions);
...@@ -620,10 +642,25 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -620,10 +642,25 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
public boolean removeClientRoute(JID route) { public boolean removeClientRoute(JID route) {
boolean anonymous = false; boolean anonymous = false;
String address = route.toString(); String address = route.toString();
ClientRoute clientRoute = usersCache.remove(address); ClientRoute clientRoute = null;
Lock lockU = CacheFactory.getLock(address, usersCache);
try {
lockU.lock();
clientRoute = usersCache.remove(address);
}
finally {
lockU.unlock();
}
if (clientRoute == null) { if (clientRoute == null) {
clientRoute = anonymousUsersCache.remove(address); Lock lockA = CacheFactory.getLock(address, anonymousUsersCache);
anonymous = true; try {
lockA.lock();
clientRoute = anonymousUsersCache.remove(address);
anonymous = true;
}
finally {
lockA.unlock();
}
} }
if (clientRoute != null && route.getResource() != null) { if (clientRoute != null && route.getResource() != null) {
Lock lock = CacheFactory.getLock(route.toBareJID(), usersSessions); Lock lock = CacheFactory.getLock(route.toBareJID(), usersSessions);
...@@ -655,7 +692,15 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -655,7 +692,15 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
public boolean removeServerRoute(JID route) { public boolean removeServerRoute(JID route) {
String address = route.getDomain(); String address = route.getDomain();
boolean removed = serversCache.remove(address) != null; boolean removed = false;
Lock lock = CacheFactory.getLock(address, serversCache);
try {
lock.lock();
removed = serversCache.remove(address) != null;
}
finally {
lock.unlock();
}
localRoutingTable.removeRoute(address); localRoutingTable.removeRoute(address);
return removed; return removed;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment