Skip to content

Commit

Permalink
CASSANDRA-19285 Fix flaky Host replacement tests and shrink tests
Browse files Browse the repository at this point in the history
The flakiness is caused by inspecting a class whose classloader is already closed. The fix is to include the those classes in the sharedClassLoader, so that the classLoader is not closed during the test.

patch by Yifan Cai; reviewed by Francisco Guerrero for CASSANDRA-19285
  • Loading branch information
yifan-c committed Feb 13, 2024
1 parent d61e44f commit c3e8803
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.cassandra.sidecar.client.SidecarClient;
import org.apache.cassandra.sidecar.client.SidecarInstanceImpl;
import org.apache.cassandra.sidecar.client.request.ImportSSTableRequest;
import org.apache.cassandra.sidecar.common.data.MD5Digest;
import org.apache.cassandra.sidecar.common.data.SSTableImportResponse;
import org.apache.cassandra.spark.common.MD5Hash;
import org.apache.cassandra.spark.common.client.ClientException;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void uploadSSTableComponent(Path componentFile,
maybeQuotedIdentifier(bridge, conf.quoteIdentifiers, conf.table),
uploadId,
componentName,
fileHash.toString(),
new MD5Digest(fileHash.toString()),
componentFile.toAbsolutePath().toString())
.get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.sidecar.testing;

import java.util.function.Predicate;

import org.apache.cassandra.distributed.impl.AbstractCluster;

/**
* Predicate to instruct the JVM DTest framework on the classes should be loaded by the shared classloader.
*/
public class JvmDTestSharedClassesPredicate implements Predicate<String>
{
public static final JvmDTestSharedClassesPredicate INSTANCE = new JvmDTestSharedClassesPredicate();

private static final Predicate<String> EXTRA = className -> {
// Those classes can be reached by Spark SizeEstimator, when it estimates the broadcast variable.
// In the test scenario containing cassandra instance shutdown, there is a chance that it pick the class
// that is loaded by the closed instance classloader, causing the following exception.
// java.lang.IllegalStateException: Can't load <CLASS>. Instance class loader is already closed.
return className.equals("org.apache.cassandra.utils.concurrent.Ref$OnLeak")
|| className.startsWith("org.apache.cassandra.metrics.RestorableMeter");
};
private static final Predicate<String> DELEGATE = AbstractCluster.SHARED_PREDICATE.or(EXTRA);

@Override
public boolean test(String s)
{
return DELEGATE.test(s);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.cassandra.distributed.api.TokenSupplier;
import org.apache.cassandra.distributed.shared.ClusterUtils;
import org.apache.cassandra.distributed.shared.Versions;
import org.apache.cassandra.sidecar.testing.JvmDTestSharedClassesPredicate;

import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;

Expand Down Expand Up @@ -175,6 +176,7 @@ private BeforeEachCallback beforeEach()
.withVersion(requestedVersion)
.withDCs(dcCount)
.withDataDirCount(annotation.numDataDirsPerInstance())
.withSharedClasses(JvmDTestSharedClassesPredicate.INSTANCE)
.withConfig(config -> annotationToFeatureList(annotation).forEach(config::with));
TokenSupplier tokenSupplier = TokenSupplier.evenlyDistributedTokens(finalNodeCount,
clusterBuilder.getTokenCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.cassandra.distributed.api.TokenSupplier;
import org.apache.cassandra.distributed.shared.Uninterruptibles;
import org.apache.cassandra.distributed.shared.Versions;
import org.apache.cassandra.sidecar.testing.JvmDTestSharedClassesPredicate;
import org.apache.cassandra.sidecar.testing.QualifiedName;
import org.apache.cassandra.spark.bulkwriter.TTLOption;
import org.apache.cassandra.spark.bulkwriter.WriterOptions;
Expand Down Expand Up @@ -108,6 +109,7 @@ protected UpgradeableCluster provisionCluster(TestVersion testVersion) throws IO
.withVersion(requestedVersion)
.withDCs(1)
.withDataDirCount(1)
.withSharedClasses(JvmDTestSharedClassesPredicate.INSTANCE)
.withConfig(config -> config.with(Feature.NATIVE_PROTOCOL)
.with(Feature.GOSSIP)
.with(Feature.JMX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.cassandra.distributed.api.Feature;
import org.apache.cassandra.distributed.api.TokenSupplier;
import org.apache.cassandra.distributed.shared.Versions;
import org.apache.cassandra.sidecar.testing.JvmDTestSharedClassesPredicate;
import org.apache.cassandra.sidecar.testing.QualifiedName;
import org.apache.cassandra.testing.TestVersion;
import org.apache.spark.sql.Dataset;
Expand Down Expand Up @@ -119,6 +120,7 @@ protected UpgradeableCluster provisionCluster(TestVersion testVersion) throws IO
.withVersion(requestedVersion)
.withDCs(1)
.withDataDirCount(1)
.withSharedClasses(JvmDTestSharedClassesPredicate.INSTANCE)
.withConfig(config -> config.with(Feature.NATIVE_PROTOCOL)
.with(Feature.GOSSIP)
.with(Feature.JMX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.cassandra.distributed.api.Feature;
import org.apache.cassandra.distributed.api.TokenSupplier;
import org.apache.cassandra.distributed.shared.Versions;
import org.apache.cassandra.sidecar.testing.JvmDTestSharedClassesPredicate;
import org.apache.cassandra.sidecar.testing.QualifiedName;
import org.apache.cassandra.spark.bulkwriter.WriterOptions;
import org.apache.cassandra.testing.TestVersion;
Expand Down Expand Up @@ -143,6 +144,7 @@ protected UpgradeableCluster provisionCluster(TestVersion testVersion) throws IO
.withVersion(requestedVersion)
.withDCs(1)
.withDataDirCount(1)
.withSharedClasses(JvmDTestSharedClassesPredicate.INSTANCE)
.withConfig(config -> config.with(Feature.NATIVE_PROTOCOL)
.with(Feature.GOSSIP)
.with(Feature.JMX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.cassandra.distributed.api.TokenSupplier;
import org.apache.cassandra.distributed.impl.AbstractCluster;
import org.apache.cassandra.distributed.shared.Versions;
import org.apache.cassandra.sidecar.testing.JvmDTestSharedClassesPredicate;
import org.apache.cassandra.sidecar.testing.QualifiedName;
import org.apache.cassandra.spark.bulkwriter.DecoratedKey;
import org.apache.cassandra.spark.bulkwriter.Tokenizer;
Expand Down Expand Up @@ -97,7 +98,8 @@ public UpgradeableCluster clusterBuilder(ClusterBuilderConfiguration configurati
.withDCs(dcCount)
.withDataDirCount(configuration.numDataDirsPerInstance)
.withConfig(config -> configuration.features.forEach(config::with))
.withTokenSupplier(tokenSupplier);
.withTokenSupplier(tokenSupplier)
.withSharedClasses(JvmDTestSharedClassesPredicate.INSTANCE);

if (dcCount > 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.cassandra.distributed.shared.Uninterruptibles;
import org.apache.cassandra.distributed.shared.Versions;
import org.apache.cassandra.distributed.shared.WithProperties;
import org.apache.cassandra.sidecar.testing.JvmDTestSharedClassesPredicate;
import org.apache.cassandra.sidecar.testing.QualifiedName;
import org.apache.cassandra.testing.TestVersion;
import org.apache.spark.sql.DataFrameReader;
Expand Down Expand Up @@ -138,6 +139,7 @@ protected UpgradeableCluster provisionCluster(TestVersion testVersion) throws IO
.withVersion(requestedVersion)
.withDataDirCount(1)
.withDCs(1)
.withSharedClasses(JvmDTestSharedClassesPredicate.INSTANCE)
.withConfig(config -> config.with(Feature.NATIVE_PROTOCOL)
.with(Feature.GOSSIP)
.with(Feature.JMX));
Expand Down

0 comments on commit c3e8803

Please sign in to comment.