szetszwo commented on code in PR #8073:
URL: https://github.com/apache/ozone/pull/8073#discussion_r1994448351
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java:
##########
@@ -87,32 +88,43 @@ public TypedTable(RDBTable rawTable,
* @param keyType The key type.
* @param valueType The value type.
* @param cacheType How to cache the entries?
- * @param threadNamePrefix
+ * @param threadNamePrefix the thread name prefix
Review Comment:
Please don't change `threadNamePrefix`; see HDDS-12590.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStore.java:
##########
@@ -302,6 +302,12 @@ public <K, V> TypedTable<K, V> getTable(String name,
valueType);
}
+ public <K, V> TypedTable<K, V> getTable(
Review Comment:
This new method is only used in test. How are you going to use it?
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/cache/TableNoCache.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.hdds.utils.db.cache;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Set;
+import org.apache.hadoop.hdds.annotation.InterfaceAudience.Private;
+import org.apache.hadoop.hdds.annotation.InterfaceStability.Evolving;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Cache implementation for the table. Partial Table cache, where the DB state
+ * and cache state will not be same. Partial table cache holds entries until
+ * flush to DB happens.
+ * @param <KEY>
+ * @param <VALUE>
Review Comment:
Please don't copy javadoc. No javadoc is better than incorrect/misleading
javadoc.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/cache/TableNoCache.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.hdds.utils.db.cache;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Set;
+import org.apache.hadoop.hdds.annotation.InterfaceAudience.Private;
+import org.apache.hadoop.hdds.annotation.InterfaceStability.Evolving;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Cache implementation for the table. Partial Table cache, where the DB state
+ * and cache state will not be same. Partial table cache holds entries until
+ * flush to DB happens.
+ * @param <KEY>
+ * @param <VALUE>
+ */
+@Private
+@Evolving
+public class TableNoCache<KEY, VALUE> implements TableCache<KEY, VALUE> {
Review Comment:
`TableNoCache` should be singleton.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/cache/TableNoCache.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.hdds.utils.db.cache;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Set;
+import org.apache.hadoop.hdds.annotation.InterfaceAudience.Private;
+import org.apache.hadoop.hdds.annotation.InterfaceStability.Evolving;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Cache implementation for the table. Partial Table cache, where the DB state
+ * and cache state will not be same. Partial table cache holds entries until
+ * flush to DB happens.
+ * @param <KEY>
+ * @param <VALUE>
+ */
+@Private
+@Evolving
+public class TableNoCache<KEY, VALUE> implements TableCache<KEY, VALUE> {
+ public static final Logger LOG = LoggerFactory.getLogger(TableNoCache.class);
+ public static final CacheStats EMPTY_STAT = new CacheStats(0, 0, 0);
+
+ @Override
+ public CacheValue<VALUE> get(CacheKey<KEY> cachekey) {
+ return null;
+ }
+
+ @Override
+ public void loadInitial(CacheKey<KEY> key, CacheValue<VALUE> value) {
+ }
+
+ @Override
+ public void put(CacheKey<KEY> cacheKey, CacheValue<VALUE> value) {
+ }
+
+ @Override
+ public void cleanup(List<Long> epochs) {
+ }
+
+ @Override
+ public int size() {
+ return 0;
+ }
+
+ @Override
+ public Iterator<Map.Entry<CacheKey<KEY>, CacheValue<VALUE>>> iterator() {
+ return Collections.emptyIterator();
+ }
+
+ @VisibleForTesting
+ @Override
+ public void evictCache(List<Long> epochs) {
+ }
+
+ @Override
+ public CacheResult<VALUE> lookup(CacheKey<KEY> cachekey) {
+ return new CacheResult<>(CacheResult.CacheStatus.MAY_EXIST, null);
Review Comment:
Add a constant and use it.
```diff
public class CacheResult<VALUE> {
+ private static final CacheResult<?> MAY_EXIST = new
CacheResult<>(CacheResult.CacheStatus.MAY_EXIST, null);
+
+ public static <T> CacheResult<T> mayExist() {
+ return (CacheResult<T>) MAY_EXIST;
+ }
```
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/cache/TableNoCache.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.hdds.utils.db.cache;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Set;
+import org.apache.hadoop.hdds.annotation.InterfaceAudience.Private;
+import org.apache.hadoop.hdds.annotation.InterfaceStability.Evolving;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Cache implementation for the table. Partial Table cache, where the DB state
+ * and cache state will not be same. Partial table cache holds entries until
+ * flush to DB happens.
+ * @param <KEY>
+ * @param <VALUE>
+ */
+@Private
+@Evolving
+public class TableNoCache<KEY, VALUE> implements TableCache<KEY, VALUE> {
+ public static final Logger LOG = LoggerFactory.getLogger(TableNoCache.class);
Review Comment:
Why adding a `LOG`?
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java:
##########
@@ -87,32 +88,43 @@ public TypedTable(RDBTable rawTable,
* @param keyType The key type.
* @param valueType The value type.
* @param cacheType How to cache the entries?
- * @param threadNamePrefix
+ * @param threadNamePrefix the thread name prefix
* @throws IOException if failed to iterate the raw table.
*/
public TypedTable(RDBTable rawTable,
CodecRegistry codecRegistry, Class<KEY> keyType,
Class<VALUE> valueType,
CacheType cacheType, String threadNamePrefix) throws IOException {
- this.rawTable = Objects.requireNonNull(rawTable, "rawTable==null");
- Objects.requireNonNull(codecRegistry, "codecRegistry == null");
+ this(rawTable, keyType, codecRegistry.getCodecFromClass(keyType),
valueType,
+ codecRegistry.getCodecFromClass(valueType), cacheType,
threadNamePrefix);
+ }
+ /**
+ * Create an TypedTable from the raw table with specified cache type.
+ *
+ * @param rawTable The underlying (untyped) table in RocksDB.
+ * @param keyType The key type.
+ * @param keyCodec The key codec.
+ * @param valueType The value type.
+ * @param valueCodec The value codec.
+ * @param cacheType How to cache the entries?
+ * @param threadNamePrefix the thread name prefix
+ * @throws IOException
+ */
+ public TypedTable(
+ RDBTable rawTable, Class<KEY> keyType, Codec<KEY> keyCodec, Class<VALUE>
valueType, Codec<VALUE> valueCodec,
Review Comment:
Remove `keyType` and use `keyCodec.getTypeClass()`.
Do the same for `valueType`.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java:
##########
@@ -87,32 +88,43 @@ public TypedTable(RDBTable rawTable,
* @param keyType The key type.
* @param valueType The value type.
* @param cacheType How to cache the entries?
- * @param threadNamePrefix
+ * @param threadNamePrefix the thread name prefix
* @throws IOException if failed to iterate the raw table.
*/
public TypedTable(RDBTable rawTable,
CodecRegistry codecRegistry, Class<KEY> keyType,
Class<VALUE> valueType,
CacheType cacheType, String threadNamePrefix) throws IOException {
- this.rawTable = Objects.requireNonNull(rawTable, "rawTable==null");
- Objects.requireNonNull(codecRegistry, "codecRegistry == null");
+ this(rawTable, keyType, codecRegistry.getCodecFromClass(keyType),
valueType,
+ codecRegistry.getCodecFromClass(valueType), cacheType,
threadNamePrefix);
+ }
+ /**
+ * Create an TypedTable from the raw table with specified cache type.
+ *
+ * @param rawTable The underlying (untyped) table in RocksDB.
+ * @param keyType The key type.
+ * @param keyCodec The key codec.
+ * @param valueType The value type.
+ * @param valueCodec The value codec.
+ * @param cacheType How to cache the entries?
+ * @param threadNamePrefix the thread name prefix
+ * @throws IOException
+ */
+ public TypedTable(
+ RDBTable rawTable, Class<KEY> keyType, Codec<KEY> keyCodec, Class<VALUE>
valueType, Codec<VALUE> valueCodec,
+ CacheType cacheType, String threadNamePrefix) throws IOException {
+ this.rawTable = Objects.requireNonNull(rawTable, "rawTable==null");
this.keyType = Objects.requireNonNull(keyType, "keyType == null");
- this.keyCodec = codecRegistry.getCodecFromClass(keyType);
- Objects.requireNonNull(keyCodec, "keyCodec == null");
-
+ this.keyCodec = Objects.requireNonNull(keyCodec, "keyCodec == null");
this.valueType = Objects.requireNonNull(valueType, "valueType == null");
- this.valueCodec = codecRegistry.getCodecFromClass(valueType);
- Objects.requireNonNull(valueCodec, "valueCodec == null");
-
- this.supportCodecBuffer = keyCodec.supportCodecBuffer()
- && valueCodec.supportCodecBuffer();
-
+ this.valueCodec = Objects.requireNonNull(valueCodec, "valueCodec == null");
+ this.supportCodecBuffer = keyCodec.supportCodecBuffer() &&
valueCodec.supportCodecBuffer();
if (cacheType == CacheType.FULL_CACHE) {
cache = new FullTableCache<>(threadNamePrefix);
//fill cache
try (TableIterator<KEY, ? extends KeyValue<KEY, VALUE>> tableIterator =
- iterator()) {
+ iterator()) {
Review Comment:
Let's put it in one line, i.e.
```diff
- try (TableIterator<KEY, ? extends KeyValue<KEY, VALUE>> tableIterator
=
- iterator()) {
-
+ try (TableIterator<KEY, ? extends KeyValue<KEY, VALUE>> tableIterator
= iterator()) {
```
--
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]