forked from voldemort/voldemort
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addressed most feedback from reviews by refactoring:
- Made ResourceRequest a first class entity rather than a nested interface - Refactored TimeoutConfig to tease apart an OpTimeMap which may be more generally useful. - Renamed slow storage configs in Voldemort config with to make their testing nature more clear. - Dropped OperationDelays object from SlowStorage in favor of OpTimeMap
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package voldemort.utils; | ||
|
||
import java.util.HashMap; | ||
|
||
import voldemort.common.VoldemortOpCode; | ||
|
||
/** | ||
* Encapsulates time to operation mapping | ||
* | ||
*/ | ||
public class OpTimeMap { | ||
|
||
private HashMap<Byte, Long> timeMap; | ||
|
||
public OpTimeMap(long time) { | ||
this(time, time, time, time, time); | ||
} | ||
|
||
public OpTimeMap(long getTime, | ||
long putTime, | ||
long deleteTime, | ||
long getAllTime, | ||
long getVersionsTime) { | ||
timeMap = new HashMap<Byte, Long>(); | ||
timeMap.put(VoldemortOpCode.GET_OP_CODE, getTime); | ||
timeMap.put(VoldemortOpCode.PUT_OP_CODE, putTime); | ||
timeMap.put(VoldemortOpCode.DELETE_OP_CODE, deleteTime); | ||
timeMap.put(VoldemortOpCode.GET_ALL_OP_CODE, getAllTime); | ||
timeMap.put(VoldemortOpCode.GET_VERSION_OP_CODE, getVersionsTime); | ||
} | ||
|
||
public long getOpTime(Byte opCode) { | ||
assert timeMap.containsKey(opCode); | ||
return timeMap.get(opCode); | ||
} | ||
|
||
public void setOpTime(Byte opCode, long time) { | ||
timeMap.put(opCode, time); | ||
} | ||
} |
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,35 @@ | ||
package voldemort.utils.pool; | ||
|
||
/** | ||
* Interface for asynchronous requests for resources. Exactly one of | ||
* useResource, handleTimeout, or handleException expected to be invoked within | ||
* deadline specified by getDeadlineNs. | ||
*/ | ||
public interface ResourceRequest<V> { | ||
|
||
/** | ||
* To be invoked with resource to use. | ||
* | ||
* @param resource. resource should not be null. | ||
*/ | ||
void useResource(V resource); | ||
|
||
/** | ||
* Invoked sometime after deadline. | ||
*/ | ||
void handleTimeout(); | ||
|
||
/** | ||
* Invoked upon exception trying to process resource request. | ||
* | ||
* @param e | ||
*/ | ||
void handleException(Exception e); | ||
|
||
/** | ||
* | ||
* @return Deadline (in nanoseconds), after which handleTimeout() should be | ||
* invoked. | ||
*/ | ||
long getDeadlineNs(); | ||
} |