forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sachin Kale
committed
May 13, 2022
1 parent
d13d423
commit 0647e2b
Showing
4 changed files
with
113 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
server/src/main/java/org/opensearch/index/store/CompositeDirectory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.store; | ||
|
||
import org.apache.lucene.store.Directory; | ||
import org.apache.lucene.store.FilterDirectory; | ||
import org.apache.lucene.store.IOContext; | ||
import org.apache.lucene.store.IndexOutput; | ||
|
||
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
public class CompositeDirectory extends FilterDirectory { | ||
private final Directory directory1; | ||
private final Directory directory2; | ||
|
||
public CompositeDirectory(Directory directory1, Directory directory2) { | ||
super(directory1); | ||
this.directory1 = directory1; | ||
this.directory2 = directory2; | ||
} | ||
|
||
@Override | ||
public void deleteFile(String name) throws IOException { | ||
directory1.deleteFile(name); | ||
directory2.deleteFile(name); | ||
} | ||
|
||
@Override | ||
public IndexOutput createOutput(String name, IOContext context) throws IOException { | ||
IndexOutput output1 = directory1.createOutput(name, context); | ||
IndexOutput output2 = directory2.createOutput(name, context); | ||
return new CompositeIndexOutput(name, name, output1, output2, directory1); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
directory1.close(); | ||
directory2.close(); | ||
} | ||
|
||
@Override | ||
public Set<String> getPendingDeletions() throws IOException { | ||
return directory1.getPendingDeletions(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
server/src/main/java/org/opensearch/index/store/CompositeIndexOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.store; | ||
|
||
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 java.io.IOException; | ||
|
||
public class CompositeIndexOutput extends IndexOutput { | ||
private final IndexOutput output1; | ||
private final IndexOutput output2; | ||
private final Directory directory1; | ||
|
||
protected CompositeIndexOutput(String resourceDescription, String name, IndexOutput output1, IndexOutput output2, Directory directory1) { | ||
super(resourceDescription, name); | ||
this.output1 = output1; | ||
this.output2 = output2; | ||
this.directory1 = directory1; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
output1.close(); | ||
IndexInput indexInput = directory1.openInput(this.getName(), IOContext.DEFAULT); | ||
output2.copyBytes(indexInput, indexInput.length()); | ||
} | ||
|
||
@Override | ||
public long getFilePointer() { | ||
return output1.getFilePointer(); | ||
} | ||
|
||
@Override | ||
public long getChecksum() throws IOException { | ||
return output1.getChecksum(); | ||
} | ||
|
||
@Override | ||
public void writeByte(byte b) throws IOException { | ||
output1.writeByte(b); | ||
} | ||
|
||
@Override | ||
public void writeBytes(byte[] b, int offset, int length) throws IOException { | ||
output1.writeBytes(b, offset, length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters