Search in sources :

Example 1 with StressProfile

use of org.apache.cassandra.stress.StressProfile in project cassandra by apache.

the class SettingsCommandUser method getFactory.

public OpDistributionFactory getFactory(final StressSettings settings) {
    final SeedManager seeds = new SeedManager(settings);
    final Map<String, TokenRangeIterator> tokenRangeIterators = new LinkedHashMap<>();
    profiles.forEach((k, v) -> tokenRangeIterators.put(k, (v.tokenRangeQueries.isEmpty() ? null : new TokenRangeIterator(settings, v.maybeLoadTokenRanges(settings)))));
    return new SampledOpDistributionFactory<String>(ratios, clustering) {

        protected List<? extends Operation> get(Timer timer, String key, boolean isWarmup) {
            Matcher m = EXTRACT_SPEC_CMD.matcher(key);
            final String profile_name;
            final String sub_key;
            if (m.matches()) {
                profile_name = m.group(1);
                sub_key = m.group(2);
            } else {
                profile_name = default_profile_name;
                sub_key = key;
            }
            if (!profiles.containsKey(profile_name)) {
                throw new IllegalArgumentException(String.format("Op name %s contains an invalid profile specname: %s", key, profile_name));
            }
            StressProfile profile = profiles.get(profile_name);
            TokenRangeIterator tokenRangeIterator = tokenRangeIterators.get(profile_name);
            PartitionGenerator generator = profile.newGenerator(settings);
            if (sub_key.equalsIgnoreCase("insert"))
                return Collections.singletonList(profile.getInsert(timer, generator, seeds, settings));
            if (sub_key.equalsIgnoreCase("validate"))
                return profile.getValidate(timer, generator, seeds, settings);
            if (profile.tokenRangeQueries.containsKey(sub_key))
                return Collections.singletonList(profile.getBulkReadQueries(sub_key, timer, settings, tokenRangeIterator, isWarmup));
            return Collections.singletonList(profile.getQuery(sub_key, timer, generator, seeds, settings, isWarmup));
        }
    };
}
Also used : StressProfile(org.apache.cassandra.stress.StressProfile) Timer(org.apache.cassandra.stress.report.Timer) PartitionGenerator(org.apache.cassandra.stress.generate.PartitionGenerator) Matcher(java.util.regex.Matcher) TokenRangeIterator(org.apache.cassandra.stress.generate.TokenRangeIterator) SeedManager(org.apache.cassandra.stress.generate.SeedManager) SampledOpDistributionFactory(org.apache.cassandra.stress.operations.SampledOpDistributionFactory) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 Matcher (java.util.regex.Matcher)1 StressProfile (org.apache.cassandra.stress.StressProfile)1 PartitionGenerator (org.apache.cassandra.stress.generate.PartitionGenerator)1 SeedManager (org.apache.cassandra.stress.generate.SeedManager)1 TokenRangeIterator (org.apache.cassandra.stress.generate.TokenRangeIterator)1 SampledOpDistributionFactory (org.apache.cassandra.stress.operations.SampledOpDistributionFactory)1 Timer (org.apache.cassandra.stress.report.Timer)1