[jboss-jira] [JBoss JIRA] Commented: (JBMESSAGING-1682) duplicate key value violates unique constraint "jbm_msg_pkey" exceptions in a clustered
Howard Gao (JIRA)
jira-events at lists.jboss.org
Thu Jul 9 04:38:41 EDT 2009
[ https://jira.jboss.org/jira/browse/JBMESSAGING-1682?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12475577#action_12475577 ]
Howard Gao commented on JBMESSAGING-1682:
-----------------------------------------
As of cp08/1.4.4.GA, the RotatingID's algorithm has been changed because of the enlargement of that range of nodeID.
The new structure of a ID is like:
[16 bits node id] + [34 bits time] + [14 bits counter]
However the code is not implementing this structure:
long id1 = nodeID << 48;
long id2 = System.currentTimeMillis() << 14;
long id = id1 | id2 | count;
and the counter is a short type value, it should be 15 bit (minus the highest sign bit).
So we can re-design the structure as:
[16 bits node id] + [33 bits time] + [15 bits counter]
Another issue is how we take the time bits off the system time (a long value). We know the upper bits of the system
changes very slow (it takes a very long time to make the 40th bit increase by one for example). So we should take the lower part.
If we take bit0 (lowest bit) to bit 32, that means for every millisecond, this field will change by one. To make this field have two same value, you need
2^33 milliseconds, that's about 2^33 / 1000 / 3600 / 24 = 99 days.
However, to make two messages have same ID, the first message must keep in the DB for at least 99 days (and for each 99 days interval thereafter). And the second message
must be sent on the 99th day within the same millisecond, and the counter value (third field) needs to be the same as the first one.
Or, in another case, if the sending rate of messages within one node is equal to or greater than 32767 (short.MAX_VALUE) messages per millisecond, and those messages are all stored in DB at the moment,
there is a chance of two messages having identical IDs.
> duplicate key value violates unique constraint "jbm_msg_pkey" exceptions in a clustered
> ---------------------------------------------------------------------------------------
>
> Key: JBMESSAGING-1682
> URL: https://jira.jboss.org/jira/browse/JBMESSAGING-1682
> Project: JBoss Messaging
> Issue Type: Bug
> Components: JMS Clustering
> Affects Versions: 1.4.0.SP3.CP07
> Reporter: Masao Kato
> Assignee: Howard Gao
>
> NodeID(server peer id) of the cluster : in the adjoined identification number such as 0 and 1, 2 and 3.
> When message ID is generated at the same time, the exception might be generated by the duplicate of ID.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list