cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [3/3] git commit: Check schema before trying to export sstable patch by Jason Brown; reviewed by jbellis for CASSANDRA-2760
Date Wed, 27 Jun 2012 00:52:54 GMT
Check schema before trying to export sstable
patch by Jason Brown; reviewed by jbellis for CASSANDRA-2760


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

Branch: refs/heads/cassandra-1.1
Commit: 98dc41393fc6cc2b2b8756f6d8b33f86c45c0726
Parents: 80d7d43
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Tue Jun 26 19:51:30 2012 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Tue Jun 26 19:51:30 2012 -0500

----------------------------------------------------------------------
 CHANGES.txt                                        |    5 +-
 .../org/apache/cassandra/tools/SSTableExport.java  |   36 +++++++++------
 .../apache/cassandra/tools/SSTableExportTest.java  |    2 +-
 3 files changed, 25 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/98dc4139/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1e9f830..1d9f20b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 1.1.2
+ * Check schema before trying to export sstable (CASSANDRA-2760)
  * Raise a meaningful exception instead of NPE when PFS encounters
    an unconfigured node + no default (CASSANDRA-4349)
  * fix bug in sstable blacklisting with LCS (CASSANDRA-4343)
@@ -7,8 +8,8 @@
  * fix NPE in compactionstats (CASSANDRA-4318)
  * enforce 1m min keycache for auto (CASSANDRA-4306)
  * Have DeletedColumn.isMFD always return true (CASSANDRA-4307)
- * ex msg for cql3 order by constraints says primary filter can be an IN clause 
-   which is misleading (CASSANDRA-4319)
+ * (cql3) exeption message for ORDER BY constraints said primary filter can be
+    an IN clause, which is misleading (CASSANDRA-4319)
  * (cql3) Reject (not yet supported) creation of 2ndardy indexes on tables with
    composite primary keys (CASSANDRA-4328)
  * Set JVM stack size to 160k for java 7 (CASSANDRA-4275)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/98dc4139/src/java/org/apache/cassandra/tools/SSTableExport.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableExport.java b/src/java/org/apache/cassandra/tools/SSTableExport.java
index 8c3dd24..9ac2123 100644
--- a/src/java/org/apache/cassandra/tools/SSTableExport.java
+++ b/src/java/org/apache/cassandra/tools/SSTableExport.java
@@ -204,14 +204,13 @@ public class SSTableExport
     /**
      * Enumerate row keys from an SSTableReader and write the result to a PrintStream.
      *
-     * @param ssTableFile the file to export the rows from
+     * @param desc the descriptor of the file to export the rows from
      * @param outs PrintStream to write the output to
      * @throws IOException on failure to read/write input/output
      */
-    public static void enumeratekeys(String ssTableFile, PrintStream outs)
+    public static void enumeratekeys(Descriptor desc, PrintStream outs)
     throws IOException
     {
-        Descriptor desc = Descriptor.fromFilename(ssTableFile);
         KeyIterator iter = new KeyIterator(desc);
         DecoratedKey lastKey = null;
         while (iter.hasNext())
@@ -232,15 +231,15 @@ public class SSTableExport
     /**
      * Export specific rows from an SSTable and write the resulting JSON to a PrintStream.
      *
-     * @param ssTableFile the SSTableScanner to export the rows from
+     * @param desc the descriptor of the sstable table to read from
      * @param outs PrintStream to write the output to
      * @param toExport the keys corresponding to the rows to export
      * @param excludes keys to exclude from export
      * @throws IOException on failure to read/write input/output
      */
-    public static void export(String ssTableFile, PrintStream outs, Collection<String>
toExport, String[] excludes) throws IOException
+    public static void export(Descriptor desc, PrintStream outs, Collection<String>
toExport, String[] excludes) throws IOException
     {
-        SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(ssTableFile));
+        SSTableReader reader = SSTableReader.open(desc);
         SSTableScanner scanner = reader.getDirectScanner();
 
         IPartitioner<?> partitioner = reader.partitioner;
@@ -330,28 +329,28 @@ public class SSTableExport
     /**
      * Export an SSTable and write the resulting JSON to a PrintStream.
      *
-     * @param ssTableFile the SSTable to export
+     * @param desc the descriptor of the sstable table to read from
      * @param outs PrintStream to write the output to
      * @param excludes keys to exclude from export
      *
      * @throws IOException on failure to read/write input/output
      */
-    public static void export(String ssTableFile, PrintStream outs, String[] excludes) throws
IOException
+    public static void export(Descriptor desc, PrintStream outs, String[] excludes) throws
IOException
     {
-        export(SSTableReader.open(Descriptor.fromFilename(ssTableFile)), outs, excludes);
+        export(SSTableReader.open(desc), outs, excludes);
     }
 
     /**
      * Export an SSTable and write the resulting JSON to standard out.
      *
-     * @param ssTableFile SSTable to export
+     * @param desc the descriptor of the sstable table to read from
      * @param excludes keys to exclude from export
      *
      * @throws IOException on failure to read/write SSTable/standard out
      */
-    public static void export(String ssTableFile, String[] excludes) throws IOException
+    public static void export(Descriptor desc, String[] excludes) throws IOException
     {
-        export(ssTableFile, System.out, excludes);
+        export(desc, System.out, excludes);
     }
 
     /**
@@ -399,17 +398,24 @@ public class SSTableExport
             System.err.println(msg);
             throw new ConfigurationException(msg);
         }
+        Descriptor descriptor = Descriptor.fromFilename(ssTableFileName);
+        if (Schema.instance.getCFMetaData(descriptor) == null)
+        {
+            System.err.println(String.format("The provided column family is not part of this
cassandra database: keysapce = %s, column family = %s",
+                                             descriptor.ksname, descriptor.cfname));
+            System.exit(1);
+        }
 
         if (cmd.hasOption(ENUMERATEKEYS_OPTION))
         {
-            enumeratekeys(ssTableFileName, System.out);
+            enumeratekeys(descriptor, System.out);
         }
         else
         {
             if ((keys != null) && (keys.length > 0))
-                export(ssTableFileName, System.out, Arrays.asList(keys), excludes);
+                export(descriptor, System.out, Arrays.asList(keys), excludes);
             else
-                export(ssTableFileName, excludes);
+                export(descriptor, excludes);
         }
 
         System.exit(0);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/98dc4139/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
index 7aa43fe..328a787 100644
--- a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
+++ b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
@@ -77,7 +77,7 @@ public class SSTableExportTest extends SchemaLoader
 
         // Enumerate and verify
         File temp = File.createTempFile("Standard1", ".txt");
-        SSTableExport.enumeratekeys(writer.getFilename(), new PrintStream(temp.getPath()));
+        SSTableExport.enumeratekeys(Descriptor.fromFilename(writer.getFilename()), new PrintStream(temp.getPath()));
 
 
         FileReader file = new FileReader(temp);


Mime
View raw message