keith-turner commented on code in PR #3929:
URL: https://github.com/apache/accumulo/pull/3929#discussion_r1383696643


##########
server/base/src/main/java/org/apache/accumulo/server/metadata/AsyncConditionalTabletsMutatorImpl.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.server.metadata;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.function.BiConsumer;
+
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+import org.apache.accumulo.core.metadata.schema.Ample;
+import org.apache.accumulo.server.ServerContext;
+
+public class AsyncConditionalTabletsMutatorImpl implements 
Ample.AsyncConditionalTabletsMutator {
+  private final BiConsumer<KeyExtent,Ample.ConditionalResult> resultsConsumer;
+  private final ExecutorService executor;
+  private Future<Map<KeyExtent,Ample.ConditionalResult>> backgroundProcessing 
= null;
+  private ConditionalTabletsMutatorImpl bufferingMutator;
+  private final ServerContext context;
+  private long mutatedTablets = 0;
+
+  public static final int BATCH_SIZE = 1000;
+
+  AsyncConditionalTabletsMutatorImpl(ServerContext context,
+      BiConsumer<KeyExtent,Ample.ConditionalResult> resultsConsumer) {
+    this.resultsConsumer = Objects.requireNonNull(resultsConsumer);
+    this.bufferingMutator = new ConditionalTabletsMutatorImpl(context);
+    this.context = context;
+    this.executor = Executors.newSingleThreadExecutor();
+
+  }
+
+  @Override
+  public Ample.OperationRequirements mutateTablet(KeyExtent extent) {
+    if (mutatedTablets > BATCH_SIZE) {
+      if (backgroundProcessing != null) {
+        // a previous batch of mutations was submitted for processing so wait 
on it.
+        try {
+          backgroundProcessing.get().forEach(resultsConsumer);

Review Comment:
   For now I think it best to just wait.  This comment made me realize that 
debugging the situation where it gets stuck could be tricky.  Also realized I 
was not using Accumulo's internal thread utilities.  So in 08608df I did the 
following.
   
    * Use Accumulo's internal Threads class to create the thread
    * Put the thread id of the creating thread in the background threads name.  
In the case where it does get stuck, this allows linking of the foreground and 
background thread in a jstack.



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