cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject git commit: use millis + atomicint for commitlog segment creation patch by amorton; reviewed by jbellis for CASSANDRA-4601
Date Tue, 04 Sep 2012 20:09:19 GMT
Updated Branches:
  refs/heads/cassandra-1.1 f94c839dc -> 5df7b2512


use millis + atomicint for commitlog segment creation
patch by amorton; reviewed by jbellis for CASSANDRA-4601


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5df7b251
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5df7b251
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5df7b251

Branch: refs/heads/cassandra-1.1
Commit: 5df7b2512de1f851d2add08d699c948f3d95d9c8
Parents: f94c839
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Tue Sep 4 15:04:16 2012 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Tue Sep 4 15:04:16 2012 -0500

----------------------------------------------------------------------
 CHANGES.txt                                        |    2 ++
 .../cassandra/db/commitlog/CommitLogArchiver.java  |    2 +-
 .../cassandra/db/commitlog/CommitLogSegment.java   |    9 ++++++++-
 3 files changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/5df7b251/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5e72de3..6125c9c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 1.1.5
+ * use millis + atomicint for commitlog segment creation instead of
+   nanotime, which has issues under some hypervisors (CASSANDRA-4601)
  * fix FD leak in slice queries (CASSANDRA-4571)
  * avoid recursion in leveled compaction (CASSANDRA-4587)
  * increase stack size under Java7 to 180K

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5df7b251/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java b/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
index 556a37a..fe66369 100644
--- a/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
+++ b/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
@@ -150,7 +150,7 @@ public class CommitLogArchiver
             {
                 File toFile = new File(DatabaseDescriptor.getCommitLogLocation(),
                                        CommitLogSegment.FILENAME_PREFIX +
-                                       System.nanoTime() +
+                                       CommitLogSegment.getNextId() +
                                        CommitLogSegment.FILENAME_EXTENSION);            

                 String command = restoreCommand.replace("%from", fromFile.getPath());
                 command = command.replace("%to", toFile.getPath());       

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5df7b251/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java b/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java
index fcd4130..290db7c 100644
--- a/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java
+++ b/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java
@@ -27,6 +27,7 @@ import java.io.RandomAccessFile;
 import java.nio.channels.FileChannel;
 import java.nio.MappedByteBuffer;
 import java.util.Collection;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.zip.Checksum;
@@ -56,6 +57,8 @@ public class CommitLogSegment
     static final String FILENAME_PREFIX = "CommitLog-";
     static final String FILENAME_EXTENSION = ".log";
     private static final Pattern COMMIT_LOG_FILE_PATTERN = Pattern.compile(FILENAME_PREFIX
+ "(\\d+)" + FILENAME_EXTENSION);
+    private final static long idBase = System.currentTimeMillis();
+    private final static AtomicInteger nextId = new AtomicInteger(1);
 
     // The commit log entry overhead in bytes (int: length + long: head checksum + long:
tail checksum)
     static final int ENTRY_OVERHEAD_SIZE = 4 + 8 + 8;
@@ -81,6 +84,10 @@ public class CommitLogSegment
         return new CommitLogSegment(null);
     }
 
+    public static long getNextId()
+    {
+        return idBase + nextId.getAndIncrement();
+    }
     /**
      * Constructs a new segment file.
      *
@@ -88,7 +95,7 @@ public class CommitLogSegment
      */
     CommitLogSegment(String filePath)
     {
-        id = System.nanoTime();
+        id = getNextId();
         logFile = new File(DatabaseDescriptor.getCommitLogLocation(), FILENAME_PREFIX + id
+ FILENAME_EXTENSION);
         boolean isCreating = true;
 


Mime
View raw message