You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Will Glass-Husain <wg...@forio.com> on 2006/12/05 16:04:42 UTC

duplicate ID exception in cluster

Hi,

I just set up a new 2 server cluster with two instances of Tomcat both
reading/writing from a single database.  I'm using Torque 3.0, the
default ID Broker and MySQL 5. (InnoDB)

My problem... Under heavy load, I notice that most write requests on
one of the servers fails with a duplicate ID error.  Typically, each
page request that fails does 10-20 insert statements.

Any tips as to how I might make this cluster work with simultaneous writes?

WILL

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: duplicate ID exception in cluster

Posted by Will Glass-Husain <wg...@forio.com>.
Converted to AUTO_INCREMENT, I'm much happier.  Also solves the
problem of restarting Tomcat and suddenly having the db id's be out of
sync with ID_TABLE.  Always hated the ID Broker :-)

WILL

On 12/6/06, Henning Schmiedehausen <hp...@intermeta.de> wrote:
> Ah, so it is an application cluster, not a db cluster (sorry, didn't saw
> that in your first mail).
>
> You get this behaviour when the two nodes refresh their Id Broker from
> the DB. Try
>
> torque.idbroker.cleverquantity=false
> torque.idbroker.prefetch=false
>
> Better yet, don't use the Id broker but use an AUTO_INCREMENT column.
>
>         Best regards
>                 Henning
>
>
>
> On Tue, 2006-12-05 at 14:42 -0800, Will Glass-Husain wrote:
> > Hi Henning!
> >
> > It's a real (Tomcat) cluster.  Two instances of Tomcat talking to a
> > single database.  (no database replication).  I use Apache/mod_jk to
> > split requests (based on session) between the two Tomcats.  Allows me
> > to run high number of users with a memory-heavy application.
> >
> > Thought briefly about database replication but since this is
> > write-heavy application it didn't seem to make sense.
> >
> > thanks,
> > WILL
> >
> > On 12/5/06, Henning P. Schmiedehausen <hp...@intermeta.de> wrote:
> > > "Will Glass-Husain" <wg...@forio.com> writes:
> > >
> > > >Hi,
> > >
> > > >I just set up a new 2 server cluster with two instances of Tomcat both
> > > >reading/writing from a single database.  I'm using Torque 3.0, the
> > > >default ID Broker and MySQL 5. (InnoDB)
> > >
> > > Real cluster or just master/slave (or master/master with only one master
> > > active at a time)? The latter is just replication, not a real cluster.
> > >
> > > >My problem... Under heavy load, I notice that most write requests on
> > > >one of the servers fails with a duplicate ID error.  Typically, each
> > > >page request that fails does 10-20 insert statements.
> > >
> > > >Any tips as to how I might make this cluster work with simultaneous writes?
> > >
> > > a) in a master/master config, you can not write to both masters at the
> > >    same time. End of story. I had a summer project where we tested
> > >    exactly that *very* extensively. It does not work. No matter what you
> > >    google on the internet or what mysql.com wants to tell you. You will
> > >    get the described error sooner or later. If you want to have
> > >    master/master with failover, that is fine. Two active masters not.
> > >
> > > b) you probably run into the AUTO_INCREMENT problem. Make sure that you
> > >    have 5.0.20 at least. See http://dev.mysql.com/doc/refman/5.0/en/replication-features.html
> > >    for some docs.
> > >
> > >
> > >         Best regards
> > >                 Henning
> > >
> > > --
> > > Henning P. Schmiedehausen  -- hps@intermeta.de | J2EE, Linux,
> > > 91054 Buckenhof, Germany   -- +49 9131 506540 | Apache person
> > > Open Source Consulting, Development, Design | Velocity - Turbine guy
> > >
> > >           "Save the cheerleader. Save the world."
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> > > For additional commands, e-mail: torque-user-help@db.apache.org
> > >
> > >
> >
> >
> --
> Henning P. Schmiedehausen  -- hps@intermeta.de | J2EE, Linux,
> 91054 Buckenhof, Germany   -- +49 9131 506540 | Apache person
> Open Source Consulting, Development, Design | Velocity - Turbine guy
>
>           "Save the cheerleader. Save the world."
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>


-- 
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: duplicate ID exception in cluster

Posted by Henning Schmiedehausen <hp...@intermeta.de>.
Ah, so it is an application cluster, not a db cluster (sorry, didn't saw
that in your first mail). 

You get this behaviour when the two nodes refresh their Id Broker from
the DB. Try

torque.idbroker.cleverquantity=false
torque.idbroker.prefetch=false

Better yet, don't use the Id broker but use an AUTO_INCREMENT column.

	Best regards
		Henning



On Tue, 2006-12-05 at 14:42 -0800, Will Glass-Husain wrote:
> Hi Henning!
> 
> It's a real (Tomcat) cluster.  Two instances of Tomcat talking to a
> single database.  (no database replication).  I use Apache/mod_jk to
> split requests (based on session) between the two Tomcats.  Allows me
> to run high number of users with a memory-heavy application.
> 
> Thought briefly about database replication but since this is
> write-heavy application it didn't seem to make sense.
> 
> thanks,
> WILL
> 
> On 12/5/06, Henning P. Schmiedehausen <hp...@intermeta.de> wrote:
> > "Will Glass-Husain" <wg...@forio.com> writes:
> >
> > >Hi,
> >
> > >I just set up a new 2 server cluster with two instances of Tomcat both
> > >reading/writing from a single database.  I'm using Torque 3.0, the
> > >default ID Broker and MySQL 5. (InnoDB)
> >
> > Real cluster or just master/slave (or master/master with only one master
> > active at a time)? The latter is just replication, not a real cluster.
> >
> > >My problem... Under heavy load, I notice that most write requests on
> > >one of the servers fails with a duplicate ID error.  Typically, each
> > >page request that fails does 10-20 insert statements.
> >
> > >Any tips as to how I might make this cluster work with simultaneous writes?
> >
> > a) in a master/master config, you can not write to both masters at the
> >    same time. End of story. I had a summer project where we tested
> >    exactly that *very* extensively. It does not work. No matter what you
> >    google on the internet or what mysql.com wants to tell you. You will
> >    get the described error sooner or later. If you want to have
> >    master/master with failover, that is fine. Two active masters not.
> >
> > b) you probably run into the AUTO_INCREMENT problem. Make sure that you
> >    have 5.0.20 at least. See http://dev.mysql.com/doc/refman/5.0/en/replication-features.html
> >    for some docs.
> >
> >
> >         Best regards
> >                 Henning
> >
> > --
> > Henning P. Schmiedehausen  -- hps@intermeta.de | J2EE, Linux,
> > 91054 Buckenhof, Germany   -- +49 9131 506540 | Apache person
> > Open Source Consulting, Development, Design | Velocity - Turbine guy
> >
> >           "Save the cheerleader. Save the world."
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: torque-user-help@db.apache.org
> >
> >
> 
> 
-- 
Henning P. Schmiedehausen  -- hps@intermeta.de | J2EE, Linux,
91054 Buckenhof, Germany   -- +49 9131 506540 | Apache person
Open Source Consulting, Development, Design | Velocity - Turbine guy

          "Save the cheerleader. Save the world."



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: duplicate ID exception in cluster

Posted by Will Glass-Husain <wg...@forio.com>.
Hi Henning!

It's a real (Tomcat) cluster.  Two instances of Tomcat talking to a
single database.  (no database replication).  I use Apache/mod_jk to
split requests (based on session) between the two Tomcats.  Allows me
to run high number of users with a memory-heavy application.

Thought briefly about database replication but since this is
write-heavy application it didn't seem to make sense.

thanks,
WILL

On 12/5/06, Henning P. Schmiedehausen <hp...@intermeta.de> wrote:
> "Will Glass-Husain" <wg...@forio.com> writes:
>
> >Hi,
>
> >I just set up a new 2 server cluster with two instances of Tomcat both
> >reading/writing from a single database.  I'm using Torque 3.0, the
> >default ID Broker and MySQL 5. (InnoDB)
>
> Real cluster or just master/slave (or master/master with only one master
> active at a time)? The latter is just replication, not a real cluster.
>
> >My problem... Under heavy load, I notice that most write requests on
> >one of the servers fails with a duplicate ID error.  Typically, each
> >page request that fails does 10-20 insert statements.
>
> >Any tips as to how I might make this cluster work with simultaneous writes?
>
> a) in a master/master config, you can not write to both masters at the
>    same time. End of story. I had a summer project where we tested
>    exactly that *very* extensively. It does not work. No matter what you
>    google on the internet or what mysql.com wants to tell you. You will
>    get the described error sooner or later. If you want to have
>    master/master with failover, that is fine. Two active masters not.
>
> b) you probably run into the AUTO_INCREMENT problem. Make sure that you
>    have 5.0.20 at least. See http://dev.mysql.com/doc/refman/5.0/en/replication-features.html
>    for some docs.
>
>
>         Best regards
>                 Henning
>
> --
> Henning P. Schmiedehausen  -- hps@intermeta.de | J2EE, Linux,
> 91054 Buckenhof, Germany   -- +49 9131 506540 | Apache person
> Open Source Consulting, Development, Design | Velocity - Turbine guy
>
>           "Save the cheerleader. Save the world."
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>


-- 
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: duplicate ID exception in cluster

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
"Will Glass-Husain" <wg...@forio.com> writes:

>Hi,

>I just set up a new 2 server cluster with two instances of Tomcat both
>reading/writing from a single database.  I'm using Torque 3.0, the
>default ID Broker and MySQL 5. (InnoDB)

Real cluster or just master/slave (or master/master with only one master
active at a time)? The latter is just replication, not a real cluster.

>My problem... Under heavy load, I notice that most write requests on
>one of the servers fails with a duplicate ID error.  Typically, each
>page request that fails does 10-20 insert statements.

>Any tips as to how I might make this cluster work with simultaneous writes?

a) in a master/master config, you can not write to both masters at the
   same time. End of story. I had a summer project where we tested
   exactly that *very* extensively. It does not work. No matter what you
   google on the internet or what mysql.com wants to tell you. You will
   get the described error sooner or later. If you want to have 
   master/master with failover, that is fine. Two active masters not.

b) you probably run into the AUTO_INCREMENT problem. Make sure that you
   have 5.0.20 at least. See http://dev.mysql.com/doc/refman/5.0/en/replication-features.html
   for some docs.


	Best regards
		Henning

-- 
Henning P. Schmiedehausen  -- hps@intermeta.de | J2EE, Linux,
91054 Buckenhof, Germany   -- +49 9131 506540 | Apache person
Open Source Consulting, Development, Design | Velocity - Turbine guy

          "Save the cheerleader. Save the world."

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: duplicate ID exception in cluster

Posted by Greg Monroe <Gr...@DukeCE.com>.
Thoralf is right, the only way to make the idBroker 
"cluster" safe is to use transactions on any Peer
doInsert/Update methods.  E.g.:

Connection con = null;
try
{
   con = Transaction.begin(dbName);
   MyTablePeer.doInsert( criteria, con);
   Transaction.commit(con);
}
catch(TorqueException e)
{
   Transaction.safeRollback(con);
   throw e;
}

You don't need to do this with the record object
save() method, because this is already wrapped
in a simple transaction.

Please note that I verified this against the latest 
code.  It may not work under V3.0.  I seem to remember
some mods going in to make the keygen stuff use the
same connection instead of a different one so the 
idBroker would be transaction safe... but this could
be a parity error in my memory.

> -----Original Message-----
> From: wglasshusain@gmail.com [mailto:wglasshusain@gmail.com] 
> On Behalf Of Will Glass-Husain
> Sent: Tuesday, December 05, 2006 10:05 AM
> To: torque-user@db.apache.org
> Subject: duplicate ID exception in cluster
> 
> Hi,
> 
> I just set up a new 2 server cluster with two instances of 
> Tomcat both reading/writing from a single database.  I'm 
> using Torque 3.0, the default ID Broker and MySQL 5. (InnoDB)
> 
> My problem... Under heavy load, I notice that most write 
> requests on one of the servers fails with a duplicate ID 
> error.  Typically, each page request that fails does 10-20 
> insert statements.
> 
> Any tips as to how I might make this cluster work with 
> simultaneous writes?
> 
> WILL
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 
> 

Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are confidential communication or may otherwise be privileged or confidential and are intended solely for the individual or entity to whom they are addressed.  If you are not the intended recipient you may not rely on the contents of this email or any attachments, and we ask that you  please not read, copy or retransmit this communication, but reply to the sender and destroy the email, its contents, and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying of this communication is strictly prohibited.



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org