Skip to content

Commit

Permalink
fix: remote renmae logging failure (#267) (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
gangliao authored Jun 10, 2020
1 parent bed83a6 commit e4dd3f9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@
import java.io.ByteArrayOutputStream;
import java.net.InetSocketAddress;

// import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.Saver.buildAclEntries;
// import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.Saver.buildXAttrs;
import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.Saver.buildAclEntries;
import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.Saver.buildXAttrs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
Expand Down Expand Up @@ -820,8 +820,6 @@ public void logAppendFile(String path, INodeFile file, boolean newBlock,
}

public void remoteLogOpenFile(INodeFile newNode, String nameNodeAddress) {
ByteArrayOutputStream out = new ByteArrayOutputStream();

INodeSection.INodeFile.Builder b = INodeSection.INodeFile.newBuilder()
.setAccessTime(newNode.getAccessTime())
.setModificationTime(newNode.getModificationTime())
Expand All @@ -838,12 +836,12 @@ public void remoteLogOpenFile(INodeFile newNode, String nameNodeAddress) {

AclFeature acl = newNode.getAclFeature();
if (acl != null) {
// b.setAcl(buildAclEntries(acl));
b.setAcl(buildAclEntries(acl));
}

XAttrFeature xAttrFeature = newNode.getXAttrFeature();
if (xAttrFeature != null) {
// b.setXAttrs(buildXAttrs(xAttrFeature));
b.setXAttrs(buildXAttrs(xAttrFeature));
}

BlockInfo[] blocks = newNode.getBlocks();
Expand All @@ -868,9 +866,8 @@ public void remoteLogOpenFile(INodeFile newNode, String nameNodeAddress) {
.setId(newNode.getId())
.setName(ByteString.copyFrom(newNode.getLocalNameBytes()))
.setType(INodeSection.INode.Type.FILE).setFile(b).build();
r.writeDelimitedTo(out);

byte[] data = out.toByteArray();
byte[] data = r.toByteArray();
FSEditLogProtocol proxy = (FSEditLogProtocol) RPC.getProxy(
FSEditLogProtocol.class, FSEditLogProtocol.versionID,
new InetSocketAddress(nameNodeAddress, 10086), new Configuration());
Expand Down Expand Up @@ -956,31 +953,28 @@ public void logUpdateBlocks(String path, INodeFile file, boolean toLogRpcIds) {
}

public void remoteLogMkDir(INodeDirectory newNode, String nameNodeAddress) {
ByteArrayOutputStream out = new ByteArrayOutputStream();

INodeSection.INodeDirectory.Builder b = INodeSection.INodeDirectory
.newBuilder()
.setModificationTime(newNode.getModificationTime())
.setPermission(newNode.getPermissionLong());

AclFeature f = newNode.getAclFeature();
if (f != null) {
// b.setAcl(buildAclEntries(f));
b.setAcl(buildAclEntries(f));
}

XAttrFeature xAttrFeature = newNode.getXAttrFeature();
if (xAttrFeature != null) {
// b.setXAttrs(buildXAttrs(xAttrFeature));
b.setXAttrs(buildXAttrs(xAttrFeature));
}

try {
INodeSection.INode r = INodeSection.INode.newBuilder()
.setId(newNode.getId())
.setName(ByteString.copyFrom(newNode.getLocalNameBytes()))
.setType(INodeSection.INode.Type.DIRECTORY).setDirectory(b).build();
r.writeDelimitedTo(out);

byte[] data = out.toByteArray();
byte[] data = r.toByteArray();

FSEditLogProtocol proxy = (FSEditLogProtocol) RPC.getProxy(
FSEditLogProtocol.class, FSEditLogProtocol.versionID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

import org.apache.commons.lang3.tuple.ImmutablePair;
import com.google.common.base.Preconditions;
import com.google.protobuf.InvalidProtocolBufferException;

public class FSEditLogProtocolImpl implements FSEditLogProtocol {

Expand Down Expand Up @@ -157,7 +158,12 @@ public INodeDirectory loadINodeDirectory(INodeSection.INode n) {

@Override
public void logEdit(byte[] in) throws IOException {
INodeSection.INode p = INodeSection.INode.parseFrom(in);
INodeSection.INode p = NULL;
try {
p = INodeSection.INode.parseFrom(in);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
INode n;
switch (p.getType()) {
case FILE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private static long buildPermissionStatus(INodeAttributes n) {
return n.getPermissionLong();
}

private static AclFeatureProto.Builder buildAclEntries(AclFeature f) {
public static AclFeatureProto.Builder buildAclEntries(AclFeature f) {
AclFeatureProto.Builder b = AclFeatureProto.newBuilder();
for (int pos = 0, e; pos < f.getEntriesSize(); pos++) {
e = f.getEntryAt(pos);
Expand All @@ -413,7 +413,7 @@ private static AclFeatureProto.Builder buildAclEntries(AclFeature f) {
return b;
}

private static XAttrFeatureProto.Builder buildXAttrs(XAttrFeature f) {
public static XAttrFeatureProto.Builder buildXAttrs(XAttrFeature f) {
XAttrFeatureProto.Builder b = XAttrFeatureProto.newBuilder();
for (XAttr a : f.getXAttrs()) {
XAttrCompactProto.Builder xAttrCompactBuilder = XAttrCompactProto.
Expand Down

0 comments on commit e4dd3f9

Please sign in to comment.