- Use new UTF8StringBytes

- Track number of SkipLevels in a SkipList
- More double-checks
- Caching cleanups
- Cleanups, logging, generics
This commit is contained in:
zzz
2011-03-27 22:36:45 +00:00
parent b7b7283ff9
commit f4905d2742
3 changed files with 24 additions and 8 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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;