Merge branch 'cassandra-3.0' into cassandra-3.11

* cassandra-3.0:
  Fix handling of cells for removed column when reading legacy sstables


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

Branch: refs/heads/trunk
Commit: 1527684462f903be6481324e401dc018da7e0e39
Parents: 710657d 5378ba2
Author: Sylvain Lebresne <sylv...@datastax.com>
Authored: Fri Oct 6 16:16:25 2017 +0200
Committer: Sylvain Lebresne <sylv...@datastax.com>
Committed: Fri Oct 6 16:16:25 2017 +0200

----------------------------------------------------------------------
 .../org/apache/cassandra/db/LegacyLayout.java   | 70 +++++++++++++-------
 .../cassandra/db/UnfilteredDeserializer.java    | 29 +++++---
 2 files changed, 67 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/15276844/src/java/org/apache/cassandra/db/LegacyLayout.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/db/LegacyLayout.java
index 77aa59a,3ba96a6..9679a32
--- a/src/java/org/apache/cassandra/db/LegacyLayout.java
+++ b/src/java/org/apache/cassandra/db/LegacyLayout.java
@@@ -1021,29 -1037,36 +1038,36 @@@ public abstract class LegacyLayou
          };
      }
  
-     public static LegacyAtom readLegacyAtom(CFMetaData metadata, 
DataInputPlus in, boolean readAllAsDynamic) throws IOException
+     public static LegacyAtom readLegacyAtom(CFMetaData metadata, 
DataInputPlus in, boolean readAllAsDynamic)
+     throws IOException, UnknownColumnException
      {
-         while (true)
-         {
-             ByteBuffer cellname = ByteBufferUtil.readWithShortLength(in);
-             if (!cellname.hasRemaining())
-                 return null; // END_OF_ROW
+         ByteBuffer cellname = ByteBufferUtil.readWithShortLength(in);
+         if (!cellname.hasRemaining())
+             return null; // END_OF_ROW
  
-             try
-             {
-                 int b = in.readUnsignedByte();
-                 return (b & RANGE_TOMBSTONE_MASK) != 0
-                     ? readLegacyRangeTombstoneBody(metadata, in, cellname)
-                     : readLegacyCellBody(metadata, in, cellname, b, 
SerializationHelper.Flag.LOCAL, readAllAsDynamic);
-             }
-             catch (UnknownColumnException e)
-             {
-                 // We can get there if we read a cell for a dropped column, 
and ff that is the case,
-                 // then simply ignore the cell is fine. But also not that we 
ignore if it's the
-                 // system keyspace because for those table we actually remove 
columns without registering
-                 // them in the dropped columns
-                 assert 
metadata.ksName.equals(SchemaConstants.SYSTEM_KEYSPACE_NAME) || 
metadata.getDroppedColumnDefinition(e.columnName) != null : e.getMessage();
-             }
+         try
+         {
+             int b = in.readUnsignedByte();
+             return (b & RANGE_TOMBSTONE_MASK) != 0
+                    ? readLegacyRangeTombstoneBody(metadata, in, cellname)
+                    : readLegacyCellBody(metadata, in, cellname, b, 
SerializationHelper.Flag.LOCAL, readAllAsDynamic);
+         }
+         catch (UnknownColumnException e)
+         {
+             // We legitimately can get here in 2 cases:
+             // 1) for system tables, because we've unceremoniously removed 
columns (without registering them as dropped)
+             // 2) for dropped columns.
+             // In any other case, there is a mismatch between the schema and 
the data, and we complain loudly in
+             // that case. Note that if we are in a legit case of an unknown 
column, we want to simply skip that cell,
+             // but we don't do this here and re-throw the exception because 
the calling code sometimes has to know
+             // about this happening. This does mean code calling this method 
should handle this case properly.
 -            if (!metadata.ksName.equals(SystemKeyspace.NAME) && 
metadata.getDroppedColumnDefinition(e.columnName) == null)
++            if (!metadata.ksName.equals(SchemaConstants.SYSTEM_KEYSPACE_NAME) 
&& metadata.getDroppedColumnDefinition(e.columnName) == null)
+                 throw new IllegalStateException(String.format("Got cell for 
unknown column %s in sstable of %s.%s: " +
+                                                               "This suggest a 
problem with the schema which doesn't list " +
+                                                               "this column. 
Even if that column was dropped, it should have " +
+                                                               "been listed as 
such", metadata.ksName, metadata.cfName, 
UTF8Type.instance.compose(e.columnName)), e);
+ 
+             throw e;
          }
      }
  

http://git-wip-us.apache.org/repos/asf/cassandra/blob/15276844/src/java/org/apache/cassandra/db/UnfilteredDeserializer.java
----------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to