Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table settings altering #2004

Merged
merged 1 commit into from
May 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public boolean equals(Object o) {

@Override
public String toString() {
return null;
return properties.toString();
}

@Override
Expand Down
29 changes: 29 additions & 0 deletions sql/src/main/java/io/crate/analyze/TableParameterInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
import io.crate.blob.v2.BlobIndices;
import io.crate.metadata.table.ColumnPolicy;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider;
import org.elasticsearch.gateway.local.LocalGatewayAllocator;
import org.elasticsearch.index.shard.service.InternalIndexShard;
import org.elasticsearch.index.translog.TranslogService;
import org.elasticsearch.indices.warmer.InternalIndicesWarmer;

public class TableParameterInfo {

Expand All @@ -34,7 +39,19 @@ public class TableParameterInfo {
public static final String AUTO_EXPAND_REPLICAS = IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS;
public static final String REFRESH_INTERVAL = InternalIndexShard.INDEX_REFRESH_INTERVAL;
public static final String NUMBER_OF_SHARDS = IndexMetaData.SETTING_NUMBER_OF_SHARDS;
public static final String READ_ONLY = IndexMetaData.SETTING_READ_ONLY;
public static final String BLOCKS_READ = IndexMetaData.SETTING_BLOCKS_READ;
public static final String BLOCKS_WRITE = IndexMetaData.SETTING_BLOCKS_WRITE;
public static final String BLOCKS_METADATA = IndexMetaData.SETTING_BLOCKS_METADATA;
public static final String BLOBS_PATH = BlobIndices.SETTING_INDEX_BLOBS_PATH;
public static final String FLUSH_THRESHOLD_OPS = TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS;
public static final String FLUSH_THRESHOLD_SIZE = TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE;
public static final String FLUSH_THRESHOLD_PERIOD = TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_PERIOD;
public static final String FLUSH_DISABLE = TranslogService.INDEX_TRANSLOG_DISABLE_FLUSH;
public static final String ROUTING_ALLOCATION_ENABLE = EnableAllocationDecider.INDEX_ROUTING_ALLOCATION_ENABLE;
public static final String TOTAL_SHARDS_PER_NODE = ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE;
public static final String RECOVERY_INITIAL_SHARDS = LocalGatewayAllocator.INDEX_RECOVERY_INITIAL_SHARDS;
public static final String WARMER_ENABLED = InternalIndicesWarmer.INDEX_WARMER_ENABLED;

// all available table mapping keys
public static final String COLUMN_POLICY = ColumnPolicy.ES_MAPPING_NAME;
Expand All @@ -43,6 +60,18 @@ public class TableParameterInfo {
ImmutableList.<String>builder()
.add(NUMBER_OF_REPLICAS)
.add(REFRESH_INTERVAL)
.add(READ_ONLY)
.add(BLOCKS_READ)
.add(BLOCKS_WRITE)
.add(BLOCKS_METADATA)
.add(FLUSH_THRESHOLD_OPS)
.add(FLUSH_THRESHOLD_SIZE)
.add(FLUSH_THRESHOLD_PERIOD)
.add(FLUSH_DISABLE)
.add(ROUTING_ALLOCATION_ENABLE)
.add(TOTAL_SHARDS_PER_NODE)
.add(RECOVERY_INITIAL_SHARDS)
.add(WARMER_ENABLED)
.build();

protected static final ImmutableList<String> SUPPORTED_INTERNAL_SETTINGS =
Expand Down
61 changes: 61 additions & 0 deletions sql/src/main/java/io/crate/analyze/TablePropertiesAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@

package io.crate.analyze;

import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.crate.analyze.expressions.ExpressionToNumberVisitor;
import io.crate.analyze.expressions.ExpressionToObjectVisitor;
import io.crate.analyze.expressions.ExpressionToStringVisitor;
import io.crate.core.NumberOfReplicas;
import io.crate.metadata.settings.CrateTableSettings;
import io.crate.metadata.table.ColumnPolicy;
import io.crate.sql.tree.ArrayLiteral;
import io.crate.sql.tree.Expression;
Expand All @@ -44,6 +47,18 @@ public class TablePropertiesAnalyzer {
ImmutableBiMap.<String, String>builder()
.put(stripIndexPrefix(TableParameterInfo.NUMBER_OF_REPLICAS), TableParameterInfo.NUMBER_OF_REPLICAS)
.put(stripIndexPrefix(TableParameterInfo.REFRESH_INTERVAL), TableParameterInfo.REFRESH_INTERVAL)
.put(stripIndexPrefix(TableParameterInfo.READ_ONLY), TableParameterInfo.READ_ONLY)
.put(stripIndexPrefix(TableParameterInfo.BLOCKS_READ), TableParameterInfo.BLOCKS_READ)
.put(stripIndexPrefix(TableParameterInfo.BLOCKS_WRITE), TableParameterInfo.BLOCKS_WRITE)
.put(stripIndexPrefix(TableParameterInfo.BLOCKS_METADATA), TableParameterInfo.BLOCKS_METADATA)
.put(stripIndexPrefix(TableParameterInfo.FLUSH_THRESHOLD_OPS), TableParameterInfo.FLUSH_THRESHOLD_OPS)
.put(stripIndexPrefix(TableParameterInfo.FLUSH_THRESHOLD_SIZE), TableParameterInfo.FLUSH_THRESHOLD_SIZE)
.put(stripIndexPrefix(TableParameterInfo.FLUSH_THRESHOLD_PERIOD), TableParameterInfo.FLUSH_THRESHOLD_PERIOD)
.put(stripIndexPrefix(TableParameterInfo.FLUSH_DISABLE), TableParameterInfo.FLUSH_DISABLE)
.put(stripIndexPrefix(TableParameterInfo.ROUTING_ALLOCATION_ENABLE), TableParameterInfo.ROUTING_ALLOCATION_ENABLE)
.put(stripIndexPrefix(TableParameterInfo.TOTAL_SHARDS_PER_NODE), TableParameterInfo.TOTAL_SHARDS_PER_NODE)
.put(stripIndexPrefix(TableParameterInfo.RECOVERY_INITIAL_SHARDS), TableParameterInfo.RECOVERY_INITIAL_SHARDS)
.put(stripIndexPrefix(TableParameterInfo.WARMER_ENABLED), TableParameterInfo.WARMER_ENABLED)
.put(stripIndexPrefix(TableParameterInfo.NUMBER_OF_SHARDS), TableParameterInfo.NUMBER_OF_SHARDS)
.put("blobs_path", TableParameterInfo.BLOBS_PATH)
.build();
Expand All @@ -64,6 +79,18 @@ public class TablePropertiesAnalyzer {
ImmutableMap.<String, SettingsApplier>builder()
.put(TableParameterInfo.NUMBER_OF_REPLICAS, new NumberOfReplicasSettingApplier())
.put(TableParameterInfo.REFRESH_INTERVAL, new RefreshIntervalSettingApplier())
.put(TableParameterInfo.READ_ONLY, new SettingsAppliers.BooleanSettingsApplier(CrateTableSettings.READ_ONLY))
.put(TableParameterInfo.BLOCKS_READ, new SettingsAppliers.BooleanSettingsApplier(CrateTableSettings.BLOCKS_READ))
.put(TableParameterInfo.BLOCKS_WRITE, new SettingsAppliers.BooleanSettingsApplier(CrateTableSettings.BLOCKS_WRITE))
.put(TableParameterInfo.BLOCKS_METADATA, new SettingsAppliers.BooleanSettingsApplier(CrateTableSettings.BLOCKS_METADATA))
.put(TableParameterInfo.FLUSH_THRESHOLD_OPS, new SettingsAppliers.IntSettingsApplier(CrateTableSettings.FLUSH_THRESHOLD_OPS))
.put(TableParameterInfo.FLUSH_THRESHOLD_SIZE, new SettingsAppliers.ByteSizeSettingsApplier(CrateTableSettings.FLUSH_THRESHOLD_SIZE))
.put(TableParameterInfo.FLUSH_THRESHOLD_PERIOD, new SettingsAppliers.TimeSettingsApplier(CrateTableSettings.FLUSH_THRESHOLD_PERIOD))
.put(TableParameterInfo.FLUSH_DISABLE, new SettingsAppliers.BooleanSettingsApplier(CrateTableSettings.FLUSH_DISABLE))
.put(TableParameterInfo.ROUTING_ALLOCATION_ENABLE, new SettingsAppliers.StringSettingsApplier(CrateTableSettings.ROUTING_ALLOCATION_ENABLE))
.put(TableParameterInfo.TOTAL_SHARDS_PER_NODE, new SettingsAppliers.IntSettingsApplier(CrateTableSettings.TOTAL_SHARDS_PER_NODE))
.put(TableParameterInfo.RECOVERY_INITIAL_SHARDS, new RecoveryInitialShardsApplier())
.put(TableParameterInfo.WARMER_ENABLED, new SettingsAppliers.BooleanSettingsApplier(CrateTableSettings.WARMER_ENABLED))
.put(TableParameterInfo.NUMBER_OF_SHARDS, new NumberOfShardsSettingsApplier())
.put(TableParameterInfo.BLOBS_PATH, new BlobPathSettingApplier())
.build();
Expand Down Expand Up @@ -235,6 +262,40 @@ public void applyValue(ImmutableSettings.Builder settingsBuilder, Object value)
}
}

private static class RecoveryInitialShardsApplier extends SettingsAppliers.AbstractSettingsApplier {

public ImmutableSet<String> ALLOWED_VALUES = ImmutableSet.of(
"quorum",
"quorum-1",
"full",
"full-1",
"half"
);

public static final Settings DEFAULT = ImmutableSettings.builder()
.put(TableParameterInfo.RECOVERY_INITIAL_SHARDS, CrateTableSettings.RECOVERY_INITIAL_SHARDS.defaultValue())
.build();

private RecoveryInitialShardsApplier() {
super(ES_TO_CRATE_SETTINGS_MAP.get(TableParameterInfo.RECOVERY_INITIAL_SHARDS), DEFAULT);
}

@SuppressWarnings("SuspiciousMethodCalls")
@Override
public void apply(ImmutableSettings.Builder settingsBuilder, Object[] parameters, Expression expression) {
Object shardsRecoverySettings;
try {
shardsRecoverySettings = ExpressionToNumberVisitor.convert(expression, parameters).intValue();
} catch (IllegalArgumentException e) {
shardsRecoverySettings = ExpressionToObjectVisitor.convert(expression, parameters).toString();
if (!ALLOWED_VALUES.contains(shardsRecoverySettings)) {
throw invalidException();
}
}
settingsBuilder.put(TableParameterInfo.RECOVERY_INITIAL_SHARDS, shardsRecoverySettings);
}
}

private static class NumberOfShardsSettingsApplier extends SettingsAppliers.AbstractSettingsApplier {

public static final Settings DEFAULT = ImmutableSettings.builder()
Expand Down
191 changes: 191 additions & 0 deletions sql/src/main/java/io/crate/metadata/settings/CrateTableSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/*
* Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership. Crate licenses
* this file to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may
* obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* However, if you have executed another commercial license agreement
* with Crate these terms will supersede the license and you may use the
* software solely pursuant to the terms of the relevant commercial agreement.
*/

package io.crate.metadata.settings;


import com.google.common.collect.ImmutableSet;
import io.crate.analyze.TableParameterInfo;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;

public class CrateTableSettings {

public static final BoolSetting READ_ONLY = new BoolSetting() {

@Override
public String name() {
return TableParameterInfo.READ_ONLY;
}

@Override
public Boolean defaultValue() {
return false;
}
};

public static final BoolSetting BLOCKS_READ = new BoolSetting() {
@Override
public String name() {
return TableParameterInfo.BLOCKS_READ;
}

@Override
public Boolean defaultValue() {
return false;
}
};

public static final BoolSetting BLOCKS_WRITE = new BoolSetting() {
@Override
public String name() {
return TableParameterInfo.BLOCKS_WRITE;
}

@Override
public Boolean defaultValue() {
return false;
}
};

public static final BoolSetting BLOCKS_METADATA = new BoolSetting() {
@Override
public String name() {
return TableParameterInfo.BLOCKS_METADATA;
}

@Override
public Boolean defaultValue() {
return false;
}
};

public static final BoolSetting FLUSH_DISABLE = new BoolSetting() {
@Override
public String name() {
return TableParameterInfo.FLUSH_DISABLE;
}

@Override
public Boolean defaultValue() {
return false;
}
};

public static final IntSetting TOTAL_SHARDS_PER_NODE = new IntSetting() {
@Override
public String name() {
return TableParameterInfo.TOTAL_SHARDS_PER_NODE;
}

@Override
public Integer defaultValue() {
return -1;
}
};

public static final StringSetting ROUTING_ALLOCATION_ENABLE = new StringSetting(ImmutableSet.of(
"primaries",
"new_primaries",
"none",
"all"
)) {

@Override
public String name() {
return TableParameterInfo.ROUTING_ALLOCATION_ENABLE;
}

@Override
public String defaultValue() {
return "all";
}


};

public static final StringSetting RECOVERY_INITIAL_SHARDS = new StringSetting() {

@Override
public String name() {
return TableParameterInfo.RECOVERY_INITIAL_SHARDS;
}

@Override
public String defaultValue() {
return "quorum";
}
};


public static final ByteSizeSetting FLUSH_THRESHOLD_SIZE = new ByteSizeSetting() {
@Override
public String name() {
return TableParameterInfo.FLUSH_THRESHOLD_SIZE;
}

@Override
public ByteSizeValue defaultValue() {
return new ByteSizeValue(200, ByteSizeUnit.MB);
}
};


public static final IntSetting FLUSH_THRESHOLD_OPS = new IntSetting() {
@Override
public String name() {
return TableParameterInfo.FLUSH_THRESHOLD_OPS;
}

@Override
public Integer defaultValue() {
return Integer.MAX_VALUE;
}
};

public static final TimeSetting FLUSH_THRESHOLD_PERIOD = new TimeSetting() {

@Override
public String name() {
return TableParameterInfo.FLUSH_THRESHOLD_PERIOD;
}

@Override
public TimeValue defaultValue() {
return TimeValue.timeValueMinutes(30);
}

};

public static final BoolSetting WARMER_ENABLED = new BoolSetting() {
@Override
public String name() {
return TableParameterInfo.WARMER_ENABLED;
}

@Override
public Boolean defaultValue() {
return true;
}
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the settings from TablePropertiesAnalyzer here as well

}
Loading