Merge branch 'cassandra-3.0' into cassandra-3.11

This commit is contained in:
Ekaterina Dimitrova 2022-04-17 14:20:39 -04:00
commit eeb89ea53b
4 changed files with 67 additions and 3 deletions

View File

@ -6,6 +6,7 @@
* Validate existence of DCs when repairing (CASSANDRA-17407)
* dropping of a materialized view creates a snapshot with dropped- prefix (CASSANDRA-17415)
Merged from 3.0:
* Fix data corruption in AbstractCompositeType due to static boolean byte buffers (CASSANDRA-14752)
* Add procps dependency to RPM/Debian packages (CASSANDRA-17516)
* Suppress CVE-2021-44521 (CASSANDRA-17492)
* ConnectionLimitHandler may leaks connection count if remote connection drops (CASSANDRA-17252)

View File

@ -196,8 +196,8 @@ public abstract class AbstractCompositeType extends AbstractType<ByteBuffer>
public ByteBuffer fromString(String source)
{
List<String> parts = split(source);
List<ByteBuffer> components = new ArrayList<ByteBuffer>(parts.size());
List<ParsedComparator> comparators = new ArrayList<ParsedComparator>(parts.size());
List<ByteBuffer> components = new ArrayList<>(parts.size());
List<ParsedComparator> comparators = new ArrayList<>(parts.size());
int totalLength = 0, i = 0;
boolean lastByteIsOne = false;
boolean lastByteIsMinusOne = false;
@ -232,7 +232,7 @@ public abstract class AbstractCompositeType extends AbstractType<ByteBuffer>
{
comparators.get(i).serializeComparator(bb);
ByteBufferUtil.writeShortLength(bb, component.remaining());
bb.put(component); // it's ok to consume component as we won't use it anymore
bb.put(component.duplicate()); // it's not ok to consume component as we did not create it (CASSANDRA-14752)
bb.put((byte)0);
++i;
}

View File

@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.distributed.test;
import org.junit.Assert;
import org.junit.Test;
import org.apache.cassandra.distributed.Cluster;
import org.apache.cassandra.distributed.api.ConsistencyLevel;
import org.apache.cassandra.serializers.BooleanSerializer;
public class BooleanTest extends TestBaseImpl
{
@Test
public void booleanTest() throws Throwable
{
try(Cluster cluster = init(Cluster.build(1).start()))
{
cluster.schemaChange("create table " + KEYSPACE + ".tbl (id int, ck boolean, t int, primary key ((id, ck)))");
for (int i = 0; i < 10; i++)
cluster.coordinator(1).execute(withKeyspace("insert into %s.tbl (id, ck, t) values (?, true, ?)"), ConsistencyLevel.ALL, i, i);
cluster.get(1).nodetoolResult("getsstables", KEYSPACE, "tbl", "1:true");
cluster.forEach(i -> i.runOnInstance(() -> {
Assert.assertEquals(0, BooleanSerializer.instance.serialize(true).position());
Assert.assertEquals(0, BooleanSerializer.instance.serialize(false).position());
}));
}
}
}

View File

@ -688,4 +688,22 @@ public class ColumnFamilyStoreCQLHelperTest extends CQLTester
"\tWITH ID = " + cfs.metadata.cfId + "\n" +
"\tAND COMPACT STORAGE"));
}
@Test
public void testBooleanCompositeKey() throws Throwable
{
createTable("CREATE TABLE %s (t_id boolean, id boolean, ck boolean, nk boolean, PRIMARY KEY ((t_id, id), ck))");
execute("insert into %s (t_id, id, ck, nk) VALUES (true, false, false, true)");
assertRows(execute("select * from %s"), row(true, false, false, true));
// CASSANDRA-14752 -
// a problem with composite boolean types meant that calling this would
// prevent any boolean values to be inserted afterwards
ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
cfs.getSSTablesForKey("false:true");
execute("insert into %s (t_id, id, ck, nk) VALUES (true, true, false, true)");
assertRows(execute("select t_id, id, ck, nk from %s"), row(true, true, false, true), row(true, false, false, true));
}
}