Merging r1435 through r1446 (Young-Seouk's changes related to log manager configuration)

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_lsm_stabilization_installer@1447 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/PersistentLocalResourceRepository.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
index cf47740..838dc6d 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
@@ -34,6 +34,7 @@
 public class PersistentLocalResourceRepository implements ILocalResourceRepository {
 
     private final String mountPoint;
+    private static final String ROOT_METADATA_DIRECTORY = "asterix_root_metadata/";
     private static final String ROOT_METADATA_FILE_NAME_PREFIX = ".asterix_root_metadata_";
     private static final long ROOT_LOCAL_RESOURCE_ID = -4321;
     private static final String METADATA_FILE_NAME = ".metadata";
@@ -54,13 +55,20 @@
         }
     }
 
-    public void initialize(String nodeId, String rootDir, boolean isNewUniverse, ResourceIdFactory resourceIdFactory) throws HyracksDataException {
+    public void initialize(String nodeId, String rootDir, boolean isNewUniverse, ResourceIdFactory resourceIdFactory)
+            throws HyracksDataException {
         LocalResource rootLocalResource = null;
 
         //#. if the rootMetadataFile doesn't exist, create it and return.
-        rootMetadataFileName = new String(mountPoint + ROOT_METADATA_FILE_NAME_PREFIX + nodeId);
+        rootMetadataFileName = new String(mountPoint + ROOT_METADATA_DIRECTORY + ROOT_METADATA_FILE_NAME_PREFIX
+                + nodeId);
         File rootMetadataFile = new File(rootMetadataFileName);
         if (isNewUniverse) {
+            File rootMetadataDir = new File(mountPoint + ROOT_METADATA_DIRECTORY);
+            if (!rootMetadataDir.exists()) {
+                rootMetadataDir.mkdir();
+            }
+
             rootMetadataFile.delete();
             if (rootDir.startsWith(System.getProperty("file.separator"))) {
                 this.rootDir = new String(mountPoint + rootDir.substring(System.getProperty("file.separator").length()));
@@ -117,7 +125,7 @@
                 }
             }
         }
-        resourceIdFactory.initId(maxResourceId+1);
+        resourceIdFactory.initId(maxResourceId + 1);
     }
 
     @Override
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogManager.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogManager.java
index 242f228..4e96d2e 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogManager.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogManager.java
@@ -143,13 +143,13 @@
 
     public LogManager(TransactionSubsystem provider) throws ACIDException {
         this.provider = provider;
-        initLogManagerProperties(null);
+        initLogManagerProperties(this.provider.getId());
         initLogManager();
     }
 
-    public LogManager(TransactionSubsystem provider, LogManagerProperties logConfiguration) throws ACIDException {
+    public LogManager(TransactionSubsystem provider, String nodeId) throws ACIDException {
         this.provider = provider;
-        initLogManagerProperties(logConfiguration);
+        initLogManagerProperties(nodeId);
         initLogManager();
     }
 
@@ -157,54 +157,26 @@
      * initialize the log manager properties either from the configuration file
      * on disk or with default values
      */
-    private void initLogManagerProperties(LogManagerProperties logProperties) throws ACIDException {
-        if (logProperties == null) {
-            InputStream is = null;
-            try {
-                is = this.getClass().getClassLoader()
-                        .getResourceAsStream(TransactionManagementConstants.LogManagerConstants.LOG_CONF_FILE);
-                if (is != null) {
-                    Properties p = new Properties();
-                    p.load(is);
-                    String logDir = p.getProperty(LogManagerProperties.LOG_DIR_KEY);
-                    if (logDir == null) {
-                        p.setProperty(LogManagerProperties.LOG_DIR_KEY,
-                                TransactionManagementConstants.LogManagerConstants.DEFAULT_LOG_DIR + File.separator
-                                        + provider.getId());
-                    }
-                    logProperties = new LogManagerProperties(p);
+    private void initLogManagerProperties(String nodeId) throws ACIDException {
+        LogManagerProperties logProperties = null;
+        InputStream is = null;
+        try {
+            is = this.getClass().getClassLoader()
+                    .getResourceAsStream(TransactionManagementConstants.LogManagerConstants.LOG_CONF_FILE);
 
-                    /*
-                    File file = new File(TransactionManagementConstants.LogManagerConstants.LOG_CONF_DIR
-                            + File.pathSeparator + TransactionManagementConstants.LogManagerConstants.LOG_CONF_FILE);
-                    if (LOGGER.isLoggable(Level.INFO)) {
-                        LOGGER.info("Log Configuration file path is " + file.getAbsolutePath());
-                    }
-                    if (file.exists()) {
-                        is = new FileInputStream(TransactionManagementConstants.LogManagerConstants.LOG_CONF_DIR
-                                + File.pathSeparator + TransactionManagementConstants.LogManagerConstants.LOG_CONF_FILE);
-                        Properties configuredProperties = new Properties();
-                        configuredProperties.load(is);
-                        logConfiguration = new LogManagerProperties(configuredProperties);
-                    */
+            Properties p = new Properties();
 
-                } else {
-                    if (LOGGER.isLoggable(Level.INFO)) {
-                        LOGGER.info("Log configuration file not found, using defaults !");
-                    }
-                    Properties configuredProperties = new Properties();
-                    configuredProperties.setProperty(LogManagerProperties.LOG_DIR_KEY,
-                            TransactionManagementConstants.LogManagerConstants.DEFAULT_LOG_DIR + File.separator
-                                    + provider.getId());
-                    logProperties = new LogManagerProperties(configuredProperties);
-                }
-            } catch (IOException ioe) {
-                if (is != null) {
-                    try {
-                        is.close();
-                    } catch (IOException e) {
-                        throw new ACIDException("unable to close input stream ", e);
-                    }
+            if (is != null) {
+                p.load(is);
+            }
+            logProperties = new LogManagerProperties(p, nodeId);
+
+        } catch (IOException ioe) {
+            if (is != null) {
+                try {
+                    is.close();
+                } catch (IOException e) {
+                    throw new ACIDException("unable to close input stream ", e);
                 }
             }
         }
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogManagerProperties.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogManagerProperties.java
index 84294c9..0211f69 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogManagerProperties.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogManagerProperties.java
@@ -22,7 +22,7 @@
     private static final long serialVersionUID = 2084227360840799662L;
 
     public static final int LOG_MAGIC_NUMBER = 123456789;
-    public static final String LOG_DIR_KEY = "log_dir";
+    public static final String LOG_DIR_SUFFIX_KEY = ".txnLogDir";
     public static final String LOG_PAGE_SIZE_KEY = "log_page_size";
     public static final String LOG_PARTITION_SIZE_KEY = "log_partition_size";
     public static final String NUM_LOG_PAGES_KEY = "num_log_pages";
@@ -34,11 +34,12 @@
     private static final long DEFAULT_LOG_PARTITION_SIZE = (long) 1024 * 1024 * 1024 * 2; //2GB 
     private static final long DEFAULT_GROUP_COMMIT_WAIT_PERIOD = 1; // time in millisec.
     private static final String DEFAULT_LOG_FILE_PREFIX = "asterix_transaction_log";
-    private static final String DEFAULT_LOG_DIRECTORY = "asterix_logs";
+    private static final String DEFAULT_LOG_DIRECTORY = "asterix_logs/";
 
     // follow the naming convention <logFilePrefix>_<number> where number starts from 0
     private final String logFilePrefix;
     private final String logDir;
+    public String logDirKey;
 
     // number of log pages in the log buffer
     private final int logPageSize;
@@ -51,12 +52,13 @@
     // maximum size of each log file
     private final long logPartitionSize;
 
-    public LogManagerProperties(Properties properties) {
+    public LogManagerProperties(Properties properties, String nodeId) {
+        this.logDirKey = new String(nodeId + LOG_DIR_SUFFIX_KEY);
         this.logPageSize = Integer.parseInt(properties.getProperty(LOG_PAGE_SIZE_KEY, "" + DEFAULT_LOG_PAGE_SIZE));
         this.numLogPages = Integer.parseInt(properties.getProperty(NUM_LOG_PAGES_KEY, "" + DEFAULT_NUM_LOG_PAGES));
         long logPartitionSize = Long.parseLong(properties.getProperty(LOG_PARTITION_SIZE_KEY, ""
                 + DEFAULT_LOG_PARTITION_SIZE));
-        this.logDir = properties.getProperty(LOG_DIR_KEY, DEFAULT_LOG_DIRECTORY);
+        this.logDir = properties.getProperty(logDirKey, DEFAULT_LOG_DIRECTORY + nodeId);
         this.logFilePrefix = properties.getProperty(LOG_FILE_PREFIX_KEY, DEFAULT_LOG_FILE_PREFIX);
         this.groupCommitWaitPeriod = Long.parseLong(properties.getProperty(GROUP_COMMIT_WAIT_PERIOD_KEY, ""
                 + DEFAULT_GROUP_COMMIT_WAIT_PERIOD));
@@ -94,6 +96,10 @@
         return groupCommitWaitPeriod;
     }
 
+    public String getLogDirKey() {
+        return logDirKey;
+    }
+
     public String toString() {
         StringBuilder builder = new StringBuilder();
         builder.append("log_dir_ : " + logDir + FileUtil.lineSeparator);
diff --git a/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/test/LogRecordReader.java b/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/test/LogRecordReader.java
index 162660f..ad1238a 100644
--- a/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/test/LogRecordReader.java
+++ b/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/test/LogRecordReader.java
@@ -73,11 +73,7 @@
      * @param args
      */
     public static void main(String[] args) throws ACIDException, Exception {
-        Properties props = new Properties();
-        props.setProperty(LogManagerProperties.LOG_DIR_KEY,
-                "/Users/kisskys/workspace/sanitycheck_lsm_merge/asterix_lsm_stabilization/asterix-app/asterix_logs/nc1");
-        LogManagerProperties logProps = new LogManagerProperties(props);
-        LogManager logManager = new LogManager(null, logProps);
+        LogManager logManager = new LogManager(null, "nc1");
         LogRecordReader logReader = new LogRecordReader(logManager);
         logReader.readLogs(0);
     }