sumitagrawl commented on code in PR #9040: URL: https://github.com/apache/ozone/pull/9040#discussion_r2369147895
########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/GlobalStatsValue.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.hadoop.ozone.recon.tasks; + +/** + * Value class for global statistics stored in RocksDB. + * Contains the statistic value and last updated timestamp (as epoch milliseconds) + * for efficient storage in the GLOBAL_STATS column family. + */ +public class GlobalStatsValue { + private final Long value; + private final Long lastUpdatedTimestamp; // epoch milliseconds for RocksDB storage + + public GlobalStatsValue(Long value, Long lastUpdatedTimestamp) { + this.value = value; + this.lastUpdatedTimestamp = lastUpdatedTimestamp; Review Comment: we are not using timestamp anywhere, is it useful? ########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/GlobalStatsValue.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.hadoop.ozone.recon.tasks; + +/** + * Value class for global statistics stored in RocksDB. + * Contains the statistic value and last updated timestamp (as epoch milliseconds) + * for efficient storage in the GLOBAL_STATS column family. + */ +public class GlobalStatsValue { + private final Long value; + private final Long lastUpdatedTimestamp; // epoch milliseconds for RocksDB storage + + public GlobalStatsValue(Long value, Long lastUpdatedTimestamp) { + this.value = value; + this.lastUpdatedTimestamp = lastUpdatedTimestamp; + } + + public Long getValue() { + return value; + } + + public Long getLastUpdatedTimestamp() { + return lastUpdatedTimestamp; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof GlobalStatsValue) { Review Comment: are we doing any comparision? if not no need to implement equals and hashcode ########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/FileCountBySizeKeyCodec.java: ########## @@ -0,0 +1,98 @@ +/* + * 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.hadoop.ozone.recon.spi.impl; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import com.google.common.base.Preconditions; +import com.google.common.primitives.Longs; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.hadoop.hdds.utils.db.Codec; +import org.apache.hadoop.ozone.recon.tasks.FileSizeCountKey; + +/** + * Codec to serialize/deserialize {@link FileSizeCountKey}. + */ +public final class FileCountBySizeKeyCodec implements Codec<FileSizeCountKey> { + + private static final String KEY_DELIMITER = "_"; + + private static final Codec<FileSizeCountKey> INSTANCE = new FileCountBySizeKeyCodec(); + + public static Codec<FileSizeCountKey> get() { + return INSTANCE; + } + + private FileCountBySizeKeyCodec() { + // singleton + } + + @Override + public Class<FileSizeCountKey> getTypeClass() { + return FileSizeCountKey.class; + } + + @Override + public byte[] toPersistedFormat(FileSizeCountKey key) { + Preconditions.checkNotNull(key, "Null object can't be converted to byte array."); + + // Serialize: volume + delimiter + bucket + delimiter + fileSize (8 bytes) + byte[] volumeBytes = key.getVolume().getBytes(UTF_8); Review Comment: we can use Message format with splitter or String builder here. Underscore is used as splitter, what if this is part of volume or bucket name ? can we use same splitter "/" for volume and bucekt and others ? ########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/GlobalStatsValueCodec.java: ########## @@ -0,0 +1,85 @@ +/* + * 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.hadoop.ozone.recon.spi.impl; + +import com.google.common.base.Preconditions; +import com.google.common.primitives.Longs; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.hadoop.hdds.utils.db.Codec; +import org.apache.hadoop.ozone.recon.tasks.GlobalStatsValue; + +/** + * Codec to serialize/deserialize {@link GlobalStatsValue}. + */ +public final class GlobalStatsValueCodec implements Codec<GlobalStatsValue> { + + private static final Codec<GlobalStatsValue> INSTANCE = new GlobalStatsValueCodec(); + + public static Codec<GlobalStatsValue> get() { + return INSTANCE; + } + + private GlobalStatsValueCodec() { + // singleton + } + + @Override + public Class<GlobalStatsValue> getTypeClass() { + return GlobalStatsValue.class; + } + + @Override + public byte[] toPersistedFormat(GlobalStatsValue value) { + Preconditions.checkNotNull(value, "Null object can't be converted to byte array."); + + // Fixed 16-byte format: 8-byte value + 8-byte timestamp + Long val = value.getValue() != null ? value.getValue() : 0L; + Long timestamp = value.getLastUpdatedTimestamp() != null ? + value.getLastUpdatedTimestamp() : 0L; + + byte[] valueBytes = Longs.toByteArray(val); Review Comment: This is specialized encoding decoding. What if use String format, with Message.format with splitter or proto object? -- 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]
