cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r934672 - in /cassandra/trunk/src/java/org/apache/cassandra/db: Table.java migration/DropColumnFamily.java migration/DropKeyspace.java migration/Migration.java
Date Fri, 16 Apr 2010 02:26:59 GMT
Author: jbellis
Date: Fri Apr 16 02:26:59 2010
New Revision: 934672

URL: http://svn.apache.org/viewvc?rev=934672&view=rev
Log:
snapshot before dropping keyspace
patch by jbellis; reviewed by gdusbabek for CASSANDRA-983

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropKeyspace.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java?rev=934672&r1=934671&r2=934672&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/Table.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/Table.java Fri Apr 16 02:26:59 2010
@@ -152,13 +152,9 @@ public class Table 
      * @param clientSuppliedName the tag associated with the name of the snapshot.  This
      *                           value can be null.
      */
-    public void snapshot(String clientSuppliedName) throws IOException
+    public void snapshot(String clientSuppliedName)
     {
-        String snapshotName = Long.toString(System.currentTimeMillis());
-        if (clientSuppliedName != null && !clientSuppliedName.equals(""))
-        {
-            snapshotName = snapshotName + "-" + clientSuppliedName;
-        }
+        String snapshotName = getTimestampedSnapshotName(clientSuppliedName);
 
         for (ColumnFamilyStore cfStore : columnFamilyStores.values())
         {
@@ -166,6 +162,20 @@ public class Table 
         }
     }
 
+    /**
+     * @param clientSuppliedName; may be null.
+     * @return
+     */
+    public static String getTimestampedSnapshotName(String clientSuppliedName)
+    {
+        String snapshotName = Long.toString(System.currentTimeMillis());
+        if (clientSuppliedName != null && !clientSuppliedName.equals(""))
+        {
+            snapshotName = snapshotName + "-" + clientSuppliedName;
+        }
+        return snapshotName;
+    }
+
 
     /**
      * Clear all the snapshots for a given table.

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java?rev=934672&r1=934671&r2=934672&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java Fri Apr
16 02:26:59 2010
@@ -4,6 +4,7 @@ import org.apache.cassandra.config.CFMet
 import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.KSMetaData;
+import org.apache.cassandra.db.ColumnFamilyStore;
 import org.apache.cassandra.db.RowMutation;
 import org.apache.cassandra.db.SystemTable;
 import org.apache.cassandra.db.Table;
@@ -18,6 +19,7 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -71,7 +73,7 @@ public class DropColumnFamily extends Mi
         KSMetaData newKsm = makeNewKeyspaceDefinition(ksm);
         rm = Migration.makeDefinitionMutation(newKsm, null, newVersion);
     }
-    
+
     private KSMetaData makeNewKeyspaceDefinition(KSMetaData ksm)
     {
         // clone ksm but do not include the new def
@@ -83,6 +85,13 @@ public class DropColumnFamily extends Mi
     }
 
     @Override
+    public void beforeApplyModels()
+    {
+        ColumnFamilyStore cfs = Table.open(tableName).getColumnFamilyStore(cfName);
+        cfs.snapshot(Table.getTimestampedSnapshotName(null));
+    }
+
+    @Override
     public ICompactSerializer getSerializer()
     {
         return serializer;

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropKeyspace.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropKeyspace.java?rev=934672&r1=934671&r2=934672&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropKeyspace.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropKeyspace.java Fri Apr 16
02:26:59 2010
@@ -68,6 +68,12 @@ public class DropKeyspace extends Migrat
     }
 
     @Override
+    public void beforeApplyModels()
+    {
+        Table.open(name).snapshot(null);
+    }
+
+    @Override
     public void applyModels() throws IOException
     {
         KSMetaData ksm = DatabaseDescriptor.getTableDefinition(name);

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java?rev=934672&r1=934671&r2=934672&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java Fri Apr 16 02:26:59
2010
@@ -90,6 +90,9 @@ public abstract class Migration
         this.newVersion = newVersion;
         this.lastVersion = lastVersion;
     }
+
+    /** override this to perform logic before writing the migration or applying it.  defaults
to nothing. */
+    public void beforeApplyModels() {}
     
     /** apply changes */
     public final void apply() throws IOException
@@ -100,6 +103,8 @@ public abstract class Migration
         // write to schema
         assert rm != null;
         rm.apply();
+
+        beforeApplyModels();
         
         // write migration.
         long now = System.currentTimeMillis();



Mime
View raw message