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

HBASE-24940: runCatalogJanitor() API should return -1 to indicate already running status #2331

Closed
Closed
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 @@ -903,7 +903,7 @@ default boolean normalize() throws IOException {
/**
* Ask for a scan of the catalog table.
*
* @return the number of entries cleaned
* @return the number of entries cleaned. Returns -1 if previous run is in progress.
* @throws IOException if a remote or network exception occurs
*/
int runCatalogJanitor() throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,16 @@ private static boolean isRIT(AssignmentManager am) {
* Run janitorial scan of catalog <code>hbase:meta</code> table looking for
* garbage to collect.
* @return How many items gc'd whether for merge or split.
* Returns -1 if previous scan is in progress.
*/
@VisibleForTesting
public int scan() throws IOException {
int gcs = 0;
try {
if (!alreadyRunning.compareAndSet(false, true)) {
LOG.debug("CatalogJanitor already running");
return gcs;
// -1 indicates previous scan is in progress
return -1;
}
this.lastReport = scanForReport();
if (!this.lastReport.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import static org.mockito.Mockito.spy;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Objects;
Expand Down Expand Up @@ -551,6 +553,29 @@ public void testDuplicateHFileResolution() throws Exception {
assertArchiveEqualToOriginal(storeFiles, archivedStoreFiles, fs, true);
}

@Test
public void testAlreadyRunningStatus() throws Exception {
int numberOfThreads = 2;
List<Integer> gcValues = new ArrayList<>();
Thread[] threads = new Thread[numberOfThreads];
for (int i = 0; i < numberOfThreads; i++) {
threads[i] = new Thread(() -> {
try {
gcValues.add(janitor.scan());
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
for (int i = 0; i < numberOfThreads; i++) {
threads[i].start();
}
for (int i = 0; i < numberOfThreads; i++) {
threads[i].join();
}
assertTrue("One janitor.scan() call should have returned -1", gcValues.contains(-1));
}

private FileStatus[] addMockStoreFiles(int count, MasterServices services, Path storedir)
throws IOException {
// get the existing store files
Expand Down