dcapwell commented on code in PR #2295:
URL: https://github.com/apache/cassandra/pull/2295#discussion_r1178242040
##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -1349,68 +1359,98 @@ public static void applyPartitioner(Config conf)
paritionerName = partitioner.getClass().getCanonicalName();
}
- @VisibleForTesting
- public static Map<String, Supplier<SSTableFormat<?, ?>>>
loadSSTableFormatFactories(List<ParameterizedClass> configuredFormats)
+ private static void
validateSSTableFormatFactories(Iterable<SSTableFormat.Factory> factories)
{
- ImmutableMap.Builder<String, Supplier<SSTableFormat<?, ?>>>
sstableFormatFactories =
ImmutableMap.builderWithExpectedSize(configuredFormats.size());
- Set<String> names = new HashSet<>(configuredFormats.size());
- Set<Integer> ids = new HashSet<>(configuredFormats.size());
+ Map<String, SSTableFormat.Factory> factoryByName = new HashMap<>();
+ for (SSTableFormat.Factory factory : factories)
+ {
+ if (factory.name() == null)
+ throw new ConfigurationException(String.format("SSTable format
name in %s cannot be null", factory.getClass().getCanonicalName()));
+
+ if (!factory.name().matches("^[a-z]+$"))
+ throw new ConfigurationException(String.format("SSTable format
name for %s must be non-empty, lower-case letters only string",
factory.getClass().getCanonicalName()));
- for (ParameterizedClass formatConfig : configuredFormats)
+ SSTableFormat.Factory prev = factoryByName.put(factory.name(),
factory);
+ if (prev != null)
+ throw new ConfigurationException(String.format("Multiple
sstable format implementations with the same name %s: %s and %s",
factory.name(), factory.getClass().getCanonicalName(),
prev.getClass().getCanonicalName()));
+ }
+ }
+
+ private static ImmutableMap<String, Supplier<SSTableFormat<?, ?>>>
validateAndMatchSSTableFormatOptions(Iterable<SSTableFormat.Factory> factories,
Map<String, Map<String, String>> options)
+ {
+ ImmutableMap.Builder<String, Supplier<SSTableFormat<?, ?>>>
providersBuilder = ImmutableMap.builder();
+ if (options == null)
+ options = ImmutableMap.of();
+ for (SSTableFormat.Factory factory : factories)
{
- assert formatConfig.parameters != null;
- Map<String, String> params = new
HashMap<>(formatConfig.parameters);
-
- String name = params.get(Config.SSTABLE_FORMAT_NAME);
- if (name == null)
- throw new ConfigurationException("Missing 'name' parameter in
sstable format configuration for " + formatConfig.class_name);
- if (!name.matches("^[a-z]+$"))
- throw new ConfigurationException("'name' parameter in sstable
format configuration for " + formatConfig.class_name + " must be non-empty,
lower-case letters only string");
- if (names.contains(name))
- throw new ConfigurationException("Name '" + name + "' of
sstable format " + formatConfig.class_name + " is already defined for another
sstable format");
- params.remove(Config.SSTABLE_FORMAT_NAME);
-
- String idString = params.get(Config.SSTABLE_FORMAT_ID);
- if (idString == null)
- throw new ConfigurationException("Missing 'id' parameter in
sstable format configuration for " + formatConfig.class_name);
- int id;
- try
- {
- id = Integer.parseInt(idString);
- }
- catch (RuntimeException ex)
- {
- throw new ConfigurationException("'id' parameter in sstable
format configuration for " + formatConfig.class_name + " must be an integer");
- }
- if (id < 0 || id > 127)
- throw new ConfigurationException("'id' parameter in sstable
format configuration for " + formatConfig.class_name + " must be within bounds
[0..127] range");
- if (ids.contains(id))
- throw new ConfigurationException("ID '" + id + "' of sstable
format " + formatConfig.class_name + " is already defined for another sstable
format");
- params.remove(Config.SSTABLE_FORMAT_ID);
-
- Supplier<SSTableFormat<?, ?>> factory = () -> {
- Class<SSTableFormat<?, ?>> cls =
FBUtilities.classForName(formatConfig.class_name, "sstable format");
- if (!SSTableFormat.class.isAssignableFrom(cls))
- throw new ConfigurationException(String.format("Class %s
for sstable format %s does not implement %s", formatConfig.class_name, name,
SSTableFormat.class.getName()));
-
- SSTableFormat<?, ?> sstableFormat =
FBUtilities.instanceOrConstruct(cls.getName(), "sstable format");
- sstableFormat.setup(id, name, params);
- return sstableFormat;
- };
- sstableFormatFactories.put(name, factory);
- names.add(name);
- ids.add(id);
+ Map<String, String> formatOptions =
ImmutableMap.copyOf(options.getOrDefault(factory.name(), ImmutableMap.of()));
+ providersBuilder.put(factory.name(), () ->
factory.getInstance(formatOptions));
+ }
+ ImmutableMap<String, Supplier<SSTableFormat<?, ?>>> providers =
providersBuilder.build();
+ if (options != null)
Review Comment:
not possible after latest commit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]