-
Notifications
You must be signed in to change notification settings - Fork 490
updates delete table to use conditional muations #3929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * 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.core.util.threads.Threads; | ||
| 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; | ||
| var creatorId = Thread.currentThread().getId(); | ||
| this.executor = Executors.newSingleThreadExecutor(runnable -> Threads.createThread( | ||
| "Async conditional tablets mutator background thread, created by : #" + creatorId, | ||
| runnable)); | ||
|
|
||
| } | ||
|
|
||
| @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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should add an optional timeout configuration for the Aync mutator to pass when waiting on the future? I'm not sure how you'd pick a good timeout value as operations could be long running so this might be the best option.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
|
||
| } catch (InterruptedException | ExecutionException e) { | ||
| throw new IllegalStateException(e); | ||
| } | ||
| } | ||
|
|
||
| // Spin up processing of the mutations submitted so far in a background thread. Must copy the | ||
| // reference for the background thread because a new one is about to be created. | ||
| var bufferingMutatorRef = bufferingMutator; | ||
| backgroundProcessing = executor.submit(() -> { | ||
| var result = bufferingMutatorRef.process(); | ||
| bufferingMutatorRef.close(); | ||
| return result; | ||
| }); | ||
|
|
||
| bufferingMutator = new ConditionalTabletsMutatorImpl(context); | ||
| mutatedTablets = 0; | ||
| } | ||
| mutatedTablets++; | ||
| return bufferingMutator.mutateTablet(extent); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| if (backgroundProcessing != null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to go through and think if there's any case where we could end up calling
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should definitely only be called by a single thread. I added a javadoc comment in 08608df. I also experimented with the |
||
| // a previous batch of mutations was submitted for processing so wait on it. | ||
| try { | ||
| backgroundProcessing.get().forEach(resultsConsumer); | ||
| } catch (InterruptedException | ExecutionException e) { | ||
| throw new IllegalStateException(e); | ||
| } | ||
| } | ||
| // process anything not processed so far | ||
| bufferingMutator.process().forEach(resultsConsumer); | ||
| bufferingMutator.close(); | ||
| executor.shutdownNow(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.