diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40CompoundReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40CompoundReader.java index da5dbbed9d9..de108dbbfa1 100644 --- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40CompoundReader.java +++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40CompoundReader.java @@ -234,12 +234,15 @@ final class Lucene40CompoundReader extends BaseDirectory { throw new UnsupportedOperationException(); } - /** Not implemented - * @throws UnsupportedOperationException always: not supported by CFS */ @Override public Lock makeLock(String name) { throw new UnsupportedOperationException(); } + + @Override + public void clearLock(String name) throws IOException { + throw new UnsupportedOperationException(); + } @Override public String toString() { diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCodec.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCodec.java index 019bb1cd518..c99eef2e12a 100644 --- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCodec.java +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCodec.java @@ -27,7 +27,6 @@ import org.apache.lucene.codecs.DocValuesFormat; import org.apache.lucene.codecs.NormsFormat; import org.apache.lucene.codecs.StoredFieldsFormat; import org.apache.lucene.codecs.TermVectorsFormat; -import org.apache.lucene.codecs.lucene50.Lucene50CompoundFormat; /** * plain text index format. @@ -44,8 +43,7 @@ public final class SimpleTextCodec extends Codec { private final NormsFormat normsFormat = new SimpleTextNormsFormat(); private final LiveDocsFormat liveDocs = new SimpleTextLiveDocsFormat(); private final DocValuesFormat dvFormat = new SimpleTextDocValuesFormat(); - // nocommit - private final CompoundFormat compoundFormat = new Lucene50CompoundFormat(); + private final CompoundFormat compoundFormat = new SimpleTextCompoundFormat(); public SimpleTextCodec() { super("SimpleText"); diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCompoundFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCompoundFormat.java new file mode 100644 index 00000000000..d6495979493 --- /dev/null +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextCompoundFormat.java @@ -0,0 +1,246 @@ +package org.apache.lucene.codecs.simpletext; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.ParseException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Locale; + +import org.apache.lucene.codecs.CompoundFormat; +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.MergeState.CheckAbort; +import org.apache.lucene.index.IndexFileNames; +import org.apache.lucene.index.SegmentInfo; +import org.apache.lucene.store.BaseDirectory; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; +import org.apache.lucene.store.IndexInput; +import org.apache.lucene.store.IndexOutput; +import org.apache.lucene.store.Lock; +import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.BytesRefBuilder; +import org.apache.lucene.util.StringHelper; + +/** + * plain text compound format. + *
+ * FOR RECREATIONAL USE ONLY
+ * @lucene.experimental
+ */
+public class SimpleTextCompoundFormat extends CompoundFormat {
+
+ @Override
+ public Directory getCompoundReader(Directory dir, SegmentInfo si, IOContext context) throws IOException {
+ String dataFile = IndexFileNames.segmentFileName(si.name, "", DATA_EXTENSION);
+ final IndexInput in = dir.openInput(dataFile, context);
+
+ BytesRefBuilder scratch = new BytesRefBuilder();
+
+ // first get to TOC:
+ DecimalFormat df = new DecimalFormat(OFFSETPATTERN, DecimalFormatSymbols.getInstance(Locale.ROOT));
+ long pos = in.length() - TABLEPOS.length - OFFSETPATTERN.length() - 1;
+ in.seek(pos);
+ SimpleTextUtil.readLine(in, scratch);
+ assert StringHelper.startsWith(scratch.get(), TABLEPOS);
+ long tablePos = -1;
+ try {
+ tablePos = df.parse(stripPrefix(scratch, TABLEPOS)).longValue();
+ } catch (ParseException e) {
+ throw new CorruptIndexException("can't parse CFS trailer, got: " + scratch.get().utf8ToString(), in);
+ }
+
+ // seek to TOC and read it
+ in.seek(tablePos);
+ SimpleTextUtil.readLine(in, scratch);
+ assert StringHelper.startsWith(scratch.get(), TABLE);
+ int numEntries = Integer.parseInt(stripPrefix(scratch, TABLE));
+
+ final String fileNames[] = new String[numEntries];
+ final long startOffsets[] = new long[numEntries];
+ final long endOffsets[] = new long[numEntries];
+
+ for (int i = 0; i < numEntries; i++) {
+ SimpleTextUtil.readLine(in, scratch);
+ assert StringHelper.startsWith(scratch.get(), TABLENAME);
+ fileNames[i] = si.name + IndexFileNames.stripSegmentName(stripPrefix(scratch, TABLENAME));
+
+ if (i > 0) {
+ // files must be unique and in sorted order
+ assert fileNames[i].compareTo(fileNames[i-1]) > 0;
+ }
+
+ SimpleTextUtil.readLine(in, scratch);
+ assert StringHelper.startsWith(scratch.get(), TABLESTART);
+ startOffsets[i] = Long.parseLong(stripPrefix(scratch, TABLESTART));
+
+ SimpleTextUtil.readLine(in, scratch);
+ assert StringHelper.startsWith(scratch.get(), TABLEEND);
+ endOffsets[i] = Long.parseLong(stripPrefix(scratch, TABLEEND));
+ }
+
+ return new BaseDirectory() {
+
+ private int getIndex(String name) throws IOException {
+ int index = Arrays.binarySearch(fileNames, name);
+ if (index < 0) {
+ throw new FileNotFoundException("No sub-file found (fileName=" + name + " files: " + Arrays.toString(fileNames) + ")");
+ }
+ return index;
+ }
+
+ @Override
+ public String[] listAll() throws IOException {
+ ensureOpen();
+ return fileNames.clone();
+ }
+
+ @Override
+ public long fileLength(String name) throws IOException {
+ ensureOpen();
+ int index = getIndex(name);
+ return endOffsets[index] - startOffsets[index];
+ }
+
+ @Override
+ public IndexInput openInput(String name, IOContext context) throws IOException {
+ ensureOpen();
+ int index = getIndex(name);
+ return in.slice(name, startOffsets[index], endOffsets[index] - startOffsets[index]);
+ }
+
+ @Override
+ public void close() throws IOException {
+ isOpen = false;
+ in.close();
+ }
+
+ // write methods: disabled
+
+ @Override
+ public IndexOutput createOutput(String name, IOContext context) { throw new UnsupportedOperationException(); }
+
+ @Override
+ public void sync(Collection