Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: libcrmcommon: handle schema versions properly #1308

Merged
merged 6 commits into from
Jul 19, 2017

Conversation

kgaillot
Copy link
Contributor

As a byproduct, this eliminates a dependency on the math library.

{
int rc = sscanf(filename, "pacemaker-%d.%d.rng", &version[0], &version[1]);

return (rc == 2)? TRUE : FALSE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return (rc == 2) suffices

@@ -134,19 +130,27 @@ get_schema_path(const char *name, const char *file)
return crm_strdup_printf("%s/%s.rng", base, name);
}

static inline bool
version_from_filename(const char *filename, int version[2])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated use of int[2] might perhaps justify a typedef'd type.
(put on the line where it became obvious to me)

}

static void
__xml_schema_add(int type, float version, const char *name,
__xml_schema_add(int type, int version[2], const char *name,
const char *location, const char *transform,
int after_transform)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const int version[2]?

@jnpkrn
Copy link
Contributor

jnpkrn commented Jul 19, 2017

Do we need to reserve negative values for anything? Otherwise I'd be in favor of unsigned char ("256 for a version part counter will be enough for everybody").

@@ -246,34 +255,35 @@ crm_schema_init(void)
int lpc, max;
const char *base = get_schema_root();
struct dirent **namelist = NULL;
int zero[2] = {0, 0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be const then...

@jnpkrn
Copy link
Contributor

jnpkrn commented Jul 19, 2017

Note that ceiling of 256 could also be good incentive not to bump the
versions excessively -- there are other connected costs (e.g. storage
for all the particular interim changes between point releases).

known_schemas[last].version = version;
sscanf(name, "%*[^-]-%d.%d",
&known_schemas[last].version[0],
&known_schemas[last].version[1]);
Copy link
Contributor

@jnpkrn jnpkrn Jul 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also nice cleanup :) (not that I am fluent with sscanf, looked that up).

struct stat s;
char *xslt = NULL;

transform = crm_strdup_printf("upgrade-%.1f.xsl", version);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently upgrading from 2.10 was unexpected in the old world order.

@jnpkrn
Copy link
Contributor

jnpkrn commented Jul 19, 2017

On the more general note, following downside for this approach to
hitting the float-trackable versions limit stated in the past:

float- and string-incompatible comparisons

which used to be noticable simplification especially in XSLT handling
(well, should it be needed). But we can live by and also XSLT should
not be impossible to handle (using substring cuts, etc.).

Looking at some other possibly affected software pieces:

TL;DR: Not the end of the world :)

@kgaillot
Copy link
Contributor Author

Added commits for review items and a little more cleanup

@kgaillot kgaillot merged commit 989f1a8 into ClusterLabs:master Jul 19, 2017
jnpkrn added a commit to jnpkrn/clufter that referenced this pull request Jul 20, 2017
Originally, pacemaker was treating versions of its CIB schema files
as floats, simplifying comparisons in a simplistic single-digit minor
version realms.  As the necessity to roll out a new schema version
catering the new needs is around the corner, it was decided[1] that
pacemaker will not bump the major part abrubtly (against the rules[2]),
but rather the overflow to a new higher digit will occur.  That breaks
the assumption of easy comparisons in two previously common angles:

- string (e.g. when looking at /cib@validate-with XPath within CIB
  or at the available, respectively named schema files)

- mentioned float (when parsing the numerical part out of the string):
  2.11 < 2.2, ....

Here, just the former is relevant; XML.etree_rng_validator_proper_specs
was supposed to return ordered sequence of embedded/available schemas,
which is used, for instance, to grab the lowest possible for the
purpose of upgrading the schema for particular CIB document internally.
Formerly, the sorting was based on lexicographical comparison, now,
thanks to `namever_partition` (added with the previous commit) wired
into the process, it performs combined lexicographical+version
comparison so everything should keep working as expected even
when 2.10+ versions of CIB schemas are common.

[1] ClusterLabs/pacemaker#1308
[2] https://github.com/ClusterLabs/pacemaker/blob/master/xml/Readme.md

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
jnpkrn added a commit to jnpkrn/clufter that referenced this pull request Jul 20, 2017
Originally, pacemaker was treating versions of its CIB schemas
(respectively named files) as floats, simplifying comparisons in
a simplistic single-digit minor version realms.  As the necessity
to roll out a new schema version catering the new needs is around
the corner, it was decided[1] that pacemaker will not bump the
major part abrubtly (against the rules[2]), but rather the overflow
to a new higher digit in the minor part will occur.  That breaks
assumption of easy comparisons in two previously common angles:

- string (e.g. when looking at /cib@validate-with XPath within CIB
  or at the available, respectively named schema files);
  example: pacemaker-2.10 < pacemaker-2.2

- mentioned float (when parsing the numerical part out of the string):
  example: 2.11 < 2.2

Here, just the former is relevant; XML.etree_rng_validator_proper_specs
was supposed to return ordered sequence of embedded/available schemas,
which is used, for instance, to grab the lowest possible for the
purpose of upgrading the schema for particular CIB document internally.
Formerly, the sorting was based on lexicographical comparison, now,
thanks to `namever_partition` (added with the previous commit) wired
into the process, it performs combined lexicographical+version
comparison so everything should keep working as expected even
when 2.10+ versions of CIB schemas are common.

[1] ClusterLabs/pacemaker#1308
[2] https://github.com/ClusterLabs/pacemaker/blob/master/xml/Readme.md

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
jnpkrn added a commit to jnpkrn/clufter that referenced this pull request Jul 20, 2017
Originally, pacemaker was treating versions of its CIB schemas
(respectively named files) as floats, simplifying comparisons in
a simplistic single-digit minor version realms.  As the necessity
to roll out a new schema version catering the new needs is around
the corner, it was decided[1] that pacemaker will not bump the
major part abrubtly (against the rules[2]), but rather the overflow
to a new higher digit in the minor part will occur.  That breaks
assumption of easy comparisons in two previously common angles:

- string (e.g. when looking at /cib@validate-with XPath within CIB
  or at the available, respectively named schema files);
  example: pacemaker-2.10 < pacemaker-2.2

- mentioned float (when parsing the numerical part out of the string):
  example: 2.11 < 2.2

Here, just the former is relevant; XML.etree_rng_validator_proper_specs
was supposed to return ordered sequence of embedded/available schemas,
which is used, for instance, to grab the lowest possible for the
purpose of upgrading the schema for particular CIB document internally.
Formerly, the sorting was based on lexicographical comparison, now,
thanks to `namever_partition` (added with the previous commit) wired
into the process, it performs combined lexicographical+version
comparison so everything should keep working as expected even
when 2.10+ versions of CIB schemas are common.

Note: misc/pacemaker-borrow-schemas with it's "sort -V" should be
covered, but the eye should be kept on that when pacemaker-2.10.rng
actually arrives.

[1] ClusterLabs/pacemaker#1308
[2] https://github.com/ClusterLabs/pacemaker/blob/master/xml/Readme.md

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
jnpkrn added a commit to jnpkrn/clufter that referenced this pull request Nov 10, 2017
Originally, pacemaker was treating versions of its CIB schemas
(respectively named files) as floats, simplifying comparisons in
a simplistic single-digit minor version realms.  As the necessity
to roll out a new schema version catering the new needs is around
the corner, it was decided[1] that pacemaker will not bump the
major part abrubtly (against the rules[2]), but rather the overflow
to a new higher digit in the minor part will occur.  That breaks
assumption of easy comparisons in two previously common angles:

- string (e.g. when looking at /cib@validate-with XPath within CIB
  or at the available, respectively named schema files);
  example: pacemaker-2.10 < pacemaker-2.2

- mentioned float (when parsing the numerical part out of the string):
  example: 2.11 < 2.2

Here, just the former is relevant; XML.etree_rng_validator_proper_specs
was supposed to return ordered sequence of embedded/available schemas,
which is used, for instance, to grab the lowest possible for the
purpose of upgrading the schema for particular CIB document internally.
Formerly, the sorting was based on lexicographical comparison, now,
thanks to `namever_partition` (added with the previous commit) wired
into the process, it performs combined lexicographical+version
comparison so everything should keep working as expected even
when 2.10+ versions of CIB schemas are common.

Note: misc/pacemaker-borrow-schemas with it's "sort -V" should be
covered, but the eye should be kept on that when pacemaker-2.10.rng
actually arrives.

[1] ClusterLabs/pacemaker#1308
[2] https://github.com/ClusterLabs/pacemaker/blob/master/xml/Readme.md

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants