Mercurial > hg > Database > Alice
changeset 476:8968b24c1ce3 dispose
TODO is to fix ParentManager information
author | sugi |
---|---|
date | Tue, 02 Dec 2014 13:43:07 +0900 |
parents | fac27e395930 |
children | f644dc9e0589 |
files | src/main/java/alice/topology/HostMessage.java src/main/java/alice/topology/fix/FixTopology.java src/main/java/alice/topology/manager/ParentManager.java |
diffstat | 3 files changed, 56 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/HostMessage.java Mon Dec 01 17:32:54 2014 +0900 +++ b/src/main/java/alice/topology/HostMessage.java Tue Dec 02 13:43:07 2014 +0900 @@ -14,6 +14,8 @@ public String remoteAbsName; public String cookie; // MD5 + public boolean alive; + public HostMessage() { } public HostMessage(String name, int port) { this.name = name; @@ -26,4 +28,8 @@ this.connectionName = connectionName; this.reverseName = reverseName; } + + public boolean isAlive() { + return alive; + } }
--- a/src/main/java/alice/topology/fix/FixTopology.java Mon Dec 01 17:32:54 2014 +0900 +++ b/src/main/java/alice/topology/fix/FixTopology.java Tue Dec 02 13:43:07 2014 +0900 @@ -8,82 +8,78 @@ import alice.datasegment.CommandType; import alice.datasegment.Receiver; import alice.topology.HostMessage; +import alice.topology.manager.ParentManager; public class FixTopology extends CodeSegment { private Receiver info = ids.create(CommandType.TAKE); // disconnection nodeInfo private Receiver info1 = ids.create(CommandType.TAKE); // all connection Info private Receiver info2 = ids.create(CommandType.TAKE); // node count - private Receiver info3 = ids.create(CommandType.TAKE); // need to search parent node + private Receiver info3 = ids.create(CommandType.TAKE); // IP Table + private Receiver info4 = ids.create(CommandType.TAKE); // parentManager + public FixTopology() { info.setKey("_DISCONNECT"); info1.setKey("topology"); info2.setKey("hostCount"); - info3.setKey("nodeConnectionInfo"); + info3.setKey("nameTable"); + info4.setKey("parentManager"); } @SuppressWarnings("unchecked") @Override public void run() { ConnectionInfo disconnect = info.asClass(ConnectionInfo.class); - - HashMap<String, HostMessage> nodeInfo = info3.asClass(HashMap.class); + HashMap<String, HostMessage> nameTable = info3.asClass(HashMap.class); + HostMessage disconnectNode = nameTable.get(disconnect.nodeName); + if (disconnectNode.isAlive()) { + // change state not Alive + disconnectNode.alive = false; + // get lastJoinedNode + int last = info2.asInteger()-1; + String lastJoinedNode = "node"+last; + if (!lastJoinedNode.equals(disconnect.nodeName)) { + HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class); - // check - if (nodeInfo.containsKey(disconnect.nodeName)) { - HostMessage registered = nodeInfo.get(disconnect.nodeName); - // if information not match, FixTopology was change Information before. - if ((registered.name.equals(disconnect.addr)||registered.name.equals(disconnect.hostname)) - && (registered.port == disconnect.port)) { - int nodeNum = info2.asInteger() - 1; // get last joined node - String nodeName = "node"+nodeNum; - if (nodeName.equals(disconnect.nodeName)) { - // if disconnect node equal last joined node, only do update topology information. - + LinkedList<HostMessage> connectionList = topology.get(lastJoinedNode); + // lastJoinedNode has one connection + HostMessage parentInfo = connectionList.poll(); + // send close message to lastJoinedNode + ods.put(lastJoinedNode, "_CLOSEMESSEAGE", parentInfo.reverseName); - } else { - // move last joined node to disconnect node position. - HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class); + // send close message to lastJoinedNode's parent + ods.put(parentInfo.absName, "_CLOSEMESSEAGE", parentInfo.connectionName); + for (HostMessage node1 : topology.get(parentInfo.absName)) { + if (node1.remoteAbsName.equals(lastJoinedNode)) { + list.remove(node1); + break; + } + } - // send disconnect Message which connected to last joined node. - LinkedList<HostMessage> list = topology.get(nodeName); - // last joined node's list has only one node (parent) - HostMessage host = list.getFirst(); - ods.put(host.absName, "_DISCONNECTREQUEST", "DISCONNECT"); - // remove last joined node information from parent and children list - list = topology.get(host.absName); - // parent list - for (HostMessage node : list) { - if (node.absName.equals(host.absName)) { - list.remove(node); + HostMessage lastJoined = nameTable.get(lastJoinedNode); + LinkedList<HostMessage> disconnectionList = topology.get(disconnect.nodeName); + // 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; break; } + ods.put(node1.remoteAbsName, node1); } - /* - * children node - * child node list has only last joined node. so list clear. - */ - int child1 = nodeNum * 2 + 1; - int child2 = child1; - String[] children = {"node"+child1, "node"+child2}; - for (String name: children) { - if (topology.containsKey(name)) - topology.get(name).clear(); - } - - - // this list can see who connected disconnect node. - //LinkedList<HostMessage> list = topology.get(disconnect.nodeName); - + node.absName = lastJoinedNode; + ods.put(lastJoinedNode, node); + connectionList.add(node); } } else { - + // disconnection node is lastJoinedNode } - } else { - // in this case. Key was deleted by FixTopology + // disconnect message already received. } - } }
--- a/src/main/java/alice/topology/manager/ParentManager.java Mon Dec 01 17:32:54 2014 +0900 +++ b/src/main/java/alice/topology/manager/ParentManager.java Tue Dec 02 13:43:07 2014 +0900 @@ -24,7 +24,7 @@ } private void checkChildNumber() { - for (;;position++) { + for (;;next()) { if (list.get(position).children() < BINARY_TREE) break; } @@ -42,4 +42,8 @@ public void previous() { position--; } + + public void overwirte(String str, String str1) { + + } }