Skip to content

Commit

Permalink
Time the runtime of Drain and DrainOnShutdown (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuffy authored Nov 12, 2024
1 parent e6c5da9 commit eea1112
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/java/org/apache/cassandra/service/StorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Stopwatch;
import com.google.common.collect.*;
import com.google.common.util.concurrent.*;
import com.palantir.cassandra.db.BootstrappingSafetyException;
Expand Down Expand Up @@ -704,6 +705,9 @@ public synchronized void initServer(int delay) throws ConfigurationException
@Override
public void runMayThrow() throws InterruptedException
{
Stopwatch watch = Stopwatch.createStarted();
logger.info("Executing drainOnShutdown hook");

inShutdownHook = true;
ExecutorService counterMutationStage = StageManager.getStage(Stage.COUNTER_MUTATION);
ExecutorService mutationStage = StageManager.getStage(Stage.MUTATION);
Expand Down Expand Up @@ -754,6 +758,8 @@ public void runMayThrow() throws InterruptedException
ScheduledExecutors.nonPeriodicTasks.shutdown();
if (!ScheduledExecutors.nonPeriodicTasks.awaitTermination(1, MINUTES))
logger.warn("Miscellaneous task executor still busy after one minute; proceeding with shutdown");

logger.info("DrainOnShutdown completed in {} ms", SafeArg.of("ms", watch.elapsed(TimeUnit.MILLISECONDS)));
}
}, "StorageServiceShutdownHook");
Runtime.getRuntime().addShutdownHook(drainOnShutdown);
Expand Down Expand Up @@ -4602,6 +4608,8 @@ public String getDrainProgress()
*/
public synchronized void drain() throws IOException, InterruptedException, ExecutionException
{
Stopwatch watch = Stopwatch.createStarted();

inShutdownHook = true;

ExecutorService counterMutationStage = StageManager.getStage(Stage.COUNTER_MUTATION);
Expand Down Expand Up @@ -4689,6 +4697,8 @@ public synchronized void drain() throws IOException, InterruptedException, Execu
ColumnFamilyStore.shutdownPostFlushExecutor();

setMode(Mode.DRAINED, true);

logger.info("Drain completed in {} ms", SafeArg.of("ms", watch.elapsed(TimeUnit.MILLISECONDS)));
}

// Never ever do this at home. Used by tests.
Expand Down

0 comments on commit eea1112

Please sign in to comment.