+1,

Does it need a unit test?

On 23/07/10 18:01, Markus Roberts wrote:
> Since we were clearing the thread variable containing the compiler's reference
> to it's environment's known resource types at the start of each compile the
> reference remaining at the end of a compilation could never be used and was
> thus just garbage that we were arbitrarily retaining.
> 
> This patch moves the clearing of the thread var to the _end_ of compilation so
> that it's always nil except in the middle of a compile.
> 
> This raises an interesting question; should the ref just live on the compiler
> object and we could dispense with the thread-var?  It might require things 
> that
> now only know about the environment to need a ref to the compiler and 
> introduce
> other thread issues (e.g. we might just end up needing a :current_compiler
> thread variable, for no net gain in simplicity).
> 
> Signed-off-by: Markus Roberts <[email protected]>
> ---
>  lib/puppet/parser/compiler.rb |   11 +++++------
>  1 files changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
> index 760d5a7..61bb13c 100644
> --- a/lib/puppet/parser/compiler.rb
> +++ b/lib/puppet/parser/compiler.rb
> @@ -15,16 +15,15 @@ class Puppet::Parser::Compiler
>    include Puppet::Resource::TypeCollectionHelper
>  
>    def self.compile(node)
> -    # At the start of a new compile we don't assume anything about 
> -    # known_resouce_types; we'll get these from the environment and
> -    # cache them in a thread variable for the duration of the 
> -    # compilation.
> -    Thread.current[:known_resource_types] = nil
>      new(node).compile.to_resource
>    rescue => detail
>      puts detail.backtrace if Puppet[:trace]
>      raise Puppet::Error, "#{detail} on node #{node.name}"
> -  end
> +  ensure
> +    # We get these from the environment and only cache them in a thread 
> +    # variable for the duration of the compilation.
> +    Thread.current[:known_resource_types] = nil
> + end
>  
>    attr_reader :node, :facts, :collections, :catalog, :node_scope, 
> :resources, :relationships
>  


-- 
Brice Figureau
My Blog: http://www.masterzen.fr/

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to