jojochuang commented on code in PR #5920:
URL: https://github.com/apache/ozone/pull/5920#discussion_r1442274300
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -3186,6 +3192,132 @@ public ServiceInfoEx getServiceInfo() throws
IOException {
return serviceInfo.provide();
}
+ @Override
+ public ListOpenFilesResult listOpenFiles(String path,
+ long maxKeys,
+ String contToken)
+ throws IOException {
+
+// metrics.incListOpenFiles(); // TODO: Do we want a counter for this?
+
+ final UserGroupInformation ugi = getRemoteUser();
+ if (!isAdmin(ugi)) {
+ final OMException omEx = new OMException(
+ "Only Ozone admins are allowed to list open files.",
+ PERMISSION_DENIED);
+ AUDIT.logWriteFailure(buildAuditMessageForFailure(
+ OMAction.LIST_OPEN_FILES, new LinkedHashMap<>(), omEx));
+ throw omEx;
+ }
+
+ final String dbOpenKeyPrefix;
+ final Table<String, OmKeyInfo> openKeyTable;
+ if (path == null || path.isEmpty() || path.equals(OM_KEY_PREFIX)) {
+ // path is root
+ dbOpenKeyPrefix = "";
+ // default to FSO. TODO: Add client option to pass OBS/LEGACY?
+ openKeyTable =
+ metadataManager.getOpenKeyTable(BucketLayout.FILE_SYSTEM_OPTIMIZED);
Review Comment:
I think it depends on whether or not we want to export only keys visible in
the namespace. If so, then this semantics is only useful for FSO. If not,
there could be use cases where it makes sense for legacy/OBS
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/om/ListOpenFilesSubCommand.java:
##########
@@ -0,0 +1,189 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.admin.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.server.JsonUtils;
+import org.apache.hadoop.ozone.om.helpers.ListOpenFilesResult;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OpenKeySession;
+import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
+import picocli.CommandLine;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+/**
+ * Handler of ozone admin om listopenfiles command.
+ */
[email protected](
+ name = "listopenfiles",
+ aliases = {"listopenkeys", "lof", "lok"},
+ description = "Lists open keys in Ozone Manager.",
+ mixinStandardHelpOptions = true,
+ versionProvider = HddsVersionProvider.class
+)
+public class ListOpenFilesSubCommand implements Callable<Void> {
+
+ @CommandLine.ParentCommand
+ private OMAdmin parent;
+
+ @CommandLine.Option(
+ names = {"-id", "--service-id"},
+ description = "Ozone Manager Service ID",
+ required = false
+ )
+ private String omServiceId;
+
+ @CommandLine.Option(
+ names = {"-host", "--service-host"},
+ description = "Ozone Manager Host. If OM HA is enabled, use -id instead.
"
+ + "If insists on using -host with OM HA, this must point directly "
+ + "to the leader OM. "
+ + "This option is required when -id is not provided or "
+ + "when HA is not enabled."
+ )
+ private String omHost;
+
+ @CommandLine.Option(names = { "--json" },
+ defaultValue = "false",
+ description = "Format output as JSON")
+ private boolean json;
+
+ @CommandLine.Option(
+ names = {"-p", "--path"},
+ description = "Show only open files under this path.",
+ defaultValue = "/",
+ hidden = false
+ )
+ private String path;
+
+ @CommandLine.Option(
+ names = {"-n"},
+ description = "Numerical limit of open files/keys to return.",
+ defaultValue = "1000",
+ hidden = false
+ )
+ private long count;
+
+ @CommandLine.Option(
+ names = {"-t", "--token"}, // TODO: Conform to Ozone CLI convention
+ description = "Previous/last file/key path as the continuation token.",
Review Comment:
Add an example?
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java:
##########
@@ -549,6 +551,44 @@ public void testOzoneAdminCmdList() throws
UnsupportedEncodingException {
execute(ozoneAdminShell, args);
}
+ @Test
+ public void testOzoneAdminCmdListOpenFiles()
+ throws IOException, InterruptedException {
+ final String volumeName = "volumelof";
+
+ final String hostPrefix = OZONE_OFS_URI_SCHEME + "://" + omServiceId;
+// final String hostPrefix = OZONE_OFS_URI_SCHEME + "://localhost:9862";
+ OzoneConfiguration clientConf =
+ getClientConfForOFS(hostPrefix, cluster.getConf());
+// getClientConfForOFS(hostPrefix, new OzoneConfiguration());
+ FileSystem fs = FileSystem.get(clientConf);
+
+ String dir1 = hostPrefix + OM_KEY_PREFIX + volumeName + OM_KEY_PREFIX +
+ "buck1" + OM_KEY_PREFIX + "dir1";
+ assertTrue(fs.mkdirs(new Path(dir1)));
+ String key1 = dir1 + OM_KEY_PREFIX + "key1";
+
+ // Create key1
+ try (FSDataOutputStream out = fs.create(new Path(key1))) {
+ out.write(1);
+ // Wait for flush
+// cluster.getOzoneManager().awaitDoubleBufferFlush();
+
+ // Hold the file open, run listopenfiles
+ String[] args = new String[] {"om", "listopenfiles", "-id", omServiceId,
+ "-p", "/volumelof/buck1"};
+ // TODO: Possible to make this work under volume level as well?
+ execute(ozoneAdminShell, args);
Review Comment:
please run listopenfiles again after out.hsync()
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]