-
Notifications
You must be signed in to change notification settings - Fork 58
CASSSIDECAR-409 Add safety check to Live Migration data copy endpoint #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
683a8b9
83aed28
e19772c
637c096
71f4f54
5ca4962
9d3f51d
a445fa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * 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.livemigration; | ||
|
|
||
| import io.vertx.core.Future; | ||
| import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata; | ||
| import org.apache.cassandra.sidecar.common.request.LiveMigrationDataCopyRequest; | ||
|
|
||
| /** | ||
| * A pluggable pre-check hook that runs before each file download iteration in the live migration | ||
| * data copy process. Since the data copy involves deleting local files and downloading files from | ||
| * the source, implementations can perform safety validations (e.g., verifying cluster state via gossip, | ||
| * checking instance readiness) to prevent data corruption or unsafe operations. | ||
| * | ||
| * <p>The pre-check is invoked at the beginning of every download iteration (not just the first one), | ||
| * allowing implementations to continuously validate that conditions remain safe throughout the | ||
| * multi-iteration copy process.</p> | ||
| * | ||
| * <p>A {@link #DEFAULT} no-op implementation is provided for cases where no pre-check is needed. | ||
| * Custom implementations can be bound via Guice to override the default behavior.</p> | ||
| * | ||
| * <p>Example use cases:</p> | ||
| * <ul> | ||
| * <li>Gossip-based validation: verify the source node is present and the destination node | ||
| * is absent from cluster gossip, preventing data copy to a node that has already joined</li> | ||
|
Comment on lines
+40
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation does not exist
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This documentation is suggesting the kind of checks users can add (line: 35-38). But do not claim that they are implemented. |
||
| * <li>Instance state checks: verify the local Cassandra process is not running</li> | ||
| * <li>Disk space validation: ensure sufficient space before downloading</li> | ||
| * </ul> | ||
| * | ||
| * @see LiveMigrationFileDownloader#downloadFiles() | ||
| */ | ||
| public interface LiveMigrationFileDownloadPreCheck | ||
| { | ||
| /** | ||
| * Default no-op implementation that always succeeds. Used when no pre-check validation is required. | ||
| */ | ||
| LiveMigrationFileDownloadPreCheck DEFAULT = context -> Future.succeededFuture(); | ||
|
|
||
| /** | ||
| * Performs a safety check before a file download iteration begins. | ||
| * | ||
| * <p>Implementations should return a succeeded future if the check passes (it is safe to proceed), | ||
| * or a failed future with a descriptive exception if the check fails (download should be aborted).</p> | ||
| * | ||
| * @param context provides access to the source host, destination instance metadata, | ||
| * sidecar port, and the data copy request parameters needed for validation | ||
| * @return a succeeded {@link Future} if the pre-check passes, a failed {@link Future} otherwise | ||
| */ | ||
| Future<Void> doCheck(PreCheckContext context); | ||
|
|
||
| /** | ||
| * Encapsulates the contextual information available to a {@link LiveMigrationFileDownloadPreCheck} | ||
| * implementation. This context is populated by the {@link LiveMigrationFileDownloader} before each | ||
| * download iteration. | ||
| * | ||
| * <p>Provides access to:</p> | ||
| * <ul> | ||
| * <li>{@link #source()} - hostname of the source instance being copied from</li> | ||
| * <li>{@link #destinationInstanceMetadata()} - metadata of the local/destination instance, | ||
| * including host, data directories, and the Cassandra adapter delegate</li> | ||
| * <li>{@link #sidecarPort()} - port on which Sidecar is running, useful for making | ||
| * Sidecar API calls to other cluster instances</li> | ||
| * <li>{@link #request()} - the original data copy request containing task parameters</li> | ||
| * </ul> | ||
| */ | ||
| interface PreCheckContext | ||
| { | ||
| /** | ||
| * @return the hostname of the source instance from which files are being copied | ||
| */ | ||
| String source(); | ||
|
|
||
| /** | ||
| * @return the metadata for the destination (local) instance where files will be written | ||
| */ | ||
| InstanceMetadata destinationInstanceMetadata(); | ||
|
|
||
| /** | ||
| * @return the Sidecar service port, useful for contacting other Sidecar instances in the cluster | ||
| */ | ||
| int sidecarPort(); | ||
|
|
||
| /** | ||
| * @return the original data copy request containing task parameters such as max iterations, | ||
| * success threshold, and max concurrency | ||
| */ | ||
| LiveMigrationDataCopyRequest request(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is identical if you just throw the exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to return the future in both positive and negative scenarios because it seems simpler than throwing an exception, catching it elsewhere, and converting it to a failed future. I can change it if it makes a difference.