cshannon commented on code in PR #3929:
URL: https://github.com/apache/accumulo/pull/3929#discussion_r1383743368


##########
server/manager/src/main/java/org/apache/accumulo/manager/tableOps/delete/ReserveTablets.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.manager.tableOps.delete;
+
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.LOCATION;
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.OPID;
+import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.PREV_ROW;
+
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.BiConsumer;
+
+import org.apache.accumulo.core.data.NamespaceId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.fate.Repo;
+import org.apache.accumulo.core.metadata.schema.Ample;
+import org.apache.accumulo.core.metadata.schema.TabletOperationId;
+import org.apache.accumulo.core.metadata.schema.TabletOperationType;
+import org.apache.accumulo.manager.Manager;
+import org.apache.accumulo.manager.tableOps.ManagerRepo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReserveTablets extends ManagerRepo {
+
+  private static final Logger log = 
LoggerFactory.getLogger(ReserveTablets.class);
+
+  private static final long serialVersionUID = 1L;
+
+  private final TableId tableId;
+  private final NamespaceId namespaceId;
+
+  public ReserveTablets(TableId tableId, NamespaceId namespaceId) {
+    this.tableId = tableId;
+    this.namespaceId = namespaceId;
+  }
+
+  @Override
+  public long isReady(long tid, Manager manager) throws Exception {
+
+    var opid = TabletOperationId.from(TabletOperationType.DELETING, tid);
+
+    // The consumer may be called in another thread so use an AtomicLong
+    AtomicLong accepted = new AtomicLong(0);
+    BiConsumer<KeyExtent,Ample.ConditionalResult> resultsConsumer = (extent, 
result) -> {
+      if (result.getStatus() == Ample.ConditionalResult.Status.ACCEPTED) {
+        accepted.incrementAndGet();
+      } else {
+        log.debug("Failed to set operation id {} {}", opid, extent);
+      }
+    };
+
+    long locations = 0;
+    long otherOps = 0;
+    long submitted = 0;
+    long tabletsSeen = 0;
+
+    try (
+        var tablets = 
manager.getContext().getAmple().readTablets().forTable(tableId)
+            .fetch(OPID, PREV_ROW, LOCATION).checkConsistency().build();
+        var conditionalMutator =
+            
manager.getContext().getAmple().conditionallyMutateTablets(resultsConsumer)) {
+      tabletsSeen++;
+      for (var tabletMeta : tablets) {

Review Comment:
   That's a good point that we can just use the stream api, so that works so 
can just use that since it already exists. The sever side iterator would be a 
nice enhancement.



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