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

Synclog: mkdirs #243

Merged
merged 3 commits into from
Feb 4, 2020
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 @@ -37,8 +37,10 @@
import org.apache.hadoop.hdfs.db.DatabaseINode;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.DeleteOp;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.AddOp;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.MkdirOp;
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_DELETE;
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_ADD;
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_MKDIR;
import com.google.common.base.Preconditions;

/**
Expand Down Expand Up @@ -188,9 +190,15 @@ public void syncDB() {

List<Long> removeIds = new ArrayList<>();
while ((op = reader.readOp(false)) != null) {
if (op.getOpCode() == OP_ADD) {
AddOp addop = (AddOp)op;
INode inode = INodeKeyedObjects.getCache().getIfPresent(Long.class, addop.getInodeId());
if (op.getOpCode() == OP_ADD || op.getOpCode() == OP_MKDIR) {
INode inode;
if (op.getOpCode() == OP_ADD) {
AddOp addop = (AddOp)op;
inode = INodeKeyedObjects.getCache().getIfPresent(Long.class, addop.getInodeId());
} else {
MkdirOp mkdirop = (MkdirOp)op;
inode = INodeKeyedObjects.getCache().getIfPresent(Long.class, mkdirop.getInodeId());
}
strAttr.add(inode.getLocalName());
longAttr.add(inode.getParentId());
longAttr.add(inode.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,22 +873,8 @@ public void logUpdateBlocks(String path, INodeFile file, boolean toLogRpcIds) {
* Add create directory record to edit log
*/
public void logMkDir(String path, INode newNode) {
PermissionStatus permissions = newNode.getPermissionStatus();
MkdirOp op = MkdirOp.getInstance(cache.get())
.setInodeId(newNode.getId())
.setPath(path)
.setTimestamp(newNode.getModificationTime())
.setPermissionStatus(permissions);

AclFeature f = newNode.getAclFeature();
if (f != null) {
op.setAclEntries(AclStorage.readINodeLogicalAcl(newNode));
}

XAttrFeature x = newNode.getXAttrFeature();
if (x != null) {
op.setXAttrs(x.getXAttrs());
}
.setInodeId(newNode.getId());
logEdit(op);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,10 @@ void resetSubFields() {
xAttrs = null;
}

long getInodeId() {
return inodeId;
}

MkdirOp setInodeId(long inodeId) {
this.inodeId = inodeId;
return this;
Expand Down Expand Up @@ -1679,14 +1683,14 @@ MkdirOp setXAttrs(List<XAttr> xAttrs) {
public
void writeFields(DataOutputStream out) throws IOException {
FSImageSerialization.writeLong(inodeId, out);
FSImageSerialization.writeString(path, out);
// FSImageSerialization.writeString(path, out);
// FSImageSerialization.writeLong(timestamp, out); // mtime
// FSImageSerialization.writeLong(timestamp, out); // atime, unused at this
// permissions.write(out);
AclEditLogUtil.write(aclEntries, out);
XAttrEditLogProto.Builder b = XAttrEditLogProto.newBuilder();
b.addAllXAttrs(PBHelperClient.convertXAttrProto(xAttrs));
b.build().writeDelimitedTo(out);
// AclEditLogUtil.write(aclEntries, out);
// XAttrEditLogProto.Builder b = XAttrEditLogProto.newBuilder();
// b.addAllXAttrs(PBHelperClient.convertXAttrProto(xAttrs));
// b.build().writeDelimitedTo(out);
}

@Override
Expand Down Expand Up @@ -5127,6 +5131,9 @@ public FSEditLogOp decodeOp() throws IOException {
} else if (op.getOpCode() == OP_DELETE) {
DeleteOp deleteop = (DeleteOp)op;
deleteop.setInodeId(in.readLong());
} else if (op.getOpCode() == OP_MKDIR) {
MkdirOp mkdirop = (MkdirOp)op;
mkdirop.setInodeId(in.readLong());
}
return op;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3236,6 +3236,12 @@ boolean mkdirs(String src, PermissionStatus permissions,
} finally {
writeUnlock(operationName);
}
String syncLog = System.getenv("SYNC_FILESCALE_LOG");
if (Boolean.parseBoolean(syncLog) == false) {
INodeKeyedObjects.asyncUpdateDB();
} else {
getEditLog().logSync();
}
logAuditEvent(true, operationName, src, null, auditStat);
return true;
}
Expand Down