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?
> + }
> + }
> + while(retryWithNewIndex);
> +
> Logger.debug(this, "Successful insert of puzzle from "
> +
identity.getNickName() + ": " + p.getRequestURI());
> }
> finally {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL:
<https://emu.freenetproject.org/pipermail/devl/attachments/20081115/d18604f2/attachment.pgp>