Merge branch 'cassandra-4.1' into trunk

This commit is contained in:
David Capwell 2023-03-15 16:19:05 -07:00
commit 92c90cd4ef
21 changed files with 84 additions and 49 deletions

View File

@ -93,7 +93,7 @@
</module>
<module name="IllegalImport">
<property name="illegalPkgs" value="junit.framework"/>
<property name="illegalClasses" value="java.io.File,java.io.FileInputStream,java.io.FileOutputStream,java.io.FileReader,java.io.FileWriter,java.io.RandomAccessFile,java.util.concurrent.Semaphore,java.util.concurrent.CountDownLatch,java.util.concurrent.Executors,java.util.concurrent.LinkedBlockingQueue,java.util.concurrent.SynchronousQueue,java.util.concurrent.ArrayBlockingQueue,com.google.common.util.concurrent.Futures,java.util.concurrent.CompletableFuture,io.netty.util.concurrent.Future,io.netty.util.concurrent.Promise,io.netty.util.concurrent.AbstractFuture,com.google.common.util.concurrent.ListenableFutureTask,com.google.common.util.concurrent.ListenableFuture,com.google.common.util.concurrent.AbstractFuture"/>
<property name="illegalClasses" value="java.io.File,java.io.FileInputStream,java.io.FileOutputStream,java.io.FileReader,java.io.FileWriter,java.io.RandomAccessFile,java.util.concurrent.Semaphore,java.util.concurrent.CountDownLatch,java.util.concurrent.Executors,java.util.concurrent.LinkedBlockingQueue,java.util.concurrent.SynchronousQueue,java.util.concurrent.ArrayBlockingQueue,com.google.common.util.concurrent.Futures,java.util.concurrent.CompletableFuture,io.netty.util.concurrent.Future,io.netty.util.concurrent.Promise,io.netty.util.concurrent.AbstractFuture,com.google.common.util.concurrent.ListenableFutureTask,com.google.common.util.concurrent.ListenableFuture,com.google.common.util.concurrent.AbstractFuture,java.nio.file.Paths"/>
</module>
<module name="IllegalInstantiation">
<property name="classes" value="java.io.File,java.lang.Thread,java.util.concurrent.FutureTask,java.util.concurrent.Semaphore,java.util.concurrent.CountDownLatch,java.util.concurrent.ScheduledThreadPoolExecutor,java.util.concurrent.ThreadPoolExecutor,java.util.concurrent.ForkJoinPool,java.lang.OutOfMemoryError"/>

View File

@ -18,7 +18,6 @@
package org.apache.cassandra.audit;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
@ -32,6 +31,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.cassandra.config.CassandraRelevantProperties;
import org.apache.cassandra.config.ParameterizedClass;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.util.File;
import org.apache.cassandra.utils.binlog.BinLogOptions;
public class AuditLogOptions extends BinLogOptions
@ -52,7 +52,7 @@ public class AuditLogOptions extends BinLogOptions
{
String auditLogDir = CassandraRelevantProperties.LOG_DIR_AUDIT.getString();
String logDir = CassandraRelevantProperties.LOG_DIR.getString() + "/audit";
Path path = auditLogDir == null ? Paths.get(logDir) : Paths.get(auditLogDir);
Path path = auditLogDir == null ? File.getPath(logDir) : File.getPath(auditLogDir);
audit_logs_dir = path.normalize().toString();
}

View File

@ -17,7 +17,6 @@
*/
package org.apache.cassandra.audit;
import java.nio.file.Paths;
import java.util.Map;
import com.google.common.annotations.VisibleForTesting;
@ -27,6 +26,7 @@ import org.slf4j.LoggerFactory;
import net.openhft.chronicle.wire.WireOut;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.io.util.File;
import org.apache.cassandra.utils.ObjectSizes;
import org.apache.cassandra.utils.binlog.BinLog;
import org.apache.cassandra.utils.concurrent.WeightedQueue;
@ -42,7 +42,7 @@ public class BinAuditLogger implements IAuditLogger
public BinAuditLogger(AuditLogOptions auditLoggingOptions)
{
this.binLog = new BinLog.Builder().path(Paths.get(auditLoggingOptions.audit_logs_dir))
this.binLog = new BinLog.Builder().path(File.getPath(auditLoggingOptions.audit_logs_dir))
.rollCycle(auditLoggingOptions.roll_cycle)
.blocking(auditLoggingOptions.block)
.maxQueueWeight(auditLoggingOptions.max_queue_weight)

View File

@ -28,7 +28,6 @@ import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.file.FileStore;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
@ -4605,9 +4604,9 @@ public class DatabaseDescriptor
logger.warn("Neither -XX:HeapDumpPath nor cassandra.yaml:heap_dump_path are set; unable to create a directory to hold the output.");
return false;
}
if (PathUtils.exists(Paths.get(conf.heap_dump_path)))
if (PathUtils.exists(File.getPath(conf.heap_dump_path)))
return true;
return PathUtils.createDirectoryIfNotExists(Paths.get(conf.heap_dump_path));
return PathUtils.createDirectoryIfNotExists(File.getPath(conf.heap_dump_path));
}
/**
@ -4626,13 +4625,13 @@ public class DatabaseDescriptor
{
Pattern HEAP_DUMP_PATH_SPLITTER = Pattern.compile("HeapDumpPath=");
String fullHeapPathString = HEAP_DUMP_PATH_SPLITTER.split(pathArg.get())[1];
Path absolutePath = Paths.get(fullHeapPathString).toAbsolutePath();
Path absolutePath = File.getPath(fullHeapPathString).toAbsolutePath();
Path basePath = fullHeapPathString.endsWith(".hprof") ? absolutePath.subpath(0, absolutePath.getNameCount() - 1) : absolutePath;
return Paths.get("/").resolve(basePath);
return File.getPath("/").resolve(basePath);
}
if (conf.heap_dump_path == null)
throw new ConfigurationException("Attempted to get heap dump path without -XX:HeapDumpPath or cassandra.yaml:heap_dump_path set.");
return Paths.get(conf.heap_dump_path);
return File.getPath(conf.heap_dump_path);
}
public static void setDumpHeapOnUncaughtException(boolean enabled)

View File

@ -20,7 +20,6 @@ package org.apache.cassandra.hadoop.cql3;
*
*/
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.InputStream;
import java.io.IOException;
import java.security.KeyManagementException;
@ -52,6 +51,7 @@ import com.datastax.driver.core.QueryOptions;
import com.datastax.driver.core.SSLOptions;
import com.datastax.driver.core.SocketOptions;
import org.apache.cassandra.hadoop.ConfigHelper;
import org.apache.cassandra.io.util.File;
import org.apache.hadoop.conf.Configuration;
@ -625,7 +625,7 @@ public class CqlConfigHelper
TrustManagerFactory tmf = null;
if (truststorePath.isPresent())
{
try (InputStream tsf = Files.newInputStream(Paths.get(truststorePath.get())))
try (InputStream tsf = Files.newInputStream(File.getPath(truststorePath.get())))
{
KeyStore ts = KeyStore.getInstance("JKS");
ts.load(tsf, truststorePassword.isPresent() ? truststorePassword.get().toCharArray() : null);
@ -637,7 +637,7 @@ public class CqlConfigHelper
KeyManagerFactory kmf = null;
if (keystorePath.isPresent())
{
try (InputStream ksf = Files.newInputStream(Paths.get(keystorePath.get())))
try (InputStream ksf = Files.newInputStream(File.getPath(keystorePath.get())))
{
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(ksf, keystorePassword.isPresent() ? keystorePassword.get().toCharArray() : null);

View File

@ -20,7 +20,6 @@ package org.apache.cassandra.io.sstable.format;
import java.io.IOError;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -380,7 +379,7 @@ public abstract class SortedTableScrubber<R extends SSTableReaderWithFilter> imp
dataFile.length(),
scrubCompactionId,
ImmutableSet.of(sstable),
Paths.get(sstable.getFilename()).getParent().toString());
File.getPath(sstable.getFilename()).getParent().toString());
}
catch (Exception e)
{

View File

@ -28,7 +28,7 @@ import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Paths; // checkstyle: permit this import
import java.util.Objects;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
@ -51,7 +51,6 @@ import static org.apache.cassandra.utils.Throwables.maybeFail;
*
* TODO codebase probably should not use tryList, as unexpected exceptions are hidden;
* probably want to introduce e.g. listIfExists
* TODO codebase probably should not use Paths.get() to ensure we can override the filesystem
*/
public class File implements Comparable<File>
{
@ -122,7 +121,7 @@ public class File implements Comparable<File>
*/
public File(URI path)
{
this(Paths.get(path));
this(Paths.get(path)); //TODO unsafe if uri is file:// as it uses default file system and not File.filesystem
if (!path.isAbsolute() || path.isOpaque()) throw new IllegalArgumentException();
}
@ -132,11 +131,16 @@ public class File implements Comparable<File>
public File(Path path)
{
if (path != null && path.getFileSystem() != filesystem)
throw new IllegalArgumentException("Incompatible file system");
throw new IllegalArgumentException("Incompatible file system; path FileSystem (" + path.getFileSystem() + ") is not the same reference (" + filesystem + ")");
this.path = path;
}
public static Path getPath(String first, String... more)
{
return filesystem.getPath(first, more);
}
/**
* Try to delete the file, returning true iff it was deleted by us. Does not ordinarily throw exceptions.
*/

View File

@ -20,7 +20,6 @@ package org.apache.cassandra.security;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.cert.X509Certificate;
@ -152,7 +151,7 @@ public abstract class FileBasedSslContextFactory extends AbstractSslContextFacto
@Override
protected TrustManagerFactory buildTrustManagerFactory() throws SSLException
{
try (InputStream tsf = Files.newInputStream(Paths.get(trustStoreContext.filePath)))
try (InputStream tsf = Files.newInputStream(File.getPath(trustStoreContext.filePath)))
{
final String algorithm = this.algorithm == null ? TrustManagerFactory.getDefaultAlgorithm() : this.algorithm;
TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
@ -169,7 +168,7 @@ public abstract class FileBasedSslContextFactory extends AbstractSslContextFacto
private KeyManagerFactory getKeyManagerFactory(final FileBasedStoreContext context) throws SSLException
{
try (InputStream ksf = Files.newInputStream(Paths.get(context.filePath)))
try (InputStream ksf = Files.newInputStream(File.getPath(context.filePath)))
{
final String algorithm = this.algorithm == null ? KeyManagerFactory.getDefaultAlgorithm() : this.algorithm;
KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);

View File

@ -18,7 +18,6 @@
package org.apache.cassandra.security;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.InputStream;
import java.io.IOException;
import java.security.Key;
@ -28,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.TransparentDataEncryptionOptions;
import org.apache.cassandra.io.util.File;
/**
* A {@code KeyProvider} that retrieves keys from a java keystore.
@ -48,7 +48,7 @@ public class JKSKeyProvider implements KeyProvider
{
this.options = options;
logger.info("initializing keystore from file {}", options.get(PROP_KEYSTORE));
try (InputStream inputStream = Files.newInputStream(Paths.get(options.get(PROP_KEYSTORE))))
try (InputStream inputStream = Files.newInputStream(File.getPath(options.get(PROP_KEYSTORE))))
{
store = KeyStore.getInstance(options.get(PROP_KEYSTORE_TYPE));
store.load(inputStream, options.get(PROP_KEYSTORE_PW).toCharArray());

View File

@ -20,7 +20,6 @@ package org.apache.cassandra.security;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.PrivateKey;
@ -306,7 +305,7 @@ public final class PEMBasedSslContextFactory extends FileBasedSslContextFactory
private String readPEMFile(String file) throws IOException
{
return new String(Files.readAllBytes(Paths.get(file)));
return new String(Files.readAllBytes(File.getPath(file)));
}
/**

View File

@ -25,7 +25,6 @@ import java.net.URL;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -520,7 +519,7 @@ public class CassandraDaemon
// the system keyspace location configured by the user (upgrade to 4.0)
// 3) The system data are stored in the first data location and need to be moved to
// the system keyspace location configured by the user (system_data_file_directory has been configured)
Path target = Paths.get(DatabaseDescriptor.getLocalSystemKeyspacesDataFileLocations()[0]);
Path target = File.getPath(DatabaseDescriptor.getLocalSystemKeyspacesDataFileLocations()[0]);
String[] nonLocalSystemKeyspacesFileLocations = DatabaseDescriptor.getNonLocalSystemKeyspacesDataFileLocations();
String[] sources = DatabaseDescriptor.useSpecificLocationForLocalSystemData() ? nonLocalSystemKeyspacesFileLocations
@ -530,7 +529,7 @@ public class CassandraDaemon
for (String source : sources)
{
Path dataFileLocation = Paths.get(source);
Path dataFileLocation = File.getPath(source);
if (!Files.exists(dataFileLocation))
continue;

View File

@ -21,7 +21,6 @@ package org.apache.cassandra.service;
import java.io.BufferedReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@ -139,7 +138,7 @@ public class FileSystemOwnershipCheck implements StartupCheck
{
logger.info("Checking for fs ownership details in file hierarchy for {}", dataDir);
int foundFiles = 0;
Path dir = Paths.get(dataDir).normalize();
Path dir = File.getPath(dataDir).normalize();
do
{
File tokenFile = resolve(dir, tokenFilename);

View File

@ -26,7 +26,6 @@ import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
@ -386,7 +385,7 @@ public class StartupChecks
{
try
{
Path p = Paths.get(dataDirectory);
Path p = File.getPath(dataDirectory);
FileStore fs = Files.getFileStore(p);
String blockDirectory = fs.name();
@ -455,7 +454,7 @@ public class StartupChecks
private long getMaxMapCount()
{
final Path path = Paths.get(MAX_MAP_COUNT_PATH);
final Path path = File.getPath(MAX_MAP_COUNT_PATH);
try (final BufferedReader bufferedReader = Files.newBufferedReader(path))
{
final String data = bufferedReader.readLine();
@ -772,7 +771,7 @@ public class StartupChecks
String deviceName = blockDirComponents[2].replaceAll("[0-9]*$", "");
if (StringUtils.isNotEmpty(deviceName))
{
readAheadKBPath = Paths.get(String.format(READ_AHEAD_KB_SETTING_PATH, deviceName));
readAheadKBPath = File.getPath(String.format(READ_AHEAD_KB_SETTING_PATH, deviceName));
}
}
}

View File

@ -25,7 +25,6 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
@ -6795,7 +6794,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
maxArchiveRetries = maxArchiveRetries != Integer.MIN_VALUE ? maxArchiveRetries : fqlOptions.max_archive_retries;
Preconditions.checkNotNull(path, "cassandra.yaml did not set log_dir and not set as parameter");
FullQueryLogger.instance.enableWithoutClean(Paths.get(path), rollCycle, blocking, maxQueueWeight, maxLogSize, archiveCommand, maxArchiveRetries);
FullQueryLogger.instance.enableWithoutClean(File.getPath(path), rollCycle, blocking, maxQueueWeight, maxLogSize, archiveCommand, maxArchiveRetries);
}
@Override

View File

@ -23,7 +23,6 @@ import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
@ -66,7 +65,7 @@ public class SnapshotLoader
public SnapshotLoader(String[] dataDirectories)
{
this(Arrays.stream(dataDirectories).map(Paths::get).collect(Collectors.toList()));
this(Arrays.stream(dataDirectories).map(File::getPath).collect(Collectors.toList()));
}
public SnapshotLoader(Collection<Path> dataDirs)

View File

@ -20,7 +20,6 @@ package org.apache.cassandra.service.snapshot;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.Collection;
import java.util.HashSet;
@ -320,7 +319,7 @@ public class TableSnapshot
if (Directories.isSecondaryIndexFolder(snapshotFilePath.getParent()))
{
// Snapshot file structure format is {data_dir}/snapshots/{snapshot_name}/.{index}/{sstable-component}.db
liveDir = Paths.get(liveDir.getParent().toString(), snapshotFilePath.getParent().getFileName().toString());
liveDir = File.getPath(liveDir.getParent().toString(), snapshotFilePath.getParent().getFileName().toString());
}
return new File(liveDir.toString(), snapshotFilePath.getFileName().toString());
}

View File

@ -22,7 +22,6 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
@ -33,6 +32,8 @@ import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.apache.cassandra.io.util.File;
import org.mindrot.jbcrypt.BCrypt;
public class HashPassword
@ -83,7 +84,7 @@ public class HashPassword
{
try
{
Path file = Paths.get(input);
Path file = File.getPath(input);
fileInput = Files.readAllBytes(file);
}
catch (IOException e)

View File

@ -22,7 +22,6 @@ import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.util.Arrays;
import java.util.List;
@ -61,7 +60,7 @@ public class SSTableRepairedAtSetter
List<String> fileNames;
if (args[2].equals("-f"))
{
fileNames = Files.readAllLines(Paths.get(args[3]), Charset.defaultCharset());
fileNames = Files.readAllLines(File.getPath(args[3]), Charset.defaultCharset());
}
else
{

View File

@ -24,7 +24,6 @@ import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.nio.file.FileStore;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.management.MBeanServer;
@ -118,7 +117,7 @@ public final class HeapUtils
HotSpotDiagnosticMXBean mxBean = ManagementFactory.newPlatformMXBeanProxy(server, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
String filename = String.format("pid%s-epoch%s.hprof", HeapUtils.getProcessId().toString(), currentTimeMillis());
String fullPath = Paths.get(absoluteBasePath.toString(), filename).toString();
String fullPath = File.getPath(absoluteBasePath.toString(), filename).toString();
logger.info("Writing heap dump to {} on partition w/ {} free bytes...", absoluteBasePath, freeSpaceBytes);
mxBean.dumpHeap(fullPath, false);

View File

@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.simulator;
public class SimulationException extends RuntimeException
{
public SimulationException(long seed, Throwable t)
{
super(createMsg(seed, null), t, true, false);
}
public SimulationException(long seed, String msg, Throwable t)
{
super(createMsg(seed, msg), t, true, false);
}
private static String createMsg(long seed, String msg)
{
return String.format("Failed on seed 0x%s%s", Long.toHexString(seed), msg == null ? "" : "; " + msg);
}
}

View File

@ -365,9 +365,14 @@ public class SimulationRunner
}
catch (Throwable t)
{
logger.error("Failed on seed {}", Long.toHexString(seed), t);
throw new SimulationException(seed, t);
}
}
catch (Throwable t)
{
if (t instanceof SimulationException) throw t;
throw new SimulationException(seed, "Failure creating the simulation", t);
}
}
}