cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r888702 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra/db: CommitLog.java RecoveryManager.java
Date Wed, 09 Dec 2009 05:02:32 GMT
Author: jbellis
Date: Wed Dec  9 05:02:32 2009
New Revision: 888702

URL: http://svn.apache.org/viewvc?rev=888702&view=rev
Log:
make CommitLog a true singleton instead of only "a singleton, except during log replay". 
patch by jbellis

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/RecoveryManager.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java?rev=888702&r1=888701&r2=888702&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java Wed Dec  9 05:02:32
2009
@@ -73,12 +73,9 @@
 {
     private static volatile int SEGMENT_SIZE = 128*1024*1024; // roll after log gets this
big
     private static volatile CommitLog instance_;
-    private static Lock lock_ = new ReentrantLock();
-    private static Logger logger_ = Logger.getLogger(CommitLog.class);
-    private static Map<String, CommitLogHeader> clHeaders_ = new HashMap<String,
CommitLogHeader>();
-
-    private ExecutorService executor;
-
+    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 final class CommitLogContext
     {
@@ -147,7 +144,7 @@
 
                 if ( instance_ == null )
                 {
-                    instance_ = new CommitLog(false);
+                    instance_ = new CommitLog();
                 }
             }
             finally
@@ -163,6 +160,7 @@
     /* header for current commit log */
     private CommitLogHeader clHeader_;
     private BufferedRandomAccessFile logWriter_;
+    private final ExecutorService executor = new CommitLogExecutorService();
 
     /*
      * Generates a file name of the format CommitLog-<table>-<timestamp>.log
in the
@@ -180,51 +178,47 @@
      * param @ recoverymode - is commit log being instantiated in
      *                        in recovery mode.
     */
-    CommitLog(boolean recoveryMode) throws IOException
+    private CommitLog() throws IOException
     {
-        if (!recoveryMode)
+        setNextFileName();
+        logWriter_ = CommitLog.createWriter(logFile_);
+        writeCommitLogHeader();
+
+        if (DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.periodic)
         {
-            executor = new CommitLogExecutorService();
-            setNextFileName();
-            logWriter_ = CommitLog.createWriter(logFile_);
-            writeCommitLogHeader();
+            final Runnable syncer = new Runnable()
+            {
+                public void run()
+                {
+                    try
+                    {
+                        sync();
+                    }
+                    catch (IOException e)
+                    {
+                        throw new RuntimeException(e);
+                    }
+                }
+            };
 
-            if (DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.periodic)
+            new Thread(new Runnable()
             {
-                final Runnable syncer = new Runnable()
+                public void run()
                 {
-                    public void run()
+                    while (true)
                     {
+                        executor.submit(syncer);
                         try
                         {
-                            sync();
+                            Thread.sleep(DatabaseDescriptor.getCommitLogSyncPeriod());
                         }
-                        catch (IOException e)
+                        catch (InterruptedException e)
                         {
                             throw new RuntimeException(e);
                         }
                     }
-                };
-
-                new Thread(new Runnable()
-                {
-                    public void run()
-                    {
-                        while (true)
-                        {
-                            executor.submit(syncer);
-                            try
-                            {
-                                Thread.sleep(DatabaseDescriptor.getCommitLogSyncPeriod());
-                            }
-                            catch (InterruptedException e)
-                            {
-                                throw new RuntimeException(e);
-                            }
-                        }
-                    }
-                }, "PERIODIC-COMMIT-LOG-SYNCER").start();
-            }
+                }
+            }, "PERIODIC-COMMIT-LOG-SYNCER").start();
         }
     }
 

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=888702&r1=888701&r2=888702&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 Wed Dec
 9 05:02:32 2009
@@ -62,7 +62,7 @@
 
         Arrays.sort(files, new FileUtils.FileComparator());
         logger_.info("Replaying " + StringUtils.join(files, ", "));
-        new CommitLog(true).recover(files);
+        CommitLog.open().recover(files);
         FileUtils.delete(files);
     }
 }



Mime
View raw message