LUCENE-3661: nuke nocommit for real, split SimpleText to use read-only bits impls whenever it can

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3661@1237127 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-01-28 18:22:49 +00:00
parent 1b8d8b4350
commit 8933cfe181
2 changed files with 22 additions and 21 deletions

View File

@ -53,13 +53,13 @@ public class SimpleTextLiveDocsFormat extends LiveDocsFormat {
@Override @Override
public MutableBits newLiveDocs(int size) throws IOException { public MutableBits newLiveDocs(int size) throws IOException {
return new SimpleTextBits(size); return new SimpleTextMutableBits(size);
} }
@Override @Override
public MutableBits newLiveDocs(Bits existing) throws IOException { public MutableBits newLiveDocs(Bits existing) throws IOException {
final SimpleTextBits bits = (SimpleTextBits) existing; final SimpleTextBits bits = (SimpleTextBits) existing;
return bits.clone(); return new SimpleTextMutableBits((BitSet)bits.bits.clone(), bits.size);
} }
@Override @Override
@ -144,16 +144,11 @@ public class SimpleTextLiveDocsFormat extends LiveDocsFormat {
} }
} }
static class SimpleTextBits implements MutableBits { // read-only
static class SimpleTextBits implements Bits {
final BitSet bits; final BitSet bits;
final int size; final int size;
SimpleTextBits(int size) {
this.size = size;
bits = new BitSet(size);
bits.set(0, size);
}
SimpleTextBits(BitSet bits, int size) { SimpleTextBits(BitSet bits, int size) {
this.bits = bits; this.bits = bits;
this.size = size; this.size = size;
@ -168,16 +163,23 @@ public class SimpleTextLiveDocsFormat extends LiveDocsFormat {
public int length() { public int length() {
return size; return size;
} }
}
// read-write
static class SimpleTextMutableBits extends SimpleTextBits implements MutableBits {
SimpleTextMutableBits(int size) {
this(new BitSet(size), size);
bits.set(0, size);
}
SimpleTextMutableBits(BitSet bits, int size) {
super(bits, size);
}
@Override @Override
public void clear(int bit) { public void clear(int bit) {
bits.clear(bit); bits.clear(bit);
} }
@Override
public SimpleTextBits clone() {
BitSet clonedBits = (BitSet) bits.clone();
return new SimpleTextBits(clonedBits, size);
}
} }
} }

View File

@ -417,7 +417,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
// docs, and it's copy-on-write (cloned whenever we need // docs, and it's copy-on-write (cloned whenever we need
// to change it but it's been shared to an external NRT // to change it but it's been shared to an external NRT
// reader). // reader).
public MutableBits liveDocs; public Bits liveDocs;
// How many further deletions we've done against // How many further deletions we've done against
// liveDocs vs when we loaded it or last wrote it: // liveDocs vs when we loaded it or last wrote it:
@ -494,8 +494,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
if (reader == null) { if (reader == null) {
reader = new SegmentReader(info, config.getReaderTermsIndexDivisor(), context); reader = new SegmentReader(info, config.getReaderTermsIndexDivisor(), context);
if (liveDocs == null) { if (liveDocs == null) {
// nocommit: still don't like this cast, gotta be a cleaner way. liveDocs = reader.getLiveDocs();
liveDocs = (MutableBits) reader.getLiveDocs();
} }
//System.out.println("ADD seg=" + rld.info + " isMerge=" + isMerge + " " + readerMap.size() + " in pool"); //System.out.println("ADD seg=" + rld.info + " isMerge=" + isMerge + " " + readerMap.size() + " in pool");
} }
@ -522,7 +521,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
} else { } else {
mergeReader = new SegmentReader(info, -1, context); mergeReader = new SegmentReader(info, -1, context);
if (liveDocs == null) { if (liveDocs == null) {
liveDocs = (MutableBits) mergeReader.getLiveDocs(); liveDocs = mergeReader.getLiveDocs();
} }
} }
} }
@ -538,7 +537,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
assert !shared; assert !shared;
final boolean didDelete = liveDocs.get(docID); final boolean didDelete = liveDocs.get(docID);
if (didDelete) { if (didDelete) {
liveDocs.clear(docID); ((MutableBits) liveDocs).clear(docID);
pendingDeleteCount++; pendingDeleteCount++;
//System.out.println(" new del seg=" + info + " docID=" + docID + " pendingDelCount=" + pendingDeleteCount + " totDelCount=" + (info.docCount-liveDocs.count())); //System.out.println(" new del seg=" + info + " docID=" + docID + " pendingDelCount=" + pendingDeleteCount + " totDelCount=" + (info.docCount-liveDocs.count()));
} }
@ -627,7 +626,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
// until segments file is written: // until segments file is written:
boolean success = false; boolean success = false;
try { try {
info.getCodec().liveDocsFormat().writeLiveDocs(liveDocs, dir, info, IOContext.DEFAULT); info.getCodec().liveDocsFormat().writeLiveDocs((MutableBits)liveDocs, dir, info, IOContext.DEFAULT);
success = true; success = true;
} finally { } finally {
if (!success) { if (!success) {