Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
db0cf77
HDDS-7083. Spread container-copy directories
symious Aug 3, 2022
ea07251
HDDS-7083. Add config in ozone-default.xml
symious Aug 3, 2022
e5c0a34
HDDS-7083. Enable spread volume feature by default
symious Aug 9, 2022
75e9f8d
HDDS-7083. Deprecate configuration and use tmp/container-copy directory
symious Aug 16, 2022
1cc345d
HDDS-7083. Fix config test
symious Aug 16, 2022
14d3e00
HDDS-7083. Add deprecated key
symious Aug 16, 2022
615070d
HDDS-7083. Download, untar, move, then load container
symious Aug 25, 2022
417fd4b
HDDS-7083. Unit test to be fixed
symious Aug 26, 2022
1ef25a4
HDDS-7083. parameter not to create dir when initializing
symious Sep 2, 2022
4bfa4df
HDDS-7083. Fix unit test
symious Sep 2, 2022
f590482
trigger new CI check
symious Sep 2, 2022
8cb4030
trigger new CI check
symious Sep 3, 2022
dfd161d
trigger new CI check
symious Sep 3, 2022
e551a67
Merge branch 'master' into HDDS-7083
symious Dec 10, 2022
205d6a3
HDDS-7083. Remove unused import
symious Dec 10, 2022
fc6bee4
Merge branch 'master' into HDDS-7083
symious Dec 14, 2022
cc5dcdf
Merge branch 'master' into HDDS-7083
symious Dec 18, 2022
4ecff14
HDDS-7083. Fix according to comments
symious Dec 18, 2022
2207a50
Merge branch 'master' into HDDS-7083
symious Jan 8, 2023
a5c34fe
HDDS-7083. Remove duplicated import
symious Jan 8, 2023
299d0f6
HDDS-7083. Delete tmp direcotry
symious Jan 9, 2023
c62d37f
HDDS-7083. Delete temporary files
symious Jan 10, 2023
e8f036e
HDDS-7083. Throw proper exception
symious Jan 10, 2023
5806f6c
HDDS-7083. Clean tmp data
symious Jan 11, 2023
0f1780d
HDDS-7083. Remove unused import
symious Jan 11, 2023
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 @@ -46,6 +46,7 @@
import org.apache.ratis.server.RaftServerConfigKeys;

import static org.apache.hadoop.hdds.ratis.RatisHelper.HDDS_DATANODE_RATIS_PREFIX_KEY;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CONTAINER_COPY_WORKDIR;

/**
* Configuration for ozone.
Expand Down Expand Up @@ -308,7 +309,9 @@ private static void addDeprecatedKeys() {
new DeprecationDelta("dfs.datanode.keytab.file",
DFSConfigKeysLegacy.DFS_DATANODE_KERBEROS_KEYTAB_FILE_KEY),
new DeprecationDelta("ozone.scm.chunk.layout",
ScmConfigKeys.OZONE_SCM_CONTAINER_LAYOUT_KEY)
ScmConfigKeys.OZONE_SCM_CONTAINER_LAYOUT_KEY),
new DeprecationDelta("hdds.datanode.replication.work.dir",
OZONE_CONTAINER_COPY_WORKDIR)
});
}
}
6 changes: 3 additions & 3 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1579,9 +1579,9 @@
<property>
<name>hdds.datanode.replication.work.dir</name>
<tag>DATANODE</tag>
<description>Temporary which is used during the container replication
betweeen datanodes. Should have enough space to store multiple container
(in compressed format), but doesn't require fast io access such as SSD.
<description>This configuration is deprecated. Temporary sub directory under
each hdds.datanode.dir will be used during the container replication between
datanodes to save the downloaded container(in compressed format).
</description>
</property>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.hadoop.fs.FileAlreadyExistsException;
Expand Down Expand Up @@ -278,4 +280,22 @@ public static long getContainerID(File containerBaseDir) {
return Long.parseLong(containerBaseDir.getName());
}

public static String getContainerTarGzName(long containerId) {
return "container-" + containerId + ".tar.gz";
}

public static long retrieveContainerIdFromTarGzName(String tarGzName)
throws IOException {
assert tarGzName != null;
Pattern pattern = Pattern.compile("container-(\\d+).tar.gz");
// Now create matcher object.
Matcher m = pattern.matcher(tarGzName);

if (m.find()) {
return Long.parseLong(m.group(1));
} else {
throw new IOException("Illegal container tar gz file " +
tarGzName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;

import org.apache.hadoop.ozone.container.common.impl.ContainerData;

Expand All @@ -39,7 +40,7 @@ public interface ContainerPacker<CONTAINERDATA extends ContainerData> {
* file but returned).
*/
byte[] unpackContainerData(Container<CONTAINERDATA> container,
InputStream inputStream)
InputStream inputStream, Path tmpDir, Path destContainerDir)
throws IOException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ public DatanodeStateMachine(DatanodeDetails datanodeDetails,
nextHB = new AtomicLong(Time.monotonicNow());

ContainerReplicator replicator =
new DownloadAndImportReplicator(container.getContainerSet(),
new DownloadAndImportReplicator(conf, container.getContainerSet(),
container.getController(),
new SimpleContainerDownloader(conf, dnCertClient),
new TarContainerPacker());
new TarContainerPacker(), container.getVolumeSet());

replicatorMetrics = new MeasuredReplicator(replicator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.hadoop.ozone.container.keyvalue.helpers.BlockUtils;
import org.apache.hadoop.ozone.container.metadata.DatanodeStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
Expand All @@ -40,6 +41,9 @@
*/
public final class HddsVolumeUtil {

private static final Logger LOG =
LoggerFactory.getLogger(HddsVolumeUtil.class);

@ChenSammi ChenSammi Jan 9, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LOG is not used in anywhere. We can revert this change in this file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not addressed yet.

// Private constructor for Utility class. Unused.
private HddsVolumeUtil() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ public StorageType getStorageType() {
}
}

public String getVolumeRootDir() {
return volumeInfo != null ? volumeInfo.getRootDir() : null;
}

public long getCapacity() {
return volumeInfo != null ? volumeInfo.getCapacity() : 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.Instant;
import java.util.Collections;
Expand Down Expand Up @@ -56,6 +58,7 @@
import org.apache.hadoop.ozone.container.keyvalue.helpers.BlockUtils;
import org.apache.hadoop.ozone.container.keyvalue.helpers.KeyValueContainerLocationUtil;
import org.apache.hadoop.ozone.container.keyvalue.helpers.KeyValueContainerUtil;
import org.apache.hadoop.ozone.container.replication.DownloadAndImportReplicator;
import org.apache.hadoop.ozone.container.upgrade.VersionedDatanodeFeatures;
import org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException;

Expand Down Expand Up @@ -507,21 +510,22 @@ public void updateDeleteTransactionId(long deleteTransactionId) {

@Override
public void importContainerData(InputStream input,
ContainerPacker<KeyValueContainerData> packer) throws IOException {
ContainerPacker<KeyValueContainerData> packer)
throws IOException {
HddsVolume hddsVolume = containerData.getVolume();
String idDir = VersionedDatanodeFeatures.ScmHA.chooseContainerPathID(
hddsVolume, hddsVolume.getClusterID());
Path destContainerDir =
Paths.get(KeyValueContainerLocationUtil.getBaseContainerLocation(
hddsVolume.getHddsRootDir().toString(), idDir,
containerData.getContainerID()));
Path tmpDir = DownloadAndImportReplicator.getUntarDirectory(hddsVolume);
writeLock();
try {
if (getContainerFile().exists()) {
String errorMessage = String.format(
"Can't import container (cid=%d) data to a specific location"
+ " as the container descriptor (%s) has already been exist.",
getContainerData().getContainerID(),
getContainerFile().getAbsolutePath());
throw new StorageContainerException(errorMessage,
CONTAINER_ALREADY_EXISTS);
}
//copy the values from the input stream to the final destination
// directory.
byte[] descriptorContent = packer.unpackContainerData(this, input);
byte[] descriptorContent = packer.unpackContainerData(this, input, tmpDir,
destContainerDir);

Preconditions.checkNotNull(descriptorContent,
"Container descriptor is missing from the container archive: "
Expand All @@ -533,8 +537,16 @@ public void importContainerData(InputStream input,
KeyValueContainerData originalContainerData =
(KeyValueContainerData) ContainerDataYaml
.readContainer(descriptorContent);
importContainerData(originalContainerData);
} finally {
writeUnlock();
}
}


public void importContainerData(KeyValueContainerData originalContainerData)
throws IOException {
writeLock();
try {
containerData.setState(originalContainerData.getState());
containerData
.setContainerDBType(originalContainerData.getContainerDBType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,16 @@ ContainerCommandResponseProto handleCreateContainer(
return getSuccessResponse(request);
}

private void populateContainerPathFields(KeyValueContainer container)
throws IOException {
private void populateContainerPathFields(KeyValueContainer container,
HddsVolume hddsVolume) throws IOException {
volumeSet.readLock();
HddsVolume containerVolume = hddsVolume;
try {
HddsVolume containerVolume = volumeChoosingPolicy.chooseVolume(
StorageVolumeUtil.getHddsVolumesList(volumeSet.getVolumesList()),
container.getContainerData().getMaxSize());
if (hddsVolume == null) {

@ChenSammi ChenSammi Jan 9, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hddsVolume should not be null here. We need to make sure that in container.importContainerData, tmpDir and DownloadAndImportReplicator.getUntarDirectory(hddsVolume) are on the same volume so that atomic Files.move will not fail.

containerVolume = volumeChoosingPolicy.chooseVolume(
StorageVolumeUtil.getHddsVolumesList(volumeSet.getVolumesList()),
container.getContainerData().getMaxSize());
}
String idDir = VersionedDatanodeFeatures.ScmHA.chooseContainerPathID(
containerVolume, clusterId);
container.populatePathFields(idDir, containerVolume);
Expand Down Expand Up @@ -1014,8 +1017,7 @@ private void checkContainerOpen(KeyValueContainer kvContainer)
@Override
public Container importContainer(ContainerData originalContainerData,
final InputStream rawContainerStream,
final TarContainerPacker packer)
throws IOException {
final TarContainerPacker packer) throws IOException {
Preconditions.checkState(originalContainerData instanceof
KeyValueContainerData, "Should be KeyValueContainerData instance");

Expand All @@ -1025,7 +1027,8 @@ public Container importContainer(ContainerData originalContainerData,
KeyValueContainer container = new KeyValueContainer(containerData,
conf);

populateContainerPathFields(container);
HddsVolume targetVolume = originalContainerData.getVolume();
populateContainerPathFields(container, targetVolume);
container.importContainerData(rawContainerStream, packer);
sendICR(container);
return container;
Expand Down
Loading