Skip to content

Commit

Permalink
Fix calling ensureOpen() on the wrong directory
Browse files Browse the repository at this point in the history
Also removes ensureCanWrite since this already passes the
TRUNCATE_EXISTING flag when opening.

Adds a REST test that fails without this fix due to the classloader
isolation.

Additionally, move SmbDirectoryWrapper into an elasticsearch package instead of a lucene one, so this would be found at compile time instead of runtime.

Forward-port of opensearch-project#16383
  • Loading branch information
dakrone committed Feb 2, 2016
1 parent 64ac037 commit 3918072
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
* under the License.
*/

package org.apache.lucene.store;
package org.elasticsearch.index.store;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.nio.channels.Channels;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.FilterDirectory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.OutputStreamIndexOutput;

/**
* This class is used to wrap an existing {@link org.apache.lucene.store.FSDirectory} so that
Expand All @@ -43,14 +48,10 @@ public SmbDirectoryWrapper(FSDirectory in) {

@Override
public IndexOutput createOutput(String name, IOContext context) throws IOException {
fsDirectory.ensureOpen();
fsDirectory.ensureCanWrite(name);
this.ensureOpen();
return new SmbFSIndexOutput(name);
}

/**
* Copied from final inner class {@link org.apache.lucene.store.FSDirectory.FSIndexOutput}
*/
final class SmbFSIndexOutput extends OutputStreamIndexOutput {
/**
* The maximum chunk size is 8192 bytes, because {@link java.io.FileOutputStream} mallocs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.MMapDirectory;
import org.apache.lucene.store.SmbDirectoryWrapper;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.index.store.FsDirectoryService;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.SmbDirectoryWrapper;

import java.io.IOException;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.SimpleFSDirectory;
import org.apache.lucene.store.SmbDirectoryWrapper;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.index.store.FsDirectoryService;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.SmbDirectoryWrapper;

import java.io.IOException;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.apache.lucene.store;
package org.elastiscearch.index.store;

/*
* Licensed to Elasticsearch under one or more contributor
Expand All @@ -21,6 +21,7 @@

import com.carrotsearch.randomizedtesting.annotations.Listeners;
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
import org.apache.lucene.store.BaseDirectoryTestCase;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TimeUnits;
import org.elasticsearch.bootstrap.BootstrapForTesting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
* under the License.
*/

package org.apache.lucene.store;
package org.elastiscearch.index.store;

import java.io.IOException;
import java.nio.file.Path;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MMapDirectory;
import org.elasticsearch.index.store.SmbDirectoryWrapper;

public class SmbMMapDirectoryTests extends ESBaseDirectoryTestCase {

@Override
protected Directory getDirectory(Path file) throws IOException {
return new SmbDirectoryWrapper(new MMapDirectory(file));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
* under the License.
*/

package org.apache.lucene.store;
package org.elastiscearch.index.store;

import java.io.IOException;
import java.nio.file.Path;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.SimpleFSDirectory;
import org.elasticsearch.index.store.SmbDirectoryWrapper;

public class SmbSimpleFSDirectoryTests extends ESBaseDirectoryTestCase {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"Test the smb_mmap_fs directory wrapper":
- do:
indices.create:
index: smb-test
body:
index:
store.type: smb_mmap_fs

- do:
cluster.health:
wait_for_status: yellow

- do:
index:
index: smb-test
type: doc
id: 1
body: { foo: bar }

- do:
get:
index: smb-test
type: doc
id: 1

- match: { _index: smb-test }
- match: { _type: doc }
- match: { _id: "1"}
- match: { _version: 1}
- match: { _source: { foo: bar }}

0 comments on commit 3918072

Please sign in to comment.