-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-29003 Proper bulk load tracking #6506
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
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
116 changes: 116 additions & 0 deletions
116
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/BackupMasterObserver.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,116 @@ | ||
| /* | ||
| * 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.hadoop.hbase.backup; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Collectors; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hbase.HBaseInterfaceAudience; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.backup.impl.BackupManager; | ||
| import org.apache.hadoop.hbase.backup.impl.BackupSystemTable; | ||
| import org.apache.hadoop.hbase.backup.impl.BulkLoad; | ||
| import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; | ||
| import org.apache.hadoop.hbase.client.Connection; | ||
| import org.apache.hadoop.hbase.client.ConnectionFactory; | ||
| import org.apache.hadoop.hbase.client.TableDescriptor; | ||
| import org.apache.hadoop.hbase.coprocessor.MasterCoprocessor; | ||
| import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment; | ||
| import org.apache.hadoop.hbase.coprocessor.MasterObserver; | ||
| import org.apache.hadoop.hbase.coprocessor.ObserverContext; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import org.apache.hbase.thirdparty.com.google.common.collect.Sets; | ||
|
|
||
| /** | ||
| * An Observer to facilitate backup operations | ||
| */ | ||
| @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG) | ||
| public class BackupMasterObserver implements MasterCoprocessor, MasterObserver { | ||
| private static final Logger LOG = LoggerFactory.getLogger(BackupMasterObserver.class); | ||
|
|
||
| @Override | ||
| public Optional<MasterObserver> getMasterObserver() { | ||
| return Optional.of(this); | ||
| } | ||
|
|
||
| @Override | ||
| public void postDeleteTable(ObserverContext<MasterCoprocessorEnvironment> ctx, | ||
| TableName tableName) throws IOException { | ||
| Configuration cfg = ctx.getEnvironment().getConfiguration(); | ||
| if (!BackupManager.isBackupEnabled(cfg)) { | ||
| LOG.debug("Skipping postDeleteTable hook since backup is disabled"); | ||
| return; | ||
| } | ||
| deleteBulkLoads(cfg, tableName, (ignored) -> true); | ||
| } | ||
|
|
||
| @Override | ||
| public void postTruncateTable(ObserverContext<MasterCoprocessorEnvironment> ctx, | ||
| TableName tableName) throws IOException { | ||
| Configuration cfg = ctx.getEnvironment().getConfiguration(); | ||
| if (!BackupManager.isBackupEnabled(cfg)) { | ||
| LOG.debug("Skipping postTruncateTable hook since backup is disabled"); | ||
| return; | ||
| } | ||
| deleteBulkLoads(cfg, tableName, (ignored) -> true); | ||
| } | ||
|
|
||
| @Override | ||
| public void postModifyTable(final ObserverContext<MasterCoprocessorEnvironment> ctx, | ||
| final TableName tableName, TableDescriptor oldDescriptor, TableDescriptor currentDescriptor) | ||
| throws IOException { | ||
| Configuration cfg = ctx.getEnvironment().getConfiguration(); | ||
| if (!BackupManager.isBackupEnabled(cfg)) { | ||
| LOG.debug("Skipping postModifyTable hook since backup is disabled"); | ||
| return; | ||
| } | ||
|
|
||
| Set<String> oldFamilies = Arrays.stream(oldDescriptor.getColumnFamilies()) | ||
| .map(ColumnFamilyDescriptor::getNameAsString).collect(Collectors.toSet()); | ||
| Set<String> newFamilies = Arrays.stream(currentDescriptor.getColumnFamilies()) | ||
| .map(ColumnFamilyDescriptor::getNameAsString).collect(Collectors.toSet()); | ||
|
|
||
| Set<String> removedFamilies = Sets.difference(oldFamilies, newFamilies); | ||
| if (!removedFamilies.isEmpty()) { | ||
| Predicate<BulkLoad> filter = bulkload -> removedFamilies.contains(bulkload.getColumnFamily()); | ||
| deleteBulkLoads(cfg, tableName, filter); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Deletes all bulk load entries for the given table, matching the provided predicate. | ||
| */ | ||
| private void deleteBulkLoads(Configuration config, TableName tableName, | ||
| Predicate<BulkLoad> filter) throws IOException { | ||
| try (Connection connection = ConnectionFactory.createConnection(config); | ||
| BackupSystemTable tbl = new BackupSystemTable(connection)) { | ||
| List<BulkLoad> bulkLoads = tbl.readBulkloadRows(List.of(tableName)); | ||
| List<byte[]> rowsToDelete = | ||
| bulkLoads.stream().filter(filter).map(BulkLoad::getRowKey).toList(); | ||
| tbl.deleteBulkLoadedRows(rowsToDelete); | ||
| } | ||
| } | ||
| } |
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
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.
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.
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.
At my company, we have a similar patch applied to our fork, and we've run into issues with batch sizes that causes backup failures. This seems to happen when there are too many rows to delete, you end up with something like
It might be worth splitting up this call to delete if they are exceptionally large
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.
@hgromer do you feel that splitting up the delete is required for this patch?
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.
@DieterDP-ng any concerns about making this change?
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 might be worth splitting this up. Introducing this means we can get into a situation where backups are unable to succeed.
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.
No objection to splitting it. Updating the PR...
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.
Rather than doing batching here, I did it at
BackupSystemTable.deleteBulkLoadedRows, since that method is used in multiple locations, and I guess they would all benefit from batching. See added commit (can be squashed).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.
(For future reference: turned out batching was already built-in, see #6506 (comment))