puppetlabs/puppetdb — pull request #174 by grimradical (2012-06-08 17:03:45+00:00)
Title: Sort unordered metaparameter values during catalog serialization

You have a resource with a metaparameter, `tag`, with a value of `["c", "b",
"a"]`. We generate a catalog and that catalog is sent to PuppetDB. The next
time Puppet runs, you get the same resource, with the same metaparameter `tag`,
only the value is now `["a", "b", "c"]`. That catalog is also sent to PuppetDB.

Everything works correctly, however PuppetDB will think that the second catalog
is different from the first catalog. That's okay in terms of correctness, but
it's slower...`tag` (and several other metaparameters) are inherently
unordered. We should treat both catalogs the same because, semantically, they
are.

This patchset munges catalogs prior to submission to PuppetDB such that all
inherently unordered metaparameters are sorted. That way the output is the same
no matter the initial ordering.

You may be wondering how it's possible that Puppet could generate 2 different
orders for the same metaparam. But imagine that you're using the spaceship
operator to set dependency relationships on resources. Puppet doesn't order the
results of a resource collection operation. Something like this, for example,
can trigger this bug:

Yumrepo <| |> -> Package <| |>

Signed-off-by: Deepak Giridharagopal