You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2012/04/16 22:46:20 UTC
[6/8] git commit: optimize truncate when autosnapshot is disabled
patch by Christian Spriegel; reviewed by jbellis for CASSANDRA-4153
optimize truncate when autosnapshot is disabled
patch by Christian Spriegel; reviewed by jbellis for CASSANDRA-4153
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/e48b9409
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e48b9409
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e48b9409
Branch: refs/heads/trunk
Commit: e48b94098efca6d1abea86c07210492315359737
Parents: 3f8372c
Author: Jonathan Ellis <jb...@apache.org>
Authored: Mon Apr 16 15:27:47 2012 -0500
Committer: Jonathan Ellis <jb...@apache.org>
Committed: Mon Apr 16 15:27:47 2012 -0500
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../org/apache/cassandra/db/ColumnFamilyStore.java | 55 ++++++++++++---
2 files changed, 45 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e48b9409/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 55dfe1a..a539e66 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
1.1.1-dev
+ * optimize truncate when autosnapshot is disabled (CASSANDRA-4153)
* add support for commitlog archiving and point-in-time recovery
(CASSANDRA-3647)
* update caches to use byte[] keys to reduce memory overhead (CASSANDRA-3966)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/e48b9409/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
index 3468487..77f4dab 100644
--- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
+++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
@@ -1674,22 +1674,55 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
// time. So to guarantee that all segments can be cleaned out, we need to
// "waitForActiveFlushes" after the new segment has been created.
logger.debug("truncating {}", columnFamily);
- // flush the CF being truncated before forcing the new segment
- forceBlockingFlush();
- CommitLog.instance.forceNewSegment();
- ReplayPosition position = CommitLog.instance.getContext();
- // now flush everyone else. re-flushing ourselves is not necessary, but harmless
- for (ColumnFamilyStore cfs : ColumnFamilyStore.all())
- cfs.forceFlush();
- waitForActiveFlushes();
- // if everything was clean, flush won't have called discard
- CommitLog.instance.discardCompletedSegments(metadata.cfId, position);
+
+ if (DatabaseDescriptor.isAutoSnapshot())
+ {
+ // flush the CF being truncated before forcing the new segment
+ forceBlockingFlush();
+ }
+ else
+ {
+ // just nuke the memtable data w/o writing to disk first
+ Table.switchLock.writeLock().lock();
+ try
+ {
+ for (ColumnFamilyStore cfs : concatWithIndexes())
+ {
+ Memtable mt = cfs.getMemtableThreadSafe();
+ if (!mt.isClean() && !mt.isFrozen())
+ {
+ mt.cfs.data.renewMemtable();
+ }
+ }
+ }
+ finally
+ {
+ Table.switchLock.writeLock().unlock();
+ }
+ }
+
+ KSMetaData ksm = Schema.instance.getKSMetaData(this.table.name);
+ if (ksm.durableWrites)
+ {
+ CommitLog.instance.forceNewSegment();
+ ReplayPosition position = CommitLog.instance.getContext();
+ // now flush everyone else. re-flushing ourselves is not necessary, but harmless
+ for (ColumnFamilyStore cfs : ColumnFamilyStore.all())
+ cfs.forceFlush();
+ waitForActiveFlushes();
+ // if everything was clean, flush won't have called discard
+ CommitLog.instance.discardCompletedSegments(metadata.cfId, position);
+ }
// sleep a little to make sure that our truncatedAt comes after any sstable
// that was part of the flushed we forced; otherwise on a tie, it won't get deleted.
try
{
- Thread.sleep(100);
+ long starttime = System.currentTimeMillis();
+ while ((System.currentTimeMillis() - starttime) < 1)
+ {
+ Thread.sleep(1);
+ }
}
catch (InterruptedException e)
{