|
|
|
@ -4,6 +4,8 @@ import ( |
|
|
|
|
"github.com/go-zookeeper/zk" |
|
|
|
|
|
|
|
|
|
"fmt" |
|
|
|
|
"path" |
|
|
|
|
"sort" |
|
|
|
|
"strings" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -46,3 +48,27 @@ func (s *NodeSync) createRecursively(path string, acl []zk.ACL) error { |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// sortChildren sorts sequenced zookeeper nodes by sequence id
|
|
|
|
|
// sequence id is a last part of node key and always consists of 10 digits
|
|
|
|
|
func sortChildren(children []string) []string { |
|
|
|
|
|
|
|
|
|
var sorted []string |
|
|
|
|
for _, child := range children { |
|
|
|
|
if len(child) <= sequenceLen { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sorted = append(sorted, child) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sort.SliceStable(sorted, func(i, j int) bool { |
|
|
|
|
|
|
|
|
|
_, a := path.Split(sorted[i]) |
|
|
|
|
_, b := path.Split(sorted[j]) |
|
|
|
|
|
|
|
|
|
return a[len(a)-sequenceLen:] < b[len(b)-sequenceLen:] |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
return sorted |
|
|
|
|
} |
|
|
|
|