Skip to content

Commit

Permalink
A workaround for RAMDISK filestore
Browse files Browse the repository at this point in the history
  • Loading branch information
madhukar-git committed Mar 5, 2020
1 parent 606a173 commit da3d2aa
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
91 changes: 91 additions & 0 deletions server/src/main/java/org/elasticsearch/env/ESDummyFileStore.java
@@ -0,0 +1,91 @@
package org.elasticsearch.env;


import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.attribute.FileAttributeView;
import java.nio.file.attribute.FileStoreAttributeView;


/**
* Dummy implementation of FileStore object.
* Its a workaround to handle the exception thrown from
* org.elasticsearch.env.Environment#getFileStore(java.nio.file.Path)
* when running on a RAMDISK machine or similar file system
*
*/
class ESDummyFileStore extends ESFileStore {

ESDummyFileStore(FileStore in) {
super(in);
}


@Override
public String name() {
return "FS_UNKNOWN_NAME";
}

@Override
public String type() {
return "FS_UNKNOWN_TYPE";
}

@Override
public boolean isReadOnly() {
return false;
}

@Override
public long getTotalSpace() throws IOException {
return Long.MAX_VALUE;
}

@Override
public long getUsableSpace() throws IOException {
return Long.MAX_VALUE;
}

@Override
public long getUnallocatedSpace() throws IOException {
return Long.MAX_VALUE;
}

@Override
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
return false;
}

@Override
public boolean supportsFileAttributeView(String name) {
if ("lucene".equals(name)) {
return true;
} else {
return false;
}

}

@Override
public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> type) {
return null;
}

@Override
public Object getAttribute(String attribute) throws IOException {
switch (attribute) {
// for the partition
case "lucene:major_device_number":
return -1;
case "lucene:minor_device_number":
return -1;
default:
return null;
}
}

@Override
public String toString() {
return "FS_UNKNOWN";
}
}
8 changes: 7 additions & 1 deletion server/src/main/java/org/elasticsearch/env/Environment.java
Expand Up @@ -35,6 +35,7 @@
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.FileSystemException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -305,7 +306,12 @@ public void validateTmpFile() throws IOException {
}

public static FileStore getFileStore(final Path path) throws IOException {
return new ESFileStore(Files.getFileStore(path));
try {
return new ESFileStore(Files.getFileStore(path));
} catch (FileSystemException ex) {
//A workaround for RAMDISK file system
return new ESDummyFileStore(null);
}
}

/**
Expand Down

0 comments on commit da3d2aa

Please sign in to comment.