keith-turner commented on code in PR #5998: URL: https://github.com/apache/accumulo/pull/5998#discussion_r2627424140
########## core/src/main/java/org/apache/accumulo/core/iteratorsImpl/system/MultiShuffledIterator.java: ########## @@ -0,0 +1,122 @@ +/* + * 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 + * + * https://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.accumulo.core.iteratorsImpl.system; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.apache.accumulo.core.data.ByteSequence; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.dataImpl.KeyExtent; +import org.apache.accumulo.core.iterators.IteratorEnvironment; +import org.apache.accumulo.core.iterators.SortedKeyValueIterator; + +/** + * An iterator capable of iterating over other iterators in sorted order while shuffling the initial + * seek ordering to avoid thread contention. + */ +public class MultiShuffledIterator extends HeapIterator { Review Comment: Experimented w/ making this extend MultiIterator to see if it would work. Found the deep copy made that tricky and a few things I tried did not work. Adding a setter method for setting iterators made the deep copy work. This minimizes copied code. ```java public class MultiShuffledIterator extends MultiIterator { protected void setIters(List<SortedKeyValueIterator<Key,Value>> iters) { var copy = new ArrayList<>(iters); Collections.shuffle(copy); super.setIters(copy); } // have to also override the constructors } ``` Made these changes in MutltiIterator ``` protected void setIters(List<SortedKeyValueIterator<Key,Value>> iters) { this.iters = iters; } private MultiIterator(MultiIterator other, IteratorEnvironment env) { super(other.iters.size()); var tmpIters = new ArrayList<SortedKeyValueIterator<Key,Value>>(); this.fence = other.fence; for (SortedKeyValueIterator<Key,Value> iter : other.iters) { tmpIters.add(iter.deepCopy(env)); } setIters(tmpIters); } // also update the other constructor to call setIters ``` ########## core/src/main/java/org/apache/accumulo/core/iteratorsImpl/system/MultiShuffledIterator.java: ########## @@ -0,0 +1,122 @@ +/* + * 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 + * + * https://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.accumulo.core.iteratorsImpl.system; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.apache.accumulo.core.data.ByteSequence; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.dataImpl.KeyExtent; +import org.apache.accumulo.core.iterators.IteratorEnvironment; +import org.apache.accumulo.core.iterators.SortedKeyValueIterator; + +/** + * An iterator capable of iterating over other iterators in sorted order while shuffling the initial + * seek ordering to avoid thread contention. + */ +public class MultiShuffledIterator extends HeapIterator { + + private final List<SortedKeyValueIterator<Key,Value>> iters; + private final Range fence; + + // deep copy with no seek/scan state + @Override + public MultiShuffledIterator deepCopy(IteratorEnvironment env) { + return new MultiShuffledIterator(this, env); + } + + private MultiShuffledIterator(MultiShuffledIterator other, IteratorEnvironment env) { + super(other.iters.size()); + this.iters = new ArrayList<>(); + this.fence = other.fence; + Collections.shuffle(other.iters); + for (SortedKeyValueIterator<Key,Value> iter : other.iters) { + iters.add(iter.deepCopy(env)); + } Review Comment: This will shuffle the iterators the deep copy is created from and make the deep copy and source have the same order. Moving the shuffle after the loop independently shuffles the deep copy. ```suggestion for (SortedKeyValueIterator<Key,Value> iter : other.iters) { iters.add(iter.deepCopy(env)); } Collections.shuffle(this.iters); ``` -- 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]
