add to index store the ability to get the backing store free / total space
This commit is contained in:
parent
edf0075025
commit
4709f00790
|
@ -19,9 +19,12 @@
|
|||
|
||||
package org.elasticsearch.index.store;
|
||||
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.index.IndexComponent;
|
||||
|
||||
/**
|
||||
* Index store is an index level information of the {@link Store} each shard will use.
|
||||
*
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public interface IndexStore extends IndexComponent {
|
||||
|
@ -31,5 +34,18 @@ public interface IndexStore extends IndexComponent {
|
|||
*/
|
||||
boolean persistent();
|
||||
|
||||
/**
|
||||
* The shard store class that should be used for each shard.
|
||||
*/
|
||||
Class<? extends Store> shardStoreClass();
|
||||
|
||||
/**
|
||||
* Returns the backing store total space. Return <tt>-1</tt> if not available.
|
||||
*/
|
||||
ByteSizeValue backingStoreTotalSpace();
|
||||
|
||||
/**
|
||||
* Returns the backing store free space. Return <tt>-1</tt> if not available.
|
||||
*/
|
||||
ByteSizeValue backingStoreFreeSpace();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.store.fs;
|
||||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.env.NodeEnvironment;
|
||||
import org.elasticsearch.index.AbstractIndexComponent;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
@ -53,6 +54,22 @@ public abstract class FsIndexStore extends AbstractIndexComponent implements Ind
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override public ByteSizeValue backingStoreTotalSpace() {
|
||||
long totalSpace = location.getTotalSpace();
|
||||
if (totalSpace == 0) {
|
||||
totalSpace = -1;
|
||||
}
|
||||
return new ByteSizeValue(totalSpace);
|
||||
}
|
||||
|
||||
@Override public ByteSizeValue backingStoreFreeSpace() {
|
||||
long usableSpace = location.getUsableSpace();
|
||||
if (usableSpace == 0) {
|
||||
usableSpace = -1;
|
||||
}
|
||||
return new ByteSizeValue(usableSpace);
|
||||
}
|
||||
|
||||
public File location() {
|
||||
return location;
|
||||
}
|
||||
|
|
|
@ -21,19 +21,26 @@ package org.elasticsearch.index.store.memory;
|
|||
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.index.AbstractIndexComponent;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
import org.elasticsearch.index.store.IndexStore;
|
||||
import org.elasticsearch.index.store.Store;
|
||||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
import org.elasticsearch.monitor.jvm.JvmStats;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public class ByteBufferIndexStore extends AbstractIndexComponent implements IndexStore {
|
||||
|
||||
private final boolean direct;
|
||||
|
||||
@Inject public ByteBufferIndexStore(Index index, @IndexSettings Settings indexSettings) {
|
||||
super(index, indexSettings);
|
||||
this.direct = componentSettings.getAsBoolean("direct", true);
|
||||
}
|
||||
|
||||
@Override public boolean persistent() {
|
||||
|
@ -43,4 +50,19 @@ public class ByteBufferIndexStore extends AbstractIndexComponent implements Inde
|
|||
@Override public Class<? extends Store> shardStoreClass() {
|
||||
return ByteBufferStore.class;
|
||||
}
|
||||
|
||||
@Override public ByteSizeValue backingStoreTotalSpace() {
|
||||
if (direct) {
|
||||
// TODO, we can use sigar...
|
||||
return new ByteSizeValue(-1, ByteSizeUnit.BYTES);
|
||||
}
|
||||
return JvmInfo.jvmInfo().mem().heapMax();
|
||||
}
|
||||
|
||||
@Override public ByteSizeValue backingStoreFreeSpace() {
|
||||
if (direct) {
|
||||
return new ByteSizeValue(-1, ByteSizeUnit.BYTES);
|
||||
}
|
||||
return JvmStats.jvmStats().mem().heapUsed();
|
||||
}
|
||||
}
|
|
@ -21,11 +21,14 @@ package org.elasticsearch.index.store.memory;
|
|||
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.index.AbstractIndexComponent;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
import org.elasticsearch.index.store.IndexStore;
|
||||
import org.elasticsearch.index.store.Store;
|
||||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
import org.elasticsearch.monitor.jvm.JvmStats;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
|
@ -43,4 +46,12 @@ public class HeapIndexStore extends AbstractIndexComponent implements IndexStore
|
|||
@Override public Class<? extends Store> shardStoreClass() {
|
||||
return HeapStore.class;
|
||||
}
|
||||
|
||||
@Override public ByteSizeValue backingStoreTotalSpace() {
|
||||
return JvmInfo.jvmInfo().getMem().heapMax();
|
||||
}
|
||||
|
||||
@Override public ByteSizeValue backingStoreFreeSpace() {
|
||||
return JvmStats.jvmStats().getMem().heapUsed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,14 @@ package org.elasticsearch.index.store.ram;
|
|||
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.index.AbstractIndexComponent;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
import org.elasticsearch.index.store.IndexStore;
|
||||
import org.elasticsearch.index.store.Store;
|
||||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
import org.elasticsearch.monitor.jvm.JvmStats;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
|
@ -43,4 +46,12 @@ public class RamIndexStore extends AbstractIndexComponent implements IndexStore
|
|||
@Override public Class<? extends Store> shardStoreClass() {
|
||||
return RamStore.class;
|
||||
}
|
||||
|
||||
@Override public ByteSizeValue backingStoreTotalSpace() {
|
||||
return JvmInfo.jvmInfo().getMem().heapMax();
|
||||
}
|
||||
|
||||
@Override public ByteSizeValue backingStoreFreeSpace() {
|
||||
return JvmStats.jvmStats().getMem().heapUsed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.monitor.jvm;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Streamable;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.builder.XContentBuilder;
|
||||
|
||||
|
@ -247,6 +248,38 @@ public class JvmInfo implements Streamable, Serializable, ToXContent {
|
|||
Mem() {
|
||||
}
|
||||
|
||||
public ByteSizeValue heapInit() {
|
||||
return new ByteSizeValue(heapInit);
|
||||
}
|
||||
|
||||
public ByteSizeValue getHeapInit() {
|
||||
return heapInit();
|
||||
}
|
||||
|
||||
public ByteSizeValue heapMax() {
|
||||
return new ByteSizeValue(heapMax);
|
||||
}
|
||||
|
||||
public ByteSizeValue getHeapMax() {
|
||||
return heapMax();
|
||||
}
|
||||
|
||||
public ByteSizeValue nonHeapInit() {
|
||||
return new ByteSizeValue(nonHeapInit);
|
||||
}
|
||||
|
||||
public ByteSizeValue getNonHeapInit() {
|
||||
return nonHeapInit();
|
||||
}
|
||||
|
||||
public ByteSizeValue nonHeapMax() {
|
||||
return new ByteSizeValue(nonHeapMax);
|
||||
}
|
||||
|
||||
public ByteSizeValue getNonHeapMax() {
|
||||
return nonHeapMax();
|
||||
}
|
||||
|
||||
public static Mem readMem(StreamInput in) throws IOException {
|
||||
Mem mem = new Mem();
|
||||
mem.readFrom(in);
|
||||
|
|
Loading…
Reference in New Issue