mirror of https://github.com/apache/cassandra
Update SyncUtil for JDK11 and JDK17
Remove --add-opens java.base/java.nio=ALL-UNNAMED which is not needed anymore patch by Ekaterina Dimitrova; reviewed by Jacek Lewandowki for CASSANDRA-17909
This commit is contained in:
parent
5722191a38
commit
b92184e90c
|
|
@ -259,7 +259,6 @@
|
|||
|
||||
<string>--add-opens java.base/sun.nio.ch=ALL-UNNAMED</string>
|
||||
<string>--add-opens java.base/java.io=ALL-UNNAMED</string>
|
||||
<string>--add-opens java.base/java.nio=ALL-UNNAMED</string>
|
||||
<string>--add-opens java.base/java.util.concurrent=ALL-UNNAMED</string>
|
||||
<string>--add-opens java.base/java.util=ALL-UNNAMED</string>
|
||||
<string>--add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED</string>
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@
|
|||
# to be addressed in CASSANDRA-17850
|
||||
--add-opens java.base/sun.nio.ch=ALL-UNNAMED
|
||||
--add-opens java.base/java.io=ALL-UNNAMED
|
||||
--add-opens java.base/java.nio=ALL-UNNAMED
|
||||
# to be addressed during jamm maintenance
|
||||
--add-opens java.base/java.util.concurrent=ALL-UNNAMED
|
||||
--add-opens java.base/java.util=ALL-UNNAMED
|
||||
|
|
|
|||
|
|
@ -90,7 +90,6 @@
|
|||
--add-opens java.base/sun.nio.ch=ALL-UNNAMED
|
||||
# https://chronicle.software/chronicle-support-java-17/
|
||||
--add-opens java.base/java.io=ALL-UNNAMED
|
||||
--add-opens java.base/java.nio=ALL-UNNAMED
|
||||
#to be addressed during jamm maintenance
|
||||
--add-opens java.base/java.util.concurrent=ALL-UNNAMED
|
||||
--add-opens java.base/java.util=ALL-UNNAMED
|
||||
|
|
|
|||
|
|
@ -21,11 +21,9 @@
|
|||
package org.apache.cassandra.utils;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
|
|
@ -38,57 +36,17 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/*
|
||||
* A wrapper around various mechanisms for syncing files that makes it possible it intercept
|
||||
* A wrapper around various mechanisms for syncing files that makes it possible to intercept
|
||||
* and skip syncing. Useful for unit tests in certain environments where syncs can have outliers
|
||||
* bad enough to causes tests to run 10s of seconds longer.
|
||||
* bad enough to cause tests to run 10s of seconds longer.
|
||||
*/
|
||||
public class SyncUtil
|
||||
{
|
||||
public static final boolean SKIP_SYNC;
|
||||
|
||||
private static final Field mbbFDField;
|
||||
private static final Field fdClosedField;
|
||||
private static final Field fdUseCountField;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SyncUtil.class);
|
||||
|
||||
static
|
||||
{
|
||||
Field mbbFDFieldTemp = null;
|
||||
try
|
||||
{
|
||||
mbbFDFieldTemp = MappedByteBuffer.class.getDeclaredField("fd");
|
||||
mbbFDFieldTemp.setAccessible(true);
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
}
|
||||
mbbFDField = mbbFDFieldTemp;
|
||||
|
||||
//Java 8
|
||||
Field fdClosedFieldTemp = null;
|
||||
try
|
||||
{
|
||||
fdClosedFieldTemp = FileDescriptor.class.getDeclaredField("closed");
|
||||
fdClosedFieldTemp.setAccessible(true);
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
}
|
||||
fdClosedField = fdClosedFieldTemp;
|
||||
|
||||
//Java 7
|
||||
Field fdUseCountTemp = null;
|
||||
try
|
||||
{
|
||||
fdUseCountTemp = FileDescriptor.class.getDeclaredField("useCount");
|
||||
fdUseCountTemp.setAccessible(true);
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
}
|
||||
fdUseCountField = fdUseCountTemp;
|
||||
|
||||
//If skipping syncing is requested by any means then skip them.
|
||||
boolean skipSyncProperty = CassandraRelevantProperties.TEST_CASSANDRA_SKIP_SYNC.getBoolean();
|
||||
boolean skipSyncEnv = CassandraRelevantEnv.CASSANDRA_SKIP_SYNC.getBoolean();
|
||||
|
|
@ -110,21 +68,6 @@ public class SyncUtil
|
|||
}
|
||||
if (SKIP_SYNC)
|
||||
{
|
||||
Object fd = null;
|
||||
try
|
||||
{
|
||||
if (mbbFDField != null)
|
||||
{
|
||||
fd = mbbFDField.get(buf);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//This is what MappedByteBuffer.force() throws if a you call force() on an umapped buffer
|
||||
if (mbbFDField != null && fd == null)
|
||||
throw new UnsupportedOperationException();
|
||||
return buf;
|
||||
}
|
||||
else
|
||||
|
|
@ -132,40 +75,12 @@ public class SyncUtil
|
|||
return buf.force();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void sync(FileDescriptor fd) throws SyncFailedException
|
||||
{
|
||||
Preconditions.checkNotNull(fd);
|
||||
if (SKIP_SYNC)
|
||||
{
|
||||
boolean closed = false;
|
||||
try
|
||||
{
|
||||
if (fdClosedField != null)
|
||||
closed = fdClosedField.getBoolean(fd);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
int useCount = 1;
|
||||
try
|
||||
{
|
||||
if (fdUseCountField != null)
|
||||
useCount = ((AtomicInteger)fdUseCountField.get(fd)).get();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (closed || !fd.valid() || useCount < 0)
|
||||
throw new SyncFailedException("Closed " + closed + " valid " + fd.valid() + " useCount " + useCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!SKIP_SYNC)
|
||||
fd.sync();
|
||||
}
|
||||
}
|
||||
|
||||
public static void force(FileChannel fc, boolean metaData) throws IOException
|
||||
|
|
@ -192,8 +107,8 @@ public class SyncUtil
|
|||
{
|
||||
if (SKIP_SYNC)
|
||||
return;
|
||||
else
|
||||
NativeLibrary.trySync(fd);
|
||||
|
||||
NativeLibrary.trySync(fd);
|
||||
}
|
||||
|
||||
public static void trySyncDir(File dir)
|
||||
|
|
|
|||
Loading…
Reference in New Issue