Author: toad
Date: 2008-12-24 19:55:57 +0000 (Wed, 24 Dec 2008)
New Revision: 24788

Modified:
   branches/db4o/freenet/src/freenet/support/io/SegmentedBucketChainBucket.java
Log:
Don't forget to set freed when freeing, to prevent further use of the bucket.
Free the segments before returning from free().
In getOutputStream(), removeFrom() the old segments if any before returning.
Allow removeFrom() if we haven't been stored (we haven't as storeTo throws). 
Necessary in splitfile insert.
Set the freed flag after removing after startup from a KillJob.


Modified: 
branches/db4o/freenet/src/freenet/support/io/SegmentedBucketChainBucket.java
===================================================================
--- 
branches/db4o/freenet/src/freenet/support/io/SegmentedBucketChainBucket.java    
    2008-12-24 19:45:26 UTC (rev 24787)
+++ 
branches/db4o/freenet/src/freenet/support/io/SegmentedBucketChainBucket.java    
    2008-12-24 19:55:57 UTC (rev 24788)
@@ -60,7 +60,13 @@
        }
 
        public void free() {
-               dbJobRunner.queue(new DBJob() {
+               synchronized(this) {
+                       freed = true;
+               }
+               // Complete the cleanup before returning.
+               // SegmentedBucketChainBucket can't be stored to disk so we 
will be run on helper threads generally,
+               // so we will have to wait for a job to complete on the 
database thread, but that is okay.
+               dbJobRunner.runBlocking(new DBJob() {
 
                        public void run(ObjectContainer container, 
ClientContext context) {
                                SegmentedChainBucketSegment[] segs;
@@ -80,7 +86,7 @@
                                }
                        }
                        
-               }, NativeThread.HIGH_PRIORITY, false);
+               }, NativeThread.HIGH_PRIORITY);
        }
 
        public InputStream getInputStream() throws IOException {
@@ -180,7 +186,7 @@
        }
 
        public OutputStream getOutputStream() throws IOException {
-               SegmentedChainBucketSegment[] segs;
+               final SegmentedChainBucketSegment[] segs;
                synchronized(this) {
                        if(readOnly) throw new IOException("Read-only");
                        if(freed) throw new IOException("Freed");
@@ -188,8 +194,18 @@
                        segs = segments.toArray(new 
SegmentedChainBucketSegment[segments.size()]);
                        segments.clear();
                }
-               for(int i=0;i<segs.length;i++) {
+               for(int i=0;i<segs.length;i++)
                        segs[i].free();
+               if(segs.length > 0) {
+                       dbJobRunner.runBlocking(new DBJob() {
+
+                               public void run(ObjectContainer container, 
ClientContext context) {
+                                       for(int i=0;i<segs.length;i++) {
+                                               segs[i].removeFrom(container);
+                                       }
+                               }
+                               
+                       }, NativeThread.HIGH_PRIORITY);
                }
                return new OutputStream() {
                        
@@ -329,7 +345,7 @@
        }
 
        public void removeFrom(ObjectContainer container) {
-               throw new UnsupportedOperationException();
+               // Valid no-op if we haven't been stored.
        }
 
        public void setReadOnly() {
@@ -409,6 +425,7 @@
                }
                container.delete(segments);
                container.delete(this);
+               freed = true; // Just in case it wasn't already.
        }
        
 }

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

Reply via email to