diff --git a/core/java/src/net/metanotion/io/block/index/BSkipLevels.java b/core/java/src/net/metanotion/io/block/index/BSkipLevels.java index 7a9dce53a1a129afcd63b4c259db4f793f47619d..0288fc45ffd73f9008df9b788c263af496c0e6f0 100644 --- a/core/java/src/net/metanotion/io/block/index/BSkipLevels.java +++ b/core/java/src/net/metanotion/io/block/index/BSkipLevels.java @@ -54,11 +54,13 @@ public class BSkipLevels extends SkipLevels { public final int levelPage; public final int spanPage; public final BlockFile bf; + private final BSkipList bsl; private boolean isKilled; public BSkipLevels(BlockFile bf, int levelPage, BSkipList bsl) throws IOException { this.levelPage = levelPage; this.bf = bf; + this.bsl = bsl; BlockFile.pageSeek(bf.file, levelPage); long magic = bf.file.readLong(); @@ -73,6 +75,9 @@ public class BSkipLevels extends SkipLevels { throw new IOException("Invalid Level Skip size " + nonNull + " / " + maxLen); spanPage = bf.file.readUnsignedInt(); bottom = bsl.spanHash.get(Integer.valueOf(spanPage)); + if (bottom == null) + // FIXME recover better? + BlockFile.log.error("No span found in cache???"); this.levels = new BSkipLevels[maxLen]; if (BlockFile.log.shouldLog(Log.DEBUG)) @@ -138,6 +143,7 @@ public class BSkipLevels extends SkipLevels { if (BlockFile.log.shouldLog(Log.INFO)) BlockFile.log.info("Killing " + this); isKilled = true; + bsl.levelHash.remove(levelPage); bf.freePage(levelPage); } diff --git a/core/java/src/net/metanotion/io/block/index/BSkipSpan.java b/core/java/src/net/metanotion/io/block/index/BSkipSpan.java index 277b9e80ac20984830d5b88548edfcb47514707e..49153399ff3e9009bc82dcb0d106b8bec5f33d5a 100644 --- a/core/java/src/net/metanotion/io/block/index/BSkipSpan.java +++ b/core/java/src/net/metanotion/io/block/index/BSkipSpan.java @@ -60,7 +60,8 @@ public class BSkipSpan extends SkipSpan { protected static final int MAGIC = 0x5370616e; // "Span" protected static final int HEADER_LEN = 20; protected static final int CONT_HEADER_LEN = 8; - protected BlockFile bf; + protected final BlockFile bf; + private final BSkipList bsl; protected int page; protected int overflowPage; @@ -113,6 +114,7 @@ public class BSkipSpan extends SkipSpan { } catch (IOException ioe) { BlockFile.log.error("Error freeing " + this, ioe); } + bsl.spanHash.remove(this.page); } public void flush() { @@ -213,7 +215,6 @@ public class BSkipSpan extends SkipSpan { protected static void loadInit(BSkipSpan bss, BlockFile bf, BSkipList bsl, int spanPage, Serializer key, Serializer val) throws IOException { if (bss.isKilled) BlockFile.log.error("Already killed!! " + bss, new Exception()); - bss.bf = bf; bss.page = spanPage; bss.keySer = key; bss.valSer = val; @@ -301,8 +302,14 @@ public class BSkipSpan extends SkipSpan { } } - protected BSkipSpan() { } + protected BSkipSpan(BlockFile bf, BSkipList bsl) { + this.bf = bf; + this.bsl = bsl; + } + public BSkipSpan(BlockFile bf, BSkipList bsl, int spanPage, Serializer key, Serializer val) throws IOException { + this.bf = bf; + this.bsl = bsl; BSkipSpan.load(this, bf, bsl, spanPage, key, val); this.next = null; this.prev = null; @@ -315,7 +322,7 @@ public class BSkipSpan extends SkipSpan { bss.next = temp; break; } - bss.next = new BSkipSpan(); + bss.next = new BSkipSpan(bf, bsl); bss.next.next = null; bss.next.prev = bss; bss = (BSkipSpan) bss.next; @@ -332,7 +339,7 @@ public class BSkipSpan extends SkipSpan { bss.next = temp; break; } - bss.prev = new BSkipSpan(); + bss.prev = new BSkipSpan(bf, bsl); bss.prev.next = bss; bss.prev.prev = null; bss = (BSkipSpan) bss.prev; diff --git a/core/java/src/net/metanotion/io/block/index/IBSkipSpan.java b/core/java/src/net/metanotion/io/block/index/IBSkipSpan.java index 8b65cb4c9776f6e39d9b32e8e5af263a53f8268d..08ac4fe9f38801339a00311427e2206d3d152833 100644 --- a/core/java/src/net/metanotion/io/block/index/IBSkipSpan.java +++ b/core/java/src/net/metanotion/io/block/index/IBSkipSpan.java @@ -232,9 +232,12 @@ public class IBSkipSpan extends BSkipSpan { } } - protected IBSkipSpan() { } + private IBSkipSpan(BlockFile bf, BSkipList bsl) { + super(bf, bsl); + } public IBSkipSpan(BlockFile bf, BSkipList bsl, int spanPage, Serializer key, Serializer val) throws IOException { + super(bf, bsl); if (BlockFile.log.shouldLog(Log.DEBUG)) BlockFile.log.debug("New ibss page " + spanPage); BSkipSpan.loadInit(this, bf, bsl, spanPage, key, val); @@ -251,7 +254,7 @@ public class IBSkipSpan extends BSkipSpan { bss.next = temp; break; } - bss.next = new IBSkipSpan(); + bss.next = new IBSkipSpan(bf, bsl); bss.next.next = null; bss.next.prev = bss; bss = (IBSkipSpan) bss.next; @@ -269,7 +272,7 @@ public class IBSkipSpan extends BSkipSpan { bss.next = temp; break; } - bss.prev = new IBSkipSpan(); + bss.prev = new IBSkipSpan(bf, bsl); bss.prev.next = bss; bss.prev.prev = null; bss = (IBSkipSpan) bss.prev;