You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/03/18 11:02:44 UTC

[GitHub] [iotdb] qiaojialin commented on a change in pull request #5198: [IOTDB-2503] Import a Status for TsFileResource

qiaojialin commented on a change in pull request #5198:
URL: https://github.com/apache/iotdb/pull/5198#discussion_r829897410



##########
File path: server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileResource.java
##########
@@ -577,32 +570,56 @@ public int hashCode() {
     return Objects.hash(file);
   }
 
-  public void setClosed(boolean closed) {
-    this.closed = closed;
-  }
-
   public boolean isDeleted() {
-    return deleted;
-  }
-
-  public void setDeleted(boolean deleted) {
-    this.deleted = deleted;
+    return this.status == TsFileResourceStatus.DELETED;
   }
 
   public boolean isCompacting() {
-    return isCompacting;
-  }
-
-  public void setCompacting(boolean compacting) {
-    isCompacting = compacting;
+    return this.status == TsFileResourceStatus.COMPACTING;
   }
 
   public boolean isCompactionCandidate() {
-    return compactionCandidate;
+    return this.status == TsFileResourceStatus.COMPACTION_CANDIDATE;
   }
 
-  public void setCompactionCandidate(boolean compactionCandidate) {
-    this.compactionCandidate = compactionCandidate;
+  public boolean setStatus(TsFileResourceStatus status) {
+    boolean success = false;
+    switch (status) {
+      case CLOSED:
+        if (this.status != TsFileResourceStatus.DELETED) {
+          this.status = TsFileResourceStatus.CLOSED;
+          success = true;
+        }
+        break;
+      case UNCLOSED:
+        // Print a stack trace in a warn statement.
+        this.status = TsFileResourceStatus.UNCLOSED;
+        RuntimeException e = new RuntimeException();
+        LOGGER.warn("The status of {} is setting to unclosed", file, e);
+        break;
+      case DELETED:
+        if (this.status == TsFileResourceStatus.CLOSED
+            || this.status == TsFileResourceStatus.COMPACTING) {
+          this.status = TsFileResourceStatus.DELETED;
+          success = true;
+        }
+        break;
+      case COMPACTING:

Review comment:
       !(compaction candidate) -> compacting, throw exception
   !unclosed -> unclosed, throw exception
   unlcosed -> deleted, throw exception

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileResource.java
##########
@@ -577,32 +570,56 @@ public int hashCode() {
     return Objects.hash(file);
   }
 
-  public void setClosed(boolean closed) {
-    this.closed = closed;
-  }
-
   public boolean isDeleted() {
-    return deleted;
-  }
-
-  public void setDeleted(boolean deleted) {
-    this.deleted = deleted;
+    return this.status == TsFileResourceStatus.DELETED;
   }
 
   public boolean isCompacting() {
-    return isCompacting;
-  }
-
-  public void setCompacting(boolean compacting) {
-    isCompacting = compacting;
+    return this.status == TsFileResourceStatus.COMPACTING;
   }
 
   public boolean isCompactionCandidate() {
-    return compactionCandidate;
+    return this.status == TsFileResourceStatus.COMPACTION_CANDIDATE;
   }
 
-  public void setCompactionCandidate(boolean compactionCandidate) {
-    this.compactionCandidate = compactionCandidate;
+  public boolean setStatus(TsFileResourceStatus status) {

Review comment:
       ```suggestion
     public void setStatus(TsFileResourceStatus status) throw StatusChangeException{
   ```




-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org