mirror of https://github.com/apache/cassandra
Merge branch 'cassandra-2.0' into cassandra-2.1
This commit is contained in:
commit
f18fb04452
|
|
@ -81,6 +81,7 @@
|
|||
* Use stdout for progress and stats in sstableloader (CASSANDRA-8982)
|
||||
* Correctly identify 2i datadir from older versions (CASSANDRA-9116)
|
||||
Merged from 2.0:
|
||||
* Do not attempt to rebuild indexes if no index accepts any column (CASSANDRA-9196)
|
||||
* Don't initiate snitch reconnection for dead states (CASSANDRA-7292)
|
||||
* Fix ArrayIndexOutOfBoundsException in CQLSSTableWriter (CASSANDRA-8978)
|
||||
* Add shutdown gossip state to prevent timeouts during rolling restarts (CASSANDRA-8336)
|
||||
|
|
|
|||
|
|
@ -308,6 +308,16 @@ public abstract class SecondaryIndex
|
|||
*/
|
||||
public abstract boolean indexes(CellName name);
|
||||
|
||||
/**
|
||||
* Returns true if the defined column is indexed by this secondary index.
|
||||
* @param column definition of the column to check
|
||||
* @return whether the supplied column is indexed or not
|
||||
*/
|
||||
public boolean indexes(ColumnDefinition column)
|
||||
{
|
||||
return columnDefs.contains(column);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the primary way to create a secondary index instance for a CF column.
|
||||
* It will validate the index_options before initializing.
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@ public class SecondaryIndexManager
|
|||
*/
|
||||
public void maybeBuildSecondaryIndexes(Collection<SSTableReader> sstables, Set<String> idxNames)
|
||||
{
|
||||
idxNames = filterByColumn(idxNames);
|
||||
if (idxNames.isEmpty())
|
||||
return;
|
||||
|
||||
|
|
@ -705,6 +706,24 @@ public class SecondaryIndexManager
|
|||
|| oldCell.timestamp() != newCell.timestamp();
|
||||
}
|
||||
|
||||
private Set<String> filterByColumn(Set<String> idxNames)
|
||||
{
|
||||
Set<SecondaryIndex> indexes = getIndexesByNames(idxNames);
|
||||
Set<String> filtered = new HashSet<>(idxNames.size());
|
||||
for (SecondaryIndex candidate : indexes)
|
||||
{
|
||||
for (ColumnDefinition column : baseCfs.metadata.allColumns())
|
||||
{
|
||||
if (candidate.indexes(column))
|
||||
{
|
||||
filtered.add(candidate.getIndexName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public static interface Updater
|
||||
{
|
||||
/** called when constructing the index against pre-existing data */
|
||||
|
|
|
|||
|
|
@ -22,20 +22,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -51,36 +38,17 @@ import org.junit.runner.RunWith;
|
|||
import org.apache.cassandra.OrderedJUnit4ClassRunner;
|
||||
import org.apache.cassandra.SchemaLoader;
|
||||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ColumnDefinition;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.IndexType;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.cql3.Operator;
|
||||
import org.apache.cassandra.db.columniterator.IdentityQueryFilter;
|
||||
import org.apache.cassandra.db.composites.CellName;
|
||||
import org.apache.cassandra.db.composites.CellNameType;
|
||||
import org.apache.cassandra.db.composites.CellNames;
|
||||
import org.apache.cassandra.db.composites.Composites;
|
||||
import org.apache.cassandra.db.filter.ColumnSlice;
|
||||
import org.apache.cassandra.db.filter.IDiskAtomFilter;
|
||||
import org.apache.cassandra.db.filter.NamesQueryFilter;
|
||||
import org.apache.cassandra.db.filter.QueryFilter;
|
||||
import org.apache.cassandra.db.filter.SliceQueryFilter;
|
||||
import org.apache.cassandra.db.composites.*;
|
||||
import org.apache.cassandra.db.filter.*;
|
||||
import org.apache.cassandra.db.index.PerRowSecondaryIndexTest;
|
||||
import org.apache.cassandra.db.index.SecondaryIndex;
|
||||
import org.apache.cassandra.db.marshal.LexicalUUIDType;
|
||||
import org.apache.cassandra.db.marshal.LongType;
|
||||
import org.apache.cassandra.dht.Bounds;
|
||||
import org.apache.cassandra.dht.ExcludingBounds;
|
||||
import org.apache.cassandra.dht.IPartitioner;
|
||||
import org.apache.cassandra.dht.IncludingExcludingBounds;
|
||||
import org.apache.cassandra.dht.Range;
|
||||
import org.apache.cassandra.io.sstable.Component;
|
||||
import org.apache.cassandra.io.sstable.Descriptor;
|
||||
import org.apache.cassandra.io.sstable.SSTableDeletingTask;
|
||||
import org.apache.cassandra.io.sstable.SSTableReader;
|
||||
import org.apache.cassandra.io.sstable.SSTableSimpleWriter;
|
||||
import org.apache.cassandra.io.sstable.SSTableWriter;
|
||||
import org.apache.cassandra.dht.*;
|
||||
import org.apache.cassandra.io.sstable.*;
|
||||
import org.apache.cassandra.io.sstable.metadata.MetadataCollector;
|
||||
import org.apache.cassandra.io.util.FileUtils;
|
||||
import org.apache.cassandra.service.ActiveRepairService;
|
||||
|
|
@ -88,10 +56,7 @@ import org.apache.cassandra.service.StorageService;
|
|||
import org.apache.cassandra.thrift.SlicePredicate;
|
||||
import org.apache.cassandra.thrift.SliceRange;
|
||||
import org.apache.cassandra.thrift.ThriftValidation;
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.utils.Pair;
|
||||
import org.apache.cassandra.utils.WrappedRunnable;
|
||||
import org.apache.cassandra.utils.*;
|
||||
|
||||
import static org.apache.cassandra.Util.cellname;
|
||||
import static org.apache.cassandra.Util.column;
|
||||
|
|
@ -2199,4 +2164,30 @@ public class ColumnFamilyStoreTest extends SchemaLoader
|
|||
});
|
||||
System.err.println("Row key: " + rowKey + " Cols: " + transformed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRebuildSecondaryIndex() throws IOException
|
||||
{
|
||||
Mutation rm;
|
||||
|
||||
rm = new Mutation("PerRowSecondaryIndex", ByteBufferUtil.bytes("k1"));
|
||||
rm.add("Indexed1", cellname("indexed"), ByteBufferUtil.bytes("foo"), 1);
|
||||
rm.apply();
|
||||
assertTrue(Arrays.equals("k1".getBytes(), PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY.array()));
|
||||
|
||||
Keyspace.open("PerRowSecondaryIndex").getColumnFamilyStore("Indexed1").forceBlockingFlush();
|
||||
|
||||
PerRowSecondaryIndexTest.TestIndex.reset();
|
||||
|
||||
ColumnFamilyStore.rebuildSecondaryIndex("PerRowSecondaryIndex", "Indexed1", PerRowSecondaryIndexTest.TestIndex.class.getSimpleName());
|
||||
assertTrue(Arrays.equals("k1".getBytes(), PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY.array()));
|
||||
|
||||
PerRowSecondaryIndexTest.TestIndex.reset();
|
||||
|
||||
PerRowSecondaryIndexTest.TestIndex.ACTIVE = false;
|
||||
ColumnFamilyStore.rebuildSecondaryIndex("PerRowSecondaryIndex", "Indexed1", PerRowSecondaryIndexTest.TestIndex.class.getSimpleName());
|
||||
assertNull(PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY);
|
||||
|
||||
PerRowSecondaryIndexTest.TestIndex.reset();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.junit.Test;
|
|||
|
||||
import org.apache.cassandra.SchemaLoader;
|
||||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.config.ColumnDefinition;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.cql3.QueryProcessor;
|
||||
import org.apache.cassandra.cql3.UntypedResultSet;
|
||||
|
|
@ -146,15 +147,23 @@ public class PerRowSecondaryIndexTest extends SchemaLoader
|
|||
|
||||
public static class TestIndex extends PerRowSecondaryIndex
|
||||
{
|
||||
public static volatile boolean ACTIVE = true;
|
||||
public static ColumnFamily LAST_INDEXED_ROW;
|
||||
public static ByteBuffer LAST_INDEXED_KEY;
|
||||
|
||||
public static void reset()
|
||||
{
|
||||
ACTIVE = true;
|
||||
LAST_INDEXED_KEY = null;
|
||||
LAST_INDEXED_ROW = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean indexes(ColumnDefinition column)
|
||||
{
|
||||
return ACTIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void index(ByteBuffer rowKey, ColumnFamily cf)
|
||||
{
|
||||
|
|
@ -188,7 +197,7 @@ public class PerRowSecondaryIndexTest extends SchemaLoader
|
|||
@Override
|
||||
public String getIndexName()
|
||||
{
|
||||
return null;
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue