Author: jbellis Date: Wed Sep 22 03:41:26 2010 New Revision: 999740 URL: http://svn.apache.org/viewvc?rev=999740&view=rev Log: extract addIndex method patch by jbellis; reviewed by gdusbabek for CASSANDRA-1415
Modified: cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Modified: cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java?rev=999740&r1=999739&r2=999740&view=diff ============================================================================== --- cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java (original) +++ cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java Wed Sep 22 03:41:26 2010 @@ -236,6 +236,27 @@ public final class CFMetaData column_metadata); } + public static CFMetaData newIndexMetadata(String table, String parentCf, ColumnDefinition info, AbstractType columnComparator) + { + return new CFMetaData(table, + parentCf + "." + (info.index_name == null ? FBUtilities.bytesToHex(info.name) : info.index_name), + ColumnFamilyType.Standard, + ClockType.Timestamp, + columnComparator, + null, + TimestampReconciler.instance, + "", + 0, + false, + 0, + 0, + DEFAULT_GC_GRACE_SECONDS, + BytesType.instance, + DEFAULT_MIN_COMPACTION_THRESHOLD, + DEFAULT_MAX_COMPACTION_THRESHOLD, + Collections.<byte[], ColumnDefinition>emptyMap()); + } + /** clones an existing CFMetaData using the same id. */ public static CFMetaData rename(CFMetaData cfm, String newName) { Modified: cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=999740&r1=999739&r2=999740&view=diff ============================================================================== --- cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original) +++ cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Wed Sep 22 03:41:26 2010 @@ -171,43 +171,15 @@ public class ColumnFamilyStore implement ssTables = new SSTableTracker(table, columnFamilyName); ssTables.add(sstables); + // create the private ColumnFamilyStores for the secondary column indexes indexedColumns = new TreeMap<byte[], ColumnFamilyStore>(getComparator()); - for (Map.Entry<byte[], ColumnDefinition> entry : metadata.column_metadata.entrySet()) + for (ColumnDefinition info : metadata.column_metadata.values()) { - byte[] column = entry.getKey(); - ColumnDefinition info = entry.getValue(); - if (info.index_type == null) - continue; - - String indexedCfName = columnFamily + "." + (info.index_name == null ? FBUtilities.bytesToHex(column) : info.index_name); - IPartitioner rowPartitioner = StorageService.getPartitioner(); - AbstractType columnComparator = (rowPartitioner instanceof OrderPreservingPartitioner || rowPartitioner instanceof ByteOrderedPartitioner) - ? BytesType.instance - : new LocalByPartionerType(StorageService.getPartitioner()); - CFMetaData indexedCfMetadata = new CFMetaData(table, - indexedCfName, - ColumnFamilyType.Standard, - ClockType.Timestamp, - columnComparator, - null, - TimestampReconciler.instance, - "", - 0, - false, - 0, - 0, - CFMetaData.DEFAULT_GC_GRACE_SECONDS, - BytesType.instance, - CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD, - CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD, - Collections.<byte[], ColumnDefinition>emptyMap()); - ColumnFamilyStore indexedCfs = ColumnFamilyStore.createColumnFamilyStore(table, - indexedCfName, - new LocalPartitioner(metadata.column_metadata.get(column).validator), - indexedCfMetadata); - indexedColumns.put(column, indexedCfs); + if (info.index_type != null) + addIndex(table, info); } - + + // register the mbean String type = this.partitioner instanceof LocalPartitioner ? "IndexColumnFamilies" : "ColumnFamilies"; mbeanName = "org.apache.cassandra.db:type=" + type + ",keyspace=" + this.table + ",columnfamily=" + columnFamily; try @@ -221,7 +193,21 @@ public class ColumnFamilyStore implement throw new RuntimeException(e); } } - + + private void addIndex(String table, ColumnDefinition info) + { + IPartitioner rowPartitioner = StorageService.getPartitioner(); + AbstractType columnComparator = (rowPartitioner instanceof OrderPreservingPartitioner || rowPartitioner instanceof ByteOrderedPartitioner) + ? BytesType.instance + : new LocalByPartionerType(StorageService.getPartitioner()); + CFMetaData indexedCfMetadata = CFMetaData.newIndexMetadata(table, columnFamily, info, columnComparator); + ColumnFamilyStore indexedCfs = ColumnFamilyStore.createColumnFamilyStore(table, + indexedCfMetadata.cfName, + new LocalPartitioner(metadata.column_metadata.get(info.name).validator), + indexedCfMetadata); + indexedColumns.put(info.name, indexedCfs); + } + // called when dropping or renaming a CF. Performs mbean housekeeping. void unregisterMBean() { @@ -353,7 +339,6 @@ public class ColumnFamilyStore implement // NB: we never "accept" a file in the FilenameFilter sense: they are added to the sstable map new File(directory).list(new FilenameFilter() { - @Override public boolean accept(File dir, String name) { Pair<Descriptor,Component> component = SSTable.tryComponentFromFilename(dir, name);