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

Optimize delete recursively #178

Merged
merged 2 commits into from
Sep 21, 2019
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ benchmark/hopfs/hops
benchmark/hopfs/META-INF

storedprocs.jar
bench/hdfs
bench/hdfs
bench/voltfs
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,20 @@ public static List<Long> getChildIdsByPath(final long id, final String[] compone
return res;
}

public static void removeChild(final long id) {
public static List<Long> removeChild(final long id) {
List<Long> childIds = new ArrayList<>();
try {
DatabaseConnection obj = Database.getInstance().getConnection();
String env = System.getenv("DATABASE");
if (env.equals("VOLT")) {
// call a stored procedure
try {
obj.getVoltClient().callProcedure(new NullCallback(), "RemoveChild", id);
VoltTable[] results = obj.getVoltClient().callProcedure(new NullCallback(), "RemoveChild", id).getResults();
VoltTable result = results[0];
result.resetRowPosition();
while (result.advanceRow()) {
childIds.add(result.getLong(0));
}
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -755,6 +761,7 @@ public static void removeChild(final long id) {
if (LOG.isInfoEnabled()) {
LOG.info("removeChild: " + id);
}
return childIds;
}

public static List<String> getPathComponents(final long childId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,12 @@ private static boolean unprotectedDelete(FSDirectory fsd, INodesInPath iip,
targetNode.cleanSubtree(reclaimContext, CURRENT_STATE_ID, latestSnapshot);
}

// ADD(gangliao): Remove inode from Postgres
DatabaseINode.removeChild(targetNode.getId());
INodeKeyedObjects.getCache().invalidateAllWithIndex(Long.class, targetNode.getId());
// ADD(gangliao): Remove inode from Database
List<Long> ids = DatabaseINode.removeChild(targetNode.getId());
INodeKeyedObjects.getCache().invalidateAllWithIndex(Long.class, targetNode.getId());
for (Long id : ids) {
INodeKeyedObjects.getCache().invalidateAllWithIndex(Long.class, id);
}

if (NameNode.stateChangeLog.isDebugEnabled()) {
NameNode.stateChangeLog.debug("DIR* FSDirectory.unprotectedDelete: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,10 @@ private void setBlocks(INodeFile that) {

/** Clear all blocks of the file. */
public void clearBlocks() {
blockNum.getAndSet(0);
DatabaseINode2Block.deleteViaBcId(this.getId());
if (numBlocks() != 0) {
blockNum.getAndSet(0);
DatabaseINode2Block.deleteViaBcId(this.getId());
}
}

private void updateRemovedUnderConstructionFiles(
Expand Down
4 changes: 2 additions & 2 deletions voltdb/RemoveChild.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class RemoveChild extends VoltProcedure {
+ " SELECT id FROM cte;");
public final SQLStmt sql2 = new SQLStmt("DELETE FROM inodes WHERE id = ?;");

public long run(long id) throws VoltAbortException {
public VoltTable[] run(long id) throws VoltAbortException {
voltQueueSQL(sql1, id);
VoltTable[] results = voltExecuteSQL();

Expand All @@ -25,6 +25,6 @@ public long run(long id) throws VoltAbortException {
voltQueueSQL(sql2, results[0].fetchRow(i).getLong(0));
}
voltExecuteSQL();
return 1;
return results;
}
}