You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/07/26 03:28:38 UTC

[GitHub] [ozone] JacksonYao287 commented on a change in pull request #2420: HDDS-5360. DN failed to process all delete block commands in one heartbeat interval

JacksonYao287 commented on a change in pull request #2420:
URL: https://github.com/apache/ozone/pull/2420#discussion_r676264678



##########
File path: hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/DeleteBlocksCommandHandler.java
##########
@@ -76,34 +84,179 @@
   private final ConfigurationSource conf;
   private int invocationCount;
   private long totalTime;
-  private boolean cmdExecuted;
+  private final ExecutorService executor;
+  private final LinkedBlockingQueue<DeleteCmdInfo> deleteCommandQueues;
+  private final Daemon handlerThread;
 
   public DeleteBlocksCommandHandler(ContainerSet cset,
-      ConfigurationSource conf) {
+      ConfigurationSource conf, int threadPoolSize, int queueLimit) {
     this.containerSet = cset;
     this.conf = conf;
+    this.executor = new ThreadPoolExecutor(
+        0, threadPoolSize, 60, TimeUnit.SECONDS,
+        new LinkedBlockingQueue<>(),
+        new ThreadFactoryBuilder().setDaemon(true)
+            .setNameFormat("DeleteBlocksCommandHandlerThread-%d")
+            .build());
+    this.deleteCommandQueues = new LinkedBlockingQueue<>(queueLimit);
+    handlerThread = new Daemon(new DeleteCmdWorker());
+    handlerThread.start();
   }
 
   @Override
   public void handle(SCMCommand command, OzoneContainer container,
       StateContext context, SCMConnectionManager connectionManager) {
-    cmdExecuted = false;
-    long startTime = Time.monotonicNow();
-    ContainerBlocksDeletionACKProto blockDeletionACK = null;
+    if (command.getType() != SCMCommandProto.Type.deleteBlocksCommand) {
+      LOG.warn("Skipping handling command, expected command "
+              + "type {} but found {}",
+          SCMCommandProto.Type.deleteBlocksCommand, command.getType());
+      return;
+    }
+
     try {
-      if (command.getType() != SCMCommandProto.Type.deleteBlocksCommand) {
-        LOG.warn("Skipping handling command, expected command "
-                + "type {} but found {}",
-            SCMCommandProto.Type.deleteBlocksCommand, command.getType());
-        return;
+      DeleteCmdInfo cmd = new DeleteCmdInfo((DeleteBlocksCommand) command,
+          container, context, connectionManager);
+      deleteCommandQueues.add(cmd);
+    } catch (IllegalStateException e) {
+      LOG.warn("Command is discarded because of the command queue is full");
+      return;
+    }
+  }
+
+  /**
+   * A delete command info.
+   */
+  public static final class DeleteCmdInfo {
+    private DeleteBlocksCommand cmd;
+    private StateContext context;
+    private OzoneContainer container;
+    private SCMConnectionManager connectionManager;
+
+    public DeleteCmdInfo(DeleteBlocksCommand command, OzoneContainer container,
+        StateContext context, SCMConnectionManager connectionManager) {
+      this.cmd = command;
+      this.context = context;
+      this.container = container;
+      this.connectionManager = connectionManager;
+    }
+    public DeleteBlocksCommand getCmd() {
+      return this.cmd;
+    }
+    public StateContext getContext() {
+      return this.context;
+    }
+    public OzoneContainer getContainer() {
+      return this.container;
+    }
+    public SCMConnectionManager getConnectionManager() {
+      return this.connectionManager;
+    }
+  }
+
+  /**
+   * Process delete commands.
+   */
+  public final class DeleteCmdWorker implements Runnable {
+
+    @Override
+    public void run() {
+      while (true) {
+        while (!deleteCommandQueues.isEmpty()) {
+          DeleteCmdInfo cmd = deleteCommandQueues.poll();
+          try {
+            processCmd(cmd.getCmd(), cmd.getContainer(), cmd.getContext(),

Review comment:
       thanks for the work ! NIT, can we use `DeleteCmdInfo` as the only one parameter of `processCmd`




-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org