adoroszlai commented on a change in pull request #480: HDDS-2927. Cache
EndPoint tasks instead of creating them all the time in RunningDatanodeState
URL: https://github.com/apache/hadoop-ozone/pull/480#discussion_r370226537
##########
File path:
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/states/datanode/RunningDatanodeState.java
##########
@@ -49,14 +52,62 @@
private final SCMConnectionManager connectionManager;
private final Configuration conf;
private final StateContext context;
- private CompletionService<EndpointStateMachine.EndPointStates> ecs;
+ private CompletionService<EndPointStates> ecs;
+ /** Cache the end point task per end point per end point state. */
+ private Map<String, Map<EndPointStates,
+ Callable<EndPointStates>>> endpointTasks;
public RunningDatanodeState(Configuration conf,
SCMConnectionManager connectionManager,
StateContext context) {
this.connectionManager = connectionManager;
this.conf = conf;
this.context = context;
+ initEndPointTask();
+ }
+
+ /**
+ * Initialize end point tasks corresponding to each end point,
+ * each end point state.
+ */
+ private void initEndPointTask() {
+ endpointTasks = new HashMap<String, Map<EndPointStates,
+ Callable<EndPointStates>>>();
+ for (EndpointStateMachine endpoint : connectionManager.getValues()) {
+ Map<EndPointStates, Callable<EndPointStates>> endpointTaskForState
+ = new HashMap<EndPointStates, Callable<EndPointStates>>();
+
+ for (EndPointStates state : EndPointStates.values()) {
+ Callable<EndPointStates> endPointTask = null;
+ switch (endpoint.getState()) {
+ case GETVERSION:
+ endPointTask = new VersionEndpointTask(endpoint, conf,
+ context.getParent().getContainer());
+ break;
+ case REGISTER:
+ endPointTask = RegisterEndpointTask.newBuilder()
+ .setConfig(conf)
+ .setEndpointStateMachine(endpoint)
+ .setContext(context)
+ .setDatanodeDetails(context.getParent().getDatanodeDetails())
+ .setOzoneContainer(context.getParent().getContainer())
+ .build();
+ break;
+ case HEARTBEAT:
+ endPointTask = HeartbeatEndpointTask.newBuilder()
+ .setConfig(conf)
+ .setEndpointStateMachine(endpoint)
+ .setDatanodeDetails(context.getParent().getDatanodeDetails())
+ .setContext(context)
+ .build();
+ break;
+ case SHUTDOWN:
+ break;
+ }
+ endpointTaskForState.put(state, endPointTask);
Review comment:
Nit: no need to store `null` task for shutdown state.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]