This is an automated email from the ASF dual-hosted git repository. benedict pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit cedde3d991da48039caee2afb421c737777267f0 Merge: 6329229 07b908c Author: Benedict Elliott Smith <[email protected]> AuthorDate: Wed Nov 10 11:13:52 2021 +0000 Merge branch 'cassandra-4.0' into trunk build.xml | 2 +- .../distributed/impl/AbstractCluster.java | 9 +++++-- .../distributed/impl/IsolatedExecutor.java | 29 +++++++++++++--------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --cc build.xml index b8eabb8,60a6b7d..085211a --- a/build.xml +++ b/build.xml @@@ -532,9 -531,8 +532,9 @@@ <dependency groupId="com.google.code.java-allocation-instrumenter" artifactId="java-allocation-instrumenter" version="${allocation-instrumenter.version}" scope="test"> <exclusion groupId="com.google.guava" artifactId="guava"/> </dependency> - <dependency groupId="org.apache.cassandra" artifactId="dtest-api" version="0.0.10" scope="test"/> + <dependency groupId="org.apache.cassandra" artifactId="dtest-api" version="0.0.11" scope="test"/> <dependency groupId="org.reflections" artifactId="reflections" version="0.9.12" scope="test"/> + <dependency groupId="com.puppycrawl.tools" artifactId="checkstyle" version="8.40" scope="test"/> <dependency groupId="org.apache.hadoop" artifactId="hadoop-core" version="1.0.3" scope="provided"> <exclusion groupId="org.mortbay.jetty" artifactId="servlet-api"/> <exclusion groupId="commons-logging" artifactId="commons-logging"/> diff --cc test/distributed/org/apache/cassandra/distributed/impl/AbstractCluster.java index be49daa,240f080..1cb7c13 --- a/test/distributed/org/apache/cassandra/distributed/impl/AbstractCluster.java +++ b/test/distributed/org/apache/cassandra/distributed/impl/AbstractCluster.java @@@ -18,14 -18,9 +18,15 @@@ package org.apache.cassandra.distributed.impl; -import java.io.File; import java.lang.annotation.Annotation; +import java.lang.reflect.Field; ++import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.net.InetSocketAddress; +import java.nio.file.FileSystem; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@@ -231,33 -212,11 +232,37 @@@ public abstract class AbstractCluster< private IInvokableInstance newInstance(int generation) { - ClassLoader classLoader = new InstanceClassLoader(generation, config.num(), version.classpath, sharedClassLoader, SHARED_PREDICATE); + ClassLoader classLoader = new InstanceClassLoader(generation, config.num(), version.classpath, sharedClassLoader, sharedClassPredicate, classTransformer); + ThreadGroup threadGroup = new ThreadGroup(clusterThreadGroup, "node" + config.num() + (generation > 1 ? "_" + generation : "")); if (instanceInitializer != null) - instanceInitializer.accept(classLoader, config.num()); - return Instance.transferAdhoc((SerializableBiFunction<IInstanceConfig, ClassLoader, Instance>)Instance::new, classLoader) - .apply(config.forVersion(version.version), classLoader); + instanceInitializer.initialise(classLoader, threadGroup, config.num(), generation); + + IInvokableInstance instance; + try + { - instance = Instance.transferAdhoc((SerializableTriFunction<IInstanceConfig, ClassLoader, FileSystem, Instance>)Instance::new, classLoader) ++ instance = Instance.transferAdhocPropagate((SerializableTriFunction<IInstanceConfig, ClassLoader, FileSystem, Instance>)Instance::new, classLoader) + .apply(config.forVersion(version.version), classLoader, root.getFileSystem()); + } - catch (NoSuchMethodError e) ++ catch (InvocationTargetException e) + { + instance = Instance.transferAdhoc((SerializableBiFunction<IInstanceConfig, ClassLoader, Instance>)Instance::new, classLoader) + .apply(config.forVersion(version.version), classLoader); + } ++ catch (IllegalAccessException e) ++ { ++ throw new RuntimeException(e); ++ } + + if (instanceInitializer != null) + instanceInitializer.beforeStartup(instance); + + return instance; + } + + public Executor executorFor(int verb) + { + // this method must be lock-free to avoid Simulator deadlock + return delegate().executorFor(verb); } public IInstanceConfig config() diff --cc test/distributed/org/apache/cassandra/distributed/impl/IsolatedExecutor.java index 2779110,dd52b5d..38151be --- a/test/distributed/org/apache/cassandra/distributed/impl/IsolatedExecutor.java +++ b/test/distributed/org/apache/cassandra/distributed/impl/IsolatedExecutor.java @@@ -159,52 -136,33 +159,57 @@@ public class IsolatedExecutor implement public <I1, I2, I3, I4, I5, O> QuintFunction<I1, I2, I3, I4, I5, Future<O>> async(QuintFunction<I1, I2, I3, I4, I5, O> f) { return (a, b, c, d, e) -> isolatedExecutor.submit(() -> f.apply(a, b, c, d, e)); } public <I1, I2, I3, I4, I5, O> QuintFunction<I1, I2, I3, I4, I5, O> sync(QuintFunction<I1, I2, I3, I4, I5, O> f) { return (a, b, c, d,e ) -> waitOn(async(f).apply(a, b, c, d, e)); } - public <E extends Serializable> E transfer(E object) + public Executor executor() { - return (E) transferOneObject(object, classLoader, deserializeOnInstance); + return isolatedExecutor; } - static <E extends Serializable> E transferAdhoc(E object, ClassLoader classLoader) + public <T extends Serializable> T transfer(T in) { - return transferOneObject(object, classLoader, lookupDeserializeOneObject(classLoader)); + return transfer.apply(in); } - private static <E extends Serializable> E transferOneObject(E object, ClassLoader classLoader, Method deserializeOnInstance) + public static <T extends Serializable> T transferAdhoc(T object, ClassLoader classLoader) { - byte[] bytes = serializeOneObject(object); + try + { - Object onInstance = deserializeOnInstance.invoke(null, bytes); - if (onInstance.getClass().getClassLoader() != classLoader) - throw new IllegalStateException(onInstance + " seemingly from wrong class loader: " + onInstance.getClass().getClassLoader() + ", but expected " + classLoader); - - return (E) onInstance; ++ return transferOneObjectAdhoc(object, classLoader, lookupDeserializeOneObject(classLoader)); + } + catch (IllegalAccessException | InvocationTargetException e) + { - throw new RuntimeException("Error while transfering object to " + classLoader, e); ++ throw new RuntimeException(e); + } + } + ++ public static <T extends Serializable> T transferAdhocPropagate(T object, ClassLoader classLoader) throws InvocationTargetException, IllegalAccessException ++ { + return transferOneObjectAdhoc(object, classLoader, lookupDeserializeOneObject(classLoader)); + } + + private static final SerializableFunction<byte[], Object> DESERIALIZE_ONE_OBJECT = IsolatedExecutor::deserializeOneObject; + + public static DynamicFunction<Serializable> transferTo(ClassLoader classLoader) + { + SerializableFunction<byte[], Object> deserializeOneObject = transferAdhoc(DESERIALIZE_ONE_OBJECT, classLoader); + return new DynamicFunction<Serializable>() + { + public <T extends Serializable> T apply(T in) + { + return (T) deserializeOneObject.apply(serializeOneObject(in)); + } + }; + } + - private static <T extends Serializable> T transferOneObjectAdhoc(T object, ClassLoader classLoader, Method deserializeOnInstance) ++ private static <T extends Serializable> T transferOneObjectAdhoc(T object, ClassLoader classLoader, Method deserializeOnInstance) throws IllegalAccessException, InvocationTargetException + { + byte[] bytes = serializeOneObject(object); - try - { - Object onInstance = deserializeOnInstance.invoke(null, bytes); - if (onInstance.getClass().getClassLoader() != classLoader) - throw new IllegalStateException(onInstance + " seemingly from wrong class loader: " + onInstance.getClass().getClassLoader() + ", but expected " + classLoader); ++ Object onInstance = deserializeOnInstance.invoke(null, bytes); ++ if (onInstance.getClass().getClassLoader() != classLoader) ++ throw new IllegalStateException(onInstance + " seemingly from wrong class loader: " + onInstance.getClass().getClassLoader() + ", but expected " + classLoader); + - return (T) onInstance; - } - catch (IllegalAccessException | InvocationTargetException e) - { - throw new RuntimeException(e); - } ++ return (T) onInstance; + } + private static Method lookupDeserializeOneObject(ClassLoader classLoader) { try --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
