Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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 @@ -25,9 +25,11 @@
import java.util.Map;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.fs.FileEncryptionInfo;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyInfo;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyLocationList;
import org.apache.hadoop.ozone.protocolPB.OMPBHelper;
Expand All @@ -52,6 +54,8 @@ public final class OmKeyInfo extends WithObjectID {
private HddsProtos.ReplicationType type;
private HddsProtos.ReplicationFactor factor;
private FileEncryptionInfo encInfo;
private String fileName; // leaf node name
private long parentObjectID; // pointer to parent directory

/**
* ACL Information.
Expand Down Expand Up @@ -94,6 +98,22 @@ public final class OmKeyInfo extends WithObjectID {
this.updateID = updateID;
}

@SuppressWarnings("parameternumber")
OmKeyInfo(String volumeName, String bucketName, String keyName,
String fileName, List<OmKeyLocationInfoGroup> versions,
long dataSize, long creationTime, long modificationTime,
HddsProtos.ReplicationType type,
HddsProtos.ReplicationFactor factor,
Map<String, String> metadata,
FileEncryptionInfo encInfo, List<OzoneAcl> acls,
long parentObjectID, long objectID, long updateID) {
this(volumeName, bucketName, keyName, versions, dataSize,
creationTime, modificationTime, type, factor, metadata, encInfo,
acls, objectID, updateID);
this.fileName = fileName;
this.parentObjectID = parentObjectID;
}

public String getVolumeName() {
return volumeName;
}
Expand Down Expand Up @@ -126,6 +146,19 @@ public void setDataSize(long size) {
this.dataSize = size;
}

public void setFileName(String fileName) {
this.fileName = fileName;
}

public String getFileName() {
return fileName;
}

public long getParentObjectID() {
return parentObjectID;
}


public synchronized OmKeyLocationInfoGroup getLatestVersionLocations() {
return keyLocationVersions.size() == 0? null :
keyLocationVersions.get(keyLocationVersions.size() - 1);
Expand Down Expand Up @@ -267,6 +300,9 @@ public static class Builder {
private List<OzoneAcl> acls;
private long objectID;
private long updateID;
// not persisted to DB. FileName will be the last element in path keyName.
private String fileName;
private long parentObjectID;

public Builder() {
this.metadata = new HashMap<>();
Expand Down Expand Up @@ -369,11 +405,22 @@ public Builder setUpdateID(long id) {
return this;
}

public Builder setFileName(String keyFileName) {
this.fileName = keyFileName;
return this;
}

public Builder setParentObjectID(long parentID) {
this.parentObjectID = parentID;
return this;
}

public OmKeyInfo build() {
return new OmKeyInfo(
volumeName, bucketName, keyName, omKeyLocationInfoGroups,
dataSize, creationTime, modificationTime, type, factor, metadata,
encInfo, acls, objectID, updateID);
volumeName, bucketName, keyName, fileName,
omKeyLocationInfoGroups, dataSize, creationTime,
modificationTime, type, factor, metadata, encInfo, acls,
parentObjectID, objectID, updateID);
}
}

Expand Down Expand Up @@ -413,7 +460,8 @@ public KeyInfo getProtobuf(boolean ignorePipeline) {
.addAllMetadata(KeyValueUtil.toProtobuf(metadata))
.addAllAcls(OzoneAclUtil.toProtobuf(acls))
.setObjectID(objectID)
.setUpdateID(updateID);
.setUpdateID(updateID)
.setParentID(parentObjectID);
if (encInfo != null) {
kb.setFileEncryptionInfo(OMPBHelper.convert(encInfo));
}
Expand Down Expand Up @@ -451,6 +499,11 @@ public static OmKeyInfo getFromProtobuf(KeyInfo keyInfo) {
if (keyInfo.hasUpdateID()) {
builder.setUpdateID(keyInfo.getUpdateID());
}
if (keyInfo.hasParentID()) {
builder.setParentObjectID(keyInfo.getParentID());
}
// not persisted to DB. FileName will be filtered out from keyName
builder.setFileName(OzoneFSUtils.getFileName(keyInfo.getKeyName()));
return builder.build();
}

Expand All @@ -464,6 +517,8 @@ public String getObjectInfo() {
", creationTime='" + creationTime + '\'' +
", type='" + type + '\'' +
", factor='" + factor + '\'' +
", objectID='" + objectID + '\'' +
", parentID='" + parentObjectID + '\'' +
'}';
}

Expand All @@ -489,12 +544,13 @@ public boolean equals(Object o) {
Objects.equals(metadata, omKeyInfo.metadata) &&
Objects.equals(acls, omKeyInfo.acls) &&
objectID == omKeyInfo.objectID &&
updateID == omKeyInfo.updateID;
updateID == omKeyInfo.updateID &&
parentObjectID == omKeyInfo.parentObjectID;
}

@Override
public int hashCode() {
return Objects.hash(volumeName, bucketName, keyName);
return Objects.hash(volumeName, bucketName, keyName, parentObjectID);
}

/**
Expand All @@ -511,8 +567,10 @@ public OmKeyInfo copyObject() {
.setReplicationType(type)
.setReplicationFactor(factor)
.setFileEncryptionInfo(encInfo)
.setObjectID(objectID).setUpdateID(updateID);

.setObjectID(objectID)
.setUpdateID(updateID)
.setParentObjectID(parentObjectID)
.setFileName(fileName);

keyLocationVersions.forEach(keyLocationVersion ->
builder.addOmKeyLocationInfoGroup(
Expand Down Expand Up @@ -540,4 +598,11 @@ public OmKeyInfo copyObject() {
public void clearFileEncryptionInfo() {
this.encInfo = null;
}

public String getPath() {
if (StringUtils.isBlank(getFileName())) {
return getKeyName();
}
return getParentObjectID() + OzoneConsts.OM_KEY_PREFIX + getFileName();
}
}
Loading