Ignore empty Counter cells on digest calculation.

patch by Francisco Fernández Castaño; reviewed by Sylvain Lebresne for CASSANDRA-14167
This commit is contained in:
Fransisco Fernandez Castano 2018-04-22 13:08:26 +02:00 committed by Sylvain Lebresne
parent c4982587bf
commit 93012e43ea
3 changed files with 27 additions and 0 deletions

View File

@ -1,4 +1,5 @@
3.0.17
* Fix potential IndexOutOfBoundsException with counters (CASSANDRA-14167)
* Restore resumable hints delivery, backport CASSANDRA-11960 (CASSANDRA-14419)
* Always close RT markers returned by ReadCommand#executeLocally() (CASSANDRA-14515)
* Reverse order queries with range tombstones can cause data loss (CASSANDRA-14513)

View File

@ -692,6 +692,9 @@ public class CounterContext
*/
public void updateDigest(MessageDigest message, ByteBuffer context)
{
// context can be empty due to the optimization from CASSANDRA-10657
if (!context.hasRemaining())
return;
ByteBuffer dup = context.duplicate();
dup.position(context.position() + headerLength(context));
message.update(dup);

View File

@ -29,13 +29,16 @@ import org.junit.Test;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.config.ColumnDefinition;
import org.apache.cassandra.db.rows.BTreeRow;
import org.apache.cassandra.db.rows.BufferCell;
import org.apache.cassandra.db.rows.Cell;
import org.apache.cassandra.db.rows.CellPath;
import org.apache.cassandra.db.rows.Cells;
import org.apache.cassandra.db.context.CounterContext;
import org.apache.cassandra.db.rows.Row;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.schema.KeyspaceParams;
import org.apache.cassandra.serializers.AsciiSerializer;
import org.apache.cassandra.utils.*;
import static org.junit.Assert.*;
@ -281,4 +284,24 @@ public class CounterCellTest
assert Arrays.equals(digest1.digest(), digest2.digest());
}
@Test
public void testDigestWithEmptyCells() throws Exception
{
// For DB-1881
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(COUNTER1);
ColumnDefinition emptyColDef = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val2"));
BufferCell emptyCell = BufferCell.live(emptyColDef, 0, ByteBuffer.allocate(0));
Row.Builder builder = BTreeRow.unsortedBuilder(0);
builder.newRow(Clustering.make(AsciiSerializer.instance.serialize("test")));
builder.addCell(emptyCell);
Row row = builder.build();
MessageDigest digest = MessageDigest.getInstance("md5");
row.digest(digest);
assertNotNull(digest.digest());
}
}