vanzin commented on a change in pull request #24499: [SPARK-27677][Core] Serve local disk persisted blocks by the external service after releasing executor by dynamic allocation URL: https://github.com/apache/spark/pull/24499#discussion_r285709291
########## File path: common/network-shuffle/src/test/java/org/apache/spark/network/shuffle/CleanupNonShuffleServiceServedFilesSuite.java ########## @@ -0,0 +1,256 @@ +/* + * 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.spark.network.shuffle; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; +import java.util.concurrent.Executor; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.util.concurrent.MoreExecutors; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.apache.spark.network.util.MapConfigProvider; +import org.apache.spark.network.util.TransportConf; + +public class CleanupNonShuffleServiceServedFilesSuite { + + // Same-thread Executor used to ensure cleanup happens synchronously in test thread. + private Executor sameThreadExecutor = MoreExecutors.sameThreadExecutor(); + + private static final String SORT_MANAGER = "org.apache.spark.shuffle.sort.SortShuffleManager"; + + private static Set<String> expectedShuffleFilesToKeep = + ImmutableSet.of("shuffle_782_450_0.index", "shuffle_782_450_0.data"); + + private static Set<String> expectedShuffleAndRddFilesToKeep = + ImmutableSet.of("shuffle_782_450_0.index", "shuffle_782_450_0.data", "rdd_12_34"); + + private TransportConf getConf(boolean isFetchRddEnabled) { + return new TransportConf( + "shuffle", + new MapConfigProvider(ImmutableMap.of( + "spark.shuffle.service.fetch.rdd.enabled", + Boolean.toString(isFetchRddEnabled)))); + } + + @Test + public void cleanupOnRemovedExecutorWithFilesToKeepFetchRddEnabled() throws IOException { + cleanupOnRemovedExecutor(true, getConf(true), expectedShuffleAndRddFilesToKeep); + } + + @Test + public void cleanupOnRemovedExecutorWithFilesToKeepFetchRddDisabled() throws IOException { + cleanupOnRemovedExecutor(true, getConf(false), expectedShuffleFilesToKeep); + } + + @Test + public void cleanupOnRemovedExecutorWithoutFilesToKeep() throws IOException { + cleanupOnRemovedExecutor(false, getConf(true), Collections.emptySet()); + } + + private void cleanupOnRemovedExecutor( + boolean withFilesToKeep, + TransportConf conf, + Set<String> expectedFilesKept) throws IOException { + TestShuffleDataContext dataContext = initDataContext(withFilesToKeep); + + ExternalShuffleBlockResolver resolver = + new ExternalShuffleBlockResolver(conf, null, sameThreadExecutor); + resolver.registerExecutor("app", "exec0", dataContext.createExecutorInfo(SORT_MANAGER)); + resolver.executorRemoved("exec0", "app"); + + assertContainedFilenames(dataContext, expectedFilesKept); + } + + @Test + public void cleanupUsesExecutorWithFilesToKeep() throws IOException { + cleanupUsesExecutor(true); + } + + @Test + public void cleanupUsesExecutorWithoutFilesToKeep() throws IOException { + cleanupUsesExecutor(false); + } + + private void cleanupUsesExecutor(boolean withFilesToKeep) throws IOException { + TestShuffleDataContext dataContext = initDataContext(withFilesToKeep); + + AtomicBoolean cleanupCalled = new AtomicBoolean(false); + + // Executor which does nothing to ensure we're actually using it. Review comment: Comment sounds weird. "Executor which only captures whether it's being used, without executing anything." ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org