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

HDDS-4357: Rename : make rename an atomic ops by updating key path entry in dir/file table #1528

Closed
wants to merge 4 commits into from
Closed
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
10 changes: 10 additions & 0 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2528,4 +2528,14 @@
filesystem semantics.
</description>
</property>

<property>
<name>ozone.om.layout.version</name>
<tag>OZONE, OM</tag>
<value>V0</value>
<description>Temporary workaround for OM upgrade and will be replaced once
upgrade HDDS-3698 story reaches consensus. Defaulting to 'V0' so that
existing unit test cases won't be affected. New OM version should be 'V1'
</description>
</property>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,12 @@ private OMConfigKeys() {
"ozone.om.enable.filesystem.paths";
public static final boolean OZONE_OM_ENABLE_FILESYSTEM_PATHS_DEFAULT =
false;

// TODO: Temporary workaround for OM upgrade path and will be replaced once
// upgrade HDDS-3698 story reaches consensus. Defaulting to 'V0' so that
// existing unit test cases won't be affected. New OM version should be 'V1'.
public static final String OZONE_OM_LAYOUT_VERSION =
"ozone.om.layout.version";
public static final String OZONE_OM_LAYOUT_VERSION_DEFAULT = "V0";
public static final String OZONE_OM_LAYOUT_VERSION_V1 = "V1";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.ozone.om.helpers;

import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;

import java.util.*;

/**
* This class represents the directory information by keeping each component
* in the user given path and a pointer to its parent directory element in the
* path. Also, it stores directory node related metdata details.
*/
public class OmDirectoryInfo extends WithObjectID {
private long parentObjectID; // pointer to parent directory

private String name; // directory name

private long creationTime;
private long modificationTime;

private List<OzoneAcl> acls;

public OmDirectoryInfo(Builder builder) {
this.name = builder.name;
this.acls = builder.acls;
this.metadata = builder.metadata;
this.objectID = builder.objectID;
this.updateID = builder.updateID;
this.parentObjectID = builder.parentObjectID;
this.creationTime = builder.creationTime;
this.modificationTime = builder.modificationTime;
}

/**
* Returns new builder class that builds a OmPrefixInfo.
*
* @return Builder
*/
public static OmDirectoryInfo.Builder newBuilder() {
return new OmDirectoryInfo.Builder();
}

/**
* Builder for Directory Info.
*/
public static class Builder {
private long parentObjectID; // pointer to parent directory

private long objectID;
private long updateID;

private String name;

private long creationTime;
private long modificationTime;

private List<OzoneAcl> acls;
private Map<String, String> metadata;

public Builder() {
//Default values
this.acls = new LinkedList<>();
this.metadata = new HashMap<>();
}

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

public Builder setObjectID(long objectId) {
this.objectID = objectId;
return this;
}

public Builder setUpdateID(long updateId) {
this.updateID = updateId;
return this;
}

public Builder setName(String dirName) {
this.name = dirName;
return this;
}

public Builder setCreationTime(long newCreationTime) {
this.creationTime = newCreationTime;
return this;
}

public Builder setModificationTime(long newModificationTime) {
this.modificationTime = newModificationTime;
return this;
}

public Builder setAcls(List<OzoneAcl> listOfAcls) {
if (listOfAcls != null) {
this.acls.addAll(listOfAcls);
}
return this;
}

public Builder addAcl(OzoneAcl ozoneAcl) {
if (ozoneAcl != null) {
this.acls.add(ozoneAcl);
}
return this;
}

public Builder addMetadata(String key, String value) {
metadata.put(key, value);
return this;
}

public Builder addAllMetadata(Map<String, String> additionalMetadata) {
if (additionalMetadata != null) {
metadata.putAll(additionalMetadata);
}
return this;
}

public OmDirectoryInfo build() {
return new OmDirectoryInfo(this);
}
}

@Override
public String toString() {
return getPath() + ":" + getObjectID();
}

public long getParentObjectID() {
return parentObjectID;
}

public String getPath() {
return getParentObjectID() + OzoneConsts.OM_KEY_PREFIX + getName();
}

public String getName() {
return name;
}

public long getCreationTime() {
return creationTime;
}

public long getModificationTime() {
return modificationTime;
}

public List<OzoneAcl> getAcls() {
return acls;
}

/**
* Creates DirectoryInfo protobuf from OmDirectoryInfo.
*/
public OzoneManagerProtocolProtos.DirectoryInfo getProtobuf() {
OzoneManagerProtocolProtos.DirectoryInfo.Builder pib =
OzoneManagerProtocolProtos.DirectoryInfo.newBuilder().setName(name)
.setCreationTime(creationTime)
.setModificationTime(modificationTime)
.addAllMetadata(KeyValueUtil.toProtobuf(metadata))
.setObjectID(objectID)
.setUpdateID(updateID)
.setParentID(parentObjectID);
if (acls != null) {
pib.addAllAcls(OzoneAclUtil.toProtobuf(acls));
}
return pib.build();
}

/**
* Parses DirectoryInfo protobuf and creates OmPrefixInfo.
* @param dirInfo
* @return instance of OmDirectoryInfo
*/
public static OmDirectoryInfo getFromProtobuf(
OzoneManagerProtocolProtos.DirectoryInfo dirInfo) {
OmDirectoryInfo.Builder opib = OmDirectoryInfo.newBuilder()
.setName(dirInfo.getName())
.setCreationTime(dirInfo.getCreationTime())
.setModificationTime(dirInfo.getModificationTime())
.setAcls(OzoneAclUtil.fromProtobuf(dirInfo.getAclsList()));
if (dirInfo.getMetadataList() != null) {
opib.addAllMetadata(KeyValueUtil
.getFromProtobuf(dirInfo.getMetadataList()));
}
if (dirInfo.hasObjectID()) {
opib.setObjectID(dirInfo.getObjectID());
}
if (dirInfo.hasParentID()) {
opib.setParentObjectID(dirInfo.getParentID());
}
if (dirInfo.hasUpdateID()) {
opib.setUpdateID(dirInfo.getUpdateID());
}
return opib.build();
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
OmDirectoryInfo omDirInfo = (OmDirectoryInfo) o;
return creationTime == omDirInfo.creationTime &&
modificationTime == omDirInfo.modificationTime &&
name.equals(omDirInfo.name) &&
Objects.equals(metadata, omDirInfo.metadata) &&
Objects.equals(acls, omDirInfo.acls) &&
objectID == omDirInfo.objectID &&
updateID == omDirInfo.updateID &&
parentObjectID == omDirInfo.parentObjectID;
}

@Override
public int hashCode() {
return Objects.hash(objectID, parentObjectID, name);
}

/**
* Return a new copy of the object.
*/
public OmDirectoryInfo copyObject() {
OmDirectoryInfo.Builder builder = new Builder()
.setName(name)
.setCreationTime(creationTime)
.setModificationTime(modificationTime)
.setParentObjectID(parentObjectID)
.setObjectID(objectID)
.setUpdateID(updateID);

acls.forEach(acl -> builder.addAcl(new OzoneAcl(acl.getType(),
acl.getName(), (BitSet) acl.getAclBitSet().clone(),
acl.getAclScope())));

if (metadata != null) {
metadata.forEach((k, v) -> builder.addMetadata(k, v));
}

return builder.build();
}
}
Loading