Repository: bookkeeper
Updated Branches:
  refs/heads/master d5af77c05 -> 61a5446b8


BOOKKEEPER-1050: Cache journalFormatVersionToWrite when starting Journal

Reading the journal version format from `ServiceConfiguration` each time is 
inefficient.
`ServiceConfiguration` is based on Java properties which is based on a String 
to object hashtable. Each read implies acquiring a mutex and converting from 
object to int.

Author: Matteo Merli <[email protected]>

Reviewers: Enrico Olivelli <None>

Closes #140 from merlimat/cache-journal-conf


Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/61a5446b
Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/61a5446b
Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/61a5446b

Branch: refs/heads/master
Commit: 61a5446b8923e5ce0b2a46891a385fd480275bac
Parents: d5af77c
Author: Matteo Merli <[email protected]>
Authored: Tue May 9 13:24:53 2017 -0700
Committer: Matteo Merli <[email protected]>
Committed: Tue May 9 13:24:53 2017 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/bookkeeper/bookie/Journal.java   | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/61a5446b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
----------------------------------------------------------------------
diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
index 1483e36..7a4687c 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
@@ -792,6 +792,8 @@ class Journal extends BookieCriticalThread implements 
CheckpointSource {
         ByteBuffer lenBuff = ByteBuffer.allocate(4);
         ByteBuffer paddingBuff = ByteBuffer.allocate(2 * 
conf.getJournalAlignmentSize());
         ZeroBuffer.put(paddingBuff);
+        final int journalFormatVersionToWrite = 
conf.getJournalFormatVersionToWrite();
+        final int journalAlignmentSize = conf.getJournalAlignmentSize();
         JournalChannel logFile = null;
         forceWriteThread.start();
         Stopwatch journalCreationWatcher = new Stopwatch();
@@ -820,9 +822,9 @@ class Journal extends BookieCriticalThread implements 
CheckpointSource {
                                         logId,
                                         journalPreAllocSize,
                                         journalWriteBufferSize,
-                                        conf.getJournalAlignmentSize(),
+                                        journalAlignmentSize,
                                         removePagesFromCache,
-                                        conf.getJournalFormatVersionToWrite());
+                                        journalFormatVersionToWrite);
                     journalCreationStats.registerSuccessfulEvent(
                             
journalCreationWatcher.stop().elapsedTime(TimeUnit.NANOSECONDS), 
TimeUnit.NANOSECONDS);
 
@@ -885,8 +887,8 @@ class Journal extends BookieCriticalThread implements 
CheckpointSource {
 
                         // toFlush is non null and not empty so should be safe 
to access getFirst
                         if (shouldFlush) {
-                            if (conf.getJournalFormatVersionToWrite() >= 
JournalChannel.V5) {
-                                writePaddingBytes(logFile, paddingBuff, 
conf.getJournalAlignmentSize());
+                            if (journalFormatVersionToWrite >= 
JournalChannel.V5) {
+                                writePaddingBytes(logFile, paddingBuff, 
journalAlignmentSize);
                             }
                             journalFlushWatcher.reset().start();
                             bc.flush(false);

Reply via email to