Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -106,6 +106,15 @@ static class AdminOpts extends ServerUtilOpts {
boolean force = false;
}

@Parameters(commandDescription = "Compaction Temp Files Utility")
static class FindCompactionTmpFilesCommand {
@Parameter(names = "--tables", description = "comma separated list of table names")
String tables;

@Parameter(names = "--delete", description = "if true, will delete tmp files")
boolean delete = false;
}

@Parameters(commandDescription = "stop the tablet server on the given hosts")
static class StopCommand {
@Parameter(description = "<host> {<host> ... }")
Expand Down Expand Up @@ -321,6 +330,9 @@ public void execute(final String[] args) {
VolumesCommand volumesCommand = new VolumesCommand();
cl.addCommand("volumes", volumesCommand);

FindCompactionTmpFilesCommand filesCommand = new FindCompactionTmpFilesCommand();
cl.addCommand("compactionTempFiles", filesCommand);

cl.parse(args);

if (opts.help || cl.getParsedCommand() == null) {
Expand Down Expand Up @@ -385,6 +397,8 @@ public void execute(final String[] args) {
tServerLocksOpts.delete);
} else if (cl.getParsedCommand().equals("fate")) {
executeFateOpsCommand(context, fateOpsCommand);
} else if (cl.getParsedCommand().equals("compactionTempFiles")) {
FindCompactionTmpFiles.execute(context, filesCommand.tables, filesCommand.delete);
} else {
everything = cl.getParsedCommand().equals("stopAll");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,36 @@ public static DeleteStats deleteTempFiles(ServerContext context, Set<Path> files
return stats;
}

public static void execute(ServerContext context, final String tablesToSearch,
final boolean delete) throws Exception {
LOG.info("Looking for compaction tmp files over tables: {}, deleting: {}", tablesToSearch,
delete);

String[] tables = tablesToSearch.split(",");
for (String table : tables) {

table = table.trim();
String tableId = context.tableOperations().tableIdMap().get(table);
if (tableId == null || tableId.isEmpty()) {
LOG.warn("TableId for table: {} does not exist, maybe the table was deleted?", table);
continue;
}

final Set<Path> matches = findTempFiles(context, tableId);
LOG.info("Found the following compaction tmp files for table {}:", table);
matches.forEach(p -> LOG.info("{}", p));

if (delete) {
LOG.info("Deleting compaction tmp files for table {}...", table);
DeleteStats stats = deleteTempFiles(context, matches);
LOG.info(
"Deletion of compaction tmp files for table {} complete. Success:{}, Failure:{}, Error:{}",
table, stats.success, stats.failure, stats.error);
}

}
}

public static void main(String[] args) throws Exception {
Opts opts = new Opts();
opts.parseArgs(FindCompactionTmpFiles.class.getName(), args);
Expand All @@ -186,30 +216,7 @@ public static void main(String[] args) throws Exception {
try (Scope scope = span.makeCurrent()) {

ServerContext context = opts.getServerContext();
String[] tables = opts.tables.split(",");

for (String table : tables) {

table = table.trim();
String tableId = context.tableOperations().tableIdMap().get(table);
if (tableId == null || tableId.isEmpty()) {
LOG.warn("TableId for table: {} does not exist, maybe the table was deleted?", table);
continue;
}

final Set<Path> matches = findTempFiles(context, tableId);
LOG.info("Found the following compaction tmp files for table {}:", table);
matches.forEach(p -> LOG.info("{}", p));

if (opts.delete) {
LOG.info("Deleting compaction tmp files for table {}...", table);
DeleteStats stats = deleteTempFiles(context, matches);
LOG.info(
"Deletion of compaction tmp files for table {} complete. Success:{}, Failure:{}, Error:{}",
table, stats.success, stats.failure, stats.error);
}

}
execute(context, opts.tables, opts.delete);

} finally {
span.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,11 @@ public void testAdminOpts() {
Admin.AdminOpts opts = new Admin.AdminOpts();
assertFalse(opts.force);
}

@Test
public void testFindCompactionTmpFilesCommand() {
Admin.FindCompactionTmpFilesCommand filesCommand = new Admin.FindCompactionTmpFilesCommand();
assertNull(filesCommand.tables);
assertFalse(filesCommand.delete);
}
}