fpj / zookeeper-book-example

This is a code example that complements the material in the ZooKeeper O'Reilly book.
Apache License 2.0
399 stars 250 forks source link

[Bug] bug in master.java #4

Open kesihai opened 4 years ago

kesihai commented 4 years ago

@fpj , I think there is a bug, and it should be the workerName, not the path in getAbsentWorkerTasks(path)

ChildrenCallback workerAssignmentCallback = new ChildrenCallback() {
        public void processResult(int rc, String path, Object ctx, List<String> children){
            switch (Code.get(rc)) { 
            case CONNECTIONLOSS:
                getAbsentWorkerTasks(path); // Here should be path.subString(path.lastIndexOf('/') + 1, path.length());
                break;
            case OK:
                LOG.info("Succesfully got a list of assignments: " 
                        + children.size() 
                        + " tasks");

                /*
                 * Reassign the tasks of the absent worker.  
                 */

                for(String task: children) {
                    getDataReassign(path + "/" + task, task);                    
                }
                break;
            default:
                LOG.error("getChildren failed",  KeeperException.create(Code.get(rc), path));
            }
        }
    };

https://github.com/fpj/zookeeper-book-example/blob/135b79b472fd2c45b82d78a3653532eecd69b6fe/src/main/java/org/apache/zookeeper/book/Master.java#L491