001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.backup; 019 020import static org.apache.hadoop.hbase.backup.TestBackupUtils.assertBackupCompleteFileDoesNotExist; 021import static org.junit.jupiter.api.Assertions.assertTrue; 022 023import java.io.IOException; 024import java.util.List; 025import org.apache.hadoop.conf.Configuration; 026import org.apache.hadoop.fs.FSDataOutputStream; 027import org.apache.hadoop.fs.FileSystem; 028import org.apache.hadoop.fs.FilterFileSystem; 029import org.apache.hadoop.fs.Path; 030import org.apache.hadoop.hbase.backup.impl.FullTableBackupClient; 031import org.apache.hadoop.hbase.backup.impl.TableBackupClient; 032import org.apache.hadoop.hbase.client.Connection; 033import org.apache.hadoop.hbase.testclassification.LargeTests; 034import org.apache.hadoop.hdfs.DistributedFileSystem; 035import org.junit.jupiter.api.Tag; 036import org.junit.jupiter.api.Test; 037import org.slf4j.Logger; 038import org.slf4j.LoggerFactory; 039 040@Tag(LargeTests.TAG) 041public class TestFullBackupMarkerFailure extends TestBackupBase { 042 043 private static final Logger LOG = LoggerFactory.getLogger(TestFullBackupMarkerFailure.class); 044 045 @Test 046 public void testFullBackupSucceedsWhenMarkerWriteFails() throws Exception { 047 // Use a special backup class that will force a failure when trying to write the 048 // .backup.complete marker file 049 conf1.set(TableBackupClient.BACKUP_CLIENT_IMPL_CLASS, 050 FullTableBackupClientWithMarkerFailure.class.getName()); 051 052 try { 053 String backupId = fullTableBackup(List.of(table1)); 054 055 // The backup should still succeed despite failure to write the .backup.complete marker file 056 assertTrue(checkSucceeded(backupId)); 057 assertBackupCompleteFileDoesNotExist(conf1, BACKUP_ROOT_DIR, backupId); 058 } finally { 059 conf1.unset(TableBackupClient.BACKUP_CLIENT_IMPL_CLASS); 060 } 061 } 062 063 // This class is used run the full backup. It is a special class that contains some overrides 064 // that will force a failure when writing the .backup.complete marker file 065 static class FullTableBackupClientWithMarkerFailure extends FullTableBackupClient { 066 public FullTableBackupClientWithMarkerFailure() { 067 } 068 069 @Override 070 protected void completeBackup(Connection conn, BackupInfo backupInfo, BackupType type, 071 Configuration conf) throws IOException { 072 Configuration markerFailConf = new Configuration(conf); 073 markerFailConf.setClass("fs.hdfs.impl", MarkerCreationFailHDFS.class, FileSystem.class); 074 markerFailConf.setBoolean("fs.hdfs.impl.disable.cache", true); 075 super.completeBackup(conn, backupInfo, type, markerFailConf); 076 } 077 } 078 079 public static class MarkerCreationFailHDFS extends FilterFileSystem { 080 public MarkerCreationFailHDFS() { 081 super(new DistributedFileSystem()); 082 } 083 084 @Override 085 public FSDataOutputStream create(Path f, boolean overwrite) throws IOException { 086 if (f.getName().equals(HBackupFileSystem.BACKUP_COMPLETE_FILE_NAME)) { 087 throw new IOException("Injected failure for marker creation test"); 088 } 089 return super.create(f, overwrite); 090 } 091 } 092}