yangzhg commented on a change in pull request #6247:
URL: https://github.com/apache/incubator-doris/pull/6247#discussion_r670908281



##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/common/proc/TrashProcNode.java
##########
@@ -0,0 +1,110 @@
+// 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.doris.common.proc;
+
+import org.apache.doris.thrift.BackendService;
+import org.apache.doris.thrift.TNetworkAddress;
+import org.apache.doris.system.Backend;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.common.Pair;
+import org.apache.doris.common.ClientPool;
+import org.apache.doris.common.util.DebugUtil;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/*
+ * Show trash
+ * SHOW PROC /trash/
+ */
+public class TrashProcNode implements ProcNodeInterface {
+    private static final Logger LOG = 
LogManager.getLogger(TrashProcNode.class);
+
+    public static final ImmutableList<String> TITLE_NAMES = new 
ImmutableList.Builder<String>()
+    .add("BackendId").add("Backend").add("TrashUsedCapacity").build();
+    
+    private List<Backend> backends = Lists.newArrayList();
+    
+    public TrashProcNode() {
+        ImmutableMap<Long, Backend> backendsInfo = 
Catalog.getCurrentSystemInfo().getIdToBackend();
+        for (Backend backend : backendsInfo.values()) {
+            this.backends.add(backend);
+        }
+    }
+    
+    @Override
+    public ProcResult fetchResult() {
+        BaseProcResult result = new BaseProcResult();
+        result.setNames(TITLE_NAMES);
+        
+        List<List<String>> infos = Lists.newArrayList();
+
+        getTrashInfo(backends, infos);
+
+        for (List<String> info : infos) {
+            result.addRow(info);
+        }
+
+        return result;
+    }
+
+    public static void getTrashInfo(List<Backend> backends, List<List<String>> 
infos) {
+        
+        for (Backend backend : backends) {
+            BackendService.Client client = null;
+            TNetworkAddress address = null;
+            Long trashUsedCapacityB = null;
+            boolean ok = false;
+            try {
+                long start = System.currentTimeMillis();
+                address = new TNetworkAddress(backend.getHost(), 
backend.getBePort());
+                client = ClientPool.backendPool.borrowObject(address);
+                trashUsedCapacityB = client.getTrashUsedCapacity();
+                ok = true;
+            } catch (Exception e) {
+                LOG.warn("task exec error. backend[{}]", backend.getId(), e);
+            } finally {
+                if (ok) {
+                    ClientPool.backendPool.returnObject(address, client);
+                } else {
+                    ClientPool.backendPool.invalidateObject(address, client);
+                }
+            }
+
+            List<String> backendInfo = new ArrayList<String>();
+            backendInfo.add(String.valueOf(backend.getId()));
+            backendInfo.add(backend.getHost() + ":" + 
String.valueOf(backend.getHeartbeatPort()));
+            if (trashUsedCapacityB != null) {
+                Pair<Double, String> trashUsedCapacity = 
DebugUtil.getByteUint(trashUsedCapacityB);
+                
backendInfo.add(DebugUtil.DECIMAL_FORMAT_SCALE_3.format(trashUsedCapacity.first)
 + " " + trashUsedCapacity.second);
+            } else {
+                backendInfo.add("null");

Review comment:
       not literal `null` 




-- 
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: commits-unsubscr...@doris.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to