Index: openacs-4/packages/acs-tcl/tcl/acs-cache-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/acs-cache-procs.tcl,v diff -u -r1.10.2.31 -r1.10.2.32 --- openacs-4/packages/acs-tcl/tcl/acs-cache-procs.tcl 14 Jun 2022 17:59:36 -0000 1.10.2.31 +++ openacs-4/packages/acs-tcl/tcl/acs-cache-procs.tcl 21 Jun 2022 10:50:39 -0000 1.10.2.32 @@ -539,194 +539,7 @@ namespace eval ::acs::cache {} } - namespace eval ::acs { - ########################################################################## - # - # Cluster Management - # - # If a site is running a cluster of OpenACS systems, certain - # commands have to be executed on cluster nodes (e.g. flushing - # caches, etc). A cluster setup is currently not commonly used and - # requires probably some more work, but the code here provides a - # basic infrastructure. It is a good practice to flag commands to - # be executed on all cluster nodes in the code with - # ::acs::clusterwide. - ########################################################################## - - proc clusterwide args { - # - # First, execute the command on the local server. - # - eval $args - # - # Then, distribute the command to all servers in the cluster. - # - ::acs::Cluster broadcast {*}$args - } - - proc cache_flush_all {cache pattern} { - # - # Provide means to perform a wildcard-based cache flushing on - # (cluster) machines. - # - foreach n [ns_cache names $cache $pattern] { - ns_cache flush $cache $n - } - } - - nx::Class create Cluster { - :property {proto http} - :property host - :property {port 80} - :property {url /acs-cluster-do} - - set :allowed_host_patterns [list] - set :url /acs-cluster-do - array set :allowed_host { "127.0.0.1" 1 } - - # - # The allowed commands are of the form - # - command names followed by - # - optional "except patterns" - # - set :allowed_command { - set "" - unset "" - nsv_set "" - nsv_unset "" - nsv_incr "" - nsv_dict "" - bgdelivery "" - callback "" - ns_cache "^ns_cache\s+eval" - ns_cache_flush "" - ns_urlspace "" - acs::cache_flush_all "" - } - - :object method log {args} { - ns_log notice "cluster: [join $args { }]" - } - :method log {args} { - ns_log notice "cluster host ${:host} ${:port}: [join $args { }]" - } - - # - # Handling the ns_filter methods - # - :public object method trace args { - #:log "trace" - return filter_return - } - - :public object method preauth args { - #:log "preauth" - :incoming_request - return filter_return - } - - :public object method postauth args { - #:log "postauth" - return filter_return - } - - :public object method allowed_command {cmd} { - # - # Check, which command are allowed to be executed in the - # cluster. - # - - #ns_log notice "--cluster allowed [dict keys ${:allowed_command}]?" - set cmd_name [lindex $cmd 0] - #ns_log notice "--cluster can i execute $cmd_name? [dict exists ${:allowed_command} $cmd_name]" - if {[dict exists ${:allowed_command} $cmd_name]} { - set except_RE [dict get ${:allowed_command} $cmd_name] - #ns_log notice "--cluster [list regexp $except_RE $cmd] -> [regexp $except_RE $cmd]" - set allowed [expr {$except_RE eq "" || ![regexp $except_RE $cmd]}] - } else { - set allowed 0 - } - return $allowed - } - - # - # handle incoming request issues - # - :public object method incoming_request {} { - set cmd [ns_queryget cmd] - set addr [lindex [ns_set iget [ns_conn headers] x-forwarded-for] end] - if {$addr eq ""} {set addr [ns_conn peeraddr]} - #ns_log notice "--cluster got cmd='$cmd' from $addr" - ad_try { - set result [::acs::Cluster execute [ns_conn peeraddr] $cmd] - } on error {errorMsg} { - ns_log notice "--cluster error: $errorMsg" - ns_return 417 text/plain $errorMsg - } on ok {r} { - #ns_log notice "--cluster success $result" - ns_return 200 text/plain $result - } - } - - # - # Handling outgoing requests - # - :public object method execute {host cmd} { - if {![info exists :allowed_host($host)]} { - set ok 0 - foreach g ${:allowed_host_patterns} { - if {[string match $g $host]} { - set ok 1 - break - } - } - if {!$ok} { - error "refuse to execute commands from $host (command: '$cmd')" - } - } - if {[::acs::Cluster allowed_command $cmd]} { - ns_log notice "--cluster executes command '$cmd' from host $host" - return [eval $cmd] - } - error "command '$cmd' from host $host not allowed" - } - - # - # Handling outgoing requests - # - :public object method broadcast args { - # - # Small optimization for cachingmode "none" - # - if {[ns_config "ns/parameters" cachingmode "per-node"] eq "none" - && [lindex $args 0] in {acs::cache_flush_all ns_cache}} { - # - # If caching mode is none, it is expected that all - # nodes have this parameter set. Therefore there is no - # need to communicate cache flushing commands. - # - return - } - foreach server [:info instances] { - $server message {*}$args - } - } - - :public method message args { - :log "--cluster outgoing request to ${:proto}://${:host}:${:port} // $args" - try { - ns_http run ${:proto}://${:host}:${:port}/${:url}?cmd=[ns_urlencode $args] - } on error {errorMsg} { - ns_log warning "-cluster: send message to ${:proto}://${:host}:${:port}/${:url}?cmd=[ns_urlencode $args] failed: $errorMsg" - } on ok {result} { - ns_log notice "-cluster: response $result" - } - } - } -} - -namespace eval ::acs { ad_proc -private try_cache {cache operation args} { Function to support caching during bootstrap. When the @@ -748,7 +561,7 @@ } ns_log warning "no cache $cache: call ignored" } - } + } }