jacek-lewandowski commented on code in PR #2064:
URL: https://github.com/apache/cassandra/pull/2064#discussion_r1093258263
##########
src/java/org/apache/cassandra/io/sstable/format/SSTableFormat.java:
##########
@@ -115,38 +123,75 @@ default boolean delete(Descriptor desc)
FileTime getLastModifiedTime(Descriptor desc);
- enum Type
+ default void setup(Map<String, String> options)
+ {
+ }
+
+ class Type
{
- //The original sstable format
- BIG("big", BigFormat.instance);
+ private final static ImmutableList<Type> types;
+
+ static
+ {
+ Map<String, Supplier<SSTableFormat<?, ?>>> factories =
DatabaseDescriptor.getSSTableFormatFactories();
+ List<Type> typesList = new ArrayList<>(factories.size());
+ factories.forEach((key, factory) -> typesList.add(new
Type(typesList.size(), key.toLowerCase(), factory.get())));
+ types = ImmutableList.copyOf(typesList);
+ }
+ public final int ordinal;
public final SSTableFormat<?, ?> info;
public final String name;
+ private final static Type[] typesArray0 = new Type[0];
+
+ private static Type currentType;
public static Type current()
{
- return
CassandraRelevantProperties.SSTABLE_FORMAT_DEFAULT.getEnum(true, Type.class);
+ if (currentType != null)
+ return currentType;
+
+ String key =
CassandraRelevantProperties.SSTABLE_FORMAT_DEFAULT.getString();
+ try
+ {
+ Type type = validate(key);
+ currentType = type;
+ return type;
+ }
+ catch (RuntimeException ex)
+ {
+ throw new ConfigurationException("SSTable format " + key + "
is not registered. Registered formats are: " + types);
+ }
}
- Type(String name, SSTableFormat<?, ?> info)
+ private Type(int ordinal, String name, SSTableFormat<?, ?> info)
{
//Since format comes right after generation
//we disallow formats with numeric names
assert !CharMatcher.digit().matchesAllOf(name);
-
+ this.ordinal = ordinal;
this.name = name;
this.info = info;
}
public static Type validate(String name)
{
- for (Type valid : Type.values())
- {
- if (valid.name.equalsIgnoreCase(name))
- return valid;
- }
+ for (int i = 0; i < types.size(); i++)
Review Comment:
ok
--
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]