Author: toad
Date: 2008-06-28 18:50:40 +0000 (Sat, 28 Jun 2008)
New Revision: 20858

Modified:
   branches/db4o/freenet/src/freenet/client/FECCodec.java
   branches/db4o/freenet/src/freenet/client/StandardOnionFECCodec.java
Log:
It's not a good idea for the FECCode to be stored in the database.
Make it transient, recreate it on restart.

Modified: branches/db4o/freenet/src/freenet/client/FECCodec.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/FECCodec.java      2008-06-28 
18:40:18 UTC (rev 20857)
+++ branches/db4o/freenet/src/freenet/client/FECCodec.java      2008-06-28 
18:50:40 UTC (rev 20858)
@@ -31,9 +31,11 @@

        private static int STRIPE_SIZE = 4096;
        static boolean logMINOR;
-       FECCode fec;
+       protected transient FECCode fec;
        protected final int k, n;

+       protected abstract void loadFEC();
+       
        protected FECCodec(int k, int n) {
                this.k = k;
                this.n = n;
@@ -86,6 +88,7 @@
        public abstract int countCheckBlocks();

        protected void realDecode(SplitfileBlock[] dataBlockStatus, 
SplitfileBlock[] checkBlockStatus, int blockLength, BucketFactory bf) throws 
IOException {
+               loadFEC();
                if(logMINOR)
                        Logger.minor(this, "Doing decode: " + 
dataBlockStatus.length + " data blocks, " + checkBlockStatus.length + " check 
blocks, block length " + blockLength + " with " + this, new Exception("debug"));
                if(dataBlockStatus.length + checkBlockStatus.length != n)
@@ -204,6 +207,7 @@
        protected void realEncode(Bucket[] dataBlockStatus,
                Bucket[] checkBlockStatus, int blockLength, BucketFactory bf)
                throws IOException {
+               loadFEC();
                //              Runtime.getRuntime().gc();
 //             Runtime.getRuntime().runFinalization();
 //             Runtime.getRuntime().gc();

Modified: branches/db4o/freenet/src/freenet/client/StandardOnionFECCodec.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/StandardOnionFECCodec.java 
2008-06-28 18:40:18 UTC (rev 20857)
+++ branches/db4o/freenet/src/freenet/client/StandardOnionFECCodec.java 
2008-06-28 18:50:40 UTC (rev 20858)
@@ -63,6 +63,15 @@
        public StandardOnionFECCodec(int k, int n) {
                super(k, n);

+               loadFEC();
+               
+               logMINOR = Logger.shouldLog(Logger.MINOR, this);
+       }
+       
+       protected void loadFEC() {
+               synchronized(this) {
+                       if(fec != null) return;
+               }
                FECCode fec2 = null;
                if(!noNative) {
                        try {
@@ -80,19 +89,22 @@
                }

                if (fec2 != null){
+                       synchronized(this) {
                        fec = fec2;
+                       }
                } else  {
-                       fec = new PureCode(k,n);
+                       fec2 = new PureCode(k,n);
+                       synchronized(this) {
+                               fec = fec2;
+                       }
                }

                // revert to below if above causes JVM crashes
                // Worst performance, but decode crashes
                // fec = new PureCode(k,n);
                // Crashes are caused by bugs which cause to use 320/128 etc. - 
n > 256, k < 256.
+       }

-               logMINOR = Logger.shouldLog(Logger.MINOR, this);
-       }
-       
        public int countCheckBlocks() {
                return n-k;
        }


Reply via email to