ChenSammi commented on code in PR #3648:
URL: https://github.com/apache/ozone/pull/3648#discussion_r1045962458
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/DownloadAndImportReplicator.java:
##########
@@ -46,36 +60,68 @@ public class DownloadAndImportReplicator implements
ContainerReplicator {
public static final Logger LOG =
LoggerFactory.getLogger(DownloadAndImportReplicator.class);
- private final ContainerSet containerSet;
+ public static final String CONTAINER_COPY_DIR = "container-copy";
+ public static final String CONTAINER_COPY_TMP_DIR = "tmp";
+ private final ConfigurationSource conf;
+ private final ContainerSet containerSet;
private final ContainerController controller;
-
private final ContainerDownloader downloader;
-
private final TarContainerPacker packer;
+ private final MutableVolumeSet volumeSet;
+ private VolumeChoosingPolicy volumeChoosingPolicy;
+ private long containerSize;
+ private Map<HddsVolume, ContainerReader> containerReaderMap;
public DownloadAndImportReplicator(
+ ConfigurationSource conf,
ContainerSet containerSet,
ContainerController controller,
ContainerDownloader downloader,
- TarContainerPacker packer) {
+ TarContainerPacker packer,
+ MutableVolumeSet volumeSet) {
+ this.conf = conf;
this.containerSet = containerSet;
this.controller = controller;
this.downloader = downloader;
this.packer = packer;
+ this.volumeSet = volumeSet;
+ try {
+ this.volumeChoosingPolicy = conf.getClass(
+ HDDS_DATANODE_VOLUME_CHOOSING_POLICY, RoundRobinVolumeChoosingPolicy
+ .class, VolumeChoosingPolicy.class).newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ this.containerSize = (long) conf.getStorageSize(
+ ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE,
+ ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES);
+
+ this.containerReaderMap = new HashMap<>();
+ for (HddsVolume hddsVolume: getHddsVolumesList()) {
+ containerReaderMap.put(hddsVolume,
+ new ContainerReader(volumeSet, hddsVolume, containerSet, conf,
+ false));
+ }
}
- public void importContainer(long containerID, Path tarFilePath)
- throws IOException {
+ public void importContainer(long containerID, Path tarFilePath,
+ HddsVolume hddsVolume) throws IOException {
+
+ HddsVolume targetVolume = hddsVolume;
+ if (targetVolume == null) {
+ targetVolume = chooseNextVolume();
+ }
+ KeyValueContainerData originalContainerData;
try {
- ContainerData originalContainerData;
- try (FileInputStream tempContainerTarStream = new FileInputStream(
+ try (FileInputStream tmpContainerTarStream = new FileInputStream(
tarFilePath.toFile())) {
byte[] containerDescriptorYaml =
- packer.unpackContainerDescriptor(tempContainerTarStream);
- originalContainerData = ContainerDataYaml.readContainer(
- containerDescriptorYaml);
+ packer.unpackContainerDescriptor(tmpContainerTarStream);
+ originalContainerData = (KeyValueContainerData) ContainerDataYaml
+ .readContainer(containerDescriptorYaml);
}
+ originalContainerData.setVolume(targetVolume);
Review Comment:
Should delete both the tarFilePath and tared file directory in finally in
case import failed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]