Skip to content

Commit

Permalink
Backport CASSANDRA-18760
Browse files Browse the repository at this point in the history
  • Loading branch information
driftx committed Sep 19, 2024
1 parent b7def63 commit 5a204a1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private void addColumn(KeyspaceMetadata keyspace,
{
// After #8099, not safe to re-add columns of incompatible types - until *maybe* deser logic with dropped
// columns is pushed deeper down the line. The latter would still be problematic in cases of schema races.
if (!type.isValueCompatibleWith(droppedColumn.type))
if (!type.isSerializationCompatibleWith(droppedColumn.type))
{
throw ire("Cannot re-add previously dropped column '%s' of type %s, incompatible with previous type %s",
name,
Expand Down
12 changes: 12 additions & 0 deletions src/java/org/apache/cassandra/db/marshal/AbstractType.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ protected boolean isValueCompatibleWithInternal(AbstractType<?> otherType)
return isCompatibleWith(otherType);
}

/**
* Similar to {@link #isValueCompatibleWith(AbstractType)}, but takes into account {@link Cell} encoding.
* In particular, this method doesn't consider two types serialization compatible if one of them has fixed
* length (overrides {@link #valueLengthIfFixed()}, and the other one doesn't.
*/
public boolean isSerializationCompatibleWith(AbstractType<?> previous)
{
return isValueCompatibleWith(previous)
&& valueLengthIfFixed() == previous.valueLengthIfFixed()
&& isMultiCell() == previous.isMultiCell();
}

/**
* An alternative comparison function used by CollectionsType in conjunction with CompositeType.
*
Expand Down
6 changes: 3 additions & 3 deletions src/java/org/apache/cassandra/db/marshal/CollectionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected boolean isCompatibleWhenFrozenWith(AbstractType<?> previous)
// nameComparator() is hard-coded), but this method is not so performance sensitive that it's worth bothering.
CollectionType<?> prev = (CollectionType<?>)previous;
return nameComparator().isCompatibleWith(prev.nameComparator())
&& valueComparator().isCompatibleWith(prev.valueComparator());
&& valueComparator().isSerializationCompatibleWith(prev.valueComparator());
}

@Override
Expand All @@ -168,7 +168,7 @@ protected boolean isCompatibleWhenNonFrozenWith(AbstractType<?> previous)
// for sorting so value-compatibility is enough.
CollectionType<?> prev = (CollectionType<?>)previous;
return nameComparator().isCompatibleWith(prev.nameComparator())
&& valueComparator().isValueCompatibleWith(prev.valueComparator());
&& valueComparator().isSerializationCompatibleWith(prev.valueComparator());
}

@Override
Expand All @@ -177,7 +177,7 @@ protected boolean isValueCompatibleWhenFrozenWith(AbstractType<?> previous)
// When frozen, the full collection is a blob, so value-compatibility is all we care for everything.
CollectionType<?> prev = (CollectionType<?>)previous;
return nameComparator().isValueCompatibleWith(prev.nameComparator())
&& valueComparator().isValueCompatibleWith(prev.valueComparator());
&& valueComparator().isSerializationCompatibleWith(prev.valueComparator());
}

public CQL3Type asCQL3Type()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.cassandra.db.memtable.TrieMemtable;
import org.apache.cassandra.dht.OrderPreservingPartitioner;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.locator.InetAddressAndPort;
import org.apache.cassandra.locator.TokenMetadata;
Expand Down Expand Up @@ -445,6 +446,37 @@ public void testDowngradeToCompact() throws Throwable
alterTable("alter table %s add v1 int");
}

@Test(expected = InvalidRequestException.class)
public void testDropFixedAddVariable() throws Throwable
{
createTable("create table %s (k int, c int, v int, PRIMARY KEY (k, c))");
execute("alter table %s drop v");
execute("alter table %s add v varint");
}

@Test(expected = InvalidRequestException.class)
public void testDropFixedCollectionAddVariableCollection() throws Throwable
{
createTable("create table %s (k int, c int, v list<int>, PRIMARY KEY (k, c))");
execute("alter table %s drop v");
execute("alter table %s add v list<varint>");
}

@Test(expected = InvalidRequestException.class)
public void testDropSimpleAddComplex() throws Throwable
{
createTable("create table %s (k int, c int, v set<text>, PRIMARY KEY (k, c))");
execute("alter table %s drop v");
execute("alter table %s add v blob");
}

@Test(expected = SyntaxException.class)
public void renameToEmptyTest() throws Throwable
{
createTable("CREATE TABLE %s (k int, c1 int, v int, PRIMARY KEY (k, c1))");
execute("ALTER TABLE %s RENAME c1 TO \"\"");
}

@Test
// tests CASSANDRA-9565
public void testDoubleWith() throws Throwable
Expand Down

1 comment on commit 5a204a1

@cassci-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build rejected: 6 NEW test failure(s) in 1 builds., Build 1: ran 17695 tests with 14 failures and 128 skipped.
Butler analysis done on ds-cassandra-pr-gate/cndb-9233 vs last 16 runs of ds-cassandra-build-nightly/main.
org.apache.cassandra.index.sai.cql.QueryWriteLifecycleTest.testWriteLifecycle[aa_CompoundKeyDataModel{primaryKey=p, c}]: test is constantly failing. No failures on upstream;
branch story: [F] vs upstream: [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]; [NEW]
org.apache.cassandra.utils.binlog.BinLogTest.testTruncationReleasesLogSpace: test is constantly failing. No failures on upstream;
branch story: [F] vs upstream: [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]; [NEW]
org.apache.cassandra.db.marshal.AbstractTypeTest.testImplementedCompatibility: test is constantly failing. No failures on upstream;
branch story: [F] vs upstream: [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]; [NEW]
org.apache.cassandra.db.marshal.AbstractTypeTest.testBackwardCompatibility: test is constantly failing. No failures on upstream;
branch story: [F] vs upstream: [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]; [NEW]
org.apache.cassandra.net.ConnectionTest.testTimeout: test is constantly failing. No failures on upstream;
branch story: [F] vs upstream: [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]; [NEW]
org.apache.cassandra.index.sai.cql.TinySegmentQueryWriteLifecycleTest.testWriteLifecycle[aa_CompoundKeyDataModel{primaryKey=p, c}]: test is constantly failing. No failures on upstream;
branch story: [F] vs upstream: [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]; [NEW]
butler comparison

Please sign in to comment.