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 ...");
+                       }
+                       }
+                       while(retryWithNewIndex);
+
                        Logger.debug(this, "Successful insert of puzzle from " 
+ identity.getNickName() + ": " + p.getRequestURI());
                }
                finally {

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to