[jboss-jira] [JBoss JIRA] Commented: (JBMESSAGING-1682) duplicate key value violates unique constraint "jbm_msg_pkey" exceptions in a clustered
Masao Kato (JIRA)
jira-events at lists.jboss.org
Wed Jul 8 23:34:30 EDT 2009
[ https://jira.jboss.org/jira/browse/JBMESSAGING-1682?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12475546#action_12475546 ]
Masao Kato commented on JBMESSAGING-1682:
-----------------------------------------
A source code to seem to be a problem
org.jboss.messaging.core.impl.RotatingID.java
public synchronized long getID()
{
long id1 = nodeID << 54;
long id2 = System.currentTimeMillis() << 14;
long id = id1 | id2 | count;
if (count == Short.MAX_VALUE)
{
count = 0;
long now = System.currentTimeMillis();
//Safety - not likely to happen
while (now == lastTime)
{
try
{
Thread.sleep(1);
}
catch (InterruptedException e)
{}
now = System.currentTimeMillis();
}
lastTime = now;
}
else
{
count++;
}
return id;
}
I think that the position of the shift of the bit is strange.
I understand that the same message ID is generated with the same count value at the same time when I carry out the following message ID generation sample programs.
public class MsgIDTest {
public static void main(String[] args) {
long tmptime = System.currentTimeMillis();
for (long i = 0; i <255; i++) {
printId(i,tmptime,(short)(Short.MAX_VALUE-1));
}
}
static public void printId(long nodeID, long time, short count) {
System.out.println(" nodeID:" + Long.toString(nodeID));
System.out.println(" ms:" + Long.toBinaryString(time));
//generate id
long id1 = nodeID << 54;
long id2 = time << 14;
long id = id1 | id2 | count;
System.out.println(" MsgID:" + Long.toString(id));
System.out.println("==Binary=");
System.out.println(" nodeID:" + Long.toBinaryString(nodeID));
System.out.println("nodeID<<54:" + Long.toBinaryString(id1));
System.out.println(" ms<<14:" + Long.toBinaryString(id2));
System.out.println(" MsgID:" + Long.toBinaryString(id));
System.out.println("");
}
}
output:
nodeID:0
ms:10010001001011101100010000101011011100010
MsgID:20432645850169344
==Binary=
nodeID:0
nodeID<<54:0
ms<<14:1001000100101110110001000010101101110001000000000000000
MsgID:1001000100101110110001000010101101110001000000000000000
nodeID:1
ms:10010001001011101100010000101011011100010
MsgID:20432645850169344
==Binary=
nodeID:1
nodeID<<54:1000000000000000000000000000000000000000000000000000000
ms<<14:1001000100101110110001000010101101110001000000000000000
MsgID:1001000100101110110001000010101101110001000000000000000
nodeID:2
ms:10010001001011101100010000101011011100010
MsgID:56461442869133312
==Binary=
nodeID:10
nodeID<<54:10000000000000000000000000000000000000000000000000000000
ms<<14:1001000100101110110001000010101101110001000000000000000
MsgID:11001000100101110110001000010101101110001000000000000000
nodeID:3
ms:10010001001011101100010000101011011100010
MsgID:56461442869133312
==Binary=
nodeID:11
nodeID<<54:11000000000000000000000000000000000000000000000000000000
ms<<14:1001000100101110110001000010101101110001000000000000000
MsgID:11001000100101110110001000010101101110001000000000000000
Workaround:
Don't use an ID number next to each other node ID in the cluster.
> 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: Tim Fox
>
> 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