swamirishi commented on code in PR #8203: URL: https://github.com/apache/ozone/pull/8203#discussion_r2094615327
########## hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RawSpliterator.java: ########## @@ -0,0 +1,128 @@ +/* + * 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 java.io.IOException; +import java.util.Spliterator; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Consumer; +import org.apache.ratis.util.ReferenceCountedObject; +import org.apache.ratis.util.function.UncheckedAutoCloseableSupplier; + +/** + * A {@link Table.KeyValueIterator} backed by a raw iterator. + * + * @param <RAW> The raw type. + */ +abstract class RawSpliterator<RAW, KEY, VALUE> implements Table.KeyValueSpliterator<KEY, VALUE> { + + private final ReferenceCountedObject<TableIterator<RAW, + UncheckedAutoCloseableSupplier<RawKeyValue<RAW>>>> rawIterator; + private final AtomicInteger maxNumberOfAdditionalSplits; + private final Lock lock; + private final AtomicReference<IOException> closeException = new AtomicReference<>(); + + abstract Table.KeyValue<KEY, VALUE> convert(RawKeyValue<RAW> kv) throws IOException; + + abstract TableIterator<RAW, UncheckedAutoCloseableSupplier<RawKeyValue<RAW>>> getRawIterator( + KEY prefix, KEY startKey, int maxParallelism) throws IOException; + + RawSpliterator(KEY prefix, KEY startKey, int maxParallelism) throws IOException { + TableIterator<RAW, UncheckedAutoCloseableSupplier<RawKeyValue<RAW>>> itr = getRawIterator(prefix, + startKey, maxParallelism); + this.lock = new ReentrantLock(); + this.maxNumberOfAdditionalSplits = new AtomicInteger(maxParallelism - 1); Review Comment: No we need it. When we pass this to StreamSupport.stream(spliterator) all splits are supposed to be ideally acting independently. One split should not impact another split. That is why we are referenceCounting here. -- 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]
