Skip to content

rename op #316

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 1 commit into from
Apr 30, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -3109,7 +3109,10 @@ boolean renameTo(String src, String dst, boolean logRetryCache)
FSDirRenameOp.RenameResult ret = null;
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
writeLock();
String enableNNProxy = System.getenv("ENABLE_NN_PROXY");
if (enableNNProxy == null) {
writeLock();
}
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot rename " + src);
Expand All @@ -3118,7 +3121,9 @@ boolean renameTo(String src, String dst, boolean logRetryCache)
logAuditEvent(false, operationName, src, dst, null);
throw e;
} finally {
writeUnlock(operationName);
if (enableNNProxy == null) {
writeUnlock(operationName);
}
}
boolean success = ret.success;
if (success) {
Expand All @@ -3135,7 +3140,10 @@ void renameTo(final String src, final String dst,
FSDirRenameOp.RenameResult res = null;
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
writeLock();
String enableNNProxy = System.getenv("ENABLE_NN_PROXY");
if (enableNNProxy == null) {
writeLock();
}
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot rename " + src);
Expand All @@ -3146,10 +3154,12 @@ void renameTo(final String src, final String dst,
Arrays.toString(options) + ")", src, dst, null);
throw e;
} finally {
writeUnlock(operationName);
if (enableNNProxy == null) {
writeUnlock(operationName);
}
}

getEditLog().logSync();
// getEditLog().logSync();

BlocksMapUpdateInfo collectedBlocks = res.collectedBlocks;
if (!collectedBlocks.getToDeleteList().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,22 +909,28 @@ void update_subtree(Set<INode> renameSet) {
}

public void remoteRename(INode node, String oldName, String oldParent, String newParent, String address) {
// FIXME: replace NameNode.getId() with 40000000 to simplify the ID assignments
int skip_id = oldParent.length();
Long old_id = node.getId();
if (node.isDirectory()) {
Queue<ImmutablePair<String, String>> q = new LinkedList<>();
q.add(new ImmutablePair<>(oldParent, oldName));

// log: delete the old directory
FSDirectory.getInstance()
.getEditLog()
.logDelete(null, old_id, node.getModificationTime(), true);
// FSDirectory.getInstance()
// .getEditLog()
// .logDelete(null, old_id, node.getModificationTime(), true);

ImmutablePair<String, String> id = null;
Set<INode> renameSet = new HashSet<>();

long dirtyCount = 100000;
String dirtyCountStr = System.getenv("FILESCALE_DIRTY_OBJECT_NUM");
if (dirtyCountStr != null) {
dirtyCount = Long.parseLong(dirtyCountStr);
}
long count = 0;
while ((id = q.poll()) != null) {
if (dirtyCount == 0) break;
INode child = FSDirectory.getInstance().getInode(id.getLeft(), id.getRight());
if (child != null) {
if (child.isDirectory()) {
Expand All @@ -938,11 +944,11 @@ public void remoteRename(INode node, String oldName, String oldParent, String ne
}
}

if (child.getId() != old_id) {
child.setParent(child.getParentId() + 40000000);
child.setParentName(newParent + child.getParentName().substring(skip_id));
}
child.setId(child.getId() + 40000000);
// if (child.getId() != old_id) {
// child.setParent(child.getParentId() + 40000000);
// child.setParentName(newParent + child.getParentName().substring(skip_id));
// }
// child.setId(child.getId() + 40000000);

// if (child.isDirectory()) {
// // log: create new diretory
Expand All @@ -957,27 +963,29 @@ public void remoteRename(INode node, String oldName, String oldParent, String ne
// }

renameSet.add(child);
// if (renameSet.size() >= 5120) {
// update_subtree(renameSet);
// }
count++;
INodeKeyedObjects.getCache().invalidate(child.getPath());
if (count == dirtyCount) {
// write back to db
LOG.info("##");
update_subtree(renameSet);
break;
}
if (renameSet.size() >= 5120) {
update_subtree(renameSet);
}
}
}
if (renameSet.size() > 0) {
// update_subtree(renameSet);
LOG.info("#### address: " + address);
update_subtree_v2(renameSet, address);
if (count < dirtyCount && renameSet.size() > 0) {
update_subtree(renameSet);
// update_subtree_v2(renameSet, address);
}

CompletableFuture.runAsync(() -> {
// CompletableFuture.runAsync(() -> {
// stored procedure:
// (1) update subtree IDs and parent fields
// DatabaseINode.updateSubtree(old_id, 100000, oldParent, "/nnThroughputBenchmark/rename", node.getParentId());
// (2) remove all childs recursively
DatabaseINode.removeChild(old_id);
}, Database.getInstance().getExecutorService());

// invalidate inode, and childs will be evicted eventually
INodeKeyedObjects.getCache().invalidate(oldParent + oldName);
// update subtree IDs and parent fields
DatabaseINode.updateSubtree(old_id, 40000000, oldParent, "/nnThroughputBenchmark/rename", node.getParentId());
// }, Database.getInstance().getExecutorService());
} else {
// log: delete old file
FSDirectory.getInstance()
Expand Down