AMQ-6377: Storing JournalSyncStrategy as an enum

Switching MessageDatabase to store JournalSyncStrategy as its enum value
instead of String to avoid the performance penalty of comparing Strings
everytime isEnableJournalDiskSyncs() is called which currently happens
on every write.
This commit is contained in:
Christopher L. Shannon (cshannon) 2017-03-06 07:53:04 -05:00
parent 01b1f7f694
commit 0d824a8e68
3 changed files with 20 additions and 10 deletions

View File

@ -52,6 +52,7 @@ import org.apache.activemq.store.TransactionStore;
import org.apache.activemq.store.kahadb.data.KahaLocalTransactionId;
import org.apache.activemq.store.kahadb.data.KahaTransactionInfo;
import org.apache.activemq.store.kahadb.data.KahaXATransactionId;
import org.apache.activemq.store.kahadb.disk.journal.Journal.JournalDiskSyncStrategy;
import org.apache.activemq.usage.SystemUsage;
import org.apache.activemq.util.ServiceStopper;
@ -461,6 +462,10 @@ public class KahaDBPersistenceAdapter extends LockableServiceSupport implements
return letter.getJournalDiskSyncStrategy();
}
public JournalDiskSyncStrategy getJournalDiskSyncStrategyEnum() {
return letter.getJournalDiskSyncStrategyEnum();
}
/**
* @param journalDiskSyncStrategy
*/

View File

@ -254,7 +254,7 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe
protected ScheduledExecutorService scheduler;
private final Object schedulerLock = new Object();
protected String journalDiskSyncStrategy = JournalDiskSyncStrategy.ALWAYS.name();
protected JournalDiskSyncStrategy journalDiskSyncStrategy = JournalDiskSyncStrategy.ALWAYS;
protected boolean archiveDataLogs;
protected File directoryArchive;
protected AtomicLong journalSize = new AtomicLong(0);
@ -3141,8 +3141,7 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe
manager.setPreallocationScope(Journal.PreallocationScope.valueOf(preallocationScope.trim().toUpperCase()));
manager.setPreallocationStrategy(
Journal.PreallocationStrategy.valueOf(preallocationStrategy.trim().toUpperCase()));
manager.setJournalDiskSyncStrategy(
Journal.JournalDiskSyncStrategy.valueOf(journalDiskSyncStrategy.trim().toUpperCase()));
manager.setJournalDiskSyncStrategy(journalDiskSyncStrategy);
if (getDirectoryArchive() != null) {
IOHelper.mkdirs(getDirectoryArchive());
manager.setDirectoryArchive(getDirectoryArchive());
@ -3200,13 +3199,12 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe
}
/**
* @deprecated use {@link #getJournalDiskSyncStrategy} instead
* @deprecated use {@link #getJournalDiskSyncStrategyEnum} or {@link #getJournalDiskSyncStrategy} instead
* @return
*/
@Deprecated
public boolean isEnableJournalDiskSyncs() {
return journalDiskSyncStrategy != null && JournalDiskSyncStrategy.ALWAYS.name().equals(
journalDiskSyncStrategy.trim().toUpperCase());
return journalDiskSyncStrategy == JournalDiskSyncStrategy.ALWAYS;
}
/**
@ -3216,18 +3214,22 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe
@Deprecated
public void setEnableJournalDiskSyncs(boolean syncWrites) {
if (syncWrites) {
journalDiskSyncStrategy = JournalDiskSyncStrategy.ALWAYS.name();
journalDiskSyncStrategy = JournalDiskSyncStrategy.ALWAYS;
} else {
journalDiskSyncStrategy = JournalDiskSyncStrategy.NEVER.name();
journalDiskSyncStrategy = JournalDiskSyncStrategy.NEVER;
}
}
public String getJournalDiskSyncStrategy() {
public JournalDiskSyncStrategy getJournalDiskSyncStrategyEnum() {
return journalDiskSyncStrategy;
}
public String getJournalDiskSyncStrategy() {
return journalDiskSyncStrategy.name();
}
public void setJournalDiskSyncStrategy(String journalDiskSyncStrategy) {
this.journalDiskSyncStrategy = journalDiskSyncStrategy;
this.journalDiskSyncStrategy = JournalDiskSyncStrategy.valueOf(journalDiskSyncStrategy.trim().toUpperCase());
}
public long getJournalDiskSyncInterval() {

View File

@ -67,6 +67,7 @@ public class JournalSyncStrategyTest {
assertTrue(journal.isJournalDiskSyncPeriodic());
assertFalse(store.isEnableJournalDiskSyncs());
assertEquals(store.getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.PERIODIC.name());
assertEquals(store.getJournalDiskSyncStrategyEnum(), JournalDiskSyncStrategy.PERIODIC);
assertEquals(store.getJournal().getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.PERIODIC);
assertEquals(store.getJournalDiskSyncInterval(), 800);
@ -87,6 +88,7 @@ public class JournalSyncStrategyTest {
assertFalse(store.getJournal().isJournalDiskSyncPeriodic());
assertTrue(store.isEnableJournalDiskSyncs());
assertEquals(store.getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.ALWAYS.name());
assertEquals(store.getJournalDiskSyncStrategyEnum(), JournalDiskSyncStrategy.ALWAYS);
assertEquals(store.getJournal().getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.ALWAYS);
MessageStore messageStore = store.createQueueMessageStore(new ActiveMQQueue("test"));
@ -101,6 +103,7 @@ public class JournalSyncStrategyTest {
assertFalse(store.getJournal().isJournalDiskSyncPeriodic());
assertFalse(store.isEnableJournalDiskSyncs());
assertEquals(store.getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.NEVER.name());
assertEquals(store.getJournalDiskSyncStrategyEnum(), JournalDiskSyncStrategy.NEVER);
assertEquals(store.getJournal().getJournalDiskSyncStrategy(), JournalDiskSyncStrategy.NEVER);
MessageStore messageStore = store.createQueueMessageStore(new ActiveMQQueue("test"));