mirror of https://github.com/apache/cassandra
Make 'static final boolean' easier to optimize for Hotspot
patch by Robert Stupp; reviewed by Branimir Lambov for CASSANDRA-12343
This commit is contained in:
parent
6dfc1e7eeb
commit
54836ec0c5
|
|
@ -1920,7 +1920,7 @@ public class DatabaseDescriptor
|
|||
|
||||
public static int getSSTablePreempiveOpenIntervalInMB()
|
||||
{
|
||||
return FBUtilities.isWindows() ? -1 : conf.sstable_preemptive_open_interval_in_mb;
|
||||
return FBUtilities.isWindows ? -1 : conf.sstable_preemptive_open_interval_in_mb;
|
||||
}
|
||||
public static void setSSTablePreempiveOpenIntervalInMB(int mb)
|
||||
{
|
||||
|
|
@ -2075,7 +2075,7 @@ public class DatabaseDescriptor
|
|||
case heap_buffers:
|
||||
return new SlabPool(heapLimit, 0, conf.memtable_cleanup_threshold, new ColumnFamilyStore.FlushLargestColumnFamily());
|
||||
case offheap_buffers:
|
||||
if (!FileUtils.isCleanerAvailable())
|
||||
if (!FileUtils.isCleanerAvailable)
|
||||
{
|
||||
throw new IllegalStateException("Could not free direct byte buffer: offheap_buffers is not a safe memtable_allocation_type without this ability, please adjust your config. This feature is only guaranteed to work on an Oracle JVM. Refusing to start.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -889,7 +889,7 @@ public class Directories
|
|||
}
|
||||
catch (FSWriteError e)
|
||||
{
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
SnapshotDeletingTask.addFailedSnapshot(snapshotDir);
|
||||
else
|
||||
throw e;
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ public class MemoryMappedSegment extends CommitLogSegment
|
|||
@Override
|
||||
protected void internalClose()
|
||||
{
|
||||
if (FileUtils.isCleanerAvailable())
|
||||
if (FileUtils.isCleanerAvailable)
|
||||
FileUtils.clean(buffer);
|
||||
super.internalClose();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ public class CompactionController implements AutoCloseable
|
|||
{
|
||||
logger.trace("Checking droppable sstables in {}", cfStore);
|
||||
|
||||
if (compacting == null || NEVER_PURGE_TOMBSTONES)
|
||||
if (NEVER_PURGE_TOMBSTONES || compacting == null)
|
||||
return Collections.<SSTableReader>emptySet();
|
||||
|
||||
if (cfStore.getCompactionStrategyManager().onlyPurgeRepairedTombstones() && !Iterables.all(compacting, SSTableReader::isRepaired))
|
||||
|
|
@ -222,7 +222,7 @@ public class CompactionController implements AutoCloseable
|
|||
*/
|
||||
public long maxPurgeableTimestamp(DecoratedKey key)
|
||||
{
|
||||
if (!compactingRepaired() || NEVER_PURGE_TOMBSTONES)
|
||||
if (NEVER_PURGE_TOMBSTONES || !compactingRepaired())
|
||||
return Long.MIN_VALUE;
|
||||
|
||||
long min = Long.MAX_VALUE;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class ViewManager
|
|||
|
||||
public boolean updatesAffectView(Collection<? extends IMutation> mutations, boolean coordinatorBatchlog)
|
||||
{
|
||||
if (coordinatorBatchlog && !enableCoordinatorBatchlog)
|
||||
if (!enableCoordinatorBatchlog && coordinatorBatchlog)
|
||||
return false;
|
||||
|
||||
for (IMutation mutation : mutations)
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ public class MappedBuffer implements Closeable
|
|||
|
||||
public void close()
|
||||
{
|
||||
if (!FileUtils.isCleanerAvailable())
|
||||
if (!FileUtils.isCleanerAvailable)
|
||||
return;
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ public class MetadataSerializer implements IMetadataSerializer
|
|||
out.flush();
|
||||
}
|
||||
// we cant move a file on top of another file in windows:
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
FileUtils.delete(descriptor.filenameFor(Component.STATS));
|
||||
FileUtils.renameWithConfirm(filePath, descriptor.filenameFor(Component.STATS));
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public final class FileUtils
|
|||
private static final double TB = 1024*1024*1024*1024d;
|
||||
|
||||
private static final DecimalFormat df = new DecimalFormat("#.##");
|
||||
private static final boolean canCleanDirectBuffers;
|
||||
public static final boolean isCleanerAvailable;
|
||||
private static final AtomicReference<Optional<FSErrorHandler>> fsErrorHandler = new AtomicReference<>(Optional.empty());
|
||||
|
||||
static
|
||||
|
|
@ -74,7 +74,7 @@ public final class FileUtils
|
|||
JVMStabilityInspector.inspectThrowable(t);
|
||||
logger.info("Cannot initialize un-mmaper. (Are you using a non-Oracle JVM?) Compacted data files will not be removed promptly. Consider using an Oracle JVM or using standard disk access mode");
|
||||
}
|
||||
canCleanDirectBuffers = canClean;
|
||||
isCleanerAvailable = canClean;
|
||||
}
|
||||
|
||||
public static void createHardLink(String from, String to)
|
||||
|
|
@ -334,16 +334,11 @@ public final class FileUtils
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean isCleanerAvailable()
|
||||
{
|
||||
return canCleanDirectBuffers;
|
||||
}
|
||||
|
||||
public static void clean(ByteBuffer buffer)
|
||||
{
|
||||
if (buffer == null)
|
||||
return;
|
||||
if (isCleanerAvailable() && buffer.isDirect())
|
||||
if (isCleanerAvailable && buffer.isDirect())
|
||||
{
|
||||
DirectBuffer db = (DirectBuffer) buffer;
|
||||
if (db.cleaner() != null)
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ public class MmappedRegions extends SharedCloseableImpl
|
|||
* If this fails (non Sun JVM), we'll have to wait for the GC to finalize the mapping.
|
||||
* If this works and a thread tries to access any segment, hell will unleash on earth.
|
||||
*/
|
||||
if (!FileUtils.isCleanerAvailable())
|
||||
if (!FileUtils.isCleanerAvailable)
|
||||
return accumulate;
|
||||
|
||||
return perform(accumulate, channel.filePath(), Throwables.FileOpType.READ,
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ public class RepairOption
|
|||
|
||||
public RepairOption(RepairParallelism parallelism, boolean primaryRange, boolean incremental, boolean trace, int jobThreads, Collection<Range<Token>> ranges, boolean isSubrangeRepair)
|
||||
{
|
||||
if (FBUtilities.isWindows() &&
|
||||
if (FBUtilities.isWindows &&
|
||||
(DatabaseDescriptor.getDiskAccessMode() != Config.DiskAccessMode.standard || DatabaseDescriptor.getIndexAccessMode() != Config.DiskAccessMode.standard) &&
|
||||
parallelism == RepairParallelism.SEQUENTIAL)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ public class CassandraDaemon
|
|||
FileUtils.setFSErrorHandler(new DefaultFSErrorHandler());
|
||||
|
||||
// Delete any failed snapshot deletions on Windows - see CASSANDRA-9658
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
WindowsFailedSnapshotTracker.deleteOldSnapshots();
|
||||
|
||||
ThreadAwareSecurityManager.install();
|
||||
|
|
@ -529,7 +529,7 @@ public class CassandraDaemon
|
|||
|
||||
// On windows, we need to stop the entire system as prunsrv doesn't have the jsvc hooks
|
||||
// We rely on the shutdown hook to drain the node
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
System.exit(0);
|
||||
|
||||
if (jmxServer != null)
|
||||
|
|
@ -581,7 +581,7 @@ public class CassandraDaemon
|
|||
//Allow the server to start even if the bean can't be registered
|
||||
}
|
||||
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
{
|
||||
// We need to adjust the system timer on windows from the default 15ms down to the minimum of 1ms as this
|
||||
// impacts timer intervals, thread scheduling, driver interrupts, etc.
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ public class StartupChecks
|
|||
{
|
||||
public void execute()
|
||||
{
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
return;
|
||||
String jemalloc = System.getProperty("cassandra.libjemalloc");
|
||||
if (jemalloc == null)
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
|
|||
private Collection<Token> bootstrapTokens = null;
|
||||
|
||||
// true when keeping strict consistency while bootstrapping
|
||||
private boolean useStrictConsistency = Boolean.parseBoolean(System.getProperty("cassandra.consistent.rangemovement", "true"));
|
||||
private static final boolean useStrictConsistency = Boolean.parseBoolean(System.getProperty("cassandra.consistent.rangemovement", "true"));
|
||||
private static final boolean allowSimultaneousMoves = Boolean.parseBoolean(System.getProperty("cassandra.consistent.simultaneousmoves.allow","false"));
|
||||
private boolean replacing;
|
||||
|
||||
|
|
@ -620,7 +620,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
|
|||
|
||||
CommitLog.instance.shutdownBlocking();
|
||||
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
WindowsTimer.endTimerPeriod(DatabaseDescriptor.getWindowsTimerInterval());
|
||||
|
||||
HintsService.instance.shutdownBlocking();
|
||||
|
|
@ -711,7 +711,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
|
|||
if (drainOnShutdown != null)
|
||||
Runtime.getRuntime().removeShutdownHook(drainOnShutdown);
|
||||
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
WindowsTimer.endTimerPeriod(DatabaseDescriptor.getWindowsTimerInterval());
|
||||
}
|
||||
|
||||
|
|
@ -1129,7 +1129,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
|
|||
null,
|
||||
FBUtilities.getBroadcastAddress(),
|
||||
"Rebuild",
|
||||
!replacing && useStrictConsistency,
|
||||
useStrictConsistency && !replacing,
|
||||
DatabaseDescriptor.getEndpointSnitch(),
|
||||
streamStateStore,
|
||||
false);
|
||||
|
|
@ -1376,7 +1376,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
|
|||
setMode(Mode.JOINING, "Starting to bootstrap...", true);
|
||||
BootStrapper bootstrapper = new BootStrapper(FBUtilities.getBroadcastAddress(), tokens, tokenMetadata);
|
||||
bootstrapper.addProgressListener(progressSupport);
|
||||
ListenableFuture<StreamState> bootstrapStream = bootstrapper.bootstrap(streamStateStore, !replacing && useStrictConsistency); // handles token update
|
||||
ListenableFuture<StreamState> bootstrapStream = bootstrapper.bootstrap(streamStateStore, useStrictConsistency && !replacing); // handles token update
|
||||
Futures.addCallback(bootstrapStream, new FutureCallback<StreamState>()
|
||||
{
|
||||
@Override
|
||||
|
|
@ -1415,7 +1415,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
|
|||
// already bootstrapped ranges are filtered during bootstrap
|
||||
BootStrapper bootstrapper = new BootStrapper(FBUtilities.getBroadcastAddress(), tokens, tokenMetadata);
|
||||
bootstrapper.addProgressListener(progressSupport);
|
||||
ListenableFuture<StreamState> bootstrapStream = bootstrapper.bootstrap(streamStateStore, !replacing && useStrictConsistency); // handles token update
|
||||
ListenableFuture<StreamState> bootstrapStream = bootstrapper.bootstrap(streamStateStore, useStrictConsistency && !replacing); // handles token update
|
||||
Futures.addCallback(bootstrapStream, new FutureCallback<StreamState>()
|
||||
{
|
||||
@Override
|
||||
|
|
@ -3155,7 +3155,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
|
|||
throw new IllegalArgumentException("Invalid parallelism degree specified: " + parallelismDegree);
|
||||
}
|
||||
RepairParallelism parallelism = RepairParallelism.values()[parallelismDegree];
|
||||
if (FBUtilities.isWindows() && parallelism != RepairParallelism.PARALLEL)
|
||||
if (FBUtilities.isWindows && parallelism != RepairParallelism.PARALLEL)
|
||||
{
|
||||
logger.warn("Snapshot-based repair is not yet supported on Windows. Reverting to parallel repair.");
|
||||
parallelism = RepairParallelism.PARALLEL;
|
||||
|
|
@ -3241,7 +3241,7 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
|
|||
throw new IllegalArgumentException("Invalid parallelism degree specified: " + parallelismDegree);
|
||||
}
|
||||
RepairParallelism parallelism = RepairParallelism.values()[parallelismDegree];
|
||||
if (FBUtilities.isWindows() && parallelism != RepairParallelism.PARALLEL)
|
||||
if (FBUtilities.isWindows && parallelism != RepairParallelism.PARALLEL)
|
||||
{
|
||||
logger.warn("Snapshot-based repair is not yet supported on Windows. Reverting to parallel repair.");
|
||||
parallelism = RepairParallelism.PARALLEL;
|
||||
|
|
|
|||
|
|
@ -74,8 +74,7 @@ public class FBUtilities
|
|||
private static final String DEFAULT_TRIGGER_DIR = "triggers";
|
||||
|
||||
private static final String OPERATING_SYSTEM = System.getProperty("os.name").toLowerCase();
|
||||
private static final boolean IS_WINDOWS = OPERATING_SYSTEM.contains("windows");
|
||||
private static final boolean HAS_PROCFS = !IS_WINDOWS && (new File(File.separator + "proc")).exists();
|
||||
public static final boolean isWindows = OPERATING_SYSTEM.contains("windows");
|
||||
|
||||
private static volatile InetAddress localInetAddress;
|
||||
private static volatile InetAddress broadcastInetAddress;
|
||||
|
|
@ -810,16 +809,6 @@ public class FBUtilities
|
|||
return historyDir;
|
||||
}
|
||||
|
||||
public static boolean isWindows()
|
||||
{
|
||||
return IS_WINDOWS;
|
||||
}
|
||||
|
||||
public static boolean hasProcFS()
|
||||
{
|
||||
return HAS_PROCFS;
|
||||
}
|
||||
|
||||
public static void updateWithShort(MessageDigest digest, int val)
|
||||
{
|
||||
digest.update((byte) ((val >> 8) & 0xFF));
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ public class SigarLibrary
|
|||
private boolean hasAcceptableAddressSpace()
|
||||
{
|
||||
// Check is invalid on Windows
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
return true;
|
||||
|
||||
try
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ public class ColumnFamilyStoreTest
|
|||
// We don't do snapshot-based repair on Windows so we don't have ephemeral snapshots from repair that need clearing.
|
||||
// This test will fail as we'll revert to the WindowsFailedSnapshotTracker and counts will be off, but since we
|
||||
// don't do snapshot-based repair on Windows, we just skip this test.
|
||||
Assume.assumeTrue(!FBUtilities.isWindows());
|
||||
Assume.assumeTrue(!FBUtilities.isWindows);
|
||||
|
||||
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_INDEX1);
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class SystemKeyspaceTest
|
|||
@BeforeClass
|
||||
public static void prepSnapshotTracker()
|
||||
{
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
WindowsFailedSnapshotTracker.deleteOldSnapshots();
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ public class SystemKeyspaceTest
|
|||
|
||||
private void assertDeletedOrDeferred(int expectedCount)
|
||||
{
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
assertEquals(expectedCount, getDeferredDeletionCount());
|
||||
else
|
||||
assertTrue(getSystemSnapshotFiles().isEmpty());
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class SnapshotDeletingTest
|
|||
@Test
|
||||
public void testCompactionHook() throws Exception
|
||||
{
|
||||
Assume.assumeTrue(FBUtilities.isWindows());
|
||||
Assume.assumeTrue(FBUtilities.isWindows);
|
||||
|
||||
Keyspace keyspace = Keyspace.open(KEYSPACE1);
|
||||
ColumnFamilyStore store = keyspace.getColumnFamilyStore(CF_STANDARD1);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class SSTableWriterTest extends SSTableWriterTestBase
|
|||
|
||||
// These checks don't work on Windows because the writer has the channel still
|
||||
// open till .abort() is called (via the builder)
|
||||
if (!FBUtilities.isWindows())
|
||||
if (!FBUtilities.isWindows)
|
||||
{
|
||||
LifecycleTransaction.waitForDeletions();
|
||||
assertFileCounts(dir.list());
|
||||
|
|
@ -128,7 +128,7 @@ public class SSTableWriterTest extends SSTableWriterTestBase
|
|||
sstable.selfRef().release();
|
||||
// These checks don't work on Windows because the writer has the channel still
|
||||
// open till .abort() is called (via the builder)
|
||||
if (!FBUtilities.isWindows())
|
||||
if (!FBUtilities.isWindows)
|
||||
{
|
||||
LifecycleTransaction.waitForDeletions();
|
||||
assertFileCounts(dir.list());
|
||||
|
|
@ -182,7 +182,7 @@ public class SSTableWriterTest extends SSTableWriterTestBase
|
|||
|
||||
// These checks don't work on Windows because the writer has the channel still
|
||||
// open till .abort() is called (via the builder)
|
||||
if (!FBUtilities.isWindows())
|
||||
if (!FBUtilities.isWindows)
|
||||
{
|
||||
LifecycleTransaction.waitForDeletions();
|
||||
assertFileCounts(dir.list());
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class SSTableWriterTestBase extends SchemaLoader
|
|||
@BeforeClass
|
||||
public static void defineSchema() throws ConfigurationException
|
||||
{
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
{
|
||||
standardMode = DatabaseDescriptor.getDiskAccessMode();
|
||||
indexMode = DatabaseDescriptor.getIndexAccessMode();
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class RepairOptionTest
|
|||
// parse with empty options
|
||||
RepairOption option = RepairOption.parse(new HashMap<String, String>(), partitioner);
|
||||
|
||||
if (FBUtilities.isWindows() && (DatabaseDescriptor.getDiskAccessMode() != Config.DiskAccessMode.standard || DatabaseDescriptor.getIndexAccessMode() != Config.DiskAccessMode.standard))
|
||||
if (FBUtilities.isWindows && (DatabaseDescriptor.getDiskAccessMode() != Config.DiskAccessMode.standard || DatabaseDescriptor.getIndexAccessMode() != Config.DiskAccessMode.standard))
|
||||
assertTrue(option.getParallelism() == RepairParallelism.PARALLEL);
|
||||
else
|
||||
assertTrue(option.getParallelism() == RepairParallelism.SEQUENTIAL);
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ public class StorageServiceServerTest
|
|||
@Test
|
||||
public void testSnapshotFailureHandler() throws IOException
|
||||
{
|
||||
assumeTrue(FBUtilities.isWindows());
|
||||
assumeTrue(FBUtilities.isWindows);
|
||||
|
||||
// Initial "run" of Cassandra, nothing in failed snapshot file
|
||||
WindowsFailedSnapshotTracker.deleteOldSnapshots();
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ public class NanoTimeToCurrentTimeMillisTest
|
|||
nowNanos = Math.max(nowNanos, System.nanoTime());
|
||||
long convertedNow = NanoTimeToCurrentTimeMillis.convert(nowNanos);
|
||||
|
||||
int maxDiff = FBUtilities.isWindows()? 15 : 1;
|
||||
int maxDiff = FBUtilities.isWindows ? 15 : 1;
|
||||
assertTrue("convertedNow = " + convertedNow + " lastConverted = " + lastConverted + " in iteration " + ii,
|
||||
convertedNow >= (lastConverted - maxDiff));
|
||||
|
||||
maxDiff = FBUtilities.isWindows()? 25 : 2;
|
||||
maxDiff = FBUtilities.isWindows ? 25 : 2;
|
||||
assertTrue("now = " + now + " convertedNow = " + convertedNow + " in iteration " + ii,
|
||||
(maxDiff - 2) <= convertedNow);
|
||||
|
||||
|
|
|
|||
|
|
@ -55,12 +55,12 @@ public final class Stress
|
|||
|
||||
public static void main(String[] arguments) throws Exception
|
||||
{
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
WindowsTimer.startTimerPeriod(1);
|
||||
|
||||
int exitCode = run(arguments);
|
||||
|
||||
if (FBUtilities.isWindows())
|
||||
if (FBUtilities.isWindows)
|
||||
WindowsTimer.endTimerPeriod(1);
|
||||
|
||||
System.exit(exitCode);
|
||||
|
|
|
|||
Loading…
Reference in New Issue