This is an automated email from the ASF dual-hosted git repository.

lta pushed a commit to branch cluster_multi_raft
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit ae1b6f30341a36da9c773cf95a20e5d9c332b5e9
Author: lta <[email protected]>
AuthorDate: Tue Dec 29 15:02:56 2020 +0800

    assign slots
---
 .../java/org/apache/iotdb/cluster/ClusterMain.java | 14 ++++----
 .../iotdb/db/metadata/logfile/MLogWriter.java      | 38 +++++++++++-----------
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java 
b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java
index 491d577..bcde426 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java
@@ -288,8 +288,8 @@ public class ClusterMain {
       @Override
       public int calculateSlotByTime(String storageGroupName, long timestamp, 
int maxSlotNum) {
         int sgSerialNum = extractSerialNumInSGName(storageGroupName) % k;
-        if (sgSerialNum > 0) {
-          return maxSlotNum / k * sgSerialNum;
+        if (sgSerialNum >= 0) {
+          return (int)(maxSlotNum / k * (sgSerialNum + 0.5));
         } else {
           return defaultStrategy.calculateSlotByTime(storageGroupName, 
timestamp, maxSlotNum);
         }
@@ -299,20 +299,20 @@ public class ClusterMain {
       public int calculateSlotByPartitionNum(String storageGroupName, long 
partitionId,
           int maxSlotNum) {
         int sgSerialNum = extractSerialNumInSGName(storageGroupName) % k;
-        if (sgSerialNum > 0) {
-          return maxSlotNum / k * sgSerialNum;
+        if (sgSerialNum >= 0) {
+          return (int)(maxSlotNum / k * (sgSerialNum + 0.5));
         } else {
           return defaultStrategy.calculateSlotByPartitionNum(storageGroupName, 
partitionId, maxSlotNum);
         }
       }
 
       private int extractSerialNumInSGName(String storageGroupName) {
-//        String[] s = storageGroupName.split("\\.");
-        String[] s = storageGroupName.split("_");
+        String[] s = storageGroupName.split("\\.");
+//        String[] s = storageGroupName.split("_");
         if (s.length != 2) {
           return -1;
         }
-//        s[1] = s[1].substring(4);
+        s[1] = s[1].substring(4);
         try {
           return Integer.parseInt(s[1]);
         } catch (NumberFormatException e) {
diff --git 
a/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogWriter.java 
b/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogWriter.java
index 6191141..aa31a4e 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogWriter.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogWriter.java
@@ -114,7 +114,7 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void createTimeseries(CreateTimeSeriesPlan createTimeSeriesPlan) 
throws IOException {
+  public synchronized void createTimeseries(CreateTimeSeriesPlan 
createTimeSeriesPlan) throws IOException {
     try {
       putLog(createTimeSeriesPlan);
     } catch (BufferOverflowException e) {
@@ -123,7 +123,7 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void deleteTimeseries(DeleteTimeSeriesPlan deleteTimeSeriesPlan) 
throws IOException {
+  public synchronized void deleteTimeseries(DeleteTimeSeriesPlan 
deleteTimeSeriesPlan) throws IOException {
     try {
       putLog(deleteTimeSeriesPlan);
     } catch (BufferOverflowException e) {
@@ -132,7 +132,7 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void setStorageGroup(PartialPath storageGroup) throws IOException {
+  public synchronized void setStorageGroup(PartialPath storageGroup) throws 
IOException {
     try {
       SetStorageGroupPlan plan = new SetStorageGroupPlan(storageGroup);
       putLog(plan);
@@ -142,7 +142,7 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void deleteStorageGroup(PartialPath storageGroup) throws IOException {
+  public synchronized void deleteStorageGroup(PartialPath storageGroup) throws 
IOException {
     try {
       DeleteStorageGroupPlan plan = new 
DeleteStorageGroupPlan(Collections.singletonList(storageGroup));
       putLog(plan);
@@ -152,7 +152,7 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void setTTL(PartialPath storageGroup, long ttl) throws IOException {
+  public synchronized void setTTL(PartialPath storageGroup, long ttl) throws 
IOException {
     try {
       SetTTLPlan plan = new SetTTLPlan(storageGroup, ttl);
       putLog(plan);
@@ -162,7 +162,7 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void changeOffset(PartialPath path, long offset) throws IOException {
+  public synchronized void changeOffset(PartialPath path, long offset) throws 
IOException {
     try {
       ChangeTagOffsetPlan plan = new ChangeTagOffsetPlan(path, offset);
       putLog(plan);
@@ -172,7 +172,7 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void changeAlias(PartialPath path, String alias) throws IOException {
+  public synchronized void changeAlias(PartialPath path, String alias) throws 
IOException {
     try {
       ChangeAliasPlan plan = new ChangeAliasPlan(path, alias);
       putLog(plan);
@@ -182,7 +182,7 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void serializeMNode(MNode node) throws IOException {
+  public synchronized void serializeMNode(MNode node) throws IOException {
     try {
       int childSize = 0;
       if (node.getChildren() != null) {
@@ -196,7 +196,7 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void serializeMeasurementMNode(MeasurementMNode node) throws 
IOException {
+  public synchronized void serializeMeasurementMNode(MeasurementMNode node) 
throws IOException {
     try {
       int childSize = 0;
       if (node.getChildren() != null) {
@@ -211,7 +211,7 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void serializeStorageGroupMNode(StorageGroupMNode node) throws 
IOException {
+  public synchronized void serializeStorageGroupMNode(StorageGroupMNode node) 
throws IOException {
     try {
       int childSize = 0;
       if (node.getChildren() != null) {
@@ -226,7 +226,7 @@ public class MLogWriter implements AutoCloseable {
   }
 
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity 
warning
-  public static void upgradeTxtToBin(String schemaDir, String oldFileName,
+  public synchronized static void upgradeTxtToBin(String schemaDir, String 
oldFileName,
                                      String newFileName, boolean isSnapshot) 
throws IOException {
     File logFile = SystemFileFactory.INSTANCE.getFile(schemaDir + 
File.separator + newFileName);
     File tmpLogFile = 
SystemFileFactory.INSTANCE.getFile(logFile.getAbsolutePath() + ".tmp");
@@ -293,13 +293,13 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public static void upgradeMLog() throws IOException {
+  public synchronized static void upgradeMLog() throws IOException {
     String schemaDir = 
IoTDBDescriptor.getInstance().getConfig().getSchemaDir();
     upgradeTxtToBin(schemaDir, MetadataConstant.METADATA_TXT_LOG, 
MetadataConstant.METADATA_LOG, false);
     upgradeTxtToBin(schemaDir, MetadataConstant.MTREE_TXT_SNAPSHOT, 
MetadataConstant.MTREE_SNAPSHOT, true);
   }
 
-  public void clear() throws IOException {
+  public synchronized void clear() throws IOException {
     sync();
     logWriter.close();
     mlogBuffer.clear();
@@ -310,18 +310,18 @@ public class MLogWriter implements AutoCloseable {
     logWriter = new LogWriter(logFile, false);
   }
 
-  public int getLogNum() {
+  public synchronized int getLogNum() {
     return logNum;
   }
 
   /**
    * only used for initialize a mlog file writer.
    */
-  public void setLogNum(int number) {
+  public synchronized void setLogNum(int number) {
     logNum = number;
   }
 
-  public void operation(String cmd, boolean isSnapshot) throws IOException, 
MetadataException {
+  public synchronized void operation(String cmd, boolean isSnapshot) throws 
IOException, MetadataException {
     if (!isSnapshot) {
       operation(cmd);
     } else {
@@ -344,7 +344,7 @@ public class MLogWriter implements AutoCloseable {
    * @throws MetadataException
    */
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity 
warning
-  public void operation(String cmd) throws IOException, MetadataException {
+  public synchronized void operation(String cmd) throws IOException, 
MetadataException {
     // see createTimeseries() to get the detailed format of the cmd
     String[] args = cmd.trim().split(",", -1);
     switch (args[0]) {
@@ -429,11 +429,11 @@ public class MLogWriter implements AutoCloseable {
     }
   }
 
-  public void force() throws IOException {
+  public synchronized void force() throws IOException {
     logWriter.force();
   }
 
-  public static PhysicalPlan convertFromString(String str) {
+  public synchronized static PhysicalPlan convertFromString(String str) {
     String[] words = str.split(",");
     switch (words[0]) {
       case "2":

Reply via email to