Skip to content

Commit

Permalink
make minimum disk space configurable and lower the boundary for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrik Muhs committed May 17, 2018
1 parent 9275e1c commit 315fbde
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ public List<Setting<?>> getSettings() {
DataCountsReporter.ACCEPTABLE_PERCENTAGE_DATE_PARSE_ERRORS_SETTING,
DataCountsReporter.ACCEPTABLE_PERCENTAGE_OUT_OF_ORDER_ERRORS_SETTING,
AutodetectProcessManager.MAX_RUNNING_JOBS_PER_NODE,
AutodetectProcessManager.MAX_OPEN_JOBS_PER_NODE));
AutodetectProcessManager.MAX_OPEN_JOBS_PER_NODE,
AutodetectProcessManager.MIN_DISK_SPACE_OFF_HEAP));
}

public Settings additionalSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.core.internal.io.IOUtils;
import org.elasticsearch.env.Environment;
Expand All @@ -24,16 +23,18 @@ public class NativeStorageProvider {

private static final Logger LOGGER = Loggers.getLogger(NativeStorageProvider.class);

// do not allow any usage below this threshold
private static final ByteSizeValue MINIMUM_LOCAL_STORAGE_AVAILABLE = new ByteSizeValue(5, ByteSizeUnit.GB);

private static final String LOCAL_STORAGE_SUBFOLDER = "ml-local-data";
private static final String LOCAL_STORAGE_TMP_FOLDER = "tmp";

private final Environment environment;

public NativeStorageProvider(Environment environment) {
// do not allow any usage below this threshold
private final ByteSizeValue minLocalStorageAvailable;

public NativeStorageProvider(Environment environment, ByteSizeValue minDiskSpaceOffHeap) {
this.environment = environment;
this.minLocalStorageAvailable = minDiskSpaceOffHeap;
}

/**
Expand Down Expand Up @@ -62,7 +63,7 @@ public void cleanupLocalTmpStorageInCaseOfUncleanShutdown() throws IOException {
public Path tryGetLocalTmpStorage(String uniqueIdentifier, ByteSizeValue requestedSize) {
for (Path path : environment.dataFiles()) {
try {
if (getUsableSpace(path) >= requestedSize.getBytes() + MINIMUM_LOCAL_STORAGE_AVAILABLE.getBytes()) {
if (getUsableSpace(path) >= requestedSize.getBytes() + minLocalStorageAvailable.getBytes()) {
Path tmpDirectory = path.resolve(LOCAL_STORAGE_SUBFOLDER).resolve(LOCAL_STORAGE_TMP_FOLDER).resolve(uniqueIdentifier);
Files.createDirectories(tmpDirectory);
return tmpDirectory;
Expand All @@ -81,7 +82,7 @@ public boolean localTmpStorageHasEnoughSpace(Path path, ByteSizeValue requestedS
for (Path p : environment.dataFiles()) {
try {
if (realPath.startsWith(p.resolve(LOCAL_STORAGE_SUBFOLDER).resolve(LOCAL_STORAGE_TMP_FOLDER))) {
return getUsableSpace(p) >= requestedSize.getBytes() + MINIMUM_LOCAL_STORAGE_AVAILABLE.getBytes();
return getUsableSpace(p) >= requestedSize.getBytes() + minLocalStorageAvailable.getBytes();
}
} catch (IOException e) {
LOGGER.debug("Failed to optain information about path [{}]: {}", path, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
Expand Down Expand Up @@ -99,6 +100,10 @@ public class AutodetectProcessManager extends AbstractComponent {
public static final Setting<Integer> MAX_OPEN_JOBS_PER_NODE =
Setting.intSetting("xpack.ml.max_open_jobs", MAX_RUNNING_JOBS_PER_NODE, 1, Property.NodeScope);

// Undocumented setting for integration test purposes
public static final Setting<ByteSizeValue> MIN_DISK_SPACE_OFF_HEAP =
Setting.byteSizeSetting("xpack.ml.min_disk_space_off_heap", new ByteSizeValue(5, ByteSizeUnit.GB), Property.NodeScope);

private final Client client;
private final Environment environment;
private final ThreadPool threadPool;
Expand Down Expand Up @@ -140,7 +145,7 @@ public AutodetectProcessManager(Environment environment, Settings settings, Clie
this.jobResultsPersister = jobResultsPersister;
this.jobDataCountsPersister = jobDataCountsPersister;
this.auditor = auditor;
this.nativeStorageProvider = new NativeStorageProvider(environment);
this.nativeStorageProvider = new NativeStorageProvider(environment, MIN_DISK_SPACE_OFF_HEAP.get(settings));
}

public void onNodeStartup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private NativeStorageProvider createNativeStorageProvider(Map<Path, Long> paths)
Environment environment = mock(Environment.class);

when(environment.dataFiles()).thenReturn(paths.keySet().toArray(new Path[paths.size()]));
NativeStorageProvider storageProvider = spy(new NativeStorageProvider(environment));
NativeStorageProvider storageProvider = spy(new NativeStorageProvider(environment, new ByteSizeValue(5, ByteSizeUnit.GB)));

doAnswer(invocation -> {
return paths.getOrDefault(invocation.getArguments()[0], Long.valueOf(0)).longValue();
Expand Down
1 change: 1 addition & 0 deletions x-pack/qa/ml-native-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ integTestCluster {
setting 'xpack.security.transport.ssl.verification_mode', 'certificate'
setting 'xpack.security.audit.enabled', 'true'
setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.ml.min_disk_space_off_heap', '200mb'

keystoreSetting 'bootstrap.password', 'x-pack-test-password'
keystoreSetting 'xpack.security.transport.ssl.keystore.secure_password', 'keypass'
Expand Down

0 comments on commit 315fbde

Please sign in to comment.