Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.iotdb.db.storageengine.dataregion.compaction.execute.performer.impl;

import org.apache.iotdb.commons.utils.FileUtils;
import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.db.storageengine.dataregion.compaction.execute.utils.CompactionUtils;
import org.apache.iotdb.db.storageengine.dataregion.compaction.execute.utils.writer.AbstractCompactionWriter;
Expand All @@ -34,7 +35,6 @@
import org.apache.tsfile.encrypt.EncryptParameter;

import java.io.IOException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -83,17 +83,18 @@ protected QueryDataSource initQueryDataSource() {
private void prepareTargetFile() throws IOException {
TsFileResource seqSourceFile = seqFiles.get(0);
TsFileResource targetFile = targetFiles.get(0);
Files.createLink(targetFile.getTsFile().toPath(), seqSourceFile.getTsFile().toPath());
FileUtils.createLink(targetFile.getTsFile().toPath(), seqSourceFile.getTsFile().toPath(), true);
ITimeIndex timeIndex = seqSourceFile.getTimeIndex();
if (timeIndex instanceof ArrayDeviceTimeIndex) {
targetFile.setTimeIndex(timeIndex);
} else {
targetFile.setTimeIndex(CompactionUtils.buildDeviceTimeIndex(seqSourceFile));
}
if (seqSourceFile.anyModFileExists()) {
Files.createLink(
FileUtils.createLink(
seqSourceFile.getCompactionModFile().getFile().toPath(),
seqSourceFile.getExclusiveModFile().getFile().toPath());
seqSourceFile.getExclusiveModFile().getFile().toPath(),
true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.iotdb.db.storageengine.dataregion.compaction.execute.task;

import org.apache.iotdb.commons.utils.FileUtils;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.i18n.StorageEngineMessages;
import org.apache.iotdb.db.service.metrics.FileMetrics;
Expand Down Expand Up @@ -221,10 +222,11 @@ public File generateTargetFile() throws IOException {
private void prepareTargetFiles() throws IOException {
File sourceTsFile = unseqFileToInsert.getTsFile();
File targetTsFile = targetFile.getTsFile();
Files.createLink(targetTsFile.toPath(), sourceTsFile.toPath());
Files.createLink(
FileUtils.createLink(targetTsFile.toPath(), sourceTsFile.toPath(), true);
FileUtils.createLink(
new File(targetTsFile.getPath() + TsFileResource.RESOURCE_SUFFIX).toPath(),
new File(sourceTsFile.getPath() + TsFileResource.RESOURCE_SUFFIX).toPath());
new File(sourceTsFile.getPath() + TsFileResource.RESOURCE_SUFFIX).toPath(),
true);

unseqFileToInsert.linkModFile(targetFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.iotdb.db.storageengine.dataregion.modification.v1;

import org.apache.iotdb.commons.utils.FileUtils;
import org.apache.iotdb.db.i18n.StorageEngineMessages;
import org.apache.iotdb.db.storageengine.dataregion.modification.v1.io.LocalTextModificationAccessor;
import org.apache.iotdb.db.storageengine.dataregion.modification.v1.io.ModificationReader;
Expand Down Expand Up @@ -181,7 +182,7 @@ public ModificationFileV1 createHardlink() {
File hardlink = new File(filePath + hardlinkSuffix);

try {
Files.createLink(Paths.get(hardlink.getAbsolutePath()), Paths.get(filePath));
FileUtils.createLink(Paths.get(hardlink.getAbsolutePath()), Paths.get(filePath), true);
return new ModificationFileV1(hardlink.getAbsolutePath());
} catch (FileAlreadyExistsException e) {
// retry a different name if the file is already created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.pipe.datastructure.resource.PersistentResource;
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
import org.apache.iotdb.commons.utils.FileUtils;
import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
Expand Down Expand Up @@ -74,7 +75,6 @@
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -407,10 +407,11 @@ public boolean anyModFileExists() {
}

public void link(TsFileResource target) throws IOException {
Files.createLink(target.getTsFile().toPath(), this.getTsFile().toPath());
Files.createLink(
FileUtils.createLink(target.getTsFile().toPath(), this.getTsFile().toPath(), true);
FileUtils.createLink(
new File(target.getTsFilePath() + TsFileResource.RESOURCE_SUFFIX).toPath(),
new File(this.getTsFilePath() + TsFileResource.RESOURCE_SUFFIX).toPath());
new File(this.getTsFilePath() + TsFileResource.RESOURCE_SUFFIX).toPath(),
true);
linkModFile(target);
}

Expand All @@ -422,8 +423,8 @@ public void linkModFile(TsFileResource target) throws IOException {
try {
if (sourceModFile.exists()) {
// inherit modifications from the source file
Files.createLink(
targetModsFile.toPath(), ModificationFile.getExclusiveMods(getTsFile()).toPath());
FileUtils.createLink(
targetModsFile.toPath(), ModificationFile.getExclusiveMods(getTsFile()).toPath(), true);
}
// ensure that new modifications will be written into the target file
targetModsFileObject = new ModificationFile(targetModsFile, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ public static boolean deleteFileIfExist(File file) {
}
}

public static void createLink(Path link, Path existing, boolean fallBackToCopy)
throws IOException {
try {
Files.createLink(link, existing);
} catch (IOException | UnsupportedOperationException e) {
if (!fallBackToCopy) {
throw e;
}
try {
Files.copy(existing, link);
} catch (IOException copyException) {
copyException.addSuppressed(e);
throw copyException;
}
}
}

public static void deleteFileOrDirectory(File file) {
deleteFileOrDirectory(file, false);
}
Expand Down
Loading