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 2019/03/20 10:24:00 UTC

[GitHub] [incubator-iotdb] fanhualta commented on a change in pull request #101: [IOTDB-51]Reimplement post-back module, rename it to synchronization module

fanhualta commented on a change in pull request #101: [IOTDB-51]Reimplement post-back module, rename it to synchronization module
URL: https://github.com/apache/incubator-iotdb/pull/101#discussion_r267269971
 
 

 ##########
 File path: iotdb/src/main/java/org/apache/iotdb/db/sync/conf/SyncSenderDescriptor.java
 ##########
 @@ -28,93 +28,110 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/**
- * @author lta
- */
-public class PostBackSenderDescriptor {
+public class SyncSenderDescriptor {
 
-  private static final Logger LOGGER = LoggerFactory.getLogger(PostBackSenderDescriptor.class);
-  private static final String POSTBACK = "postback";
-  private PostBackSenderConfig conf = new PostBackSenderConfig();
+  private static final Logger LOGGER = LoggerFactory.getLogger(SyncSenderDescriptor.class);
+  private SyncSenderConfig conf = new SyncSenderConfig();
 
-  private PostBackSenderDescriptor() {
+  private SyncSenderDescriptor() {
     loadProps();
   }
 
-  public static final PostBackSenderDescriptor getInstance() {
+  public static final SyncSenderDescriptor getInstance() {
     return PostBackDescriptorHolder.INSTANCE;
   }
 
-  public PostBackSenderConfig getConfig() {
+  public SyncSenderConfig getConfig() {
     return conf;
   }
 
-  public void setConfig(PostBackSenderConfig conf) {
+  public void setConfig(SyncSenderConfig conf) {
     this.conf = conf;
   }
 
   /**
-   * load an properties file and set TsfileDBConfig variables
+   * load an properties file and set sync config variables
    */
   private void loadProps() {
+    conf.init();
+    InputStream inputStream;
     String url = System.getProperty(IoTDBConstant.IOTDB_CONF, null);
     if (url == null) {
       url = System.getProperty(IoTDBConstant.IOTDB_HOME, null);
       if (url != null) {
         url = url + File.separatorChar + "conf" + File.separatorChar
-            + PostBackSenderConfig.CONFIG_NAME;
+            + Constans.CONFIG_NAME;
       } else {
         LOGGER.warn(
             "Cannot find IOTDB_HOME or IOTDB_CONF environment variable when loading config file {}, use default configuration",
-            PostBackSenderConfig.CONFIG_NAME);
+            Constans.CONFIG_NAME);
         return;
       }
     } else {
-      url += (File.separatorChar + PostBackSenderConfig.CONFIG_NAME);
+      url += (File.separatorChar + Constans.CONFIG_NAME);
+    }
+
+    try {
+      inputStream = new FileInputStream(new File(url));
+    } catch (FileNotFoundException e) {
+      LOGGER.warn("Fail to find sync config file {}", url, e);
+      return;
     }
 
-    LOGGER.info("Start to read config file {}", url);
+    LOGGER.info("Start to read sync config file {}", url);
     Properties properties = new Properties();
-    try (InputStream inputStream = new FileInputStream(new File(url))) {
+    try {
       properties.load(inputStream);
 
       conf.setServerIp(properties.getProperty("server_ip", conf.getServerIp()));
       conf.setServerPort(Integer
           .parseInt(properties.getProperty("server_port", Integer.toString(conf.getServerPort()))));
-
-      conf.setClientPort(Integer
-          .parseInt(properties.getProperty("client_port", Integer.toString(conf.getClientPort()))));
       conf.setUploadCycleInSeconds(Integer.parseInt(properties
           .getProperty("upload_cycle_in_seconds",
               Integer.toString(conf.getUploadCycleInSeconds()))));
       conf.setSchemaPath(properties.getProperty("iotdb_schema_directory", conf.getSchemaPath()));
-      conf.setClearEnable(Boolean
-          .parseBoolean(
-              properties.getProperty("is_clear_enable", Boolean.toString(conf.getClearEnable()))));
-      conf.setUuidPath(conf.getDataDirectory() + POSTBACK + File.separator + "uuid.txt");
+      conf.setDataDirectory(
+          properties.getProperty("iotdb_bufferWrite_directory", conf.getDataDirectory()));
+      String dataDirectory = conf.getDataDirectory();
+      if (dataDirectory.length() > 0
+          && dataDirectory.charAt(dataDirectory.length() - 1) != File.separatorChar) {
+        dataDirectory += File.separatorChar;
+      }
+      conf.setUuidPath(
+          dataDirectory + Constans.SYNC_CLIENT + File.separatorChar + Constans.UUID_FILE_NAME);
       conf.setLastFileInfo(
-          conf.getDataDirectory() + POSTBACK + File.separator + "lastLocalFileList.txt");
-      String[] iotdbBufferwriteDirectory = conf.getIotdbBufferwriteDirectory();
-      String[] snapshots = new String[conf.getIotdbBufferwriteDirectory().length];
-      for (int i = 0; i < conf.getIotdbBufferwriteDirectory().length; i++) {
-        iotdbBufferwriteDirectory[i] = new File(iotdbBufferwriteDirectory[i]).getAbsolutePath();
-        if (!iotdbBufferwriteDirectory[i].endsWith(File.separator)) {
-          iotdbBufferwriteDirectory[i] = iotdbBufferwriteDirectory[i] + File.separator;
+          dataDirectory + Constans.SYNC_CLIENT + File.separatorChar
+              + Constans.LAST_LOCAL_FILE_NAME);
+      String[] iotdbBufferwriteDirectory = conf.getBufferwriteDirectory();
+      String[] snapshots = new String[conf.getBufferwriteDirectory().length];
+      for (int i = 0; i < conf.getBufferwriteDirectory().length; i++) {
+        if (iotdbBufferwriteDirectory[i].length() > 0
+            && iotdbBufferwriteDirectory[i].charAt(iotdbBufferwriteDirectory[i].length() - 1)
+            != File.separatorChar) {
+          iotdbBufferwriteDirectory[i] = iotdbBufferwriteDirectory[i] + File.separatorChar;
         }
-        snapshots[i] = iotdbBufferwriteDirectory[i] + POSTBACK + File.separator + "dataSnapshot"
-            + File.separator;
+        snapshots[i] = iotdbBufferwriteDirectory[i] + Constans.SYNC_CLIENT + File.separatorChar
+            + Constans.DATA_SNAPSHOT_NAME + File.separatorChar;
       }
-      conf.setIotdbBufferwriteDirectory(iotdbBufferwriteDirectory);
+      conf.setBufferwriteDirectory(iotdbBufferwriteDirectory);
       conf.setSnapshotPaths(snapshots);
     } catch (IOException e) {
       LOGGER.warn("Cannot load config file because {}, use default configuration", e);
     } catch (Exception e) {
       LOGGER.warn("Error format in config file because {}, use default configuration", e);
+    } finally {
+      if (inputStream != null) {
 
 Review comment:
   I imitate conf.IoTDBDescriptor and that has the same unnecessary code, fixed.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services