yifan-c commented on code in PR #4458:
URL: https://github.com/apache/cassandra/pull/4458#discussion_r2496063572
##########
src/java/org/apache/cassandra/tools/NodeProbe.java:
##########
@@ -2697,11 +2698,87 @@ public void setMixedMajorVersionRepairEnabled(boolean
enabled)
* @throws IllegalArgumentException if table doesn't support dictionary
compression
*/
public void trainCompressionDictionary(String keyspace, String table,
boolean force) throws IOException
+ {
+ doWithCompressionDictionaryManagerMBean(proxy -> { proxy.train(force);
return null; }, keyspace, table);
+ }
+
+ /**
+ * Returns latest dictionary for given keyspace and table.
+ *
+ * @param keyspace the keyspace name
+ * @param table the table name
+ * @return the latest dictionary for given keyspace and table
+ * @throws IOException if there's an error accessing the MBean
+ * @throws IllegalArgumentException if table doesn't support dictionary
compression
+ */
+ public CompositeData getCompressionDictionary(String keyspace, String
table) throws IOException
+ {
+ return
doWithCompressionDictionaryManagerMBean(CompressionDictionaryManagerMBean::getCompressionDictionary,
keyspace, table);
+ }
+
+ /**
+ * Returns the dictionary for given keyspace and table and dictionary id.
+ *
+ * @param keyspace the keyspace name
+ * @param table the table name
+ * @param dictId id of dictionary to get
+ * @return the dictionary for given keyspace and table and dictionary id.
+ * @throws IOException if there's an error accessing the MBean
+ * @throws IllegalArgumentException if table doesn't support dictionary
compression
+ */
+ public CompositeData getCompressionDictionary(String keyspace, String
table, long dictId) throws IOException
+ {
+ return doWithCompressionDictionaryManagerMBean(proxy ->
proxy.getCompressionDictionary(dictId), keyspace, table);
+ }
+
+ /**
+ * Imports dictionary in composite data to database.
+ *
+ * @param compositeData data to import
+ * @throws IOException if there's an error accessing the MBean
+ * @throws IllegalArgumentException if table doesn't support dictionary
compression
+ */
+ public void importCompressionDictionary(CompositeData compositeData)
throws IOException
+ {
+ String keyspace = (String)
compositeData.get(CompressionDictionaryDetailsTabularData.KEYSPACE_NAME);
+ String table = (String)
compositeData.get(CompressionDictionaryDetailsTabularData.TABLE_NAME);
+
+ if (keyspace == null || table == null)
+ {
+ throw new IllegalStateException("Argument must have keyspace and
table values.");
+ }
+
+ doWithCompressionDictionaryManagerMBean(proxy -> {
proxy.importDictionary(compositeData); return null; }, keyspace, table);
+ }
+
+ private <T> T
doWithCompressionDictionaryManagerMBean(Function<CompressionDictionaryManagerMBean,
T> func,
+ String keyspace,
String table) throws IOException
+ {
+ try
+ {
+ return func.apply(getDictionaryManagerProxy(keyspace, table));
+ }
+ catch (Exception e)
+ {
+ if (e.getCause() instanceof InstanceNotFoundException)
+ {
+ String message = String.format("Table %s.%s does not exist or
does not support dictionary compression",
+ keyspace, table);
+ throw new IllegalArgumentException(message);
+ }
+ else
+ {
+ throw new IOException(e.getMessage());
+ }
+ }
+ }
+
+ public TabularData listCompressionDictionaries(String keyspace, String
table) throws IOException
{
CompressionDictionaryManagerMBean proxy =
getDictionaryManagerProxy(keyspace, table);
try
{
- proxy.train(force);
+ return proxy.listCompressionDictionaries();
Review Comment:
Looks like `doWithCompressionDictionaryManagerMBean` is suitable for this
method too.
--
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]