From 34cf556077192f8c5684daf9db03c0eefd434a6b Mon Sep 17 00:00:00 2001 From: Jonathan Cone Date: Mon, 28 Dec 2020 19:51:19 +0000 Subject: [PATCH 1/3] Remove zk nodes not present in local with zsync Contains some debug code to be removed in next commit BCK-2966 --- zookeeper.tcl | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/zookeeper.tcl b/zookeeper.tcl index 28b18d0..b4e1db0 100644 --- a/zookeeper.tcl +++ b/zookeeper.tcl @@ -5,6 +5,7 @@ package require base64 package require sha1 +package require struct::set namespace eval ::zookeeper { variable zkwd "/" @@ -80,19 +81,32 @@ namespace eval ::zookeeper { # # zsync - sync a filesystem tree to a znode tree + # removes any items in zk not found in the local + # path # # zpath is prepended to the destination path # proc zsync {zk path zpath {pattern *}} { mkpath $zk $zpath - set regexp "^${path}(.*)" + #set regexp "^${path}(.*)" + set locals [list] foreach file [lsort [glob -nocomplain -dir $path -types f $pattern]] { - regexp $regexp $file dummy tail - copy_file $zk $file $zpath$tail + #regexp $regexp $file dummy tail + set tail [file tail $file] + copy_file $zk $file [file join $zpath $tail] + lappend locals $tail } foreach dir [lsort [glob -nocomplain -dir $path -types d *]] { - regexp $regexp $dir dummy tailDir - zsync $zk $dir $zpath$tailDir $pattern + #regexp $regexp $dir dummy tailDir + set tailDir [file tail $dir] + zsync $zk $dir [file join $zpath $tailDir] $pattern + lappend locals $tailDir + } + set nodesToRemove [::struct::set difference [$zk children $zpath] $locals] + #puts stderr "path: $path zpath: $zpath nodesToRemove: $nodesToRemove dirs + files: $locals children: [$zk children $zpath]" + foreach node $nodesToRemove { + puts stderr "Removing [file join $zpath $node]" + rmrf $zk [file join $zpath $node] } } @@ -182,7 +196,7 @@ namespace eval ::zookeeper { if {$where eq ""} { set zkwd / } else { - set children + set children } return } From 3963f61fe9520fa9e71c9da64de8c5779a72f855 Mon Sep 17 00:00:00 2001 From: Jonathan Cone Date: Mon, 28 Dec 2020 20:21:42 +0000 Subject: [PATCH 2/3] Cleanup debug & simplify implementation BCK-2966 --- zookeeper.tcl | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/zookeeper.tcl b/zookeeper.tcl index b4e1db0..0bbd771 100644 --- a/zookeeper.tcl +++ b/zookeeper.tcl @@ -88,24 +88,17 @@ namespace eval ::zookeeper { # proc zsync {zk path zpath {pattern *}} { mkpath $zk $zpath - #set regexp "^${path}(.*)" set locals [list] - foreach file [lsort [glob -nocomplain -dir $path -types f $pattern]] { - #regexp $regexp $file dummy tail - set tail [file tail $file] - copy_file $zk $file [file join $zpath $tail] - lappend locals $tail + foreach file [lsort [glob -nocomplain -tails -dir $path -types f $pattern]] { + copy_file $zk [file join $path $file] [file join $zpath $file] + lappend locals $file } - foreach dir [lsort [glob -nocomplain -dir $path -types d *]] { - #regexp $regexp $dir dummy tailDir - set tailDir [file tail $dir] - zsync $zk $dir [file join $zpath $tailDir] $pattern - lappend locals $tailDir + foreach dir [lsort [glob -nocomplain -tails -dir $path -types d *]] { + zsync $zk [file join $path $dir] [file join $zpath $dir] $pattern + lappend locals $dir } set nodesToRemove [::struct::set difference [$zk children $zpath] $locals] - #puts stderr "path: $path zpath: $zpath nodesToRemove: $nodesToRemove dirs + files: $locals children: [$zk children $zpath]" foreach node $nodesToRemove { - puts stderr "Removing [file join $zpath $node]" rmrf $zk [file join $zpath $node] } } From 28c73c62924fcb042fe9a6653f30dc44dd2a9b37 Mon Sep 17 00:00:00 2001 From: Jonathan Cone Date: Mon, 28 Dec 2020 20:24:27 +0000 Subject: [PATCH 3/3] Remove unnecessary temporary var BCK-2966 --- zookeeper.tcl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zookeeper.tcl b/zookeeper.tcl index 0bbd771..683745d 100644 --- a/zookeeper.tcl +++ b/zookeeper.tcl @@ -97,8 +97,7 @@ namespace eval ::zookeeper { zsync $zk [file join $path $dir] [file join $zpath $dir] $pattern lappend locals $dir } - set nodesToRemove [::struct::set difference [$zk children $zpath] $locals] - foreach node $nodesToRemove { + foreach node [::struct::set difference [$zk children $zpath] $locals] { rmrf $zk [file join $zpath $node] } }