Skip to content

optimize async i/o #315

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 27, 2021
Merged
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 @@ -421,6 +421,7 @@ public static final void invalidateAndWriteBackDB(String parent, String name) {
if (dirtyCountStr != null) {
dirtyCount = Long.parseLong(dirtyCountStr);
}
if (dirtyCount == 0) return;

Queue<ImmutablePair<String, String>> q = new LinkedList<>();
q.add(new ImmutablePair<>(parent, name));
Expand All @@ -441,7 +442,12 @@ public static final void invalidateAndWriteBackDB(String parent, String name) {
count++;
// invalidate inode
INodeKeyedObjects.getCache().invalidate(child.getPath());
if (count < dirtyCount && inodes.size() >= 5120) {
if (count == dirtyCount) {
// write back to db
update_subtree(inodes);
break;
}
if (inodes.size() >= 5120) {
// write back to db
update_subtree(inodes);
}
Expand All @@ -457,22 +463,34 @@ private final void remoteChmod(Set<Pair<String, String>> mpoints) {
// 1. invalidate cache and write back dirty data
List<String> parents = new ArrayList<>();
List<String> names = new ArrayList<>();
List<CompletableFuture<Void>> list = new ArrayList<>();
for (Pair<String, String> pair : mpoints) {
File file = new File(pair.getLeft());
String parent = file.getParent();
String name = file.getName();
String url = pair.getRight();
try {
if (url == "localhost") {
invalidateAndWriteBackDB(parent, name);
list.add(CompletableFuture.runAsync(
() -> {
invalidateAndWriteBackDB(parent, name);
},
Database.getInstance().getExecutorService()));
} else {
MountPoint.Builder b = MountPoint.newBuilder().setParent(parent).setName(name);
byte[] data = b.build().toByteArray();

FSEditLogProtocol proxy = (FSEditLogProtocol) RPC.getProxy(
FSEditLogProtocol.class, FSEditLogProtocol.versionID,
new InetSocketAddress(url, 10087), new Configuration());
proxy.invalidateAndWriteBackDB(data);
list.add(CompletableFuture.runAsync(
() -> {
MountPoint.Builder b = MountPoint.newBuilder().setParent(parent).setName(name);
byte[] data = b.build().toByteArray();
try {
FSEditLogProtocol proxy = (FSEditLogProtocol) RPC.getProxy(
FSEditLogProtocol.class, FSEditLogProtocol.versionID,
new InetSocketAddress(url, 10087), new Configuration());
proxy.invalidateAndWriteBackDB(data);
} catch (Exception e) {
e.printStackTrace();
}
},
Database.getInstance().getExecutorService()));
}
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -481,6 +499,7 @@ private final void remoteChmod(Set<Pair<String, String>> mpoints) {
parents.add(parent);
names.add(name);
}
CompletableFuture.allOf(list.toArray(new CompletableFuture[list.size()])).join();

// 2. execute distributed txn
LOG.info("Execute dist txn for chmod");
Expand Down