Search in sources :

Example 6 with ClusterRuntimeException

use of com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException in project dal by ctripcorp.

the class ModShardStrategy method calcAllTableShards.

@Override
protected Set<String> calcAllTableShards(String tableName) {
    Integer mod = getTableShardMod(tableName);
    if (mod == null)
        throw new ClusterRuntimeException(String.format("table shard mod undefined for table '%s'", tableName));
    Set<String> allShards = new HashSet<>();
    for (int i = 0; i < mod; i++) allShards.add(String.valueOf(i));
    return allShards;
}
Also used : ClusterRuntimeException(com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException) HashSet(java.util.HashSet)

Example 7 with ClusterRuntimeException

use of com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException in project dal by ctripcorp.

the class ShardStrategyElement method start.

@Override
public void start() {
    for (TablesElement tablesElement : tablesElements) {
        tablesElement.merge(this);
        tablesElement.start();
        for (String tableName : tablesElement.getTableNames()) {
            PropertyAccessor properties = tablesElement.getTableProperties(tableName);
            if (tableProperties.put(tableName, properties) != null)
                throw new ClusterRuntimeException("duplicate table names defined under ShardStrategyElement");
        }
    }
}
Also used : PropertyAccessor(com.ctrip.framework.dal.cluster.client.base.PropertyAccessor) ClusterRuntimeException(com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException)

Aggregations

ClusterRuntimeException (com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException)7 PropertyAccessor (com.ctrip.framework.dal.cluster.client.base.PropertyAccessor)1 DefaultClusterRouteStrategyConfig (com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig)1 ClusterIdGeneratorConfig (com.ctrip.framework.dal.cluster.client.sharding.idgen.ClusterIdGeneratorConfig)1 ModShardStrategy (com.ctrip.framework.dal.cluster.client.sharding.strategy.ModShardStrategy)1 ShardStrategy (com.ctrip.framework.dal.cluster.client.sharding.strategy.ShardStrategy)1 StringReader (java.io.StringReader)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 InputSource (org.xml.sax.InputSource)1