From b0db519b79701cecac92a7a2c93101cf17fb928d Mon Sep 17 00:00:00 2001 From: adelapena Date: Fri, 21 Apr 2017 09:33:16 +0100 Subject: [PATCH 1/2] Fix 2ndary indexes on primary key columns to don't create expiring entries (CASSANDRA-13412) --- CHANGES.txt | 1 + ...AbstractSimplePerColumnSecondaryIndex.java | 2 +- .../entities/SecondaryIndexTest.java | 42 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 251743271f..f62f16265d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.1.18 + * Fix 2ndary indexes on primary key columns to don't create expiring entries (CASSANDRA-13412) * Set javac encoding to utf-8 (CASSANDRA-13466) * Fix 2ndary index queries on partition keys for tables with static columns (CASSANDRA-13147) * Fix ParseError unhashable type list in cqlsh copy from (CASSANDRA-13364) diff --git a/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java b/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java index e80c7bde18..d7a1d8aadb 100644 --- a/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java +++ b/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java @@ -116,7 +116,7 @@ public abstract class AbstractSimplePerColumnSecondaryIndex extends PerColumnSec DecoratedKey valueKey = getIndexKeyFor(getIndexedValue(rowKey, cell)); ColumnFamily cfi = ArrayBackedSortedColumns.factory.create(indexCfs.metadata, false, 1); CellName name = makeIndexColumnName(rowKey, cell); - if (cell instanceof ExpiringCell) + if (!columnDef.isPrimaryKeyColumn() && cell instanceof ExpiringCell) { ExpiringCell ec = (ExpiringCell) cell; cfi.addColumn(new BufferExpiringCell(name, ByteBufferUtil.EMPTY_BYTE_BUFFER, ec.timestamp(), ec.getTimeToLive(), ec.getLocalDeletionTime())); diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java index b723f60244..1e63e3a414 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java @@ -819,4 +819,46 @@ public class SecondaryIndexTest extends CQLTester assertRows(execute("SELECT * FROM %s WHERE v = ?", 1), row(1, 1, 9, 1)); } + + @Test + public void testIndexOnPartitionKeyInsertExpiringColumn() throws Throwable + { + createTable("CREATE TABLE %s (k1 int, k2 int, a int, b int, PRIMARY KEY ((k1, k2)))"); + createIndex("CREATE INDEX on %s(k1)"); + execute("INSERT INTO %s (k1, k2, a, b) VALUES (1, 2, 3, 4)"); + assertRows(execute("SELECT * FROM %s WHERE k1 = 1"), row(1, 2, 3, 4)); + execute("UPDATE %s USING TTL 1 SET b = 10 WHERE k1 = 1 AND k2 = 2"); + Thread.sleep(1000); + assertRows(execute("SELECT * FROM %s WHERE k1 = 1"), row(1, 2, 3, null)); + } + + @Test + public void testIndexOnClusteringKeyInsertExpiringColumn() throws Throwable + { + createTable("CREATE TABLE %s (pk int, ck int, a int, b int, PRIMARY KEY (pk, ck))"); + createIndex("CREATE INDEX on %s(ck)"); + execute("INSERT INTO %s (pk, ck, a, b) VALUES (1, 2, 3, 4)"); + assertRows(execute("SELECT * FROM %s WHERE ck = 2"), row(1, 2, 3, 4)); + execute("UPDATE %s USING TTL 1 SET b = 10 WHERE pk = 1 AND ck = 2"); + Thread.sleep(1000); + assertRows(execute("SELECT * FROM %s WHERE ck = 2"), row(1, 2, 3, null)); + } + + @Test + public void testIndexOnRegularColumnInsertExpiringColumn() throws Throwable + { + createTable("CREATE TABLE %s (pk int, ck int, a int, b int, PRIMARY KEY (pk, ck))"); + createIndex("CREATE INDEX on %s(a)"); + execute("INSERT INTO %s (pk, ck, a, b) VALUES (1, 2, 3, 4)"); + assertRows(execute("SELECT * FROM %s WHERE a = 3"), row(1, 2, 3, 4)); + + execute("UPDATE %s USING TTL 1 SET b = 10 WHERE pk = 1 AND ck = 2"); + Thread.sleep(1000); + assertRows(execute("SELECT * FROM %s WHERE a = 3"), row(1, 2, 3, null)); + + execute("UPDATE %s USING TTL 1 SET a = 5 WHERE pk = 1 AND ck = 2"); + Thread.sleep(1000); + assertEmpty(execute("SELECT * FROM %s WHERE a = 3")); + assertEmpty(execute("SELECT * FROM %s WHERE a = 5")); + } } From 480a612eeffa6d3e77cd4f25676a90a2917da4a4 Mon Sep 17 00:00:00 2001 From: Martin Langhoff Date: Wed, 3 May 2017 16:54:28 -0400 Subject: [PATCH 2/2] RPM - rpmbuild tolerate binaries in noarch, README update patch by Martin A. Langhoff; reviewed by Stefan Podkowinski for CASSANDRA-13433 --- redhat/README.md | 19 ++++++++++--------- redhat/cassandra.spec | 5 ++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/redhat/README.md b/redhat/README.md index 0b2ab0df8b..cab42a752e 100644 --- a/redhat/README.md +++ b/redhat/README.md @@ -7,25 +7,26 @@ ### Step 1: - Build and copy sources to build tree: ``` -ant artifacts -cp build/apache-cassandra-*-src.tar.gz $RPM_BUILD_DIR/SOURCES/ +ant artifacts -Drelease=true ``` ### Step 2: - Since there is no version specified in the SPEC file, one needs to be passed at `rpmbuild` time (example with 4.0): ``` -rpmbuild --define="version 4.0" -ba redhat/cassandra.spec +mkdir -p build/rpmbuild/{BUILD,RPMS,SPECS,SRPMS} +rpmbuild --define="version 4.0" \ + --define="revision $(date +"%Y%m%d")git$(git rev-parse --short HEAD)%{?dist}" \ + --define "_topdir $(pwd)/build/rpmbuild" \ + --define "_sourcedir $(pwd)/build" \ + -ba redhat/cassandra.spec ``` +Use revision value in the example above for git based snapshots. Change to `--define="revision 1"` for non-snapshot releases. + - RPM files can be found in their respective build tree directories: ``` -ls -l $RPM_BUILD_DIR/{SRPMS,RPMS}/ +ls -l build/rpmbuild/{SRPMS,RPMS}/ ``` ### Hint: - Don't build packages as root.. -``` -# this makes your RPM_BUILD_DIR = ~/rpmbuild -mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} -echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros -``` diff --git a/redhat/cassandra.spec b/redhat/cassandra.spec index c3c22d0d53..ad4095df32 100644 --- a/redhat/cassandra.spec +++ b/redhat/cassandra.spec @@ -2,10 +2,13 @@ # Turn off the brp-python-bytecompile script %global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g') +# rpmbuild should not barf when it spots we ship +# binary executable files in our 'noarch' package +%define _binaries_in_noarch_packages_terminate_build 0 + %global username cassandra %define relname apache-cassandra-%{version} -%define revision 1 Name: cassandra Version: %{version}