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.master.cleaner; 019 020import java.util.Map; 021import org.apache.hadoop.conf.Configurable; 022import org.apache.hadoop.fs.FileStatus; 023import org.apache.hadoop.fs.Path; 024import org.apache.hadoop.hbase.Stoppable; 025import org.apache.yetus.audience.InterfaceAudience; 026 027/** 028 * General interface for cleaning files from a folder (generally an archive or backup folder). These 029 * are chained via the {@link CleanerChore} to determine if a given file should be deleted. 030 */ 031@InterfaceAudience.Private 032public interface FileCleanerDelegate extends Configurable, Stoppable { 033 034 /** 035 * Determines which of the given files are safe to delete 036 * <p> 037 * This method can be called concurrently by multiple threads. Implementations must be thread 038 * safe. 039 * </p> 040 * @param files files to check for deletion 041 * @return files that are ok to delete according to this cleaner 042 */ 043 Iterable<FileStatus> getDeletableFiles(Iterable<FileStatus> files); 044 045 /** 046 * this method is used to pass some instance into subclass 047 */ 048 void init(Map<String, Object> params); 049 050 /** 051 * Used to do some initialize work before every period clean 052 */ 053 default void preClean() { 054 } 055 056 /** 057 * Will be called after cleaner run. 058 */ 059 default void postClean() { 060 } 061 062 /** 063 * Check if a empty directory with no subdirs or subfiles can be deleted 064 * @param dir Path of the directory 065 * @return True if the directory can be deleted, otherwise false 066 */ 067 default boolean isEmptyDirDeletable(Path dir) { 068 return true; 069 } 070}