merge in a lookup speedup from hiera master

7657d43a35
This commit is contained in:
jasper 2014-01-16 10:18:22 +00:00
parent 019c31e186
commit 5c7fdf90b1
3 changed files with 101 additions and 1 deletions

View File

@ -1,9 +1,10 @@
# $OpenBSD: Makefile,v 1.14 2013/12/04 19:49:37 jasper Exp $
# $OpenBSD: Makefile,v 1.15 2014/01/16 10:18:22 jasper Exp $
COMMENT= simple pluggable hierarchical database
V= 1.3.0
DISTNAME= hiera-${V}
REVISION= 0
CATEGORIES= databases

View File

@ -0,0 +1,71 @@
$OpenBSD: patch-lib_hiera_backend_rb,v 1.1 2014/01/16 10:18:22 jasper Exp $
From 00be33858e98459e5125d46ea546e91a888b0e6c Mon Sep 17 00:00:00 2001
From: Andrew Parker <andy@puppetlabs.com>
Date: Tue, 10 Dec 2013 11:17:51 -0800
Subject: [PATCH 2/2] (#22142) Extract method to list all hierarchy files
--- lib/hiera/backend.rb.orig Thu Jan 1 01:00:00 1970
+++ lib/hiera/backend.rb Thu Jan 16 11:09:41 2014
@@ -35,15 +35,19 @@ class Hiera
#
# If the file is not found nil is returned
def datafile(backend, scope, source, extension)
- file = File.join([datadir(backend, scope), "#{source}.#{extension}"])
+ datafile_in(datadir(backend, scope), source, extension)
+ end
- unless File.exist?(file)
- Hiera.debug("Cannot find datafile #{file}, skipping")
+ # @api private
+ def datafile_in(datadir, source, extension)
+ file = File.join(datadir, "#{source}.#{extension}")
- return nil
+ if File.exist?(file)
+ file
+ else
+ Hiera.debug("Cannot find datafile #{file}, skipping")
+ nil
end
-
- return file
end
# Constructs a list of data sources to search
@@ -71,6 +75,35 @@ class Hiera
hierarchy.flatten.map do |source|
source = parse_string(source, scope)
yield(source) unless source == "" or source =~ /(^\/|\/\/|\/$)/
+ end
+ end
+
+ # Constructs a list of data files to search
+ #
+ # If you give it a specific hierarchy it will just use that
+ # else it will use the global configured one, failing that
+ # it will just look in the 'common' data source.
+ #
+ # An override can be supplied that will be pre-pended to the
+ # hierarchy.
+ #
+ # The source names will be subject to variable expansion based
+ # on scope
+ #
+ # Only files that exist will be returned. If the file is missing, then
+ # the block will not receive the file.
+ #
+ # @yield [String, String] the source string and the name of the resulting file
+ # @api public
+ def datasourcefiles(backend, scope, extension, override=nil, hierarchy=nil)
+ datadir = Backend.datadir(backend, scope)
+ Backend.datasources(scope, override, hierarchy) do |source|
+ Hiera.debug("Looking for data source #{source}")
+ file = datafile_in(datadir, source, extension)
+
+ if file
+ yield source, file
+ end
end
end

View File

@ -0,0 +1,28 @@
$OpenBSD: patch-lib_hiera_backend_yaml_backend_rb,v 1.1 2014/01/16 10:18:22 jasper Exp $
From 1f856c12a46dea7e8278a55371de4c278d0a21ed Mon Sep 17 00:00:00 2001
From: Eric Sorenson <eric.sorenson@puppetlabs.com>
Date: Wed, 23 Oct 2013 17:34:34 -0700
Subject: [PATCH 1/2] (#22142) Substantial speed increase in lookups
From 00be33858e98459e5125d46ea546e91a888b0e6c Mon Sep 17 00:00:00 2001
From: Andrew Parker <andy@puppetlabs.com>
Date: Tue, 10 Dec 2013 11:17:51 -0800
Subject: [PATCH 2/2] (#22142) Extract method to list all hierarchy files
--- lib/hiera/backend/yaml_backend.rb.orig Thu Jan 1 01:00:00 1970
+++ lib/hiera/backend/yaml_backend.rb Thu Jan 16 11:10:36 2014
@@ -13,12 +13,7 @@ class Hiera
Hiera.debug("Looking up #{key} in YAML backend")
- Backend.datasources(scope, order_override) do |source|
- Hiera.debug("Looking for data source #{source}")
- yamlfile = Backend.datafile(:yaml, scope, source, "yaml") || next
-
- next unless File.exist?(yamlfile)
-
+ Backend.datasourcefiles(:yaml, scope, "yaml", order_override) do |source, yamlfile|
data = @cache.read_file(yamlfile, Hash) do |data|
YAML.load(data)
end