Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-04-09 Thread via GitHub


EdColeman merged PR #4116:
URL: https://github.com/apache/accumulo/pull/4116


-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-26 Thread via GitHub


keith-turner commented on code in PR #4116:
URL: https://github.com/apache/accumulo/pull/4116#discussion_r1468071154


##
server/tserver/src/test/java/org/apache/accumulo/tserver/util/CreateEmptyTest.java:
##
@@ -0,0 +1,206 @@
+/*
+ * 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.util;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.tserver.log.DfsLogger.LOG_FILE_HEADER_V4;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.mock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.accumulo.core.conf.ConfigurationCopy;
+import org.apache.accumulo.core.conf.DefaultConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.spi.crypto.CryptoService;
+import org.apache.accumulo.core.spi.crypto.GenericCryptoServiceFactory;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.fs.VolumeManagerImpl;
+import org.apache.accumulo.tserver.logger.LogEvents;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+public class CreateEmptyTest {
+  @TempDir
+  private static File tempDir;
+
+  private ServerContext context;
+
+  @BeforeEach
+  public void init() throws IOException {
+ConfigurationCopy config = new 
ConfigurationCopy(DefaultConfiguration.getInstance());
+config.set(Property.INSTANCE_VOLUMES.getKey(), "file:///");
+
+context = mock(ServerContext.class);
+expect(context.getCryptoFactory()).andReturn(new 
GenericCryptoServiceFactory()).anyTimes();
+expect(context.getConfiguration()).andReturn(config).anyTimes();
+expect(context.getHadoopConf()).andReturn(new Configuration()).anyTimes();
+VolumeManager volumeManager = VolumeManagerImpl.get(config, new 
Configuration());
+expect(context.getVolumeManager()).andReturn(volumeManager).anyTimes();
+replay(context);
+  }
+
+  @AfterEach
+  public void verifyMock() {
+verify(context);
+  }
+
+  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "path 
provided by test")
+  @Test
+  public void exceptionOnFileExistsTest() throws Exception {
+CreateEmpty createEmpty = new CreateEmpty();
+
+String wal1 = genFilename(tempDir.getAbsolutePath() + "/empty", ".wal");
+String rf1 = genFilename(tempDir.getAbsolutePath() + "/empty", ".rf");
+
+// create the file so it exists
+File f = new File(wal1);
+assertTrue(f.createNewFile());
+
+String[] walArgs = {"--type", "WAL", wal1};
+CreateEmpty.Opts walOpts = new CreateEmpty.Opts();
+walOpts.parseArgs("accumulo create-empty", walArgs);
+
+assertThrows(IllegalArgumentException.class,
+() -> createEmpty.createEmptyWal(walOpts, context));
+
+// create the file so it exists
+File f2 = new File(rf1);
+assertTrue(f2.createNewFile());
+
+String[] rfArgs = {"--type", "RF", rf1};
+CreateEmpty.Opts rfOpts = new CreateEmpty.Opts();
+rfOpts.parseArgs("accumulo create-empty", rfArgs);
+assertThrows(IllegalArgumentException.class,
+() -> createEmpty.createEmptyRFile(walOpts, context));
+  }
+
+  @Test
+  

Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-26 Thread via GitHub


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


##
server/tserver/src/test/java/org/apache/accumulo/tserver/util/CreateEmptyTest.java:
##
@@ -0,0 +1,206 @@
+/*
+ * 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.util;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.tserver.log.DfsLogger.LOG_FILE_HEADER_V4;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.mock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.accumulo.core.conf.ConfigurationCopy;
+import org.apache.accumulo.core.conf.DefaultConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.spi.crypto.CryptoService;
+import org.apache.accumulo.core.spi.crypto.GenericCryptoServiceFactory;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.fs.VolumeManagerImpl;
+import org.apache.accumulo.tserver.logger.LogEvents;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+public class CreateEmptyTest {
+  @TempDir
+  private static File tempDir;
+
+  private ServerContext context;
+
+  @BeforeEach
+  public void init() throws IOException {
+ConfigurationCopy config = new 
ConfigurationCopy(DefaultConfiguration.getInstance());
+config.set(Property.INSTANCE_VOLUMES.getKey(), "file:///");
+
+context = mock(ServerContext.class);
+expect(context.getCryptoFactory()).andReturn(new 
GenericCryptoServiceFactory()).anyTimes();
+expect(context.getConfiguration()).andReturn(config).anyTimes();
+expect(context.getHadoopConf()).andReturn(new Configuration()).anyTimes();
+VolumeManager volumeManager = VolumeManagerImpl.get(config, new 
Configuration());
+expect(context.getVolumeManager()).andReturn(volumeManager).anyTimes();
+replay(context);
+  }
+
+  @AfterEach
+  public void verifyMock() {
+verify(context);
+  }
+
+  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "path 
provided by test")
+  @Test
+  public void exceptionOnFileExistsTest() throws Exception {
+CreateEmpty createEmpty = new CreateEmpty();
+
+String wal1 = genFilename(tempDir.getAbsolutePath() + "/empty", ".wal");
+String rf1 = genFilename(tempDir.getAbsolutePath() + "/empty", ".rf");
+
+// create the file so it exists
+File f = new File(wal1);
+assertTrue(f.createNewFile());
+
+String[] walArgs = {"--type", "WAL", wal1};
+CreateEmpty.Opts walOpts = new CreateEmpty.Opts();
+walOpts.parseArgs("accumulo create-empty", walArgs);
+
+assertThrows(IllegalArgumentException.class,
+() -> createEmpty.createEmptyWal(walOpts, context));
+
+// create the file so it exists
+File f2 = new File(rf1);
+assertTrue(f2.createNewFile());
+
+String[] rfArgs = {"--type", "RF", rf1};
+CreateEmpty.Opts rfOpts = new CreateEmpty.Opts();
+rfOpts.parseArgs("accumulo create-empty", rfArgs);
+assertThrows(IllegalArgumentException.class,
+() -> createEmpty.createEmptyRFile(walOpts, context));
+  }
+
+  @Test
+  

Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-26 Thread via GitHub


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


##
server/tserver/src/test/java/org/apache/accumulo/tserver/util/CreateEmptyTest.java:
##
@@ -0,0 +1,206 @@
+/*
+ * 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.util;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.tserver.log.DfsLogger.LOG_FILE_HEADER_V4;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.mock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.accumulo.core.conf.ConfigurationCopy;
+import org.apache.accumulo.core.conf.DefaultConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.spi.crypto.CryptoService;
+import org.apache.accumulo.core.spi.crypto.GenericCryptoServiceFactory;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.fs.VolumeManagerImpl;
+import org.apache.accumulo.tserver.logger.LogEvents;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+public class CreateEmptyTest {
+  @TempDir
+  private static File tempDir;
+
+  private ServerContext context;
+
+  @BeforeEach
+  public void init() throws IOException {
+ConfigurationCopy config = new 
ConfigurationCopy(DefaultConfiguration.getInstance());
+config.set(Property.INSTANCE_VOLUMES.getKey(), "file:///");
+
+context = mock(ServerContext.class);
+expect(context.getCryptoFactory()).andReturn(new 
GenericCryptoServiceFactory()).anyTimes();
+expect(context.getConfiguration()).andReturn(config).anyTimes();
+expect(context.getHadoopConf()).andReturn(new Configuration()).anyTimes();
+VolumeManager volumeManager = VolumeManagerImpl.get(config, new 
Configuration());
+expect(context.getVolumeManager()).andReturn(volumeManager).anyTimes();
+replay(context);
+  }
+
+  @AfterEach
+  public void verifyMock() {
+verify(context);
+  }
+
+  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "path 
provided by test")
+  @Test
+  public void exceptionOnFileExistsTest() throws Exception {
+CreateEmpty createEmpty = new CreateEmpty();
+
+String wal1 = genFilename(tempDir.getAbsolutePath() + "/empty", ".wal");
+String rf1 = genFilename(tempDir.getAbsolutePath() + "/empty", ".rf");
+
+// create the file so it exists
+File f = new File(wal1);
+assertTrue(f.createNewFile());
+
+String[] walArgs = {"--type", "WAL", wal1};
+CreateEmpty.Opts walOpts = new CreateEmpty.Opts();
+walOpts.parseArgs("accumulo create-empty", walArgs);
+
+assertThrows(IllegalArgumentException.class,
+() -> createEmpty.createEmptyWal(walOpts, context));
+
+// create the file so it exists
+File f2 = new File(rf1);
+assertTrue(f2.createNewFile());
+
+String[] rfArgs = {"--type", "RF", rf1};
+CreateEmpty.Opts rfOpts = new CreateEmpty.Opts();
+rfOpts.parseArgs("accumulo create-empty", rfArgs);
+assertThrows(IllegalArgumentException.class,
+() -> createEmpty.createEmptyRFile(walOpts, context));
+  }
+
+  @Test
+  

Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-26 Thread via GitHub


keith-turner commented on code in PR #4116:
URL: https://github.com/apache/accumulo/pull/4116#discussion_r1467765241


##
server/tserver/src/test/java/org/apache/accumulo/tserver/util/CreateEmptyTest.java:
##
@@ -0,0 +1,206 @@
+/*
+ * 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.util;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.tserver.log.DfsLogger.LOG_FILE_HEADER_V4;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.mock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.accumulo.core.conf.ConfigurationCopy;
+import org.apache.accumulo.core.conf.DefaultConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.spi.crypto.CryptoService;
+import org.apache.accumulo.core.spi.crypto.GenericCryptoServiceFactory;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.fs.VolumeManagerImpl;
+import org.apache.accumulo.tserver.logger.LogEvents;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+public class CreateEmptyTest {
+  @TempDir
+  private static File tempDir;
+
+  private ServerContext context;
+
+  @BeforeEach
+  public void init() throws IOException {
+ConfigurationCopy config = new 
ConfigurationCopy(DefaultConfiguration.getInstance());
+config.set(Property.INSTANCE_VOLUMES.getKey(), "file:///");
+
+context = mock(ServerContext.class);
+expect(context.getCryptoFactory()).andReturn(new 
GenericCryptoServiceFactory()).anyTimes();
+expect(context.getConfiguration()).andReturn(config).anyTimes();
+expect(context.getHadoopConf()).andReturn(new Configuration()).anyTimes();
+VolumeManager volumeManager = VolumeManagerImpl.get(config, new 
Configuration());
+expect(context.getVolumeManager()).andReturn(volumeManager).anyTimes();
+replay(context);
+  }
+
+  @AfterEach
+  public void verifyMock() {
+verify(context);
+  }
+
+  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "path 
provided by test")
+  @Test
+  public void exceptionOnFileExistsTest() throws Exception {
+CreateEmpty createEmpty = new CreateEmpty();
+
+String wal1 = genFilename(tempDir.getAbsolutePath() + "/empty", ".wal");
+String rf1 = genFilename(tempDir.getAbsolutePath() + "/empty", ".rf");
+
+// create the file so it exists
+File f = new File(wal1);
+assertTrue(f.createNewFile());
+
+String[] walArgs = {"--type", "WAL", wal1};
+CreateEmpty.Opts walOpts = new CreateEmpty.Opts();
+walOpts.parseArgs("accumulo create-empty", walArgs);
+
+assertThrows(IllegalArgumentException.class,
+() -> createEmpty.createEmptyWal(walOpts, context));
+
+// create the file so it exists
+File f2 = new File(rf1);
+assertTrue(f2.createNewFile());
+
+String[] rfArgs = {"--type", "RF", rf1};
+CreateEmpty.Opts rfOpts = new CreateEmpty.Opts();
+rfOpts.parseArgs("accumulo create-empty", rfArgs);
+assertThrows(IllegalArgumentException.class,
+() -> createEmpty.createEmptyRFile(walOpts, context));
+  }
+
+  @Test
+  

Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-25 Thread via GitHub


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


##
test/src/main/java/org/apache/accumulo/test/functional/RecoveryWithEmptyRFileIT.java:
##
@@ -95,7 +95,8 @@ public void replaceMissingRFile() throws Exception {
   Path rfile = 
StoredTabletFile.of(entry.getKey().getColumnQualifier()).getPath();
   log.debug("Removing rfile '{}'", rfile);
   cluster.getFileSystem().delete(rfile, false);
-  Process processInfo = cluster.exec(CreateEmpty.class, 
rfile.toString()).getProcess();
+  Process processInfo =
+  cluster.exec(CreateEmpty.class, "--type", "rfile", 
rfile.toString()).getProcess();

Review Comment:
   Reverted RecoveryWithEmptyRFileIT to use default in 2124f38165.  Also added 
a specific test in CreateEmptyTest to catch if the default changes without 
needing to run an IT.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-25 Thread via GitHub


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


##
server/tserver/src/main/java/org/apache/accumulo/tserver/util/CreateEmpty.java:
##
@@ -0,0 +1,200 @@
+/*
+ * 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.util;
+
+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.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.accumulo.core.cli.ConfigOpts;
+import org.apache.accumulo.core.conf.DefaultConfiguration;
+import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.file.FileSKVWriter;
+import org.apache.accumulo.core.file.rfile.RFileOperations;
+import org.apache.accumulo.core.file.rfile.bcfile.Compression;
+import org.apache.accumulo.core.metadata.UnreferencedTabletFile;
+import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.spi.crypto.CryptoService;
+import org.apache.accumulo.core.spi.file.rfile.compression.NoCompression;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.accumulo.tserver.logger.LogFileValue;
+import org.apache.hadoop.fs.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.IParameterValidator;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.ParameterException;
+import com.google.auto.service.AutoService;
+
+/**
+ * Create an empty RFile for use in recovering from data loss where Accumulo 
still refers internally
+ * to a path.
+ */
+@AutoService(KeywordExecutable.class)
+public class CreateEmpty implements KeywordExecutable {
+  private static final Logger LOG = LoggerFactory.getLogger(CreateEmpty.class);
+  public static final String RF_EXTENSION = ".rf";
+  public static final String WAL_EXTENSION = ".wal";
+
+  public static class MatchesValidFileExtension implements IParameterValidator 
{
+@Override
+public void validate(String name, String value) throws ParameterException {
+  if (value.endsWith(RF_EXTENSION) || value.endsWith(WAL_EXTENSION)) {
+return;
+  }
+  throw new ParameterException("File must end with either " + RF_EXTENSION 
+ " or "
+  + WAL_EXTENSION + " and '" + value + "' does not.");
+}
+  }
+
+  public static class IsSupportedCompressionAlgorithm implements 
IParameterValidator {
+@Override
+public void validate(String name, String value) throws ParameterException {
+  List algorithms = Compression.getSupportedAlgorithms();
+  if (!algorithms.contains(value)) {
+throw new ParameterException("Compression codec must be one of " + 
algorithms);
+  }
+}
+  }
+
+  static class Opts extends ConfigOpts {
+@Parameter(names = {"-c", "--codec"}, description = "the compression codec 
to use.",
+validateWith = IsSupportedCompressionAlgorithm.class)
+String codec = new NoCompression().getName();
+@Parameter(
+description = "  {  ... } Each path given is a URL."
++ " Relative paths are resolved according to the default 
filesystem defined in"
++ " your Hadoop configuration, which is usually an HDFS instance.",
+required = true, validateWith = MatchesValidFileExtension.class)
+List files = new ArrayList<>();
+
+public enum OutFileType {
+  rfile, wal

Review Comment:
   changed in 2124f38165



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-25 Thread via GitHub


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


##
test/src/main/java/org/apache/accumulo/test/functional/RecoveryWithEmptyRFileIT.java:
##
@@ -95,7 +95,8 @@ public void replaceMissingRFile() throws Exception {
   Path rfile = 
StoredTabletFile.of(entry.getKey().getColumnQualifier()).getPath();
   log.debug("Removing rfile '{}'", rfile);
   cluster.getFileSystem().delete(rfile, false);
-  Process processInfo = cluster.exec(CreateEmpty.class, 
rfile.toString()).getProcess();
+  Process processInfo =
+  cluster.exec(CreateEmpty.class, "--type", "rfile", 
rfile.toString()).getProcess();

Review Comment:
   Okay, I'll change it back to test the default.  At one point I was "why did 
this work?" and then realized that oh, yea, it is the default  ;-)



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-25 Thread via GitHub


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


##
test/src/main/java/org/apache/accumulo/test/functional/RecoveryWithEmptyRFileIT.java:
##
@@ -95,7 +95,8 @@ public void replaceMissingRFile() throws Exception {
   Path rfile = 
StoredTabletFile.of(entry.getKey().getColumnQualifier()).getPath();
   log.debug("Removing rfile '{}'", rfile);
   cluster.getFileSystem().delete(rfile, false);
-  Process processInfo = cluster.exec(CreateEmpty.class, 
rfile.toString()).getProcess();
+  Process processInfo =
+  cluster.exec(CreateEmpty.class, "--type", "rfile", 
rfile.toString()).getProcess();

Review Comment:
   I was thinking this could be a nice coverage for the default case. As long 
as there's some coverage for the default case, I think either is fine here.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-25 Thread via GitHub


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


##
test/src/main/java/org/apache/accumulo/test/functional/RecoveryWithEmptyRFileIT.java:
##
@@ -95,7 +95,8 @@ public void replaceMissingRFile() throws Exception {
   Path rfile = 
StoredTabletFile.of(entry.getKey().getColumnQualifier()).getPath();
   log.debug("Removing rfile '{}'", rfile);
   cluster.getFileSystem().delete(rfile, false);
-  Process processInfo = cluster.exec(CreateEmpty.class, 
rfile.toString()).getProcess();
+  Process processInfo =
+  cluster.exec(CreateEmpty.class, "--type", "rfile", 
rfile.toString()).getProcess();

Review Comment:
   It is the default type and this worked without the change, but I thought 
that being specific here was better that relying on the default behavior.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-25 Thread via GitHub


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


##
server/tserver/src/main/java/org/apache/accumulo/tserver/util/CreateEmpty.java:
##
@@ -0,0 +1,200 @@
+/*
+ * 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.util;
+
+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.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.accumulo.core.cli.ConfigOpts;
+import org.apache.accumulo.core.conf.DefaultConfiguration;
+import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.file.FileSKVWriter;
+import org.apache.accumulo.core.file.rfile.RFileOperations;
+import org.apache.accumulo.core.file.rfile.bcfile.Compression;
+import org.apache.accumulo.core.metadata.UnreferencedTabletFile;
+import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.spi.crypto.CryptoService;
+import org.apache.accumulo.core.spi.file.rfile.compression.NoCompression;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.accumulo.tserver.logger.LogFileValue;
+import org.apache.hadoop.fs.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.IParameterValidator;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.ParameterException;
+import com.google.auto.service.AutoService;
+
+/**
+ * Create an empty RFile for use in recovering from data loss where Accumulo 
still refers internally
+ * to a path.
+ */
+@AutoService(KeywordExecutable.class)
+public class CreateEmpty implements KeywordExecutable {
+  private static final Logger LOG = LoggerFactory.getLogger(CreateEmpty.class);
+  public static final String RF_EXTENSION = ".rf";
+  public static final String WAL_EXTENSION = ".wal";
+
+  public static class MatchesValidFileExtension implements IParameterValidator 
{
+@Override
+public void validate(String name, String value) throws ParameterException {
+  if (value.endsWith(RF_EXTENSION) || value.endsWith(WAL_EXTENSION)) {
+return;
+  }
+  throw new ParameterException("File must end with either " + RF_EXTENSION 
+ " or "
+  + WAL_EXTENSION + " and '" + value + "' does not.");
+}
+  }
+
+  public static class IsSupportedCompressionAlgorithm implements 
IParameterValidator {
+@Override
+public void validate(String name, String value) throws ParameterException {
+  List algorithms = Compression.getSupportedAlgorithms();
+  if (!algorithms.contains(value)) {
+throw new ParameterException("Compression codec must be one of " + 
algorithms);
+  }
+}
+  }
+
+  static class Opts extends ConfigOpts {
+@Parameter(names = {"-c", "--codec"}, description = "the compression codec 
to use.",
+validateWith = IsSupportedCompressionAlgorithm.class)
+String codec = new NoCompression().getName();
+@Parameter(
+description = "  {  ... } Each path given is a URL."
++ " Relative paths are resolved according to the default 
filesystem defined in"
++ " your Hadoop configuration, which is usually an HDFS instance.",
+required = true, validateWith = MatchesValidFileExtension.class)
+List files = new ArrayList<>();
+
+public enum OutFileType {
+  rfile, wal
+}
+
+// rfile as default keeps previous behaviour
+@Parameter(names = "--type")
+public OutFileType fileType = OutFileType.rfile;
+
+  }
+
+  public static void main(String[] args) throws Exception {
+new CreateEmpty().execute(args);
+  }
+
+  @Override
+  public String keyword() {
+return "create-empty";
+  }
+
+  @Override
+  public String description() {
+return "Creates empty rfiles and 

Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-25 Thread via GitHub


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


##
server/tserver/src/main/java/org/apache/accumulo/tserver/util/CreateEmpty.java:
##
@@ -0,0 +1,200 @@
+/*
+ * 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.util;
+
+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.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.accumulo.core.cli.ConfigOpts;
+import org.apache.accumulo.core.conf.DefaultConfiguration;
+import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.file.FileSKVWriter;
+import org.apache.accumulo.core.file.rfile.RFileOperations;
+import org.apache.accumulo.core.file.rfile.bcfile.Compression;
+import org.apache.accumulo.core.metadata.UnreferencedTabletFile;
+import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.spi.crypto.CryptoService;
+import org.apache.accumulo.core.spi.file.rfile.compression.NoCompression;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.accumulo.tserver.logger.LogFileValue;
+import org.apache.hadoop.fs.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.IParameterValidator;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.ParameterException;
+import com.google.auto.service.AutoService;
+
+/**
+ * Create an empty RFile for use in recovering from data loss where Accumulo 
still refers internally
+ * to a path.
+ */
+@AutoService(KeywordExecutable.class)
+public class CreateEmpty implements KeywordExecutable {
+  private static final Logger LOG = LoggerFactory.getLogger(CreateEmpty.class);
+  public static final String RF_EXTENSION = ".rf";
+  public static final String WAL_EXTENSION = ".wal";
+
+  public static class MatchesValidFileExtension implements IParameterValidator 
{
+@Override
+public void validate(String name, String value) throws ParameterException {
+  if (value.endsWith(RF_EXTENSION) || value.endsWith(WAL_EXTENSION)) {
+return;
+  }
+  throw new ParameterException("File must end with either " + RF_EXTENSION 
+ " or "
+  + WAL_EXTENSION + " and '" + value + "' does not.");
+}
+  }
+
+  public static class IsSupportedCompressionAlgorithm implements 
IParameterValidator {
+@Override
+public void validate(String name, String value) throws ParameterException {
+  List algorithms = Compression.getSupportedAlgorithms();
+  if (!algorithms.contains(value)) {
+throw new ParameterException("Compression codec must be one of " + 
algorithms);
+  }
+}
+  }
+
+  static class Opts extends ConfigOpts {
+@Parameter(names = {"-c", "--codec"}, description = "the compression codec 
to use.",
+validateWith = IsSupportedCompressionAlgorithm.class)
+String codec = new NoCompression().getName();
+@Parameter(
+description = "  {  ... } Each path given is a URL."
++ " Relative paths are resolved according to the default 
filesystem defined in"
++ " your Hadoop configuration, which is usually an HDFS instance.",
+required = true, validateWith = MatchesValidFileExtension.class)
+List files = new ArrayList<>();
+
+public enum OutFileType {
+  rfile, wal
+}
+
+// rfile as default keeps previous behaviour
+@Parameter(names = "--type")
+public OutFileType fileType = OutFileType.rfile;
+
+  }
+
+  public static void main(String[] args) throws Exception {
+new CreateEmpty().execute(args);
+  }
+
+  @Override
+  public String keyword() {
+return "create-empty";
+  }
+
+  @Override
+  public String description() {
+return "Creates empty rfiles and 

Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-25 Thread via GitHub


EdColeman commented on PR #4116:
URL: https://github.com/apache/accumulo/pull/4116#issuecomment-1910683832

   4741d79ea8 removes create-empty-wal as a stand-alone and adds a type option 
[rfile, wal] to create-empty.


-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-23 Thread via GitHub


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


##
server/tserver/src/main/java/org/apache/accumulo/tserver/log/CreateEmptyWal.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
+ *
+ *   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 java.nio.file.StandardOpenOption.CREATE_NEW;
+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.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.apache.accumulo.core.cli.ConfigOpts;
+import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.spi.crypto.CryptoService;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.accumulo.tserver.logger.LogFileValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+import com.google.common.annotations.VisibleForTesting;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@AutoService(KeywordExecutable.class)
+public class CreateEmptyWal implements KeywordExecutable {
+  private static final Logger LOG = 
LoggerFactory.getLogger(CreateEmptyWal.class);
+  private static final LogFileValue EMPTY = new LogFileValue();
+
+  static class Opts extends ConfigOpts {
+@Parameter(
+description = "  the path / filename of the created empty wal 
file. The file cannot exist",
+required = true)
+String walFilename;

Review Comment:
   > If I recall, when needing to use an empty rfile it was convenient to have 
a "local" file.
   
   The empty RFile create tool doesn't create a local file, though. It creates 
one in the DFS. However, you can specify a local file by using a URL filename 
pattern, like `file:///path/to/empty.rf`.
   
   > you could create an single file and then either use the command line or 
better, a simple script to do the delete / copy.
   
   I agree, and think that's probably how most will use it. But the current 
CreateEmpty is more flexible than that by allowing creation of multiple at a 
time. I don't know how people will use that, but that's how it's implemented.
   
   > If the intended usage is the utility would to create the files directly - 
you would still need to delete the original files. Overwriting is probably a 
bad idea - if there was mistake, you could clobber valid files.
   
   Understood, but creating in DFS isn't about overwriting. It's about where 
you're placing the seed file before you move it into place. You can place it in 
the DFS, so it's a simple hdfs mv instead of a copyFromLocal.
   
   > I assumed that the intention of this utility was to simply create the 
empty seed file. These changes can be done. but it seems to be unnecessarily 
complicating things to create that empty wal seed file.
   
   It can definitely serve that purpose, but I do not want to restrict the 
user's ability to do things in batches, if that's how they've written their 
scripts. and it's not that much complexity to just loop over the file names to 
create multiple. This is already a feature for the CreateEmpty utility. Using 
the DFS API to create a file from a URL rather than a local file does add a 
tiny bit of complexity, but I still think it's worth it to keep parity with the 
behavior of CreateEmpty. Users don't need to learn two different sets of 
quirks/restrictions for two, essentially equivalent, utilities that vary only 
in the type of empty file being created. In fact, I think this utility could 
just be a `--type wal|rf` option to the existing CreateEmpty, with a default 
type of `rf`, which would make adding this utility very trivial... but that 
would require more complex changes to the filename 

Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-23 Thread via GitHub


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


##
server/tserver/src/main/java/org/apache/accumulo/tserver/log/CreateEmptyWal.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
+ *
+ *   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 java.nio.file.StandardOpenOption.CREATE_NEW;
+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.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.apache.accumulo.core.cli.ConfigOpts;
+import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.spi.crypto.CryptoService;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.accumulo.tserver.logger.LogFileValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+import com.google.common.annotations.VisibleForTesting;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@AutoService(KeywordExecutable.class)
+public class CreateEmptyWal implements KeywordExecutable {
+  private static final Logger LOG = 
LoggerFactory.getLogger(CreateEmptyWal.class);
+  private static final LogFileValue EMPTY = new LogFileValue();
+
+  static class Opts extends ConfigOpts {
+@Parameter(
+description = "  the path / filename of the created empty wal 
file. The file cannot exist",
+required = true)
+String walFilename;

Review Comment:
   If I recall, when needing to use an empty rfile it was convenient to have a 
"local" file.  That file could the be reused when needed by using hadoop 
copyFromLocal to the desired directory and filename. The empty rfile utility 
was only needed when the empty.rf "seed" file was not available.   
   
   It would seem this could be similar.  If you have a recovery problem and you 
want to move on (and accept the data loss) you would identify the file(s) that 
are missing / corrupt and then copy an empty wal to replace them.  If the files 
are corrupt or cannot be processed, would need to delete the current files and 
then replace them with the empty file.
   
   Rather than running this utility to create each empty file on demand, you 
could create an single file and then either use the command line or better, a 
simple script to do the delete / copy.
   
   The file could be created in hdfs, but then you would likely need to create 
a temporary directory in the proper namespace - in which case copyFromLocal is 
just as easy to use.
   
   If the intended usage is the utility would to create the files directly - 
you would still need to delete the original files. Overwriting is probably a 
bad idea - if there was mistake, you could clobber valid files.   
   
   I assumed that the intention of this utility was to simply create the empty 
seed file.  These changes can be done. but it seems to be unnecessarily 
complicating things to create that empty wal seed file.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2024-01-23 Thread via GitHub


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


##
server/tserver/src/main/java/org/apache/accumulo/tserver/log/CreateEmptyWal.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
+ *
+ *   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 java.nio.file.StandardOpenOption.CREATE_NEW;
+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.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.apache.accumulo.core.cli.ConfigOpts;
+import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
+import org.apache.accumulo.core.crypto.CryptoUtils;
+import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
+import org.apache.accumulo.core.spi.crypto.CryptoService;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.tserver.logger.LogFileKey;
+import org.apache.accumulo.tserver.logger.LogFileValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+import com.google.common.annotations.VisibleForTesting;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@AutoService(KeywordExecutable.class)
+public class CreateEmptyWal implements KeywordExecutable {
+  private static final Logger LOG = 
LoggerFactory.getLogger(CreateEmptyWal.class);
+  private static final LogFileValue EMPTY = new LogFileValue();
+
+  static class Opts extends ConfigOpts {
+@Parameter(
+description = "  the path / filename of the created empty wal 
file. The file cannot exist",
+required = true)
+String walFilename;

Review Comment:
   If this is to work like CreateEmpty for wal files, this needs to be:
   
   ```suggestion
   List files = new ArrayList<>();
   ```
   
   And then the execute method needs to loop over each file name to create a 
WAL for each one.
   
   Also, like CreateEmpty, each path should be a URL and be written to a Path 
in HDFS (`org.apache.hadoop.fs.Path`), not a `java.nio.file.Path`.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2023-12-28 Thread via GitHub


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


##
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 = "  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:
   b07123b3af - uses crypto factory obtained from context.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2023-12-28 Thread via GitHub


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


##
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 = "  the output directory, output will be 
[dir]/empty.wal",
+required = true, validateWith = DirValidator.class)
+String dirName;
+  }

Review Comment:
   b07123b3af - removed named option in favor of unnamed parameter to proved 
file / path name,



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2023-12-27 Thread via GitHub


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


##
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 = "  the output directory, output will be 
[dir]/empty.wal",
+required = true, validateWith = DirValidator.class)
+String dirName;
+  }

Review Comment:
   Keeping JCommander to work similarly to the RFile create empty command seems 
reasonable, but if the goal is to make it as similar as possible, it should not 
have a `-w` or `--wal-file` option, but instead accept a list of unnamed 
parameters without flags, as in: `  {  ... }`.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2023-12-27 Thread via GitHub


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


##
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 = "  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:
   The problem is that the NoFileEncrypter does *NOT* create a "universally 
readable wal stub". Rather, it creates one that is specifically capable of 
being read by *our* implementation, because of the specific decryption 
parameters we use for it. Those decryption params are not universal at all.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2023-12-27 Thread via GitHub


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


##
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 = "  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:
   > It would be simple enough to combine if a there is a preferable module to 
put it.
   
   If we were to combine it, it'd have to go in another module, that depends on 
the others... maybe o.a.a.server.tools... which may be worth doing at some 
point, but probably not right now. I think your current approach is fine, given 
the constraints of the class path layout right now.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2023-12-27 Thread via GitHub


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


##
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 = "  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:
   Using a user specified encryption seems more complicated than may be 
necessary. This utility needs to create a universally readable wal stub that is 
intended to allow recovery to progress (with potential data loss) it has no 
content, no sensitive information,...  
   
   Like with the empty rfile utility, once a user has an empty file, it can be 
"reused" by copying the file as many times needed.  The file can be created 
anywhere, at any time without regard to a specific system configuration.  
   



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2023-12-27 Thread via GitHub


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


##
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 = "  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:
   Changed in ab4e900992



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2023-12-27 Thread via GitHub


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


##
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 = "  the output directory, output will be 
[dir]/empty.wal",
+required = true, validateWith = DirValidator.class)
+String dirName;
+  }

Review Comment:
   ab4e900992 - Changed to take file and delegate file existence check to use 
`CREATE_NEW` 
   
   Kept JCommander.
 - Keeps utility similar to other keyword executable utilities.
 - Simplifies potential merging into CreateEmpty



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2023-12-27 Thread via GitHub


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


##
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 = "  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:
   Having one utility would require moving additional code around.  The empty 
rfile utility is buried in `org.apache.accumulo.core.file.rfile` and the wal 
file header constants (at a minimum) need access to 
`org.apache.accumulo.tserver.log.`  
   
   Rather than move the empty rfile utility (which would also require 
additional doc changes) or refactoring the wal code it seemed preferable to add 
a new keyword executable.
   
   It would be simple enough to combine if a there is a preferable module to 
put it.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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



Re: [PR] Add utility to create an empty wal file. [accumulo]

2023-12-26 Thread via GitHub


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 = "  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