-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-26271: Cleanup the broken store files under data directory #3786
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
8 commits
Select commit
Hold shift + click to select a range
15681eb
HBASE-26079 Use StoreFileTracker when splitting and merging (#3617)
wchevreuil 4fa03c3
HBASE-26264 Add more checks to prevent misconfiguration on store file…
Apache9 b047f09
HBASE-26271: Cleanup the broken store files under data directory
BukrosSzabolcs 2f5cd86
HBASE-26271: Cleanup the broken store files under data directory
BukrosSzabolcs 9608c7f
HBASE-26271: Cleanup the broken store files under data directory
BukrosSzabolcs 956f74e
HBASE-26271: Cleanup the broken store files under data directory
BukrosSzabolcs ae0fa65
HBASE-26271: Cleanup the broken store files under data directory
BukrosSzabolcs ed0e58d
HBASE-26271: Cleanup the broken store files under data directory
BukrosSzabolcs 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
202 changes: 202 additions & 0 deletions
202
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/BrokenStoreFileCleaner.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,202 @@ | ||
/** | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.regionserver; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileStatus; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.hbase.ScheduledChore; | ||
import org.apache.hadoop.hbase.Stoppable; | ||
import org.apache.hadoop.hbase.io.HFileLink; | ||
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; | ||
import org.apache.hadoop.ipc.RemoteException; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This Chore, every time it runs, will clear the unsused HFiles in the data | ||
* folder. | ||
*/ | ||
@InterfaceAudience.Private | ||
public class BrokenStoreFileCleaner extends ScheduledChore { | ||
private static final Logger LOG = LoggerFactory.getLogger(BrokenStoreFileCleaner.class); | ||
public static final String BROKEN_STOREFILE_CLEANER_ENABLED = | ||
"hbase.region.broken.storefilecleaner.enabled"; | ||
public static final boolean DEFAULT_BROKEN_STOREFILE_CLEANER_ENABLED = false; | ||
public static final String BROKEN_STOREFILE_CLEANER_TTL = | ||
"hbase.region.broken.storefilecleaner.ttl"; | ||
public static final long DEFAULT_BROKEN_STOREFILE_CLEANER_TTL = 1000 * 60 * 60 * 12; //12h | ||
public static final String BROKEN_STOREFILE_CLEANER_DELAY = | ||
"hbase.region.broken.storefilecleaner.delay"; | ||
public static final int DEFAULT_BROKEN_STOREFILE_CLEANER_DELAY = 1000 * 60 * 60 * 2; //2h | ||
public static final String BROKEN_STOREFILE_CLEANER_DELAY_JITTER = | ||
"hbase.region.broken.storefilecleaner.delay.jitter"; | ||
public static final double DEFAULT_BROKEN_STOREFILE_CLEANER_DELAY_JITTER = 0.25D; | ||
public static final String BROKEN_STOREFILE_CLEANER_PERIOD = | ||
"hbase.region.broken.storefilecleaner.period"; | ||
public static final int DEFAULT_BROKEN_STOREFILE_CLEANER_PERIOD = 1000 * 60 * 60 * 6; //6h | ||
|
||
private HRegionServer regionServer; | ||
private final AtomicBoolean enabled = new AtomicBoolean(true); | ||
private long fileTtl; | ||
|
||
public BrokenStoreFileCleaner(final int delay, final int period, final Stoppable stopper, | ||
Configuration conf, HRegionServer regionServer) { | ||
super("BrokenStoreFileCleaner", stopper, period, delay); | ||
this.regionServer = regionServer; | ||
setEnabled( | ||
conf.getBoolean(BROKEN_STOREFILE_CLEANER_ENABLED, DEFAULT_BROKEN_STOREFILE_CLEANER_ENABLED)); | ||
fileTtl = conf.getLong(BROKEN_STOREFILE_CLEANER_TTL, DEFAULT_BROKEN_STOREFILE_CLEANER_TTL); | ||
} | ||
|
||
public boolean setEnabled(final boolean enabled) { | ||
return this.enabled.getAndSet(enabled); | ||
} | ||
|
||
public boolean getEnabled() { | ||
return this.enabled.get(); | ||
} | ||
|
||
@Override | ||
public void chore() { | ||
if (getEnabled()) { | ||
long start = EnvironmentEdgeManager.currentTime(); | ||
AtomicLong deletedFiles = new AtomicLong(0); | ||
AtomicLong failedDeletes = new AtomicLong(0); | ||
for (HRegion region : regionServer.getRegions()) { | ||
for (HStore store : region.getStores()) { | ||
//only do cleanup in stores not using tmp directories | ||
if (store.getStoreEngine().requireWritingToTmpDirFirst()) { | ||
continue; | ||
} | ||
Path storePath = | ||
new Path(region.getRegionFileSystem().getRegionDir(), store.getColumnFamilyName()); | ||
|
||
try { | ||
List<FileStatus> fsStoreFiles = | ||
Arrays.asList(region.getRegionFileSystem().fs.listStatus(storePath)); | ||
fsStoreFiles.forEach( | ||
file -> cleanFileIfNeeded(file, store, deletedFiles, failedDeletes)); | ||
} catch (IOException e) { | ||
LOG.warn("Failed to list files in {}, cleanup is skipped there",storePath); | ||
continue; | ||
} | ||
} | ||
} | ||
LOG.debug( | ||
"BrokenStoreFileCleaner on {} run for: {}ms. It deleted {} files and tried but failed " | ||
+ "to delete {}", | ||
regionServer.getServerName().getServerName(), EnvironmentEdgeManager.currentTime() - start, | ||
deletedFiles.get(), failedDeletes.get()); | ||
} else { | ||
LOG.trace("Broken storefile Cleaner chore disabled! Not cleaning."); | ||
} | ||
} | ||
|
||
private void cleanFileIfNeeded(FileStatus file, HStore store, | ||
AtomicLong deletedFiles, AtomicLong failedDeletes) { | ||
if(file.isDirectory()){ | ||
LOG.trace("This is a Directory {}, skip cleanup", file.getPath()); | ||
return; | ||
} | ||
|
||
if(!validate(file.getPath())){ | ||
LOG.trace("Invalid file {}, skip cleanup", file.getPath()); | ||
return; | ||
} | ||
|
||
if(!isOldEnough(file)){ | ||
LOG.trace("Fresh file {}, skip cleanup", file.getPath()); | ||
return; | ||
} | ||
|
||
if(isActiveStorefile(file, store)){ | ||
LOG.trace("Actively used storefile file {}, skip cleanup", file.getPath()); | ||
return; | ||
} | ||
|
||
// Compacted files can still have readers and are cleaned by a separate chore, so they have to | ||
// be skipped here | ||
if(isCompactedFile(file, store)){ | ||
LOG.trace("Cleanup is done by a different chore for file {}, skip cleanup", file.getPath()); | ||
return; | ||
} | ||
|
||
if(isCompactionResultFile(file, store)){ | ||
LOG.trace("The file is the result of an ongoing compaction {}, skip cleanup", file.getPath()); | ||
return; | ||
} | ||
|
||
deleteFile(file, store, deletedFiles, failedDeletes); | ||
} | ||
|
||
private boolean isCompactionResultFile(FileStatus file, HStore store) { | ||
return store.getStoreEngine().getCompactor().getCompactionTargets().contains(file.getPath()); | ||
} | ||
|
||
// Compacted files can still have readers and are cleaned by a separate chore, so they have to | ||
// be skipped here | ||
private boolean isCompactedFile(FileStatus file, HStore store) { | ||
Apache9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return store.getStoreEngine().getStoreFileManager().getCompactedfiles().stream() | ||
.anyMatch(sf -> sf.getPath().equals(file.getPath())); | ||
} | ||
|
||
private boolean isActiveStorefile(FileStatus file, HStore store) { | ||
return store.getStoreEngine().getStoreFileManager().getStorefiles().stream() | ||
.anyMatch(sf -> sf.getPath().equals(file.getPath())); | ||
} | ||
|
||
boolean validate(Path file) { | ||
if (HFileLink.isBackReferencesDir(file) || HFileLink.isBackReferencesDir(file.getParent())) { | ||
return true; | ||
} | ||
return StoreFileInfo.validateStoreFileName(file.getName()); | ||
} | ||
|
||
boolean isOldEnough(FileStatus file){ | ||
return file.getModificationTime() + fileTtl < EnvironmentEdgeManager.currentTime(); | ||
} | ||
|
||
private void deleteFile(FileStatus file, HStore store, AtomicLong deletedFiles, | ||
AtomicLong failedDeletes) { | ||
Path filePath = file.getPath(); | ||
LOG.debug("Removing {} from store", filePath); | ||
try { | ||
boolean success = store.getFileSystem().delete(filePath, false); | ||
if (!success) { | ||
failedDeletes.incrementAndGet(); | ||
LOG.warn("Attempted to delete:" + filePath | ||
+ ", but couldn't. Attempt to delete on next pass."); | ||
} | ||
else{ | ||
deletedFiles.incrementAndGet(); | ||
} | ||
} catch (IOException e) { | ||
e = e instanceof RemoteException ? | ||
((RemoteException)e).unwrapRemoteException() : e; | ||
LOG.warn("Error while deleting: " + filePath, e); | ||
} | ||
} | ||
|
||
} |
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
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.