You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2021/08/27 04:49:08 UTC

[GitHub] [bookkeeper] eolivelli commented on a change in pull request #2768: Add metrics and internal command for AutoRecovery

eolivelli commented on a change in pull request #2768:
URL: https://github.com/apache/bookkeeper/pull/2768#discussion_r697149707



##########
File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/QueryAutoRecoveryStatusCommand.java
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.bookkeeper.tools.cli.commands.autorecovery;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.bookkeeper.meta.MetadataDrivers.runFunctionWithLedgerManagerFactory;
+import static org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager.getBasePath;
+import static org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager.getUrLedgerLockZnode;
+import com.beust.jcommander.Parameter;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.protobuf.TextFormat;
+import java.net.URI;
+import java.util.LinkedList;
+import java.util.List;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.meta.LedgerManager;
+import org.apache.bookkeeper.meta.zk.ZKMetadataDriverBase;
+import org.apache.bookkeeper.proto.DataFormats;
+import org.apache.bookkeeper.tools.cli.helpers.BookieCommand;
+import org.apache.bookkeeper.tools.framework.CliFlags;
+import org.apache.bookkeeper.tools.framework.CliSpec;
+import org.apache.bookkeeper.util.BookKeeperConstants;
+import org.apache.bookkeeper.zookeeper.ZooKeeperClient;
+import org.apache.zookeeper.ZooKeeper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Command to Query current auto recovery status.
+ */
+public class QueryAutoRecoveryStatusCommand
+        extends BookieCommand<QueryAutoRecoveryStatusCommand.QFlags> {
+    static final Logger LOG = LoggerFactory.
+            getLogger(QueryAutoRecoveryStatusCommand.class);
+    private static final String NAME = "queryautorecoverystatus";
+    private static final String DESC = "Query autorecovery status.";
+
+    public QueryAutoRecoveryStatusCommand() {
+        super(CliSpec.<QFlags>newBuilder()
+                .withName(NAME)
+                .withDescription(DESC)
+                .withFlags(new QFlags())
+                .build());
+    }
+
+    @Override
+    public boolean apply(ServerConfiguration conf, QFlags cmdFlags) {
+        try {
+            return handler(conf, cmdFlags);
+        } catch (Exception e) {
+            throw new UncheckedExecutionException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Flags for list under replicated command.
+     */
+    @Accessors(fluent = true)
+    @Setter
+    public static class QFlags extends CliFlags{
+        @Parameter(names =  {"-v", "--verbose"}, description = "list recovering detailed ledger info")
+        private Boolean verbose = false;
+    }
+
+    private static class LedgerRecoverInfo {
+        Long ledgerId;
+        String bookieId;
+        LedgerRecoverInfo(Long ledgerId, String bookieId) {
+            this.ledgerId = ledgerId;
+            this.bookieId = bookieId;
+        }
+    }
+
+
+    /*
+    Print Message format is like this:
+
+     CurrentRecoverLedgerInfo:
+        LedgerId:   BookieId:     LedgerSize:(detail)
+        LedgerId:   BookieId:     LedgerSize:(detail)
+     */
+    public boolean handler(ServerConfiguration conf, QFlags flag) throws Exception {
+        ZooKeeper zk = null;
+        try {
+            String metadataServiceUri = conf.getMetadataServiceUri();
+            String zkServers = ZKMetadataDriverBase.getZKServersFromServiceUri(URI.create(metadataServiceUri));
+            zk = ZooKeeperClient.newBuilder()

Review comment:
       Do we miss some API in the MetadataDriver module to be able to do this without explicitly using Zookeeper?
   
   If we refer directly to zk it won't be possible to use this command with ETCD or other Metadata drivers




-- 
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@bookkeeper.apache.org

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