-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[WIP] segment management using HTTP Endpoints #2368
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1c4072d
Abstract out LoadQueuePeon to make it extensible
nishantmonu51 26c217b
Separate out ZKCoordination and SegmentManager
nishantmonu51 8819adc
Add Http Endpoints for requests processing and pending request polling
nishantmonu51 1b55a8a
Http Load Queue Peon initial imply
nishantmonu51 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
515 changes: 515 additions & 0 deletions
515
server/src/main/java/io/druid/server/coordination/SegmentManager.java
Large diffs are not rendered by default.
Oops, something went wrong.
404 changes: 5 additions & 399 deletions
404
server/src/main/java/io/druid/server/coordination/ZkCoordinator.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
server/src/main/java/io/druid/server/coordinator/HttpLoadQueuePeon.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| /* | ||
| * 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.coordinator; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.google.common.base.Charsets; | ||
| import com.google.common.base.Predicate; | ||
| import com.google.common.collect.Maps; | ||
| import com.metamx.common.ISE; | ||
| import com.metamx.emitter.EmittingLogger; | ||
| import com.metamx.http.client.HttpClient; | ||
| import com.metamx.http.client.Request; | ||
| import com.metamx.http.client.response.StatusResponseHandler; | ||
| import com.metamx.http.client.response.StatusResponseHolder; | ||
| import io.druid.server.coordination.DataSegmentChangeRequest; | ||
| import io.druid.server.coordination.SegmentChangeRequestNoop; | ||
| import org.apache.curator.framework.CuratorFramework; | ||
| import org.apache.curator.framework.api.CuratorWatcher; | ||
| import org.apache.curator.utils.ZKPaths; | ||
| import org.apache.zookeeper.CreateMode; | ||
| import org.apache.zookeeper.WatchedEvent; | ||
| import org.apache.zookeeper.data.Stat; | ||
| import org.jboss.netty.handler.codec.http.HttpMethod; | ||
| import org.jboss.netty.handler.codec.http.HttpResponseStatus; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import javax.ws.rs.core.MediaType; | ||
| import java.net.MalformedURLException; | ||
| import java.net.URL; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public class HttpLoadQueuePeon extends LoadQueuePeon | ||
| { | ||
| private static final EmittingLogger log = new EmittingLogger(HttpLoadQueuePeon.class); | ||
|
|
||
| private final HttpClient httpClient; | ||
| private final String baseURL; | ||
| private final ObjectMapper jsonMapper; | ||
| private final ScheduledExecutorService processingExecutor; | ||
| private final DruidCoordinatorConfig config; | ||
| private final StatusResponseHandler responseHandler; | ||
| private final Map<DataSegmentChangeRequest, Runnable> pendingRequests = Maps.newConcurrentMap(); | ||
|
|
||
| HttpLoadQueuePeon( | ||
| final HttpClient httpClient, | ||
| String baseURL, | ||
| ObjectMapper jsonMapper, | ||
| ScheduledExecutorService processingExecutor, | ||
| ExecutorService callbackExecutor, | ||
| DruidCoordinatorConfig config | ||
| ) | ||
| { | ||
| super(baseURL, processingExecutor, callbackExecutor); | ||
| this.httpClient = httpClient; | ||
| this.baseURL = baseURL; | ||
| this.jsonMapper = jsonMapper; | ||
| this.processingExecutor = processingExecutor; | ||
| this.config = config; | ||
| this.responseHandler = new StatusResponseHandler(Charsets.UTF_8); | ||
| processingExecutor.scheduleAtFixedRate( | ||
| new Runnable() | ||
| { | ||
| @Override | ||
| public void run() | ||
| { | ||
| try { | ||
| final List<DataSegmentChangeRequest> remotePendingRequests = getRemotePendingRequests(); | ||
| Map<DataSegmentChangeRequest, Runnable> completedRequests = Maps.newHashMap(Maps.filterKeys( | ||
| pendingRequests, | ||
| new Predicate<DataSegmentChangeRequest>() | ||
| { | ||
| @Override | ||
| public boolean apply( | ||
| DataSegmentChangeRequest request | ||
| ) | ||
| { | ||
| return !remotePendingRequests.contains(request); | ||
| } | ||
| } | ||
| )); | ||
| for (Map.Entry<DataSegmentChangeRequest, Runnable> completedRequest : completedRequests.entrySet()) { | ||
| completedRequest.getValue().run(); | ||
| pendingRequests.remove(completedRequest.getKey()); | ||
| } | ||
| } | ||
| catch (Exception e) { | ||
| log.error("Exception while fetching remote requests, Will retry again..", e); | ||
| } | ||
| } | ||
| }, | ||
| config.getLoadStatusPollDuration().getMillis(), | ||
| config.getLoadStatusPollDuration().getMillis(), | ||
| TimeUnit.MILLISECONDS | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| private List<DataSegmentChangeRequest> getRemotePendingRequests() throws Exception | ||
| { | ||
| StatusResponseHolder response = httpClient.go( | ||
| new Request( | ||
| HttpMethod.GET, new URL(String.format("%s/pendingRequests", baseURL)) | ||
| ), | ||
| responseHandler | ||
| ).get(); | ||
| if (!response.getStatus().equals(HttpResponseStatus.OK)) { | ||
| throw new ISE( | ||
| "Error while fetching pending Requests on url[%s] status[%s] content[%s]", | ||
| baseURL, | ||
| response.getStatus(), | ||
| response.getContent() | ||
| ); | ||
| } | ||
| return jsonMapper.readValue( | ||
| response.getContent(), | ||
| new TypeReference<List<DataSegmentChangeRequest>>() | ||
| { | ||
| } | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| void processHolder(final SegmentHolder holder) | ||
| { | ||
| try { | ||
| StatusResponseHolder response = httpClient.go( | ||
| new Request( | ||
| HttpMethod.POST, new URL(String.format("%s/processRequest", baseURL)) | ||
| ).setContent( | ||
| MediaType.APPLICATION_JSON, | ||
| jsonMapper.writeValueAsBytes(holder.getChangeRequest()) | ||
| ), | ||
| responseHandler | ||
| ).get(); | ||
|
|
||
| if (!response.getStatus().equals(HttpResponseStatus.OK)) { | ||
| throw new ISE( | ||
| "Error while processing SegmentChangeRequest on url[%s] status[%s] content[%s]", | ||
| baseURL, | ||
| response.getStatus(), | ||
| response.getContent() | ||
| ); | ||
| } | ||
| // Add to pending Requests will be called when the request completes. | ||
| pendingRequests.put(holder.getChangeRequest(), new Runnable() | ||
| { | ||
| @Override | ||
| public void run() | ||
| { | ||
| actionCompleted(holder); | ||
| } | ||
| }); | ||
|
|
||
| // Schedule timeout check. | ||
| processingExecutor.schedule( | ||
| new Runnable() | ||
| { | ||
| @Override | ||
| public void run() | ||
| { | ||
| if (pendingRequests.remove(holder.getChangeRequest()) != null) { | ||
| failAssign(holder, new ISE("%s was never processed! Failing this operation!", holder)); | ||
| } | ||
| } | ||
| }, | ||
| config.getLoadTimeoutDelay().getMillis(), | ||
| TimeUnit.MILLISECONDS | ||
| ); | ||
|
|
||
|
|
||
| } | ||
| catch (Exception e) { | ||
| failAssign(holder, e); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
63 changes: 63 additions & 0 deletions
63
server/src/main/java/io/druid/server/coordinator/HttpLoadQueueTaskMaster.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * 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.coordinator; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.google.inject.Inject; | ||
| import com.metamx.http.client.HttpClient; | ||
| import io.druid.client.ImmutableDruidServer; | ||
| import org.apache.curator.framework.CuratorFramework; | ||
|
|
||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
|
|
||
| /** | ||
| * Provides HttpLoadQueuePeons | ||
| */ | ||
| public class HttpLoadQueueTaskMaster implements LoadQueueTaskMaster | ||
| { | ||
| private final HttpClient httpClient; | ||
| private final ObjectMapper jsonMapper; | ||
| private final ScheduledExecutorService peonExec; | ||
| private final ExecutorService callbackExec; | ||
| private final DruidCoordinatorConfig config; | ||
|
|
||
| @Inject | ||
| public HttpLoadQueueTaskMaster( | ||
| HttpClient httpClient, | ||
| ObjectMapper jsonMapper, | ||
| ScheduledExecutorService peonExec, | ||
| ExecutorService callbackExec, | ||
| DruidCoordinatorConfig config | ||
| ) | ||
| { | ||
| this.httpClient = httpClient; | ||
| this.jsonMapper = jsonMapper; | ||
| this.peonExec = peonExec; | ||
| this.callbackExec = callbackExec; | ||
| this.config = config; | ||
| } | ||
|
|
||
| public LoadQueuePeon giveMePeon(ImmutableDruidServer druidServer) | ||
| { | ||
| String baseUrl = String.format("http://%s/druid/historical/v1", druidServer.getHost()); | ||
|
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. can you just build url directly? |
||
| return new HttpLoadQueuePeon(httpClient,baseUrl, jsonMapper, peonExec, callbackExec, config); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
parameters should be flipped i think