From be424c45645b2c25c61b5e6ca0f137abe50bec16 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Tue, 30 Oct 2012 21:42:58 -0400 Subject: [PATCH] lucene4: fixed SwitchDirectory and CompressedDirectory (except fileLength method) --- .../common/compress/CompressedDirectory.java | 44 ++++--------------- .../common/compress/CompressedIndexInput.java | 2 +- .../common/lucene/store/SwitchDirectory.java | 27 +++--------- 3 files changed, 16 insertions(+), 57 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/compress/CompressedDirectory.java b/src/main/java/org/elasticsearch/common/compress/CompressedDirectory.java index 81e96e6f703..3f62ebfdb88 100644 --- a/src/main/java/org/elasticsearch/common/compress/CompressedDirectory.java +++ b/src/main/java/org/elasticsearch/common/compress/CompressedDirectory.java @@ -1,5 +1,6 @@ package org.elasticsearch.common.compress; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import org.apache.lucene.store.*; import org.elasticsearch.index.store.support.ForceSyncDirectory; @@ -60,16 +61,6 @@ public class CompressedDirectory extends Directory implements ForceSyncDirectory return dir.fileExists(name); } - @Override - public long fileModified(String name) throws IOException { - return dir.fileModified(name); - } - - @Override - public void touchFile(String name) throws IOException { - dir.touchFile(name); - } - @Override public void deleteFile(String name) throws IOException { dir.deleteFile(name); @@ -97,24 +88,19 @@ public class CompressedDirectory extends Directory implements ForceSyncDirectory dir.sync(names); } - @Override - public void sync(String name) throws IOException { - dir.sync(name); - } - @Override public void forceSync(String name) throws IOException { if (dir instanceof ForceSyncDirectory) { ((ForceSyncDirectory) dir).forceSync(name); } else { - dir.sync(name); + dir.sync(ImmutableList.of(name)); } } @Override - public IndexInput openInput(String name) throws IOException { + public IndexInput openInput(String name, IOContext context) throws IOException { if (decompressExtensions.contains(getExtension(name))) { - IndexInput in = dir.openInput(name); + IndexInput in = dir.openInput(name, context); Compressor compressor1 = CompressorFactory.compressor(in); if (compressor1 != null) { return compressor1.indexInput(in); @@ -122,29 +108,15 @@ public class CompressedDirectory extends Directory implements ForceSyncDirectory return in; } } - return dir.openInput(name); + return dir.openInput(name, context); } @Override - public IndexInput openInput(String name, int bufferSize) throws IOException { - if (decompressExtensions.contains(getExtension(name))) { - IndexInput in = dir.openInput(name, bufferSize); - Compressor compressor1 = CompressorFactory.compressor(in); - if (compressor1 != null) { - return compressor1.indexInput(in); - } else { - return in; - } - } - return dir.openInput(name, bufferSize); - } - - @Override - public IndexOutput createOutput(String name) throws IOException { + public IndexOutput createOutput(String name, IOContext context) throws IOException { if (compress && compressExtensions.contains(getExtension(name))) { - return compressor.indexOutput(dir.createOutput(name)); + return compressor.indexOutput(dir.createOutput(name, context)); } - return dir.createOutput(name); + return dir.createOutput(name, context); } // can't override this one, we need to open the correct compression diff --git a/src/main/java/org/elasticsearch/common/compress/CompressedIndexInput.java b/src/main/java/org/elasticsearch/common/compress/CompressedIndexInput.java index c127f8dd612..153edae03b3 100644 --- a/src/main/java/org/elasticsearch/common/compress/CompressedIndexInput.java +++ b/src/main/java/org/elasticsearch/common/compress/CompressedIndexInput.java @@ -203,7 +203,7 @@ public abstract class CompressedIndexInput extends protected abstract int uncompress(IndexInput in, byte[] out) throws IOException; @Override - public Object clone() { + public IndexInput clone() { // we clone and we need to make sure we keep the same positions! CompressedIndexInput cloned = (CompressedIndexInput) super.clone(); cloned.uncompressed = new byte[uncompressedLength]; diff --git a/src/main/java/org/elasticsearch/common/lucene/store/SwitchDirectory.java b/src/main/java/org/elasticsearch/common/lucene/store/SwitchDirectory.java index 8252ba13200..1d453802aa7 100644 --- a/src/main/java/org/elasticsearch/common/lucene/store/SwitchDirectory.java +++ b/src/main/java/org/elasticsearch/common/lucene/store/SwitchDirectory.java @@ -19,8 +19,10 @@ package org.elasticsearch.common.lucene.store; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; 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.elasticsearch.index.store.support.ForceSyncDirectory; @@ -123,16 +125,6 @@ public class SwitchDirectory extends Directory implements ForceSyncDirectory { return getDirectory(name).fileExists(name); } - @Override - public long fileModified(String name) throws IOException { - return getDirectory(name).fileModified(name); - } - - @Override - public void touchFile(String name) throws IOException { - getDirectory(name).touchFile(name); - } - @Override public void deleteFile(String name) throws IOException { getDirectory(name).deleteFile(name); @@ -144,8 +136,8 @@ public class SwitchDirectory extends Directory implements ForceSyncDirectory { } @Override - public IndexOutput createOutput(String name) throws IOException { - return getDirectory(name).createOutput(name); + public IndexOutput createOutput(String name, IOContext context) throws IOException { + return getDirectory(name).createOutput(name, context); } @Override @@ -163,23 +155,18 @@ public class SwitchDirectory extends Directory implements ForceSyncDirectory { secondaryDir.sync(secondaryNames); } - @Override - public void sync(String name) throws IOException { - getDirectory(name).sync(name); - } - @Override public void forceSync(String name) throws IOException { Directory dir = getDirectory(name); if (dir instanceof ForceSyncDirectory) { ((ForceSyncDirectory) dir).forceSync(name); } else { - dir.sync(name); + dir.sync(ImmutableList.of(name)); } } @Override - public IndexInput openInput(String name) throws IOException { - return getDirectory(name).openInput(name); + public IndexInput openInput(String name, IOContext context) throws IOException { + return getDirectory(name).openInput(name, context); } }