-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Allow forking task runners to terminate and pickup their tasks. #1521
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
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets 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 | ||
| * | ||
| * http://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 io.druid.server.http; | ||
|
|
||
| import com.google.common.util.concurrent.ListeningScheduledExecutorService; | ||
| import com.google.common.util.concurrent.MoreExecutors; | ||
| import com.google.inject.Inject; | ||
| import com.metamx.common.lifecycle.Lifecycle; | ||
| import com.metamx.common.logger.Logger; | ||
|
|
||
| import javax.ws.rs.DELETE; | ||
| import javax.ws.rs.Path; | ||
| import javax.ws.rs.core.Response; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| @Path("/shutdown") | ||
| public class ShutdownResource | ||
| { | ||
| private final Lifecycle lifecycle; | ||
| @Inject | ||
| public ShutdownResource( | ||
| Lifecycle lifecycle | ||
| ){ | ||
| this.lifecycle = lifecycle; | ||
| } | ||
| private static final Logger log = new Logger(ShutdownResource.class); | ||
| private final ListeningScheduledExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1)); | ||
|
|
||
| @DELETE | ||
|
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. DELETE seems weird here. You're not really "deleting" the /shutdown resource. I think sticking with good ol' POST is fine |
||
| public Response shutDown() | ||
| { | ||
| log.info("Received shutdown request"); | ||
|
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. did you mean to call lifecycle.shutdown() somewhere here or register it as a shutdown hook. I don't see lifecycle being used in this class.
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. I did at one point due to how peons were shutting down, but now it is all done through shutdown hooks and this will be removed
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. ok, yeah, just saw the other PR with the update to CliPeon . |
||
| executorService.schedule( | ||
| new Runnable() | ||
| { | ||
| @Override | ||
| public void run() | ||
| { | ||
| System.exit(0); | ||
| } | ||
| }, | ||
| 1, | ||
| TimeUnit.SECONDS | ||
| ); | ||
| executorService.shutdown(); | ||
| return Response.status(Response.Status.ACCEPTED).build(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an easy way to make sure all the tasks are dead when killing a middleManager would be useful. Sometimes you really do want it to die. So IMO removing this means we should have some other way. Maybe the middleManager should heartbeat to its tasks, and they should exit if they haven't got a heartbeat in a certain amount of time? Something long enough to cover any reasonable update + restart time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gianm How would you feel about forcing a node restart if you wanted to make absolutely sure all peons were dead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like, restarting the actual OS? I think it's best to have some other way to do it, since I think people expect apps to be able to be lifecycled independently of the host OS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be ok to make it a config in runtime.props, also a flag while starting up the middlemanager indicating if we want to start with a clean state by killing any left over tasks from previous run can be useful.