-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
HBASE-26551 Add FastPath feature to HBase RWQueueRpcExecutor #3929
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c224a92
HBASE-26551 Add FastPath feature to HBase RWQueueRpcExecutor
YutSean a076850
Extraced RpcHandler implementation
YutSean d75aa45
Refined code style
YutSean ef98168
Refined the code style in FPBQ
YutSean 881d405
Refine code style in FPRWQExecutor
YutSean a7dbbda
Refined the variable name in dispatch function
YutSean 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
This file contains 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
72 changes: 72 additions & 0 deletions
72
hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/FastPathRWQueueRpcExecutor.java
This file contains 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,72 @@ | ||
/** | ||
|
||
* 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 | ||
* | ||
* 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 org.apache.hadoop.hbase.ipc; | ||
|
||
import java.util.Deque; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.ConcurrentLinkedDeque; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hbase.Abortable; | ||
import org.apache.hadoop.hbase.HBaseInterfaceAudience; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
import org.apache.yetus.audience.InterfaceStability; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* RPC Executor that extends {@link RWQueueRpcExecutor} with fast-path feature, used in | ||
* {@link FastPathBalancedQueueRpcExecutor}. | ||
*/ | ||
@InterfaceAudience.LimitedPrivate({ HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX}) | ||
@InterfaceStability.Evolving | ||
public class FastPathRWQueueRpcExecutor extends RWQueueRpcExecutor { | ||
private static final Logger LOG = LoggerFactory.getLogger(RWQueueRpcExecutor.class); | ||
|
||
private final Deque<FastPathRpcHandler> readHandlerStack = new ConcurrentLinkedDeque<>(); | ||
private final Deque<FastPathRpcHandler> writeHandlerStack = new ConcurrentLinkedDeque<>(); | ||
private final Deque<FastPathRpcHandler> scanHandlerStack = new ConcurrentLinkedDeque<>(); | ||
|
||
public FastPathRWQueueRpcExecutor(String name, int handlerCount, int maxQueueLength, | ||
PriorityFunction priority, Configuration conf, Abortable abortable) { | ||
super(name, handlerCount, maxQueueLength, priority, conf, abortable); | ||
} | ||
|
||
@Override | ||
protected RpcHandler getHandler(final String name, final double handlerFailureThreshhold, | ||
final int handlerCount, final BlockingQueue<CallRunner> q, | ||
final AtomicInteger activeHandlerCount, final AtomicInteger failedHandlerCount, | ||
final Abortable abortable) { | ||
Deque<FastPathRpcHandler> handlerStack = name.contains("read") ? readHandlerStack : | ||
name.contains("write") ? writeHandlerStack : scanHandlerStack; | ||
return new FastPathRpcHandler(name, handlerFailureThreshhold, handlerCount, q, | ||
activeHandlerCount, failedHandlerCount, abortable, handlerStack); | ||
} | ||
|
||
@Override | ||
public boolean dispatch(final CallRunner callTask) throws InterruptedException { | ||
RpcCall call = callTask.getRpcCall(); | ||
boolean isWriteRequest = isWriteRequest(call.getHeader(), call.getParam()); | ||
boolean shouldDispatchToScanQueue = shouldDispatchToScanQueue(callTask); | ||
FastPathRpcHandler handler = isWriteRequest ? writeHandlerStack.poll() : | ||
shouldDispatchToScanQueue ? scanHandlerStack.poll() : readHandlerStack.poll(); | ||
return handler != null ? handler.loadCallRunner(callTask) : | ||
dispatchTo(isWriteRequest, shouldDispatchToScanQueue, callTask); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/FastPathRpcHandler.java
This file contains 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,76 @@ | ||
/** | ||
* 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 | ||
* | ||
* 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 org.apache.hadoop.hbase.ipc; | ||
|
||
import java.util.Deque; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.Semaphore; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.apache.hadoop.hbase.Abortable; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
|
||
@InterfaceAudience.Private | ||
public class FastPathRpcHandler extends RpcHandler { | ||
// Below are for fast-path support. Push this Handler on to the fastPathHandlerStack Deque | ||
// if an empty queue of CallRunners so we are available for direct handoff when one comes in. | ||
final Deque<FastPathRpcHandler> fastPathHandlerStack; | ||
// Semaphore to coordinate loading of fastpathed loadedTask and our running it. | ||
// UNFAIR synchronization. | ||
private Semaphore semaphore = new Semaphore(0); | ||
// The task we get when fast-pathing. | ||
private CallRunner loadedCallRunner; | ||
|
||
FastPathRpcHandler(String name, double handlerFailureThreshhold, int handlerCount, | ||
BlockingQueue<CallRunner> q, AtomicInteger activeHandlerCount, | ||
AtomicInteger failedHandlerCount, final Abortable abortable, | ||
final Deque<FastPathRpcHandler> fastPathHandlerStack) { | ||
super(name, handlerFailureThreshhold, handlerCount, q, activeHandlerCount, failedHandlerCount, | ||
abortable); | ||
this.fastPathHandlerStack = fastPathHandlerStack; | ||
} | ||
|
||
@Override | ||
protected CallRunner getCallRunner() throws InterruptedException { | ||
// Get a callrunner if one in the Q. | ||
CallRunner cr = this.q.poll(); | ||
if (cr == null) { | ||
// Else, if a fastPathHandlerStack present and no callrunner in Q, register ourselves for | ||
// the fastpath handoff done via fastPathHandlerStack. | ||
if (this.fastPathHandlerStack != null) { | ||
this.fastPathHandlerStack.push(this); | ||
this.semaphore.acquire(); | ||
cr = this.loadedCallRunner; | ||
this.loadedCallRunner = null; | ||
} else { | ||
// No fastpath available. Block until a task comes available. | ||
cr = super.getCallRunner(); | ||
} | ||
} | ||
return cr; | ||
} | ||
|
||
/** | ||
* @param cr Task gotten via fastpath. | ||
* @return True if we successfully loaded our task | ||
*/ | ||
boolean loadCallRunner(final CallRunner cr) { | ||
this.loadedCallRunner = cr; | ||
this.semaphore.release(); | ||
return true; | ||
} | ||
} |
This file contains 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
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.
here it uses
isWriteRequest
, can you rename itisScanRequest
as well? Naming alias.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.
How about change the isWriteRequest to shouldDispatchToWriteQueue. While scan requests can also be handled as read requests when the scan ratio is 0.0.