-
Notifications
You must be signed in to change notification settings - Fork 182
feat(import): add script tool for multiple hbase snapshot imports) #4606
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
Open
tianlei2
wants to merge
9
commits into
googleapis:main
Choose a base branch
from
tianlei2:add-snapshot-import-script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
26e20e4
feat(import): add support for multiple hbase snapshot imports
tianlei2 58cb66e
fix(import): add fork to compiler plugin and optimize GCS search in E…
tianlei2 66659a8
fix(import): format non-complying files for Google Java Style compliance
tianlei2 a1f9b04
fix(import): exclude hbase-shaded-client from mapreduce to prevent dn…
tianlei2 49c3e28
test(import): switch to mockito-inline and fix unit tests in ImportJo…
tianlei2 5ec8dc1
test(import): fix test isolation and timestamp parsing in SnapshotUti…
tianlei2 c85ce52
feat(import): add helper script to run dataflow snapshot import
tianlei2 958c187
feat(import): enhance helper script with range support and auto-paral…
tianlei2 af3976d
comment and file cleanup
tianlei2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
bigtable-dataflow-parent/bigtable-beam-import/run-snapshot-import.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This script runs a range of Dataflow snapshot import jobs sequentially. | ||
| # It should be executed from the 'bigtable-dataflow-parent/bigtable-beam-import' directory. | ||
| # | ||
| # Usage: ./run-snapshot-import.sh <start_shard> <end_shard> | ||
| # Or: ./run-snapshot-import.sh --all | ||
| # Example: ./run-snapshot-import.sh 0 3 | ||
| # Example: ./run-snapshot-import.sh --all | ||
| # | ||
| # You can override default configurations by setting environment variables in your terminal. | ||
| # Example: TABLE_NAME="my-table" SNAPSHOT_NAME="my-snap" ./run-snapshot-import.sh 0 3 | ||
| # | ||
| # NOTE: If you are running on a newer JDK (like Java 21 or 26) and hit ByteBuddy errors, | ||
| # you can add '-Dnet.bytebuddy.experimental=true' to the java command lines below. | ||
| # | ||
| # --- Manual Parallel Execution --- | ||
| # To run shards in parallel groups of 4 (assuming 20 shards total), you can run 5 instances of this script. | ||
| # | ||
| # IMPORTANT: Shard 0 performs the restore step. You MUST run the first group (including shard 0) | ||
| # first and let it complete the restore step before launching other groups in parallel, | ||
| # otherwise they will fail because the restored files won't exist yet! | ||
| # | ||
| # Example for manual parallel execution: | ||
| # ./run-snapshot-import.sh 0 3 & # Run this first! | ||
| # # Wait for shard 0 to finish restore, then run the rest: | ||
| # ./run-snapshot-import.sh 4 7 & | ||
| # ./run-snapshot-import.sh 8 11 & | ||
| # ./run-snapshot-import.sh 12 15 & | ||
| # ./run-snapshot-import.sh 16 19 & | ||
| # | ||
| # --- Automated Parallel Execution --- | ||
| # Alternatively, use the --all flag to automatically handle the restore step and launch all groups: | ||
| # ./run-snapshot-import.sh --all | ||
|
|
||
| if [ "$#" -ne 2 ] && [ "$1" != "--all" ]; then | ||
| echo "Usage: $0 <start_shard> <end_shard>" | ||
| echo " Or: $0 --all" | ||
| exit 1 | ||
| fi | ||
|
|
||
| START_SHARD=$1 | ||
| END_SHARD=$2 | ||
|
|
||
| # Configurations (Uses environment variables if set, otherwise defaults) | ||
| export PROJECT_ID="${PROJECT_ID:-google.com:cloud-bigtable-dev}" | ||
| export INSTANCE_ID="${INSTANCE_ID:-tianlei-test-inst}" | ||
| export BUCKET="${BUCKET:-tianlei-beam-test-bucket}" | ||
| export REGION="${REGION:-us-central1}" | ||
|
|
||
| export TABLE_NAME="${TABLE_NAME:-validation_test}" | ||
|
Member
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. where is the doc that shows what are available env variables and what is expected to be set there? |
||
| export SNAPSHOT_NAME="${SNAPSHOT_NAME:-validation_test_20200929}" | ||
| export SERVICE_ACCOUNT="${SERVICE_ACCOUNT:-295490517436-compute@developer.gserviceaccount.com}" | ||
|
|
||
| export NUM_SHARDS="${NUM_SHARDS:-20}" | ||
|
|
||
| export NETWORK="${NETWORK:-tianlei-network}" | ||
| export SUBNETWORK="${SUBNETWORK:-regions/us-central1/subnetworks/tianlei-network}" | ||
|
|
||
| JAR_PATH="target/bigtable-beam-import-2.17.0-shaded.jar" | ||
|
|
||
| # --- AUTO-PARALLEL MODE --- | ||
| if [ "$1" == "--all" ]; then | ||
| echo "🚀 Starting fully automated snapshot import..." | ||
|
|
||
| # Step 1: Perform ONLY the restore step | ||
| echo "Step 1/2: Performing snapshot restore (blocking)..." | ||
| java -jar ${JAR_PATH} importsnapshot \ | ||
| --runner=DataflowRunner \ | ||
| --project=${PROJECT_ID} \ | ||
| --bigtableInstanceId=${INSTANCE_ID} \ | ||
| --bigtableTableId=${TABLE_NAME} \ | ||
| --importConfigFilePath=import-config-test.json \ | ||
| --stagingLocation=gs://${BUCKET}/dataflow/staging \ | ||
| --tempLocation=gs://${BUCKET}/dataflow/temp \ | ||
| --region=${REGION} \ | ||
| --performOnlyRestoreStep=true \ | ||
| --jobName="restore-job" \ | ||
| --network=${NETWORK} \ | ||
| --subnetwork=${SUBNETWORK} | ||
|
|
||
| echo "Restore completed. Proceeding to data import." | ||
|
|
||
| # Step 2: Launch parallel groups of 4 | ||
| echo "Step 2/2: Launching parallel groups of 4 shards..." | ||
| SHARDS_PER_GROUP=4 | ||
|
|
||
| for (( start=0; start<$NUM_SHARDS; start+=$SHARDS_PER_GROUP )); do | ||
| end=$((start + SHARDS_PER_GROUP - 1)) | ||
| [ $end -ge $NUM_SHARDS ] && end=$((NUM_SHARDS - 1)) | ||
|
|
||
| echo "Launching group: shards $start to $end in background" | ||
| # Call ourselves with the range! | ||
| $0 $start $end & | ||
| done | ||
|
|
||
| echo "All groups launched. Waiting for all background jobs to finish..." | ||
| wait | ||
| echo "🎉 All import jobs completed!" | ||
| exit 0 | ||
| fi | ||
| # ---------------------------------------- | ||
|
|
||
| # Standard Range Mode | ||
| for i in $(seq $START_SHARD $END_SHARD); do | ||
| echo "Submitting Dataflow job for shardIndex: $i" | ||
|
|
||
| # We skip restore for all shards if running via --all because Step 1 handled it. | ||
| # If running manually via ranges, shard 0 will perform restore. | ||
| SKIP_RESTORE="true" | ||
| if [ $i -eq 0 ]; then | ||
| SKIP_RESTORE="false" | ||
| fi | ||
|
|
||
| JOB="job-${i}" | ||
| java -jar ${JAR_PATH} importsnapshot \ | ||
| --runner=DataflowRunner \ | ||
| --project=${PROJECT_ID} \ | ||
| --bigtableInstanceId=${INSTANCE_ID} \ | ||
| --bigtableTableId=${TABLE_NAME} \ | ||
| --importConfigFilePath=import-config-test.json \ | ||
| --stagingLocation=gs://${BUCKET}/dataflow/staging \ | ||
| --tempLocation=gs://${BUCKET}/dataflow/temp \ | ||
| --workerMachineType=n1-highmem-4 \ | ||
| --diskSizeGb=500 \ | ||
| --maxNumWorkers=10 \ | ||
| --region=${REGION} \ | ||
| --serviceAccount=${SERVICE_ACCOUNT} \ | ||
| --usePublicIps=false \ | ||
| --enableSnappy=true \ | ||
| --skipRestoreStep=${SKIP_RESTORE} \ | ||
| --numShards=${NUM_SHARDS} \ | ||
| --shardIndex=$i \ | ||
| --jobName="${JOB}" \ | ||
| --network=${NETWORK} \ | ||
| --subnetwork=${SUBNETWORK} | ||
|
|
||
| # Sequential within this script instance | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can't have defaults here.