jt2594838 commented on a change in pull request #1169:
URL: https://github.com/apache/incubator-iotdb/pull/1169#discussion_r427948083
##########
File path:
server/src/main/java/org/apache/iotdb/db/engine/modification/ModificationFile.java
##########
@@ -125,4 +133,34 @@ public void remove() throws IOException {
FSFactoryProducer.getFSFactory().getFile(filePath).delete();
}
+ public boolean exists() {
+ return new File(filePath).exists();
+ }
+
+ /**
+ * Create a hardlink for the modification file.
+ * The hardlink with have a suffix like ".{sysTime}_{randomLong}"
+ * @return a new ModificationFile with its path changed to the hardlink, or
null if the origin
+ * file does not exist or the hardlink cannot be created.
+ */
+ public ModificationFile createHardlink() {
+ if (!exists()) {
+ return null;
+ }
+
+ while (true) {
+ String hardlinkSuffix = "." + System.currentTimeMillis() + "_" +
random.nextLong();
+ File hardlink = new File(filePath + hardlinkSuffix);
+
+ try {
+ Files.createLink(Paths.get(hardlink.getAbsolutePath()),
Paths.get(filePath));
+ return new ModificationFile(hardlink.getAbsolutePath());
+ } catch (FileAlreadyExistsException e) {
+ // retry a different name if the file is already created
Review comment:
The name is generated randomly, so continuing is a retry.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]