Review Board 1.7.22


Delayed RPC: add ability to set return value immediately at call return

Review Request #1257 - Created Aug. 2, 2011 and updated

Vlad Dogaru
trunk
HBASE-3899
Reviewers
hbase
hbase-git
Some use cases of delayed RPCs need the ability to delay the call until a further moment, but set the return value immediately.  For example, if a handler calls a function returning void that might delay (a sync), the result does not depend on the function's result (since it has none).  This patch enables that by making the following changes:

* change the Delayable interface so that startDelay specifies whether the return value should be set immediately after call return or at the end of the delay;
* make HBaseServer work according to the new semantics;
* add a unit test.  We now have testDelayedRpc{Immediate,Delayed}Response, testing that immediate and delayed return values work.

Please review, thanks!
Since the code is not used yet, it does not affect other areas of the codebase.  Running unit tests as we speak.

Diff revision 2

This is not the most recent revision of the diff. The latest diff is revision 4. See what's changed.

1 2 3 4
1 2 3 4

  1. src/main/java/org/apache/hadoop/hbase/ipc/Delayable.java: Loading...
  2. src/main/java/org/apache/hadoop/hbase/ipc/HBaseServer.java: Loading...
  3. src/test/java/org/apache/hadoop/hbase/ipc/TestDelayedRpc.java: Loading...
src/main/java/org/apache/hadoop/hbase/ipc/Delayable.java
Revision f2ae31e New Change
[20] 18 lines
[+20]
19
 */
19
 */
20
package org.apache.hadoop.hbase.ipc;
20
package org.apache.hadoop.hbase.ipc;
21

    
   
21

   
22
import java.io.IOException;
22
import java.io.IOException;
23

    
   
23

   
24
import org.apache.hadoop.io.Writable;

   
25

    
   

   
26
/**
24
/**
27
 * A call whose response can be delayed by the server.
25
 * A call whose response can be delayed by the server.
28
 */
26
 */
29
public interface Delayable {
27
public interface Delayable {
30
  /**
28
  /**
31
   * Signal that the call response should be delayed, thus freeing the RPC
29
   * Signal that the call response should be delayed, thus freeing the RPC
32
   * server to handle different requests.
30
   * server to handle different requests.

    
   
31
   *

    
   
32
   * @param delayReturnValue Controls whether the return value of the call

    
   
33
   * should be set when ending the delay or right away.  There are cases when

    
   
34
   * the return value can be set right away, even if the call is delayed.
33
   */
35
   */
34
  public void startDelay();
36
  public void startDelay(boolean delayReturnValue);
35

    
   
37

   
36
  /**
38
  /**
37
   * @return is the call delayed?
39
   * @return is the call delayed?
38
   */
40
   */
39
  public boolean isDelayed();
41
  public boolean isDelayed();
40

    
   
42

   
41
  /**
43
  /**
42
   * Signal that the response to the call is ready and the RPC server is now
44
   * @return is the return value delayed?
43
   * allowed to send the response.
45
   */
44
   * @param result The result to return to the caller.
46
  public boolean isReturnValueDelayed();

    
   
47

   

    
   
48
  /**

    
   
49
   * Signal that the  RPC server is now allowed to send the response.

    
   
50
   * @param result The value to return to the caller.  If the corresponding

    
   
51
   * {@link #delayResponse(boolean)} specified that the return value should

    
   
52
   * not be delayed, this parameter must be null.
45
   * @throws IOException
53
   * @throws IOException
46
   */
54
   */
47
  public void endDelay(Object result) throws IOException;
55
  public void endDelay(Object result) throws IOException;
48
}
56
}
src/main/java/org/apache/hadoop/hbase/ipc/HBaseServer.java
Revision 2f7dfae New Change
 
src/test/java/org/apache/hadoop/hbase/ipc/TestDelayedRpc.java
Revision 60777cf New Change
 
  1. src/main/java/org/apache/hadoop/hbase/ipc/Delayable.java: Loading...
  2. src/main/java/org/apache/hadoop/hbase/ipc/HBaseServer.java: Loading...
  3. src/test/java/org/apache/hadoop/hbase/ipc/TestDelayedRpc.java: Loading...