Skip to content

Commit e2f74ed

Browse files
shruti-p-ssmiklosovic
authored andcommitted
Adding missing configs in system_views.settings to be backward compatible
patch by Sudipta Laha; reviewed by Stefan Miklosovic, Tiago L. Alves, Francisco Guerrero, Yifan Cai for CASSANDRA-20863
1 parent 965eb1d commit e2f74ed

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
5.0.7
2+
* Adding missing configs in system_views.settings to be backward compatible (CASSANDRA-20863)
23
* Heap dump should not be generated on handled exceptions (CASSANDRA-20974)
34
Merged from 4.1:
45
* ReadCommandController should close fast to avoid deadlock when building secondary index (CASSANDRA-19564)

src/java/org/apache/cassandra/db/virtual/SettingsTable.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242
import org.apache.cassandra.service.ClientWarn;
4343
import org.yaml.snakeyaml.introspector.Property;
4444

45-
final class SettingsTable extends AbstractVirtualTable
45+
@VisibleForTesting
46+
public final class SettingsTable extends AbstractVirtualTable
4647
{
4748
private static final String NAME = "name";
4849
private static final String VALUE = "value";
4950

50-
private static final Map<String, String> BACKWARDS_COMPATABLE_NAMES = ImmutableMap.copyOf(getBackwardsCompatableNames());
51+
public static final Map<String, String> BACKWARDS_COMPATIBLE_NAMES = ImmutableMap.copyOf(getBackwardsCompatibleNames());
5152
protected static final Map<String, Property> PROPERTIES = ImmutableMap.copyOf(getProperties());
5253

5354
private final Config config;
@@ -76,8 +77,8 @@ public DataSet data(DecoratedKey partitionKey)
7677
{
7778
SimpleDataSet result = new SimpleDataSet(metadata());
7879
String name = UTF8Type.instance.compose(partitionKey.getKey());
79-
if (BACKWARDS_COMPATABLE_NAMES.containsKey(name))
80-
ClientWarn.instance.warn("key '" + name + "' is deprecated; should switch to '" + BACKWARDS_COMPATABLE_NAMES.get(name) + "'");
80+
if (BACKWARDS_COMPATIBLE_NAMES.containsKey(name))
81+
ClientWarn.instance.warn("key '" + name + "' is deprecated; should switch to '" + BACKWARDS_COMPATIBLE_NAMES.get(name) + "'");
8182
if (PROPERTIES.containsKey(name))
8283
result.row(name).column(VALUE, getValue(PROPERTIES.get(name)));
8384
return result;
@@ -163,7 +164,7 @@ private static Map<String, Property> getProperties()
163164
assert conflict == null || r.oldName.equals(r.newName) : String.format("New property %s attempted to replace %s, but this property already exists", latest.getName(), conflict.getName());
164165
}
165166
}
166-
for (Map.Entry<String, String> e : BACKWARDS_COMPATABLE_NAMES.entrySet())
167+
for (Map.Entry<String, String> e : BACKWARDS_COMPATIBLE_NAMES.entrySet())
167168
{
168169
String oldName = e.getKey();
169170
if (properties.containsKey(oldName))
@@ -183,7 +184,7 @@ private static Map<String, Property> getProperties()
183184
* There were a handle full of properties which had custom names, names not present in the yaml, this map also
184185
* fixes this and returns the proper (what is accessable via yaml) names.
185186
*/
186-
private static Map<String, String> getBackwardsCompatableNames()
187+
private static Map<String, String> getBackwardsCompatibleNames()
187188
{
188189
Map<String, String> names = new HashMap<>();
189190
// Names that dont match yaml
@@ -192,6 +193,12 @@ private static Map<String, String> getBackwardsCompatableNames()
192193
names.put("server_encryption_options_endpoint_verification", "server_encryption_options.require_endpoint_verification");
193194
names.put("server_encryption_options_legacy_ssl_storage_port", "server_encryption_options.legacy_ssl_storage_port_enabled");
194195
names.put("server_encryption_options_protocol", "server_encryption_options.accepted_protocols");
196+
names.put("authenticator", "authenticator.class_name");
197+
names.put("authorizer", "authorizer.class_name");
198+
names.put("network_authorizer", "network_authorizer.class_name");
199+
names.put("role_manager", "role_manager.class_name");
200+
names.put("internode_authenticator", "internode_authenticator.class_name");
201+
195202

196203
// matching names
197204
names.put("audit_logging_options_audit_logs_dir", "audit_logging_options.audit_logs_dir");

test/unit/org/apache/cassandra/config/ConfigCompatibilityTest.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
import org.apache.cassandra.distributed.upgrade.ConfigCompatibilityTestGenerate;
5555
import org.yaml.snakeyaml.introspector.Property;
5656

57+
import static org.apache.cassandra.db.virtual.SettingsTable.BACKWARDS_COMPATIBLE_NAMES;
58+
5759
/**
5860
* To create the test files used by this class, run {@link ConfigCompatibilityTestGenerate}.
5961
*/
@@ -163,7 +165,9 @@ private void diff(String original, Set<String> ignore, Set<String> expectedError
163165
Map<Class<?>, Map<String, Replacement>> replacements = Replacements.getNameReplacements(type);
164166
Set<String> missing = new HashSet<>();
165167
Set<String> errors = new HashSet<>();
166-
diff(loader, replacements, previous, type, "", missing, errors);
168+
Map<String, String> backwardsCompatNames = BACKWARDS_COMPATIBLE_NAMES;
169+
170+
diff(loader, replacements, previous, type, "", missing, errors, backwardsCompatNames);
167171
missing = Sets.difference(missing, ignore);
168172
errors = Sets.difference(errors, expectedErrors);
169173
StringBuilder msg = new StringBuilder();
@@ -179,7 +183,7 @@ private void diff(String original, Set<String> ignore, Set<String> expectedError
179183
throw new AssertionError(msg);
180184
}
181185

182-
private void diff(Loader loader, Map<Class<?>, Map<String, Replacement>> replacements, ClassTree previous, Class<?> type, String prefix, Set<String> missing, Set<String> errors)
186+
private void diff(Loader loader, Map<Class<?>, Map<String, Replacement>> replacements, ClassTree previous, Class<?> type, String prefix, Set<String> missing, Set<String> errors, Map<String, String> backwardsCompatNames)
183187
{
184188
Map<String, Replacement> replaces = replacements.getOrDefault(type, Collections.emptyMap());
185189
Map<String, Property> properties = loader.getProperties(type);
@@ -210,7 +214,7 @@ private void diff(Loader loader, Map<Class<?>, Map<String, Replacement>> replace
210214
if (node instanceof ClassTree)
211215
{
212216
// current is nested type
213-
diff(loader, replacements, (ClassTree) node, prop.getType(), prefix + name + ".", missing, errors);
217+
diff(loader, replacements, (ClassTree) node, prop.getType(), prefix + name + ".", missing, errors, backwardsCompatNames);
214218
}
215219
else
216220
{
@@ -225,7 +229,19 @@ private void diff(Loader loader, Map<Class<?>, Map<String, Replacement>> replace
225229
// previous is leaf, is current?
226230
Map<String, Property> children = Properties.isPrimitive(prop) || Properties.isCollection(prop) ? Collections.emptyMap() : loader.getProperties(prop.getType());
227231
if (!children.isEmpty())
232+
{
228233
errors.add(String.format("Property %s used to be a value-type, but now is nested type %s", name, prop.getType()));
234+
235+
// Verify SettingsTable maps old name to new nested path for backwards compatibility (e.g., "authenticator" -> "authenticator.class_name")
236+
if (!backwardsCompatNames.containsKey(name))
237+
{
238+
errors.add(String.format(
239+
"Property %s changed to nested type but is missing from SettingsTable.BACKWARDS_COMPATIBLE_NAMES. " +
240+
"Add mapping for '%s' to its new nested property path.",
241+
name, name));
242+
}
243+
}
244+
229245
typeCheck(null, toString(prop.getType()), ((Leaf) node).type, name, errors);
230246
}
231247
}

test/unit/org/apache/cassandra/db/virtual/SettingsTableTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ public void virtualTableBackwardCompatibility() throws Throwable
176176
assertRowsNet(executeNet(q), new Object[] {"credentials_update_interval", null});
177177
q = "SELECT * FROM vts.settings WHERE name = 'credentials_update_interval_in_ms';";
178178
assertRowsNet(executeNet(q), new Object[] {"credentials_update_interval_in_ms", "-1"});
179+
180+
// test non matching auth related properties
181+
q = "SELECT * FROM vts.settings WHERE name = 'authenticator';";
182+
assertRowsNet(executeNet(q), new Object[] {"authenticator", null});
183+
q = "SELECT * FROM vts.settings WHERE name = 'authorizer';";
184+
assertRowsNet(executeNet(q), new Object[] {"authorizer", null});
185+
q = "SELECT * FROM vts.settings WHERE name = 'network_authorizer';";
186+
assertRowsNet(executeNet(q), new Object[] {"network_authorizer", null});
187+
q= "select * from vts.settings where name = 'role_manager';";
188+
assertRowsNet(executeNet(q), new Object[] {"role_manager", null});
179189
}
180190

181191
private void check(String keyspaceTable, String setting, String expected)

0 commit comments

Comments
 (0)