Skip to content
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 @@ -27,22 +27,23 @@
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeType;
import org.apache.hadoop.hdds.server.ServerUtils;
import org.apache.hadoop.hdds.upgrade.HDDSLayoutFeature;
import org.apache.hadoop.hdds.utils.HddsServerUtil;
import org.apache.hadoop.ozone.common.Storage;

/**
* DataNodeStorageConfig is responsible for management of the
* StorageDirectories used by the DataNode.
*/
public class DatanodeLayoutStorage extends Storage {

/**
* Construct DataNodeStorageConfig.
* @throws IOException if any directories are inaccessible.
*/
public DatanodeLayoutStorage(OzoneConfiguration conf, String dataNodeId)
throws IOException {
super(NodeType.DATANODE, ServerUtils.getOzoneMetaDirPath(conf),
DATANODE_LAYOUT_VERSION_DIR, dataNodeId, maxLayoutVersion());
DATANODE_LAYOUT_VERSION_DIR, dataNodeId, getDefaultLayoutVersion(conf));
}

public DatanodeLayoutStorage(OzoneConfiguration conf, String dataNodeId,
Expand All @@ -61,4 +62,36 @@ public File getCurrentDir() {
protected Properties getNodeProperties() {
return new Properties();
}

/**
* Older versions of the code did not write a VERSION file to disk for the
* datanode. Therefore, When a datanode starts up and does not find a metadata
* layout version written to disk, it must figure out whether
* it is being installed on a new system, or as part of an upgrade to an
* existing system. To do this, it will use the presence of the datanode.id
* file to indicate that it is being started as part of an upgrade and
* should start with the initial layout version. Otherwise, it will use the
* latest layout version.
*
* This is only an issue when upgrading from software layout version
* {@link HDDSLayoutFeature#INITIAL_VERSION} to
* {@link HDDSLayoutFeature#DATANODE_SCHEMA_V2}. After this, the upgrade
* framework will write a VERSION file for the datanode and future software
* versions will always know the MLV to use. The result of this method will
* not be used in this case.
*
* @return The layout version that should be used for the datanode if no
* layout version is found on disk.
*/
private static int getDefaultLayoutVersion(OzoneConfiguration conf) {
int defaultLayoutVersion = maxLayoutVersion();

File dnIdFile = new File(HddsServerUtil.getDatanodeIdFilePath(conf));
if (dnIdFile.exists()) {
defaultLayoutVersion =
HDDSLayoutFeature.INITIAL_VERSION.layoutVersion();
}

return defaultLayoutVersion;
}
}