Skip to content
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

[improve](backup) Add config ignore_backup_tmp_partitions #45240

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,15 @@ public class Config extends ConfigBase {
@ConfField(mutable = true, masterOnly = true)
public static boolean ignore_backup_not_support_table_type = false;

/**
* whether to ignore temp partitions when backup, and not report exception.
*/
@ConfField(mutable = true, masterOnly = true, description = {
"是否忽略备份临时分区,不报异常",
"Whether to ignore temp partitions when backup, and not report exception."
})
public static boolean ignore_backup_tmp_partitions = false;

/**
* A internal config, to control the update interval of backup handler. Only used to speed up tests.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,14 @@ private void backup(Repository repository, Database db, BackupStmt stmt) throws
OlapTable olapTbl = (OlapTable) tbl;
tbl.readLock();
try {
if (olapTbl.existTempPartitions()) {
if (!Config.ignore_backup_tmp_partitions && olapTbl.existTempPartitions()) {
ErrorReport.reportDdlException(ErrorCode.ERR_COMMON_ERROR,
"Do not support backup table " + olapTbl.getName() + " with temp partitions");
}

PartitionNames partitionNames = tblRef.getPartitionNames();
if (partitionNames != null) {
if (partitionNames.isTemp()) {
if (!Config.ignore_backup_tmp_partitions && partitionNames.isTemp()) {
ErrorReport.reportDdlException(ErrorCode.ERR_COMMON_ERROR,
"Do not support backup temp partitions in table " + tblRef.getName());
}
Expand Down
15 changes: 10 additions & 5 deletions fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,15 @@ private void prepareSnapshotTaskForOlapTableWithoutLock(Database db, OlapTable o
// check backup table again
if (backupTableRef.getPartitionNames() != null) {
for (String partName : backupTableRef.getPartitionNames().getPartitionNames()) {
Partition partition = olapTable.getPartition(partName);
Partition partition = olapTable.getPartition(partName, false); // exclude tmp partitions
if (partition == null) {
status = new Status(ErrCode.NOT_FOUND, "partition " + partName
+ " does not exist in table" + backupTableRef.getName().getTbl());
if (olapTable.getPartition(partName, true) != null) {
status = new Status(ErrCode.NOT_FOUND, "backup tmp partition " + partName
+ " in table " + backupTableRef.getName().getTbl() + " is not supported");
} else {
status = new Status(ErrCode.NOT_FOUND, "partition " + partName
+ " does not exist in table " + backupTableRef.getName().getTbl());
}
return;
}
}
Expand All @@ -609,10 +614,10 @@ private void prepareSnapshotTaskForOlapTableWithoutLock(Database db, OlapTable o
// create snapshot tasks
List<Partition> partitions = Lists.newArrayList();
if (backupTableRef.getPartitionNames() == null) {
partitions.addAll(olapTable.getPartitions());
partitions.addAll(olapTable.getPartitions()); // no temp partitions in OlapTable.getPartitions()
} else {
for (String partName : backupTableRef.getPartitionNames().getPartitionNames()) {
Partition partition = olapTable.getPartition(partName);
Partition partition = olapTable.getPartition(partName, false); // exclude tmp partitions
partitions.add(partition);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,14 @@ public OlapTable selectiveCopy(Collection<String> reservedPartitions, IndexExtSt
}
}

if (isForBackup) {
// drop all tmp partitions in copied table
for (Partition partition : copied.tempPartitions.getAllPartitions()) {
copied.partitionInfo.dropPartition(partition.getId());
}
copied.tempPartitions = new TempPartitions();
}

if (reservedPartitions == null || reservedPartitions.isEmpty()) {
// reserve all
return copied;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ suite("test_backup_restore_backup_temp_partition", "backup_restore") {
ALTER TABLE ${dbName}.${tableName} ADD TEMPORARY PARTITION tp1 VALUES LESS THAN ("70")
"""

sql "ADMIN SET FRONTEND CONFIG ('ignore_backup_tmp_partitions' = 'false')"
test {
sql """
BACKUP SNAPSHOT ${dbName}.${snapshotName}
Expand All @@ -71,6 +72,39 @@ suite("test_backup_restore_backup_temp_partition", "backup_restore") {
exception "Do not support backup table ${tableName} with temp partitions"
}

// ignore the tmp partitions
sql "ADMIN SET FRONTEND CONFIG ('ignore_backup_tmp_partitions' = 'true')"
sql """
BACKUP SNAPSHOT ${dbName}.${snapshotName}
TO `${repoName}`
ON (${tableName})
"""

syncer.waitSnapshotFinish(dbName)
def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
assertTrue(snapshot != null)

// The restored table has no tmp partitions
sql "DROP TABLE IF EXISTS ${dbName}.${tableName}"

sql """
RESTORE SNAPSHOT ${dbName}.${snapshotName}
FROM `${repoName}`
ON (
`${tableName}` PARTITION (p1, p2, p3)
)
PROPERTIES
(
"backup_timestamp" = "${snapshot}",
"reserve_replica" = "true"
)
"""

syncer.waitAllRestoreFinish(dbName)
def res = sql "SHOW TEMPORARY PARTITIONS FROM ${dbName}.${tableName}"
assertTrue(res.size() == 0);

sql "ADMIN SET FRONTEND CONFIG ('ignore_backup_tmp_partitions' = 'false')"
sql "DROP TABLE ${dbName}.${tableName} FORCE"
sql "DROP DATABASE ${dbName} FORCE"
sql "DROP REPOSITORY `${repoName}`"
Expand Down
Loading