jojochuang commented on code in PR #9489: URL: https://github.com/apache/ozone/pull/9489#discussion_r2615588302
########## hadoop-hdds/rocks-native/src/main/native/ManagedRawSSTFileIterator.cpp: ########## @@ -16,57 +16,50 @@ * limitations under the License. */ -#include "org_apache_hadoop_hdds_utils_db_managed_ManagedRawSSTFileIterator.h" +#include "org_apache_hadoop_hdds_utils_db_ManagedRawSSTFileIterator.h" #include "rocksdb/options.h" #include "rocksdb/raw_iterator.h" #include <string> #include "cplusplus_to_java_convert.h" #include <iostream> -jboolean Java_org_apache_hadoop_hdds_utils_db_managed_ManagedRawSSTFileIterator_hasNext(JNIEnv *env, jobject obj, +template <class T> +static jint copyToDirect(JNIEnv* env, T& source, jobject jtarget, jint jtarget_off, jint jtarget_len); Review Comment: added a copyToDirect function here, which is used by Java_org_apache_hadoop_hdds_utils_db_ManagedRawSSTFileIterator_getKey ########## hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Buffer.java: ########## @@ -0,0 +1,80 @@ +/* + * 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; + +import org.apache.ratis.util.Preconditions; + +class Buffer { Review Comment: moved and extracted out from RDBStoreCodecBufferIterator.Buffer ########## hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/db/ManagedRawSSTFileIterator.java: ########## @@ -31,19 +30,33 @@ public class ManagedRawSSTFileIterator<T> implements ClosableIterator<T> { // Native address of pointer to the object. private final long nativeHandle; private final Function<KeyValue, T> transformer; + private final IteratorType type; + private boolean closed; + private final Buffer keyBuffer; + private final Buffer valueBuffer; - ManagedRawSSTFileIterator(long nativeHandle, Function<KeyValue, T> transformer) { + ManagedRawSSTFileIterator(String name, long nativeHandle, Function<KeyValue, T> transformer, IteratorType type) { this.nativeHandle = nativeHandle; this.transformer = transformer; + this.type = type; + this.closed = false; + this.keyBuffer = new Buffer( + new CodecBuffer.Capacity(name + " iterator-key", 1 << 10), Review Comment: 1KB ########## hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/IteratorType.java: ########## @@ -0,0 +1,48 @@ +/* + * 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; + +/** + * The iterator type. + */ +public enum IteratorType { Review Comment: moved from KeyValueIterator. ########## hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/db/package-info.java: ########## @@ -16,6 +16,6 @@ */ /** - * This package contains utility classes related to Managed SST dump tool. + * Native rocksdb utilities. */ -package org.apache.hadoop.hdds.utils.db.managed; +package org.apache.hadoop.hdds.utils.db; Review Comment: Relocated package path from org.apache.hadoop.hdds.utils.db.managed to org.apache.hadoop.hdds.utils.db ########## hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/db/ManagedRawSSTFileIterator.java: ########## @@ -31,19 +30,33 @@ public class ManagedRawSSTFileIterator<T> implements ClosableIterator<T> { // Native address of pointer to the object. private final long nativeHandle; private final Function<KeyValue, T> transformer; + private final IteratorType type; + private boolean closed; + private final Buffer keyBuffer; + private final Buffer valueBuffer; - ManagedRawSSTFileIterator(long nativeHandle, Function<KeyValue, T> transformer) { + ManagedRawSSTFileIterator(String name, long nativeHandle, Function<KeyValue, T> transformer, IteratorType type) { this.nativeHandle = nativeHandle; this.transformer = transformer; + this.type = type; + this.closed = false; + this.keyBuffer = new Buffer( + new CodecBuffer.Capacity(name + " iterator-key", 1 << 10), + this.type.readKey() ? buffer -> this.getKey(this.nativeHandle, buffer, buffer.position(), + buffer.remaining()) : null); + this.valueBuffer = new Buffer( + new CodecBuffer.Capacity(name + " iterator-value", 4 << 10), Review Comment: 4KB ########## hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/db/ManagedRawSSTFileIterator.java: ########## @@ -31,19 +30,33 @@ public class ManagedRawSSTFileIterator<T> implements ClosableIterator<T> { // Native address of pointer to the object. private final long nativeHandle; private final Function<KeyValue, T> transformer; + private final IteratorType type; + private boolean closed; + private final Buffer keyBuffer; + private final Buffer valueBuffer; - ManagedRawSSTFileIterator(long nativeHandle, Function<KeyValue, T> transformer) { + ManagedRawSSTFileIterator(String name, long nativeHandle, Function<KeyValue, T> transformer, IteratorType type) { this.nativeHandle = nativeHandle; this.transformer = transformer; + this.type = type; + this.closed = false; + this.keyBuffer = new Buffer( + new CodecBuffer.Capacity(name + " iterator-key", 1 << 10), + this.type.readKey() ? buffer -> this.getKey(this.nativeHandle, buffer, buffer.position(), + buffer.remaining()) : null); + this.valueBuffer = new Buffer( + new CodecBuffer.Capacity(name + " iterator-value", 4 << 10), + this.type.readValue() ? buffer -> this.getValue(this.nativeHandle, buffer, buffer.position(), Review Comment: do we need to handle the case where the initial buffer size is not big enough? Similar to https://github.com/apache/ozone/blob/48c985f8f65c9c0d99c2b3fadc74683f05c1efc7/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStoreCodecBufferIterator.java#L146 ########## hadoop-hdds/rocks-native/src/test/java/org/apache/hadoop/hdds/utils/db/TestManagedRawSSTFileIterator.java: ########## Review Comment: we may want to add a test case for when the sst key/value to be read is longer than the initial buffer size. -- 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]
