dlmarion commented on code in PR #5451:
URL: https://github.com/apache/accumulo/pull/5451#discussion_r2039405998


##########
core/src/main/java/org/apache/accumulo/core/util/tables/TableMapping.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.util.tables;
+
+import static java.util.Collections.emptySortedMap;
+import static java.util.Objects.requireNonNull;
+import static 
org.apache.accumulo.core.clientImpl.NamespaceMapping.deserializeMap;
+import static 
org.apache.accumulo.core.clientImpl.NamespaceMapping.serializeMap;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.SortedMap;
+import java.util.stream.Stream;
+
+import org.apache.accumulo.core.Constants;
+import 
org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException;
+import org.apache.accumulo.core.clientImpl.ClientContext;
+import org.apache.accumulo.core.clientImpl.Namespace;
+import org.apache.accumulo.core.clientImpl.thrift.TableOperation;
+import org.apache.accumulo.core.clientImpl.thrift.TableOperationExceptionType;
+import org.apache.accumulo.core.data.NamespaceId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.core.metadata.AccumuloTable;
+import org.apache.accumulo.core.zookeeper.ZcStat;
+import org.apache.accumulo.core.zookeeper.ZooCache;
+import org.apache.zookeeper.KeeperException;
+
+import com.google.common.collect.ImmutableSortedMap;
+
+public class TableMapping {
+
+  private final ClientContext context;
+  private final NamespaceId namespaceId;
+  private volatile SortedMap<TableId,String> currentTableMap = 
emptySortedMap();
+  private volatile SortedMap<String,TableId> currentTableReverseMap = 
emptySortedMap();
+  private volatile long lastMzxid;
+
+  public TableMapping(ClientContext context, NamespaceId namespaceId) {
+    this.context = context;
+    this.namespaceId = namespaceId;
+  }
+
+  public void put(final ClientContext context, TableId tableId, String 
tableName,
+      TableOperation operation)
+      throws InterruptedException, KeeperException, 
AcceptableThriftTableOperationException {
+    var zoo = context.getZooSession().asReaderWriter();
+    Stream.of(zoo, tableId, namespaceId, 
tableName).forEach(Objects::requireNonNull);

Review Comment:
   The only thing that I have seen with respect to Streams being faster than a 
for loop, is when you use parallel streams, which we don't do. Parallel streams 
use the common ForkJoinPool, unless you create your own ForkJoinPool and use 
it. Traditional for loops and `for (item : items)` style for loops are going to 
be the fastest.
   
   In fact, if you look at the implementation of 
[Collection.forEach](https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/Iterable.java#L72),
 it's using the `for (item : items)` style for loop. If you wanted to still do 
this in a single line of code, then you could do something like the following, 
which still has some overhead for creating the Set.
   ```
   Set.of(a, b, c, d).forEach(Objects::requireNonNull);
   ```
   
   I can see a case for Streams to replace some complex for loop where the 
overhead introduced by the Stream replaces some complex operations happening 
inside the loop.



-- 
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]

Reply via email to