cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r908162 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra/db: ColumnFamilyStore.java RecoveryManager.java Table.java commitlog/CommitLog.java commitlog/CommitLogExecutorService.java
Date Tue, 09 Feb 2010 19:22:13 GMT
Author: jbellis
Date: Tue Feb  9 19:22:12 2010
New Revision: 908162

URL: http://svn.apache.org/viewvc?rev=908162&view=rev
Log:
replace double-checked locking in CL.open() with initialize on demand holder in CL.instance().
 patch by jbellis

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/RecoveryManager.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLogExecutorService.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=908162&r1=908161&r2=908162&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Tue
Feb  9 19:22:12 2010
@@ -366,7 +366,7 @@
         Table.flusherLock.writeLock().lock();
         try
         {
-            final CommitLog.CommitLogContext ctx = CommitLog.open().getContext(); // this
is harmless if !writeCommitLog
+            final CommitLog.CommitLogContext ctx = CommitLog.instance().getContext(); //
this is harmless if !writeCommitLog
 
             if (oldMemtable.isFrozen())
             {
@@ -541,7 +541,7 @@
     {
         if (cLogCtx.isValidContext())
         {
-            CommitLog.open().onMemtableFlush(table_, columnFamily_, cLogCtx);
+            CommitLog.instance().onMemtableFlush(table_, columnFamily_, cLogCtx);
         }
     }
 

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/RecoveryManager.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/RecoveryManager.java?rev=908162&r1=908161&r2=908162&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/RecoveryManager.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/RecoveryManager.java Tue Feb
 9 19:22:12 2010
@@ -53,7 +53,7 @@
 
         Arrays.sort(files, new FileUtils.FileComparator());
         logger_.info("Replaying " + StringUtils.join(files, ", "));
-        CommitLog.open().recover(files);
+        CommitLog.instance().recover(files);
         FileUtils.delete(files);
         logger_.info("Log replay complete");
     }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java?rev=908162&r1=908161&r2=908162&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java Tue Feb  9 19:22:12
2010
@@ -396,7 +396,7 @@
         {
             if (writeCommitLog)
             {
-                Future<CommitLog.CommitLogContext> future = CommitLog.open().add(mutation,
serializedMutation);
+                Future<CommitLog.CommitLogContext> future = CommitLog.instance().add(mutation,
serializedMutation);
                 if (waitForCommitLog)
                 {
                     try

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLog.java?rev=908162&r1=908161&r2=908162&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLog.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLog.java Tue
Feb  9 19:22:12 2010
@@ -77,11 +77,19 @@
 public class CommitLog
 {
     private static volatile int SEGMENT_SIZE = 128*1024*1024; // roll after log gets this
big
-    private static volatile CommitLog instance_;
-    private static final Lock lock_ = new ReentrantLock();
     private static final Logger logger_ = Logger.getLogger(CommitLog.class);
     private static final Map<String, CommitLogHeader> clHeaders_ = new HashMap<String,
CommitLogHeader>();
 
+    public static CommitLog instance()
+    {
+        return CLHandle.instance;
+    }
+
+    private static class CLHandle
+    {
+        public static final CommitLog instance = new CommitLog();
+    }
+
     public static class CommitLogContext
     {
         /* Commit Log associated with this operation */
@@ -139,27 +147,6 @@
         return new BufferedRandomAccessFile(file, "rw");
     }
 
-    public static CommitLog open() throws IOException
-    {
-        if ( instance_ == null )
-        {
-            CommitLog.lock_.lock();
-            try
-            {
-
-                if ( instance_ == null )
-                {
-                    instance_ = new CommitLog();
-                }
-            }
-            finally
-            {
-                CommitLog.lock_.unlock();
-            }
-        }
-        return instance_;
-    }
-
     /* Current commit log file */
     private String logFile_;
     /* header for current commit log */
@@ -183,11 +170,18 @@
      * param @ recoverymode - is commit log being instantiated in
      *                        in recovery mode.
     */
-    private CommitLog() throws IOException
+    private CommitLog()
     {
         setNextFileName();
-        logWriter_ = CommitLog.createWriter(logFile_);
-        writeCommitLogHeader();
+        try
+        {
+            logWriter_ = CommitLog.createWriter(logFile_);
+            writeCommitLogHeader();
+        }
+        catch (IOException e)
+        {
+            throw new IOError(e);
+        }
 
         if (DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.periodic)
         {
@@ -224,19 +218,6 @@
         }
     }
 
-    /*
-     * This ctor is currently used only for debugging. We
-     * are now using it to modify the header so that recovery
-     * can be tested in as many scenarios as we could imagine.
-     *
-     * param @ logFile - logfile which we wish to modify.
-    */
-    CommitLog(File logFile) throws IOException
-    {
-        logFile_ = logFile.getAbsolutePath();
-        logWriter_ = CommitLog.createWriter(logFile_);
-    }
-
     String getLogFile()
     {
         return logFile_;

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLogExecutorService.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLogExecutorService.java?rev=908162&r1=908161&r2=908162&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLogExecutorService.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLogExecutorService.java
Tue Feb  9 19:22:12 2010
@@ -126,7 +126,7 @@
         // now sync and set the tasks' values (which allows thread calling get() to proceed)
         try
         {
-            CommitLog.open().sync();
+            CommitLog.instance().sync();
         }
         catch (IOException e)
         {



Mime
View raw message