title: Cassandra CQLSSTableWriter Issue
body: <p>In our production environment we are using <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cassandra/cassandra-all/2.1.3/org/apache/cassandra/io/sstable/CQLSSTableWriter.java#CQLSSTableWriter" rel="nofollow">CQLSStablWriter</a> to create SSTables for future bulk load <a href="https://gist.github.com/tamilmani58/aaa093cbc3855dca5fc5" rel="nofollow">Sample Gist</a>. After the process of sstable creation. Once we boot cassandra up, we were getting following exceptions. All our CFs are counter column families.</p>
  
  <p>Versions Tried 2.1.5 and 2.0.8</p>
  
  <p><a href="http://pastebin.com/HkHwgsGt" rel="nofollow">Exception 1</a> and <a href="http://pastebin.com/CQc54ueD" rel="nofollow">Exception 2</a></p>
  
  <p>When looking up the code, we found that in <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cassandra/cassandra-all/2.1.3/org/apache/cassandra/db/ColumnFamily.java#303" rel="nofollow">ColumnFamily.java</a>, <code>cellInternal</code> is of type <code>BufferedCounterUpdateCell</code>, whose <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cassandra/cassandra-all/2.1.3/org/apache/cassandra/db/BufferCounterUpdateCell.java#54" rel="nofollow">diff</a> operation is not supported. As well reconcile method is called on a <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cassandra/cassandra-all/2.1.3/org/apache/cassandra/db/BufferCounterUpdateCell.java#61" rel="nofollow">wrong type</a> too.</p>
  
  <p>Just to confirm the issue, we did use the <code>sstable2json</code> utility to inspect the data. And as we guessed
  Cells of a properly dumped sstable had valid counters</p>
  
  <pre><code>(":1:c05:desktop/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/","00010000db5ad3b00d4711e5b52dab7bf928868d00000000000000590000000000000059",1433835586985,"c",-9223372036854775808),
  (":1:c05:*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/","00010000db5ad3b00d4711e5b52dab7bf928868d00000000000000590000000000000059",1433835586985,"c",-9223372036854775808)
  </code></pre>
  
  <p>whereas the faulty ones had buffered counters and hence the sstable2json failed</p>
  
  <pre><code>("*:0:c01:*/direct/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/","0000000000000001",1433924262793),
  ("*:0:c01:*/*/singapore/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/","0000000000000002",1433924262793),
  </code></pre>
  
  <p>Basically <code>sstable2json</code> <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cassandra/cassandra-all/2.1.3/org/apache/cassandra/tools/SSTableExport.java#SSTableExport.serializeColumn%28org.apache.cassandra.db.Cell%2Corg.apache.cassandra.config.CFMetaData%29" rel="nofollow">doesn't have support</a> for dumping BufferedCounterUpdateCells, Hence it assumes such cells to be of normal type and dumps them.</p>
  
  <p>It is evident from error logs and <code>sstable2json</code> output, that instead of dumping CounterColumns, CQLSSTableWriter dumped Counter Update Columns <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cassandra/cassandra-all/2.1.3/org/apache/cassandra/db/ColumnSerializer.java#133" rel="nofollow">counter types with a different mask</a>, which resulted in error while cassandra tried to load SSTables with such columns up. </p>
  
  <p>We see this issue happening always when SSTable get created via CQLSSTableWriter.</p>
  
  <p>While going through any issues reported on the same note, we stalled on <a href="https://issues.apache.org/jira/browse/CASSANDRA-8978" rel="nofollow">this</a>. Something related to switching CFs for writing. We guess problem could be on the same lines. Any inputs are welcome.</p>
  
  <p>----Update
  On further debugging we figured out that CQLSSTableWriter fails to convert CounterUpdateColumns to CounterColumns as it is usually done in all other cases <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cassandra/cassandra-all/2.1.3/org/apache/cassandra/db/CounterMutation.java#CounterMutation.processModifications%28org.apache.cassandra.db.ColumnFamily%29" rel="nofollow">row mutations</a>. Might need a patch </p>