Mercurial > hg > Database > Alice
changeset 482:8227a2fd5a55 dispose
bug fix
author | sugi |
---|---|
date | Fri, 05 Dec 2014 17:22:33 +0900 |
parents | 549cc29aca59 |
children | 86c45738dd9e |
files | src/main/java/alice/daemon/AcceptThread.java src/main/java/alice/topology/fix/FixTopology.java src/main/java/alice/topology/manager/ParentManager.java src/main/java/alice/topology/manager/SendNodeInfo.java src/main/java/alice/topology/node/ReceiveCloseMessage.java |
diffstat | 5 files changed, 49 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/daemon/AcceptThread.java Fri Dec 05 17:22:11 2014 +0900 +++ b/src/main/java/alice/daemon/AcceptThread.java Fri Dec 05 17:22:33 2014 +0900 @@ -30,11 +30,11 @@ String key = "accept" + counter; IncomingTcpConnection in = new IncomingTcpConnection(connection, DataSegment.get("local"), key); - in.setName("IncomingTcp"); + in.setName(connection.getInfoString()+"-IncomingTcp"); in.start(); DataSegment.setAccept(key, in); OutboundTcpConnection out = new OutboundTcpConnection(connection); - out.setName("OutboundTcp"); + out.setName(connection.getInfoString()+"-OutboundTcp"); out.start(); counter++; } catch (IOException e) {
--- a/src/main/java/alice/topology/fix/FixTopology.java Fri Dec 05 17:22:11 2014 +0900 +++ b/src/main/java/alice/topology/fix/FixTopology.java Fri Dec 05 17:22:33 2014 +0900 @@ -29,58 +29,70 @@ @SuppressWarnings("unchecked") @Override public void run() { - ConnectionInfo disconnect = info.asClass(ConnectionInfo.class); // send Data is wrong. + ConnectionInfo disconnect = info.asClass(ConnectionInfo.class); HashMap<String, HostMessage> nameTable = info3.asClass(HashMap.class); ParentManager manager = info4.asClass(ParentManager.class); - HostMessage disconnectNode = nameTable.get(disconnect.nodeName); HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class); + HostMessage disconnectNode = null; + String disconnectNodeName = null; + for (String name : nameTable.keySet()) { + disconnectNode = nameTable.get(name); + if ((disconnectNode.name.equals(disconnect.addr)||disconnectNode.name.equals(disconnect.hostname)) + && disconnectNode.port == disconnect.port) { + disconnectNodeName = name; + break; + } + disconnectNode = null; + } - if (disconnectNode.isAlive()) { + if (disconnectNode!=null && disconnectNode.isAlive()) { // change state not Alive disconnectNode.alive = false; // get lastJoinedNode int last = info2.asInteger()-1; - String lastJoinedNode = "node"+last; - LinkedList<HostMessage> connectionList = topology.get(lastJoinedNode); + String lastJoinNodeName = "node"+last; + LinkedList<HostMessage> connectionList = topology.get(lastJoinNodeName); // lastJoinedNode has one connection - HostMessage parentInfo = connectionList.poll(); + HostMessage parentNode = connectionList.poll(); - for (HostMessage node1 : topology.get(parentInfo.absName)) { - if (node1.remoteAbsName.equals(lastJoinedNode)) { - list.remove(node1); + connectionList = topology.get(parentNode.absName); + for (HostMessage node1 : connectionList) { + if (node1.absName.equals(lastJoinNodeName)) { + connectionList.remove(node1); break; } } - if (!lastJoinedNode.equals(disconnect.nodeName)) { + if (!lastJoinNodeName.equals(disconnectNodeName)) { // send close message to lastJoinedNode - ods.put(lastJoinedNode, "_CLOSEMESSEAGE", parentInfo.reverseName); + ods.put(lastJoinNodeName, "_CLOSEMESSEAGE", parentNode.reverseName); // send close message to lastJoinedNode's parent - ods.put(parentInfo.absName, "_CLOSEMESSEAGE", parentInfo.connectionName); + ods.put(parentNode.absName, "_CLOSEMESSEAGE", parentNode.connectionName); - HostMessage lastJoined = nameTable.get(lastJoinedNode); - LinkedList<HostMessage> disconnectionList = topology.get(disconnect.nodeName); + HostMessage lastJoinNode = nameTable.get(lastJoinNodeName); + connectionList = topology.get(lastJoinNodeName); + LinkedList<HostMessage> disconnectionList = topology.get(disconnectNodeName); // remove NodeInformation from disconnection node's children and parent for (HostMessage node :disconnectionList) { LinkedList<HostMessage> list = topology.get(node.absName); for (HostMessage node1 : list) { - if (node1.absName.equals(disconnect.nodeName)) { - node1.name = lastJoined.name; - node1.port = lastJoined.port; - node1.absName = lastJoinedNode; + if (node1.absName.equals(disconnectNodeName)) { + node1.name = lastJoinNode.name; + node1.port = lastJoinNode.port; + node1.absName = lastJoinNodeName; + ods.put(node1.remoteAbsName, node1); break; } - ods.put(node1.remoteAbsName, node1); } - node.absName = lastJoinedNode; - ods.put(lastJoinedNode, node); + node.remoteAbsName = lastJoinNodeName; + ods.put(node.remoteAbsName, node); connectionList.add(node); } - - manager.replaceAndRemove(disconnect.nodeName, lastJoinedNode); + disconnectionList.clear(); + manager.replaceAndRemove(disconnectNodeName, lastJoinNodeName); } else { // disconnection node is lastJoinedNode - manager.remove(disconnect.nodeName); + manager.remove(disconnectNodeName); } } else { // disconnect message already received. @@ -88,12 +100,15 @@ // need debug option for (LinkedList<HostMessage> list :topology.values()){ - System.out.print(list.get(0).remoteAbsName+" : "); - for (HostMessage host : list){ - System.out.print("[ "+host.absName+" "+host.name+" "+host.port+" "+host.connectionName+" "+host.reverseName+" "+host.remoteAbsName+" ]"); + if (list.size() !=0) { + System.out.print(list.get(0).remoteAbsName+" : "); + for (HostMessage host : list){ + System.out.print("[ "+host.absName+" "+host.name+" "+host.port+" "+host.connectionName+" "+host.reverseName+" "+host.remoteAbsName+" ]"); + } + System.out.println(); } - System.out.println(); } + ods.put(info1.key, topology); ods.put(info2.key, info2.getReceiveData()); ods.put(info3.key, nameTable);
--- a/src/main/java/alice/topology/manager/ParentManager.java Fri Dec 05 17:22:11 2014 +0900 +++ b/src/main/java/alice/topology/manager/ParentManager.java Fri Dec 05 17:22:33 2014 +0900 @@ -62,7 +62,7 @@ boolean found = false; int i = 0; for (;i<list.size();i++) { - if (list.get(i).equals(name)) { + if (list.get(i).getName().equals(name)) { found = true; break; }
--- a/src/main/java/alice/topology/manager/SendNodeInfo.java Fri Dec 05 17:22:11 2014 +0900 +++ b/src/main/java/alice/topology/manager/SendNodeInfo.java Fri Dec 05 17:22:33 2014 +0900 @@ -48,6 +48,7 @@ absCookieTable.put(cookie, nodeName); ods.put(info4.key, absCookieTable); ods.put(info1.key, comingHostCount+1); + host.alive = true; nameTable.put(nodeName, host); manager.register(nodeName);
--- a/src/main/java/alice/topology/node/ReceiveCloseMessage.java Fri Dec 05 17:22:11 2014 +0900 +++ b/src/main/java/alice/topology/node/ReceiveCloseMessage.java Fri Dec 05 17:22:33 2014 +0900 @@ -16,7 +16,8 @@ @Override public void run() { String managerKey = info.asString(); - DataSegment.get(managerKey).close(); + if (DataSegment.contains(managerKey)) + DataSegment.get(managerKey).close(); new ReceiveCloseMessage(); }