lucene4: fixed SwitchDirectory and CompressedDirectory (except fileLength method)
This commit is contained in:
parent
e8092fe290
commit
be424c4564
|
@ -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
|
||||
|
|
|
@ -203,7 +203,7 @@ public abstract class CompressedIndexInput<T extends CompressorContext> 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];
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue