Slightly improved the problem with stale objects in the requested objects list. But I don't know how to properly solve it, there may always be some left.

This commit is contained in:
Christian Basler 2016-08-25 12:44:06 +02:00
parent 102d63e2c6
commit 53aa2c6804
2 changed files with 10 additions and 6 deletions

View File

@ -183,7 +183,7 @@ public abstract class AbstractConnection {
} }
private void receiveMessage(Addr addr) { private void receiveMessage(Addr addr) {
LOG.debug("Received " + addr.getAddresses().size() + " addresses."); LOG.trace("Received " + addr.getAddresses().size() + " addresses.");
ctx.getNodeRegistry().offerAddresses(addr.getAddresses()); ctx.getNodeRegistry().offerAddresses(addr.getAddresses());
} }

View File

@ -64,7 +64,7 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex
private Selector selector; private Selector selector;
private ServerSocketChannel serverChannel; private ServerSocketChannel serverChannel;
private Map<ConnectionInfo, SelectionKey> connections = new ConcurrentHashMap<>(); private Map<ConnectionInfo, SelectionKey> connections = new ConcurrentHashMap<>();
private volatile int requestedObjectsCount; private final Set<InventoryVector> requestedObjects = Collections.newSetFromMap(new ConcurrentHashMap<InventoryVector, Boolean>(10_000));
private Thread starter; private Thread starter;
@ -147,7 +147,6 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex
} catch (IOException e) { } catch (IOException e) {
throw new ApplicationException(e); throw new ApplicationException(e);
} }
final Set<InventoryVector> requestedObjects = new HashSet<>();
thread("connection listener", new Runnable() { thread("connection listener", new Runnable() {
@Override @Override
public void run() { public void run() {
@ -287,7 +286,6 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex
connection.disconnect(); connection.disconnect();
} }
} }
requestedObjectsCount = requestedObjects.size();
} }
for (Map.Entry<ConnectionInfo, SelectionKey> e : connections.entrySet()) { for (Map.Entry<ConnectionInfo, SelectionKey> e : connections.entrySet()) {
if (e.getValue().isValid() && (e.getValue().interestOps() & OP_WRITE) == 0) { if (e.getValue().isValid() && (e.getValue().interestOps() & OP_WRITE) == 0) {
@ -370,7 +368,10 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex
@Override @Override
public void request(Collection<InventoryVector> inventoryVectors) { public void request(Collection<InventoryVector> inventoryVectors) {
if (!isRunning()) return; if (!isRunning()) {
requestedObjects.clear();
return;
}
Iterator<InventoryVector> iterator = inventoryVectors.iterator(); Iterator<InventoryVector> iterator = inventoryVectors.iterator();
if (!iterator.hasNext()) { if (!iterator.hasNext()) {
return; return;
@ -408,6 +409,9 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex
} }
} while (iterator.hasNext()); } while (iterator.hasNext());
// remove objects nobody knows of
requestedObjects.removeAll(inventoryVectors);
for (ConnectionInfo connection : distribution.keySet()) { for (ConnectionInfo connection : distribution.keySet()) {
List<InventoryVector> ivs = distribution.get(connection); List<InventoryVector> ivs = distribution.get(connection);
if (!ivs.isEmpty()) { if (!ivs.isEmpty()) {
@ -449,7 +453,7 @@ public class NioNetworkHandler implements NetworkHandler, InternalContext.Contex
return new Property("network", null, return new Property("network", null,
new Property("connectionManager", isRunning() ? "running" : "stopped"), new Property("connectionManager", isRunning() ? "running" : "stopped"),
new Property("connections", null, streamProperties), new Property("connections", null, streamProperties),
new Property("requestedObjects", requestedObjectsCount) new Property("requestedObjects", requestedObjects.size())
); );
} }