yifan-c commented on code in PR #4458: URL: https://github.com/apache/cassandra/pull/4458#discussion_r2487676146
########## src/java/org/apache/cassandra/db/compression/CompressionDictionaryDetailsTabularData.java: ########## @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.db.compression; + +import java.util.Arrays; +import javax.management.openmbean.ArrayType; +import javax.management.openmbean.CompositeData; +import javax.management.openmbean.CompositeDataSupport; +import javax.management.openmbean.CompositeType; +import javax.management.openmbean.OpenDataException; +import javax.management.openmbean.OpenType; +import javax.management.openmbean.SimpleType; +import javax.management.openmbean.TabularDataSupport; +import javax.management.openmbean.TabularType; + +import static java.lang.String.format; + +public class CompressionDictionaryDetailsTabularData +{ + public static final String KEYSPACE_NAME = "Keyspace"; + public static final String TABLE_NAME = "Table"; + public static final String DICT_ID_NAME = "DictId"; + public static final String DICT_NAME = "Dict"; + public static final String KIND_NAME = "Kind"; + public static final String CHECKSUM_NAME = "Checksum"; + public static final String SIZE_NAME = "Size"; + + + private static final String[] ITEM_NAMES = new String[]{ KEYSPACE_NAME, + TABLE_NAME, + DICT_ID_NAME, + DICT_NAME, + KIND_NAME, + CHECKSUM_NAME, + SIZE_NAME }; + + private static final String[] ITEM_DESCS = new String[]{ "keyspace", + "table", + "dictionary_id", + "dictionary_bytes", + "kind", + "checksum", + "size" }; + + private static final String TYPE_NAME = "DictionaryDetails"; + private static final String ROW_DESC = "DictionaryDetails"; + private static final OpenType<?>[] ITEM_TYPES; + private static final CompositeType COMPOSITE_TYPE; + public static final TabularType TABULAR_TYPE; + + static + { + try + { + ITEM_TYPES = new OpenType[]{ SimpleType.STRING, // keyspace + SimpleType.STRING, // table + SimpleType.LONG, // dict id + new ArrayType<String[]>(SimpleType.BYTE, true), // dict bytes + SimpleType.STRING, // kind + SimpleType.INTEGER, // checksum + SimpleType.INTEGER }; // size of dict bytes + + COMPOSITE_TYPE = new CompositeType(TYPE_NAME, ROW_DESC, ITEM_NAMES, ITEM_DESCS, ITEM_TYPES); + TABULAR_TYPE = new TabularType(TYPE_NAME, ROW_DESC, COMPOSITE_TYPE, ITEM_NAMES); + } + catch (OpenDataException e) + { + throw new RuntimeException(e); + } + } + + public static void from(String keyspace, + String table, + CompressionDictionary dictionary, + TabularDataSupport result) + { + result.put(from(keyspace, table, dictionary)); + } + + public static CompositeData from(String keyspace, String table, CompressionDictionary dictionary) + { + try + { + return new CompositeDataSupport(COMPOSITE_TYPE, + ITEM_NAMES, + new Object[] + { + keyspace, + table, + dictionary.dictId().id, + dictionary.rawDictionary(), + dictionary.kind().name(), + dictionary.checksum(), + dictionary.size(), + }); + } + catch (OpenDataException e) + { + throw new RuntimeException(e); + } + } + + public static CompositeData from(CompressionDictionaryPojo pojo) + { + try + { + return new CompositeDataSupport(COMPOSITE_TYPE, + ITEM_NAMES, + new Object[] + { + pojo.keyspace, + pojo.table, + pojo.dictId, + pojo.dict, + pojo.kind, + pojo.dictChecksum, + pojo.dictLength + }); + } + catch (OpenDataException e) + { + throw new RuntimeException(e); + } + } + + /** + * Deserializes data to convenience object to work further with. + * + * @param compositeData data to create pojo from + * @return deserialized composite data to convenience object + * @throws IllegalArgumentException if values in deserialized object are invalid. + * @see CompressionDictionaryPojo#validate() + */ + public static CompressionDictionaryPojo from(CompositeData compositeData) Review Comment: Why both methods are named "from"? They reads confusing. ``` public static CompositeData from(CompressionDictionaryPojo pojo) public static CompressionDictionaryPojo from(CompositeData compositeData) ``` ########## src/java/org/apache/cassandra/tools/nodetool/CompressionDictionary.java: ########## @@ -18,25 +18,42 @@ package org.apache.cassandra.tools.nodetool; import java.io.PrintStream; +import java.util.ArrayList; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import javax.management.openmbean.CompositeData; +import javax.management.openmbean.TabularData; import com.google.common.util.concurrent.Uninterruptibles; +import org.apache.cassandra.db.compression.CompressionDictionaryDetailsTabularData; +import org.apache.cassandra.db.compression.CompressionDictionaryDetailsTabularData.CompressionDictionaryPojo; import org.apache.cassandra.db.compression.ICompressionDictionaryTrainer.TrainingStatus; import org.apache.cassandra.db.compression.TrainingState; +import org.apache.cassandra.io.util.File; +import org.apache.cassandra.io.util.FileUtils; import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.nodetool.formatter.TableBuilder; import org.apache.cassandra.utils.Clock; +import org.apache.cassandra.utils.JsonUtils; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; +import static java.nio.file.StandardOpenOption.CREATE; +import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; +import static java.nio.file.StandardOpenOption.WRITE; + @Command(name = "compressiondictionary", - description = "Manage compression dictionaries", - subcommands = { CompressionDictionary.Train.class }) +description = "Manage compression dictionaries", +subcommands = { CompressionDictionary.Train.class, + CompressionDictionary.List.class, + CompressionDictionary.Export.class, + CompressionDictionary.Import.class }) Review Comment: can we add test cases for the new commands? ########## src/java/org/apache/cassandra/db/compression/CompressionDictionaryDetailsTabularData.java: ########## @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.db.compression; + +import java.util.Arrays; +import javax.management.openmbean.ArrayType; +import javax.management.openmbean.CompositeData; +import javax.management.openmbean.CompositeDataSupport; +import javax.management.openmbean.CompositeType; +import javax.management.openmbean.OpenDataException; +import javax.management.openmbean.OpenType; +import javax.management.openmbean.SimpleType; +import javax.management.openmbean.TabularDataSupport; +import javax.management.openmbean.TabularType; + +import static java.lang.String.format; + +public class CompressionDictionaryDetailsTabularData Review Comment: Could you add tests for this class? 1. conversion between CompressionDictionary and CompositeData 2. validation -- 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]

