David J,
back in October we were dialoging about XidFactory
and a transaction id problem that could occur if MS SQL Server is not restarted
when JBoss is stopped and started. The problem was traced to the XidFactory
using the same baseGlobalId and resetting its globalIdNumber to zero each time
it is started.
Ive made some changes to JBossXidFactory based on
our discussion.
At the time you asked about looking into a guid
that is used in other parts of JBoss as a solution to creating a unique
baseGlobalId each time JBoss is started. The org.jboss.util.id package has a
GUID class that creates unique ids based on the host address, time stamps and
counters. The guid it creates is around 40 characters long and will be unique
even for multiple instances of JBoss on the same physical machine.
I wasnt sure if you still wanted to keep the
hostname in baseGlobalId. Ive kept it in but, its likely it will be truncated
alot of the time because of the size of the GUID.
The JBossXidFactory sticks to reserving 14
characters for the globalIdNumber. The setter method for baseGlobalId doesnt
enforce this. Ive added code to truncate the value passed to the setter if it is
too long. Im not sure if this is the best approach though. Truncating the value
may remove enough significant characters from the string that it is no longer
unique. Maybe it would be better to throw some exception if
the baseGlobalId was set to a string that doesnt
leave 14 characters for the globalIdNumber. What
is your view on this?
In the old XidFactory you had a setter method for
the globalIdNumber. You dont have this in JBossXidFactory so the
next comment isnt very relevant, but l'll make it to be thorough. The
globalIdNumber is a long which can be up to 22 digits. My thought with the old
XidFactory was that someone could supply a globalIdNumber that was greater than
14 digits. If you put a setter method for globalIdNumber back into
JBossXidFactory or if you get more than 10^14 transactions taking place in the
lifetime of a JBoss instance (pretty unlikely l guess) you will have the
potential for non-unique transaction ids.
One last thing - again to be thorough. The GUID
uses the system time a few times to create its unique string. The system time on
MS Windows is only accurate to the nearest 10-15 milliseconds. Someone would be
pretty unlucky to get two GUIDs that are the same, but it is possible on a
Windows machine if they are created within 10-15 ms of each other. If it does
happen to someone maybe they will find this posting. I cant see a way to get a
100% guarantee of uniqueness.
Ive attached JBossXidFactory with the changes lve
made.
Let me know if you need
anything done.
Jamie
|
JBossXidFactory.java
Description: Binary data