-
Notifications
You must be signed in to change notification settings - Fork 182
feat: Ability to import HBase Snapshot data into Cloud Bigtable using Dataflow #2755
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
32c1e6d
Support import from HBase snapshot
lichng 7d63490
Update document
lichng 6c0ed5e
Change the conf type for HBaseSnapshotInputConfiguration for
lichng fc728a8
Rename HBASE_ROOT_PATH to HBASE_EXPORT_ROOT_PATH in example doc for
lichng 316c0aa
Addressing the review comments:
lichng 6188efa
Add the original Main.java under sequencefiles back
lichng f621dc0
gcs connector still requires non-android guava version
lichng 68d88f4
Support import from HBase snapshot
lichng 53f73bc
Addressing the review comments:
lichng cfe86e2
switch HBasesnapshotConfiguration to a builder class
lichng f6cdabf
use DataflowRunner instead of DirectRunner for integration tests
lichng bf7409e
revert pom file override
lichng fa0d8a8
Remove all ValueProvider for now
lichng 1ca1fd8
Add gcsProject parameter and remove template related document
lichng f5b086f
recover the dependency missed in the rebase
lichng d0389c0
Update new files using latest header comment format and update year to
lichng 27e3657
Remove workaround for BIGTABLE_BULK_AUTOFLUSH_MS_KEY
lichng 0a5ced1
Exclude hbase-shaded-client
lichng 19b2a5c
Clean up all transitive depdendencies on hbase-shaded-client
lichng 61987c3
Add document for integration test generation instructions
lichng 77f528b
Update document
lichng 703fe6a
Fail the pipeline building when there is an exception configuring input
lichng 049cc43
renaming according to review comments
lichng 2f44f4d
update comments
lichng 39b003e
More document about hbase snapshot file structure
lichng d96cffb
System.out -> LOG
lichng ce4e2cf
throw out exception instead of terminating JVM
lichng fc6e1e4
Remove outside visible parameter restoreDir, use a default dir instead
lichng e871418
use pattern without ending '/'
lichng 6f15d81
use listObject instead of match since GcsUtil expand intentionally
lichng 5db7ce6
Using a unique suffix for restore dir to avoid conflict
lichng 87b0eff
Add dependency to pom.xml
lichng c967d17
minimize accessibility for class
lichng 59e7a55
Fix typo and Add header comment for CleanupHBaseSnapshotRestoreFilesFn
lichng 2596d88
Adding more error messages for HBaseSnapshotInputConfigBuilder
lichng 94270af
Add document about how to handle temp files during job failures
lichng 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
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
79 changes: 79 additions & 0 deletions
79
...taflow-parent/bigtable-beam-import/src/main/java/com/google/cloud/bigtable/beam/Main.java
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,79 @@ | ||
| /* | ||
| * Copyright 2021 Google LLC | ||
| * | ||
| * Licensed 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 com.google.cloud.bigtable.beam; | ||
|
igorbernstein2 marked this conversation as resolved.
|
||
|
|
||
| import com.google.bigtable.repackaged.com.google.api.core.InternalApi; | ||
| import com.google.bigtable.repackaged.com.google.api.core.InternalExtensionOnly; | ||
| import com.google.cloud.bigtable.beam.hbasesnapshots.ImportJobFromHbaseSnapshot; | ||
| import com.google.cloud.bigtable.beam.sequencefiles.CreateTableHelper; | ||
| import com.google.cloud.bigtable.beam.sequencefiles.ExportJob; | ||
| import com.google.cloud.bigtable.beam.sequencefiles.ImportJob; | ||
| import java.io.File; | ||
| import java.net.URISyntaxException; | ||
| import java.util.Arrays; | ||
|
|
||
| /** Entry point for create-table/import/export job submission. */ | ||
| @InternalExtensionOnly | ||
|
lichng marked this conversation as resolved.
|
||
| final class Main { | ||
| /** For internal use only - public for technical reasons. */ | ||
|
igorbernstein2 marked this conversation as resolved.
|
||
| @InternalApi("For internal usage only") | ||
| public Main() {} | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| if (args.length < 1) { | ||
| usage(); | ||
| System.exit(1); | ||
| } | ||
|
|
||
| String[] subArgs = Arrays.copyOfRange(args, 1, args.length); | ||
|
|
||
| switch (args[0]) { | ||
| case "export": | ||
| ExportJob.main(subArgs); | ||
| break; | ||
| case "import": | ||
| ImportJob.main(subArgs); | ||
| break; | ||
| case "importsnapshot": | ||
| ImportJobFromHbaseSnapshot.main(subArgs); | ||
| break; | ||
| case "create-table": | ||
| CreateTableHelper.main(subArgs); | ||
| break; | ||
| default: | ||
| usage(); | ||
| System.exit(1); | ||
| } | ||
| } | ||
|
|
||
| private static void usage() { | ||
| String jarName; | ||
|
lichng marked this conversation as resolved.
|
||
|
|
||
| try { | ||
| jarName = | ||
| new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()) | ||
| .getName(); | ||
| } catch (URISyntaxException e) { | ||
| jarName = "<jar>"; | ||
| } | ||
|
|
||
| System.out.printf( | ||
| "java -jar %s <action> <action_params>\n" | ||
| + "Where <action> can be 'export', 'import' , 'importsnapshot' or 'create-table'. To get further help, run: \n" | ||
| + "java -jar %s <action> --help\n", | ||
| jarName, jarName); | ||
| } | ||
| } | ||
84 changes: 84 additions & 0 deletions
84
...ava/com/google/cloud/bigtable/beam/hbasesnapshots/CleanupHBaseSnapshotRestoreFilesFn.java
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,84 @@ | ||
| /* | ||
| * Copyright 2021 Google LLC | ||
| * | ||
| * Licensed 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 com.google.cloud.bigtable.beam.hbasesnapshots; | ||
|
|
||
| import com.google.api.services.storage.model.Objects; | ||
| import com.google.common.base.Preconditions; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.apache.beam.sdk.extensions.gcp.options.GcpOptions; | ||
| import org.apache.beam.sdk.extensions.gcp.util.GcsUtil; | ||
| import org.apache.beam.sdk.extensions.gcp.util.gcsfs.GcsPath; | ||
| import org.apache.beam.sdk.transforms.DoFn; | ||
| import org.apache.beam.sdk.values.KV; | ||
| import org.apache.commons.logging.Log; | ||
| import org.apache.commons.logging.LogFactory; | ||
|
|
||
| /** | ||
| * A {@link DoFn} that could be used for cleaning up temp files generated during HBase snapshot | ||
| * scans in Google Cloud Storage(GCS) bucket via GCS connector. | ||
| */ | ||
| class CleanupHBaseSnapshotRestoreFilesFn extends DoFn<KV<String, String>, Boolean> { | ||
| private static final Log LOG = LogFactory.getLog(CleanupHBaseSnapshotRestoreFilesFn.class); | ||
|
|
||
| @ProcessElement | ||
| public void processElement(ProcessContext context) throws IOException { | ||
| KV<String, String> elem = context.element(); | ||
|
|
||
| String hbaseSnapshotDir = elem.getKey(); | ||
| String restorePath = elem.getValue(); | ||
| String prefix = getListPrefix(restorePath); | ||
| String bucketName = getWorkingBucketName(hbaseSnapshotDir); | ||
| Preconditions.checkState( | ||
| !prefix.isEmpty() && !hbaseSnapshotDir.contains(String.format("%s/%s", bucketName, prefix)), | ||
| "restore folder should not be empty or a subfolder of hbaseSnapshotSourceDir"); | ||
| GcpOptions gcpOptions = context.getPipelineOptions().as(GcpOptions.class); | ||
| GcsUtil gcsUtil = new GcsUtil.GcsUtilFactory().create(gcpOptions); | ||
|
|
||
| String pageToken = null; | ||
| List<String> results = new ArrayList<>(); | ||
| do { | ||
| Objects objects = gcsUtil.listObjects(bucketName, prefix, pageToken); | ||
| if (objects.getItems() == null) { | ||
| break; | ||
| } | ||
|
|
||
| objects.getItems().stream() | ||
| .map(storageObject -> GcsPath.fromObject(storageObject).toString()) | ||
| .forEach(results::add); | ||
| pageToken = objects.getNextPageToken(); | ||
| } while (pageToken != null); | ||
| gcsUtil.remove(results); | ||
| context.output(true); | ||
| } | ||
|
|
||
| public static String getWorkingBucketName(String hbaseSnapshotDir) { | ||
| Preconditions.checkArgument( | ||
| hbaseSnapshotDir.startsWith(GcsPath.SCHEME), | ||
| "snapshot folder must be hosted in a GCS bucket "); | ||
|
|
||
| return GcsPath.fromUri(hbaseSnapshotDir).getBucket(); | ||
| } | ||
| // getListPrefix convert absolute restorePath in a Hadoop filesystem | ||
| // to a match prefix in a GCS bucket | ||
| public static String getListPrefix(String restorePath) { | ||
| Preconditions.checkArgument( | ||
| restorePath.startsWith("/"), | ||
| "restore folder must be an absolute path in current filesystem"); | ||
| return restorePath.substring(1); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.