> -----Original Message-----
> From: devl-bounces at freenetproject.org 
> [mailto:devl-bounces at freenetproject.org] On Behalf Of Matthew Toseland
> Sent: Saturday, November 15, 2008 1:14 AM
> To: devl at freenetproject.org
> Subject: Re: [freenet-dev] [freenet-cvs] r23578 
> -trunk/plugins/WoT/introduction
> 
> On Friday 14 November 2008 15:11, xor at freenetproject.org wrote:
> > Author: xor
> > Date: 2008-11-14 15:11:39 +0000 (Fri, 14 Nov 2008) New 
> Revision: 23578
> > 
> > Modified:
> >    trunk/plugins/WoT/introduction/IntroductionServer.java
> > Log:
> > Search free index by skipping collisions if database loses puzzles.
> > 
> > Modified: trunk/plugins/WoT/introduction/IntroductionServer.java
> > ===================================================================
> > --- trunk/plugins/WoT/introduction/IntroductionServer.java  
> 2008-11-14 
> 14:59:39 UTC (rev 23577)
> > +++ trunk/plugins/WoT/introduction/IntroductionServer.java  
> 2008-11-14 
> 15:11:39 UTC (rev 23578)
> > @@ -208,7 +208,11 @@
> >             OutputStream os = tempB.getOutputStream();
> >             
> >             try {
> > -                   IntroductionPuzzle p = 
> mPuzzleFactories[(int)(Math.random() * 100) % 
> mPuzzleFactories.length].generatePuzzle(db, identity);
> > +                   boolean retryWithNewIndex = false;
> > +                   IntroductionPuzzle p = null;
> > +                   do {
> > +                   try {
> > +                   p = 
> mPuzzleFactories[(int)(Math.random() * 100) %
> mPuzzleFactories.length].generatePuzzle(db, identity);
> >                     p.exportToXML(os);
> >                     os.close(); os = null;
> >                     tempB.setReadOnly();
> > @@ -218,11 +222,23 @@
> >  
> >                     Logger.debug(this, "Started insert 
> puzzle from " +
> identity.getNickName());
> >  
> > -                   /* FIXME: use nonblocking insert */
> > -                   mClient.insert(ib, false, 
> p.getInsertURI().getDocName());
> > +                   /* FIXME: use nonblocking insert maybe */
> > +                   mClient.insert(ib, false, null);
> >  
> >                     db.store(p);
> >                     db.commit();
> > +                   }
> > +                   catch(InsertException e) {
> > +                           if(e.errorCodes.getFirstCode() 
> == InsertException.COLLISION)
> > +                                   retryWithNewIndex = true;
> > +                           else
> > +                                   throw e;
> > +                           
> > +                           Logger.error(this, "Puzzle with 
> index " + p.getIndex() + " 
> > +already
> inserted and not found in database! Retrying with next index ...");
> 
> That just means somebody else got there first, right?

No, this code inserts puzzles, not puzzle solutions. The URI
of a puzzle is SSK and therefore nobody else than the identity
which owns the SSK can insert there.

I added this code because the database sometimes lost the stored,
inserted puzzles: This code will find out the smallest free index
where a puzzle can be inserted for the current day. This is normally
found out by a database query which returns the highest taken index
of the current day.

> 
> > +                   }
> > +                   }
> > +                   while(retryWithNewIndex);
> > +
> >                     Logger.debug(this, "Successful insert 
> of puzzle from " +
> identity.getNickName() + ": " + p.getRequestURI());
> >             }
> >             finally {
> 


Reply via email to