Compacting product version strings into shorts
brian.stansberry Feb 12, 2006 1:59 AMJBoss has recently standardized the naming conventions for product releases (see http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossProductVersioning). This thread is aimed at deriving a standard mechanism for converting the String identifier for releases into a short.
Background:
Both JBoss Cache and JGroups encode their release version into a short for inclusion in data transmitted between cluster nodes. This information is used to control interoperation between nodes running different releases of the software.
In the JGroups case at least, the use of a short (as opposed to, say, an int) is important, as the value is included with every message and needs to be transmitted as efficiently as possible.
Other projects may have a similar need. Many projects may have no such need, or may prefer to encode in an int. For reasons discussed below, I don't advocate that all projects be able to convert version strings into shorts; only that those who do should follow a common mechanism.
Proposal:
The JBoss convention is that release names are of format X.Y.ZZ.Q*, where Q is an alpha-numeric qualifier. I propose simply to put X in the thousands position, Y in the hundreds, Z in the tens. The final position would be 0 unless Q == "SP", in which case the final position would be the digit immediately following SP. If Q were a digit, the final digit would be Q.
Thus 1.2.4.SP1 would be 1241, 1.3 would be 1300. 2.2.9.1 would be 2291.
A couple issues arise with this scheme:
1) All versions up to and including the GA release all resolve to the same short. In the clustering use cases for these shorts, this is not an issue; if, for example, JBossCache 1.3.0.Alpha1 and 1.3.0.Alpha2 had different wire formats, the short wouldn't be useful in distinguishing the versions, but who cares if different pre-GA versions don't interoperate?
(This "problem"could be resolved by giving a position to the alpha qualifier, shifting higher order elements up. But then release numbers > 3.2.7 would not be possible; 6.5.5 if unsigned shorts were used.)
2) Clearly, numeric values other than the major version number cannot be > 9. This is a significant limitation. I would suggest that projects that see the possibility of lower-level version numbers going higher than nine should not use shorts for version encoding.
Please note also that even in the string versions of release names, using values > 9 in positions other than the major version field results in strings that sort incorrectly, e.g.
1.2.0
1.2.1
1.2.10
1.2.2
1.2.9