Fix system_views.settings to handle array types

patch by Stefan Miklosovic; reviewed by Brandon Williams for CASSANDRA-19475
This commit is contained in:
Stefan Miklosovic 2024-03-19 14:55:42 +01:00
parent 8502da494c
commit e4ae1f3a4f
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
3 changed files with 23 additions and 12 deletions

View File

@ -1,4 +1,5 @@
4.1.5
* Fix system_views.settings to handle array types (CASSANDRA-19475)
Merged from 4.0:
* Push LocalSessions info logs to debug (CASSANDRA-18335)
* Filter remote DC replicas out when constructing the initial replica plan for the local read repair (CASSANDRA-19120)

View File

@ -17,9 +17,12 @@
*/
package org.apache.cassandra.db.virtual;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import org.apache.cassandra.config.Config;
@ -83,10 +86,17 @@ final class SettingsTable extends AbstractVirtualTable
return result;
}
private String getValue(Property prop)
@VisibleForTesting
String getValue(Property prop)
{
Object value = prop.get(config);
return value == null ? null : value.toString();
if (value == null)
return null;
if (value.getClass().isArray())
return Arrays.asList((Object[]) value).toString();
return value.toString();
}
private static Map<String, Property> getProperties()

View File

@ -62,11 +62,19 @@ public class SettingsTableTest extends CQLTester
config.cache_load_timeout = new DurationSpec.IntSecondsBound(0);
config.commitlog_sync_group_window = new DurationSpec.IntMillisecondsBound(0);
config.credentials_update_interval = null;
config.data_file_directories = new String[] {"/my/data/directory", "/another/data/directory"};
table = new SettingsTable(KS_NAME, config);
VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
disablePreparedReuseForTest();
}
@Test
public void testArray() throws Throwable
{
Row one = executeNet("SELECT value FROM vts.settings WHERE name = 'data_file_directories'").one();
Assert.assertEquals("[/my/data/directory, /another/data/directory]", one.getString("value"));
}
@Test
public void testSelectAll() throws Throwable
{
@ -79,7 +87,7 @@ public class SettingsTableTest extends CQLTester
String name = r.getString("name");
Property prop = SettingsTable.PROPERTIES.get(name);
if (prop != null) // skip overrides
Assert.assertEquals(getValue(prop), r.getString("value"));
Assert.assertEquals(table.getValue(prop), r.getString("value"));
}
Assert.assertTrue(SettingsTable.PROPERTIES.size() <= i);
}
@ -92,7 +100,7 @@ public class SettingsTableTest extends CQLTester
String name = e.getKey();
Property prop = e.getValue();
String q = "SELECT * FROM vts.settings WHERE name = '"+name+'\'';
assertRowsNet(executeNet(q), new Object[] { name, getValue(prop) });
assertRowsNet(executeNet(q), new Object[] { name, table.getValue(prop) });
}
}
@ -146,14 +154,6 @@ public class SettingsTableTest extends CQLTester
assertRowsNet(executeNet(q), new Object[] {"credentials_update_interval_in_ms", "-1"});
}
private String getValue(Property prop)
{
Object v = prop.get(config);
if (v != null)
return v.toString();
return null;
}
private void check(String setting, String expected) throws Throwable
{
String q = "SELECT * FROM vts.settings WHERE name = '"+setting+'\'';