ctubbsii commented on code in PR #4116:
URL: https://github.com/apache/accumulo/pull/4116#discussion_r1436734510


##########
server/tserver/src/main/java/org/apache/accumulo/tserver/log/CreateEmptyWal.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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
+ *
+ *   https://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.accumulo.tserver.log;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.tserver.log.DfsLogger.LOG_FILE_HEADER_V4;
+import static org.apache.accumulo.tserver.logger.LogEvents.OPEN;
+
+import java.io.DataOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.NoFileEncrypter;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.accumulo.tserver.logger.LogFileValue;
+
+import com.beust.jcommander.IParameterValidator;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.ParameterException;
+import com.google.auto.service.AutoService;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@AutoService(KeywordExecutable.class)
+public class CreateEmptyWal implements KeywordExecutable {
+  private static final LogFileValue EMPTY = new LogFileValue();
+
+  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
+      justification = "file output path provided by an admin")
+  // public to allow jcommander access
+  public static class DirValidator implements IParameterValidator {
+    @Override
+    public void validate(String name, String value) throws ParameterException {
+      Path path = Paths.get(value);
+      if (!Files.exists(path)) {
+        throw new ParameterException("Directory " + path.toAbsolutePath() + " 
does not exist");
+      }
+      if (!Files.isDirectory(path)) {
+        throw new ParameterException(path.toAbsolutePath() + " is not a 
directory");
+      }
+    }
+  }
+
+  static class Opts extends Help {
+    @Parameter(names = {"-d", "--dir"},
+        description = " <dir> the output directory, output will be 
[dir]/empty.wal",
+        required = true, validateWith = DirValidator.class)
+    String dirName;
+  }
+
+  @Override
+  public String keyword() {
+    return "create-empty-wal";

Review Comment:
   This could be a "--walog" option on the existing "create-empty" utility 
instead of a separate utility. I'm just thinking, what if we later add a 
"create empty intermediate WAL" utility. Seems like creating an empty file, of 
any type, could all be part of the same utility.



##########
server/tserver/src/main/java/org/apache/accumulo/tserver/log/CreateEmptyWal.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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
+ *
+ *   https://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.accumulo.tserver.log;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.tserver.log.DfsLogger.LOG_FILE_HEADER_V4;
+import static org.apache.accumulo.tserver.logger.LogEvents.OPEN;
+
+import java.io.DataOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.NoFileEncrypter;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.accumulo.tserver.logger.LogFileValue;
+
+import com.beust.jcommander.IParameterValidator;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.ParameterException;
+import com.google.auto.service.AutoService;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@AutoService(KeywordExecutable.class)
+public class CreateEmptyWal implements KeywordExecutable {
+  private static final LogFileValue EMPTY = new LogFileValue();
+
+  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
+      justification = "file output path provided by an admin")
+  // public to allow jcommander access
+  public static class DirValidator implements IParameterValidator {
+    @Override
+    public void validate(String name, String value) throws ParameterException {
+      Path path = Paths.get(value);
+      if (!Files.exists(path)) {
+        throw new ParameterException("Directory " + path.toAbsolutePath() + " 
does not exist");
+      }
+      if (!Files.isDirectory(path)) {
+        throw new ParameterException(path.toAbsolutePath() + " is not a 
directory");
+      }
+    }
+  }
+
+  static class Opts extends Help {
+    @Parameter(names = {"-d", "--dir"},
+        description = " <dir> the output directory, output will be 
[dir]/empty.wal",
+        required = true, validateWith = DirValidator.class)
+    String dirName;
+  }

Review Comment:
   Rather than specify a directory and hard-code the file name, why not just 
allow the user to specify the file specifically?
   
   Also, I'm not sure we need JCommander here at all... we should certainly 
fail if the specified output file exists already, but that's trivially done by 
passing `CREATE_NEW` option when the data stream is opened. We don't need all 
the complexity for validation, when the built-in behavior with simpler code 
already gets us the validation checks when we specify the output file.



##########
server/tserver/src/main/java/org/apache/accumulo/tserver/log/CreateEmptyWal.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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
+ *
+ *   https://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.accumulo.tserver.log;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.tserver.log.DfsLogger.LOG_FILE_HEADER_V4;
+import static org.apache.accumulo.tserver.logger.LogEvents.OPEN;
+
+import java.io.DataOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.NoFileEncrypter;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.accumulo.tserver.logger.LogFileValue;
+
+import com.beust.jcommander.IParameterValidator;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.ParameterException;
+import com.google.auto.service.AutoService;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@AutoService(KeywordExecutable.class)
+public class CreateEmptyWal implements KeywordExecutable {
+  private static final LogFileValue EMPTY = new LogFileValue();
+
+  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
+      justification = "file output path provided by an admin")
+  // public to allow jcommander access
+  public static class DirValidator implements IParameterValidator {
+    @Override
+    public void validate(String name, String value) throws ParameterException {
+      Path path = Paths.get(value);
+      if (!Files.exists(path)) {
+        throw new ParameterException("Directory " + path.toAbsolutePath() + " 
does not exist");
+      }
+      if (!Files.isDirectory(path)) {
+        throw new ParameterException(path.toAbsolutePath() + " is not a 
directory");
+      }
+    }
+  }
+
+  static class Opts extends Help {
+    @Parameter(names = {"-d", "--dir"},
+        description = " <dir> the output directory, output will be 
[dir]/empty.wal",
+        required = true, validateWith = DirValidator.class)
+    String dirName;
+  }
+
+  @Override
+  public String keyword() {
+    return "create-empty-wal";
+  }
+
+  @Override
+  public String description() {
+    return "creates an empty wal file in the directory specified";
+  }
+
+  @Override
+  public void execute(String[] args) throws Exception {
+
+    Opts opts = new Opts();
+    opts.parseArgs("accumulo create-empty-wal", args);
+
+    var path = Path.of(opts.dirName + "/empty.wal");
+
+    System.out.println("Output file: " + path.toAbsolutePath());
+
+    try (var out = new DataOutputStream(Files.newOutputStream(path))) {

Review Comment:
   ```suggestion
       try (var out = new DataOutputStream(Files.newOutputStream(path, 
CREATE_NEW))) {
   ```



##########
server/tserver/src/main/java/org/apache/accumulo/tserver/log/CreateEmptyWal.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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
+ *
+ *   https://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.accumulo.tserver.log;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.tserver.log.DfsLogger.LOG_FILE_HEADER_V4;
+import static org.apache.accumulo.tserver.logger.LogEvents.OPEN;
+
+import java.io.DataOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.NoFileEncrypter;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.accumulo.tserver.logger.LogFileValue;
+
+import com.beust.jcommander.IParameterValidator;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.ParameterException;
+import com.google.auto.service.AutoService;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@AutoService(KeywordExecutable.class)
+public class CreateEmptyWal implements KeywordExecutable {
+  private static final LogFileValue EMPTY = new LogFileValue();
+
+  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
+      justification = "file output path provided by an admin")
+  // public to allow jcommander access
+  public static class DirValidator implements IParameterValidator {
+    @Override
+    public void validate(String name, String value) throws ParameterException {
+      Path path = Paths.get(value);
+      if (!Files.exists(path)) {
+        throw new ParameterException("Directory " + path.toAbsolutePath() + " 
does not exist");
+      }
+      if (!Files.isDirectory(path)) {
+        throw new ParameterException(path.toAbsolutePath() + " is not a 
directory");
+      }
+    }
+  }
+
+  static class Opts extends Help {
+    @Parameter(names = {"-d", "--dir"},
+        description = " <dir> the output directory, output will be 
[dir]/empty.wal",
+        required = true, validateWith = DirValidator.class)
+    String dirName;
+  }
+
+  @Override
+  public String keyword() {
+    return "create-empty-wal";
+  }
+
+  @Override
+  public String description() {
+    return "creates an empty wal file in the directory specified";
+  }
+
+  @Override
+  public void execute(String[] args) throws Exception {
+
+    Opts opts = new Opts();
+    opts.parseArgs("accumulo create-empty-wal", args);
+
+    var path = Path.of(opts.dirName + "/empty.wal");
+
+    System.out.println("Output file: " + path.toAbsolutePath());
+
+    try (var out = new DataOutputStream(Files.newOutputStream(path))) {
+      out.write(LOG_FILE_HEADER_V4.getBytes(UTF_8));
+      byte[] decryptionParams = new 
NoFileEncrypter().getDecryptionParameters();

Review Comment:
   Hard-coding the NoFileEncrypter seems like it could be a bad idea, since its 
implementation is specific to the built-in encryption factory that we provide, 
and not necessarily compatible with something the user has configured. It'd be 
better to defer to the user's configured encryption factory with the site or 
system config than to hard-code this encrypter.



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

Reply via email to