Changes to use a property file to initialize LogManager
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_lsm_stabilization@1378 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogCursor.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogCursor.java
index e04ca95..9ad66bc 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogCursor.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogCursor.java
@@ -107,7 +107,7 @@
while (logicalLogLocator.getMemoryOffset() <= readOnlyBuffer.getSize()
- logManager.getLogRecordHelper().getLogHeaderSize(LogType.COMMIT)) {
integerRead = readOnlyBuffer.readInt(logicalLogLocator.getMemoryOffset());
- if (integerRead == logManager.getLogManagerProperties().logMagicNumber) {
+ if (integerRead == logManager.getLogManagerProperties().LOG_MAGIC_NUMBER) {
logRecordBeginPosFound = true;
break;
}
@@ -193,7 +193,7 @@
//----------------------------------------------------------------
int readNumber = -1;
int logPageSize = logManager.getLogManagerProperties().getLogPageSize();
- int logMagicNumber = logManager.getLogManagerProperties().logMagicNumber;
+ int logMagicNumber = logManager.getLogManagerProperties().LOG_MAGIC_NUMBER;
int bytesSkipped = 0;
boolean logRecordBeginPosFound = false;
//check whether the currentOffset has enough space to have new log record by comparing
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 64376aa..f3c33f8 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
@@ -15,7 +15,6 @@
package edu.uci.ics.asterix.transaction.management.service.logging;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
@@ -158,21 +157,37 @@
* initialize the log manager properties either from the configuration file
* on disk or with default values
*/
- private void initLogManagerProperties(LogManagerProperties logConfiguration) throws ACIDException {
- if (logConfiguration == null) {
+ private void initLogManagerProperties(LogManagerProperties logProperties) throws ACIDException {
+ if (logProperties == null) {
InputStream is = null;
try {
- 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
+ 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);
+
+ /*
+ File file = new File(TransactionManagementConstants.LogManagerConstants.LOG_CONF_DIR
+ File.pathSeparator + TransactionManagementConstants.LogManagerConstants.LOG_CONF_FILE);
- Properties configuredProperties = new Properties();
- configuredProperties.load(is);
- logConfiguration = new LogManagerProperties(configuredProperties);
+ 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);
+ */
+
} else {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Log configuration file not found, using defaults !");
@@ -181,7 +196,7 @@
configuredProperties.setProperty(LogManagerProperties.LOG_DIR_KEY,
TransactionManagementConstants.LogManagerConstants.DEFAULT_LOG_DIR + File.separator
+ provider.getId());
- logConfiguration = new LogManagerProperties(configuredProperties);
+ logProperties = new LogManagerProperties(configuredProperties);
}
} catch (IOException ioe) {
if (is != null) {
@@ -193,7 +208,7 @@
}
}
}
- logManagerProperties = logConfiguration;
+ logManagerProperties = logProperties;
}
private void initLogManager() throws ACIDException {
@@ -574,7 +589,7 @@
fileChannel.position(fileOffset);
fileChannel.read(buffer);
buffer.position(0);
-
+
byte logType = buffer.get(4);
int logHeaderSize = logRecordHelper.getLogHeaderSize(logType);
int logBodySize = buffer.getInt(logHeaderSize - 4);
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 fde0669..84294c9 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
@@ -17,82 +17,63 @@
import java.io.Serializable;
import java.util.Properties;
-import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionManagementConstants;
-
public class LogManagerProperties implements Serializable {
- /**
- * generated SerialVersionUID
- */
private static final long serialVersionUID = 2084227360840799662L;
- private String logFilePrefix = "asterix_transaction_log"; // log files
-
- // follow the
- // naming
- // convention
- // <logFilePrefix>_<number>
- // where number
- // starts from 0
-
- private String logDir = "asterix_logs"; // the path where the LogManager
- // will create log files
-
- private int logPageSize = 128 * 1024; // 128 KB
- private int numLogPages = 8; // number of log pages in the log buffer.
-
- private long groupCommitWaitPeriod = 1; // time in milliseconds for which a
- // commit record will wait before
- // the housing page is marked for
- // flushing.
- private int logBufferSize = logPageSize * numLogPages;
- // maximum size of each log file
- private long logPartitionSize = logBufferSize * 1024 * 2; //2GB
-
- public int logMagicNumber = 123456789;
-
- public static final String LOG_PARTITION_SIZE_KEY = "log_partition_size";
+ public static final int LOG_MAGIC_NUMBER = 123456789;
public static final String LOG_DIR_KEY = "log_dir";
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";
public static final String LOG_FILE_PREFIX_KEY = "log_file_prefix";
- public static final String GROUP_COMMIT_WAIT_PERIOD = "group_commit_wait_period";
+ public static final String GROUP_COMMIT_WAIT_PERIOD_KEY = "group_commit_wait_period";
+
+ private static final int DEFAULT_LOG_PAGE_SIZE = 128 * 1024; //128KB
+ private static final int DEFAULT_NUM_LOG_PAGES = 8;
+ 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";
+
+ // follow the naming convention <logFilePrefix>_<number> where number starts from 0
+ private final String logFilePrefix;
+ private final String logDir;
+
+ // number of log pages in the log buffer
+ private final int logPageSize;
+ // number of log pages in the log buffer.
+ private final int numLogPages;
+ // time in milliseconds
+ private final long groupCommitWaitPeriod;
+ // logBufferSize = logPageSize * numLogPages;
+ private final int logBufferSize;
+ // maximum size of each log file
+ private final long logPartitionSize;
public LogManagerProperties(Properties properties) {
- if (properties.get(LOG_PAGE_SIZE_KEY) != null) {
- logPageSize = Integer.parseInt(properties.getProperty(LOG_PAGE_SIZE_KEY));
- }
- if (properties.get(NUM_LOG_PAGES_KEY) != null) {
- numLogPages = Integer.parseInt(properties.getProperty(NUM_LOG_PAGES_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.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));
- if (properties.get(LOG_PARTITION_SIZE_KEY) != null) {
- logPartitionSize = Long.parseLong(properties.getProperty(LOG_PARTITION_SIZE_KEY));
- }
-
- groupCommitWaitPeriod = Long.parseLong(properties.getProperty("group_commit_wait_period", ""
- + groupCommitWaitPeriod));
- logFilePrefix = properties.getProperty(LOG_FILE_PREFIX_KEY, logFilePrefix);
- logDir = properties
- .getProperty(LOG_DIR_KEY, TransactionManagementConstants.LogManagerConstants.DEFAULT_LOG_DIR);
+ this.logBufferSize = logPageSize * numLogPages;
+ //make sure that the log partition size is the multiple of log buffer size.
+ this.logPartitionSize = (logPartitionSize / logBufferSize) * logBufferSize;
}
public long getLogPartitionSize() {
return logPartitionSize;
}
- public void setLogPartitionSize(long logPartitionSize) {
- this.logPartitionSize = logPartitionSize;
- }
-
public String getLogFilePrefix() {
return logFilePrefix;
}
- public void setLogDir(String logDir) {
- this.logDir = logDir;
- }
-
public String getLogDir() {
return logDir;
}
@@ -101,8 +82,16 @@
return logPageSize;
}
- public void setLogPageSize(int logPageSize) {
- this.logPageSize = logPageSize;
+ public int getNumLogPages() {
+ return numLogPages;
+ }
+
+ public int getLogBufferSize() {
+ return logBufferSize;
+ }
+
+ public long getGroupCommitWaitPeriod() {
+ return groupCommitWaitPeriod;
}
public String toString() {
@@ -115,29 +104,4 @@
builder.append("group_commit_wait_period : " + groupCommitWaitPeriod + FileUtil.lineSeparator);
return builder.toString();
}
-
- public void setNumLogPages(int numLogPages) {
- this.numLogPages = numLogPages;
- }
-
- public int getNumLogPages() {
- return numLogPages;
- }
-
- public void setLogBufferSize(int logBufferSize) {
- this.logBufferSize = logBufferSize;
- }
-
- public int getLogBufferSize() {
- return logBufferSize;
- }
-
- public long getGroupCommitWaitPeriod() {
- return groupCommitWaitPeriod;
- }
-
- public void setGroupCommitWaitPeriod(long groupCommitWaitPeriod) {
- this.groupCommitWaitPeriod = groupCommitWaitPeriod;
- }
-
}
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogRecordHelper.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogRecordHelper.java
index d9ee278..6b882ef 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogRecordHelper.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/LogRecordHelper.java
@@ -178,7 +178,7 @@
/* magic no */
(logicalLogLocator.getBuffer()).writeInt(logicalLogLocator.getMemoryOffset() + MAGIC_NO_POS,
- logManager.getLogManagerProperties().logMagicNumber);
+ logManager.getLogManagerProperties().LOG_MAGIC_NUMBER);
/* log type */
(logicalLogLocator.getBuffer()).put(logicalLogLocator.getMemoryOffset() + LOG_TYPE_POS, logType);
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/recovery/RecoveryManager.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/recovery/RecoveryManager.java
index 226c81b..e2f26b2 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/recovery/RecoveryManager.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/recovery/RecoveryManager.java
@@ -24,7 +24,6 @@
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -681,7 +680,7 @@
while (iter.hasNext()) {
//TODO
//Sort the lsns in order to undo in one pass.
-
+
Map.Entry<TxnId, List<Long>> loserTxn = (Map.Entry<TxnId, List<Long>>) iter.next();
txnId = loserTxn.getKey();
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionManagementConstants.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionManagementConstants.java
index cb71e9f..3d25e54 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionManagementConstants.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionManagementConstants.java
@@ -27,7 +27,7 @@
public static class LogManagerConstants {
public static final String LOG_CONF_DIR = "log_conf";
- public static final String LOG_CONF_FILE = "log.conf";
+ public static final String LOG_CONF_FILE = "log.properties";
public static final String ASTERIX_CONF_DIR = "src/main/resources";
public static final String ASTERIX_CONF_FILE = "test.properties";
public static final String DEFAULT_LOG_DIR = "asterix_logs";
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionSubsystem.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionSubsystem.java
index 35d1c9b..c83b7bc 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionSubsystem.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionSubsystem.java
@@ -51,8 +51,12 @@
this.loggerRepository = new IndexLoggerRepository(this);
this.resourceRepository = new TransactionalResourceManagerRepository();
this.asterixAppRuntimeContextProvider = asterixAppRuntimeContextProvider;
- this.checkpointThread = new CheckpointThread(recoveryManager,
- asterixAppRuntimeContextProvider.getIndexLifecycleManager(), 0);
+ if (asterixAppRuntimeContextProvider != null) {
+ this.checkpointThread = new CheckpointThread(recoveryManager,
+ asterixAppRuntimeContextProvider.getIndexLifecycleManager(), 0);
+ } else {
+ this.checkpointThread = null;
+ }
}
public ILogManager getLogManager() {