diff --git a/CHANGES.txt b/CHANGES.txt index a2e44f4e0f..b25e0a42d4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,7 @@ * make index_interval configurable per columnfamily (CASSANDRA-3961) * add default_tim_to_live (CASSANDRA-3974) * add memtable_flush_period_in_ms (CASSANDRA-4237) + * replace supercolumns internally by composites (CASSANDRA-3237) 1.2.1 diff --git a/examples/client_only/src/ClientOnlyExample.java b/examples/client_only/src/ClientOnlyExample.java index fa69965fb9..d6f80ae977 100644 --- a/examples/client_only/src/ClientOnlyExample.java +++ b/examples/client_only/src/ClientOnlyExample.java @@ -20,7 +20,7 @@ import java.nio.ByteBuffer; import java.util.*; import org.apache.cassandra.db.*; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.filter.NamesQueryFilter; import org.apache.cassandra.service.StorageProxy; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.thrift.*; @@ -64,8 +64,7 @@ public class ClientOnlyExample for (int i = 0; i < 100; i++) { RowMutation change = new RowMutation(KEYSPACE, ByteBufferUtil.bytes(("key" + i))); - ColumnPath cp = new ColumnPath(COLUMN_FAMILY).setColumn(("colb").getBytes()); - change.add(new QueryPath(cp), ByteBufferUtil.bytes(("value" + i)), 0); + change.add(COLUMN_FAMILY, ByteBufferUtil.bytes("colb"), ByteBufferUtil.bytes(("value" + i)), 0); // don't call change.apply(). The reason is that is makes a static call into Table, which will perform // local storage initialization, which creates local directories. @@ -80,15 +79,10 @@ public class ClientOnlyExample private static void testReading() throws Exception { // do some queries. - Collection cols = new ArrayList() - {{ - add(ByteBufferUtil.bytes("colb")); - }}; for (int i = 0; i < 100; i++) { List commands = new ArrayList(); - SliceByNamesReadCommand readCommand = new SliceByNamesReadCommand(KEYSPACE, ByteBufferUtil.bytes(("key" + i)), - new QueryPath(COLUMN_FAMILY, null, null), cols); + SliceByNamesReadCommand readCommand = new SliceByNamesReadCommand(KEYSPACE, ByteBufferUtil.bytes(("key" + i)), COLUMN_FAMILY, new NamesQueryFilter(ByteBufferUtil.bytes("colb"))); readCommand.setDigestQuery(false); commands.add(readCommand); List rows = StorageProxy.read(commands, ConsistencyLevel.ONE); diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java b/src/java/org/apache/cassandra/config/CFMetaData.java index 803cea10ff..359bbb3957 100644 --- a/src/java/org/apache/cassandra/config/CFMetaData.java +++ b/src/java/org/apache/cassandra/config/CFMetaData.java @@ -17,11 +17,13 @@ */ package org.apache.cassandra.config; +import java.io.DataInput; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.nio.ByteBuffer; import java.util.*; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.MapDifference; import com.google.common.collect.Maps; import org.apache.commons.lang.ArrayUtils; @@ -47,9 +49,9 @@ import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.exceptions.RequestValidationException; import org.apache.cassandra.exceptions.SyntaxException; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.compress.CompressionParameters; import org.apache.cassandra.io.compress.SnappyCompressor; +import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.thrift.IndexType; import org.apache.cassandra.tracing.Tracing; import org.apache.cassandra.utils.ByteBufferUtil; @@ -251,7 +253,6 @@ public final class CFMetaData public final String cfName; // name of this column family public final ColumnFamilyType cfType; // standard, super public volatile AbstractType comparator; // bytes, long, timeuuid, utf8, etc. - public volatile AbstractType subcolumnComparator; // like comparator, for supercolumns //OPTIONAL private volatile String comment = ""; @@ -308,17 +309,22 @@ public final class CFMetaData public CFMetaData(String keyspace, String name, ColumnFamilyType type, AbstractType comp, AbstractType subcc) { - this(keyspace, name, type, comp, subcc, getId(keyspace, name)); + this(keyspace, name, type, makeComparator(type, comp, subcc)); } - CFMetaData(String keyspace, String name, ColumnFamilyType type, AbstractType comp, AbstractType subcc, UUID id) + public CFMetaData(String keyspace, String name, ColumnFamilyType type, AbstractType comp) + { + this(keyspace, name, type, comp, getId(keyspace, name)); + } + + @VisibleForTesting + CFMetaData(String keyspace, String name, ColumnFamilyType type, AbstractType comp, UUID id) { // Final fields must be set in constructor ksName = keyspace; cfName = name; cfType = type; comparator = comp; - subcolumnComparator = enforceSubccDefault(type, subcc); cfId = id; updateCfDef(); // init cqlCfDef @@ -344,9 +350,11 @@ public final class CFMetaData return compile(id, cql, Table.SYSTEM_KS); } - private AbstractType enforceSubccDefault(ColumnFamilyType cftype, AbstractType subcc) + private static AbstractType makeComparator(ColumnFamilyType cftype, AbstractType comp, AbstractType subcc) { - return (subcc == null) && (cftype == ColumnFamilyType.Super) ? BytesType.instance : subcc; + return cftype == ColumnFamilyType.Super + ? CompositeType.getInstance(comp, subcc == null ? BytesType.instance : subcc) + : comp; } private static String enforceCommentNotNull (CharSequence comment) @@ -386,7 +394,7 @@ public final class CFMetaData ? Caching.KEYS_ONLY : Caching.NONE; - return new CFMetaData(parent.ksName, parent.indexColumnFamilyName(info), ColumnFamilyType.Standard, columnComparator, null) + return new CFMetaData(parent.ksName, parent.indexColumnFamilyName(info), ColumnFamilyType.Standard, columnComparator, (AbstractType)null) .keyValidator(info.getValidator()) .readRepairChance(0.0) .dcLocalReadRepairChance(0.0) @@ -409,13 +417,13 @@ public final class CFMetaData public CFMetaData clone() { - return copyOpts(new CFMetaData(ksName, cfName, cfType, comparator, subcolumnComparator, cfId), this); + return copyOpts(new CFMetaData(ksName, cfName, cfType, comparator, cfId), this); } // Create a new CFMD by changing just the cfName public static CFMetaData rename(CFMetaData cfm, String newName) { - return copyOpts(new CFMetaData(cfm.ksName, newName, cfm.cfType, cfm.comparator, cfm.subcolumnComparator, cfm.cfId), cfm); + return copyOpts(new CFMetaData(cfm.ksName, newName, cfm.cfType, cfm.comparator, cfm.cfId), cfm); } static CFMetaData copyOpts(CFMetaData newCFMD, CFMetaData oldCFMD) @@ -468,6 +476,11 @@ public final class CFMetaData return comment; } + public boolean isSuper() + { + return cfType == ColumnFamilyType.Super; + } + public double getReadRepairChance() { return readRepairChance; @@ -542,11 +555,6 @@ public final class CFMetaData return Collections.unmodifiableMap(column_metadata); } - public AbstractType getComparatorFor(ByteBuffer superColumnName) - { - return superColumnName == null ? comparator : subcolumnComparator; - } - public double getBloomFilterFpChance() { return bloomFilterFpChance == null @@ -591,7 +599,6 @@ public final class CFMetaData .append(cfName, rhs.cfName) .append(cfType, rhs.cfType) .append(comparator, rhs.comparator) - .append(subcolumnComparator, rhs.subcolumnComparator) .append(comment, rhs.comment) .append(readRepairChance, rhs.readRepairChance) .append(dcLocalReadRepairChance, rhs.dcLocalReadRepairChance) @@ -624,7 +631,6 @@ public final class CFMetaData .append(cfName) .append(cfType) .append(comparator) - .append(subcolumnComparator) .append(comment) .append(readRepairChance) .append(dcLocalReadRepairChance) @@ -739,7 +745,7 @@ public final class CFMetaData .replicateOnWrite(cf_def.replicate_on_write) .defaultValidator(TypeParser.parse(cf_def.default_validation_class)) .keyValidator(TypeParser.parse(cf_def.key_validation_class)) - .columnMetadata(ColumnDefinition.fromThrift(cf_def.column_metadata)) + .columnMetadata(ColumnDefinition.fromThrift(cf_def.column_metadata, newCFMD.isSuper())) .compressionParameters(cp); } catch (SyntaxException e) @@ -783,10 +789,9 @@ public final class CFMetaData validateCompatility(cfm); // TODO: this method should probably return a new CFMetaData so that - // 1) we can keep comparator and subcolumnComparator final + // 1) we can keep comparator final // 2) updates are applied atomically comparator = cfm.comparator; - subcolumnComparator = cfm.subcolumnComparator; // compaction thresholds are checked by ThriftValidation. We shouldn't be doing // validation on the apply path; it's too late for that. @@ -859,14 +864,6 @@ public final class CFMetaData if (!cfm.comparator.isCompatibleWith(comparator)) throw new ConfigurationException("comparators do not match or are not compatible."); - if (cfm.subcolumnComparator == null) - { - if (subcolumnComparator != null) - throw new ConfigurationException("subcolumncomparators do not match."); - // else, it's null and we're good. - } - else if (!cfm.subcolumnComparator.isCompatibleWith(subcolumnComparator)) - throw new ConfigurationException("subcolumncomparators do not match or are note compatible."); } public static Class createCompactionStrategy(String className) throws ConfigurationException @@ -908,13 +905,18 @@ public final class CFMetaData { org.apache.cassandra.thrift.CfDef def = new org.apache.cassandra.thrift.CfDef(ksName, cfName); def.setColumn_type(cfType.name()); - def.setComparator_type(comparator.toString()); - if (subcolumnComparator != null) + + if (isSuper()) { - assert cfType == ColumnFamilyType.Super - : String.format("%s CF %s should not have subcomparator %s defined", cfType, cfName, subcolumnComparator); - def.setSubcomparator_type(subcolumnComparator.toString()); + CompositeType ct = (CompositeType)comparator; + def.setComparator_type(ct.types.get(0).toString()); + def.setSubcomparator_type(ct.types.get(1).toString()); } + else + { + def.setComparator_type(comparator.toString()); + } + def.setComment(enforceCommentNotNull(comment)); def.setRead_repair_chance(readRepairChance); def.setDclocal_read_repair_chance(dcLocalReadRepairChance); @@ -961,7 +963,7 @@ public final class CFMetaData */ public ColumnDefinition getColumnDefinitionFromColumnName(ByteBuffer columnName) { - if (comparator instanceof CompositeType) + if (!isSuper() && (comparator instanceof CompositeType)) { CompositeType composite = (CompositeType)comparator; ByteBuffer[] components = composite.split(columnName); @@ -1039,18 +1041,16 @@ public final class CFMetaData return (cfName + "_" + comparator.getString(columnName) + "_idx").replaceAll("\\W", ""); } - public IColumnSerializer getColumnSerializer() + public Iterator getOnDiskIterator(DataInput dis, int count, Descriptor.Version version) { - if (cfType == ColumnFamilyType.Standard) - return Column.serializer(); - return SuperColumn.serializer(subcolumnComparator); + return getOnDiskIterator(dis, count, ColumnSerializer.Flag.LOCAL, (int) (System.currentTimeMillis() / 1000), version); } - public OnDiskAtom.Serializer getOnDiskSerializer() + public Iterator getOnDiskIterator(DataInput dis, int count, ColumnSerializer.Flag flag, int expireBefore, Descriptor.Version version) { - if (cfType == ColumnFamilyType.Standard) - return Column.onDiskSerializer(); - return SuperColumn.onDiskSerializer(subcolumnComparator); + if (version.hasSuperColumns && cfType == ColumnFamilyType.Super) + return SuperColumns.onDiskIterator(dis, count, flag, expireBefore); + return Column.onDiskIterator(dis, count, flag, expireBefore, version); } public static boolean isNameValid(String name) @@ -1073,22 +1073,9 @@ public final class CFMetaData if (cfType == null) throw new ConfigurationException(String.format("Invalid column family type for %s", cfName)); - if (cfType == ColumnFamilyType.Super) - { - if (subcolumnComparator == null) - throw new ConfigurationException(String.format("Missing subcolumn comparator for super column family %s", cfName)); - } - else - { - if (subcolumnComparator != null) - throw new ConfigurationException(String.format("Subcolumn comparator (%s) is invalid for standard column family %s", subcolumnComparator, cfName)); - } - if (comparator instanceof CounterColumnType) throw new ConfigurationException("CounterColumnType is not a valid comparator"); - if (subcolumnComparator instanceof CounterColumnType) - throw new ConfigurationException("CounterColumnType is not a valid sub-column comparator"); if (keyValidator instanceof CounterColumnType) throw new ConfigurationException("CounterColumnType is not a valid key validator"); @@ -1315,9 +1302,21 @@ public final class CFMetaData cf.addColumn(Column.create(oldId, timestamp, cfName, "id")); cf.addColumn(Column.create(cfType.toString(), timestamp, cfName, "type")); - cf.addColumn(Column.create(comparator.toString(), timestamp, cfName, "comparator")); - if (subcolumnComparator != null) - cf.addColumn(Column.create(subcolumnComparator.toString(), timestamp, cfName, "subcomparator")); + + if (isSuper()) + { + // We need to continue saving the comparator and subcomparator separatly, otherwise + // we won't know at deserialization if the subcomparator should be taken into account + // TODO: we should implement an on-start migration if we want to get rid of that. + CompositeType ct = (CompositeType)comparator; + cf.addColumn(Column.create(ct.types.get(0).toString(), timestamp, cfName, "comparator")); + cf.addColumn(Column.create(ct.types.get(1).toString(), timestamp, cfName, "subcomparator")); + } + else + { + cf.addColumn(Column.create(comparator.toString(), timestamp, cfName, "comparator")); + } + cf.addColumn(comment == null ? DeletedColumn.create(ldt, timestamp, cfName, "comment") : Column.create(comment, timestamp, cfName, "comment")); cf.addColumn(Column.create(readRepairChance, timestamp, cfName, "read_repair_chance")); @@ -1462,7 +1461,7 @@ public final class CFMetaData public AbstractType getColumnDefinitionComparator(Integer componentIndex) { - AbstractType cfComparator = cfType == ColumnFamilyType.Super ? subcolumnComparator : comparator; + AbstractType cfComparator = cfType == ColumnFamilyType.Super ? ((CompositeType)comparator).types.get(1) : comparator; if (cfComparator instanceof CompositeType) { if (componentIndex == null) @@ -1515,7 +1514,7 @@ public final class CFMetaData */ public boolean isThriftIncompatible() { - if (!cqlCfDef.isComposite) + if (isSuper() || !cqlCfDef.isComposite) return false; for (ColumnDefinition columnDef : column_metadata.values()) @@ -1535,7 +1534,6 @@ public final class CFMetaData .append("cfName", cfName) .append("cfType", cfType) .append("comparator", comparator) - .append("subcolumncomparator", subcolumnComparator) .append("comment", comment) .append("readRepairChance", readRepairChance) .append("dclocalReadRepairChance", dcLocalReadRepairChance) diff --git a/src/java/org/apache/cassandra/config/ColumnDefinition.java b/src/java/org/apache/cassandra/config/ColumnDefinition.java index 328d0ff427..81fce0b882 100644 --- a/src/java/org/apache/cassandra/config/ColumnDefinition.java +++ b/src/java/org/apache/cassandra/config/ColumnDefinition.java @@ -25,7 +25,6 @@ import com.google.common.collect.Maps; import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.cql3.UntypedResultSet; import org.apache.cassandra.db.*; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.*; import org.apache.cassandra.exceptions.*; import org.apache.cassandra.service.StorageService; @@ -116,24 +115,25 @@ public class ColumnDefinition return cd; } - public static ColumnDefinition fromThrift(ColumnDef thriftColumnDef) throws SyntaxException, ConfigurationException + public static ColumnDefinition fromThrift(ColumnDef thriftColumnDef, boolean isSuper) throws SyntaxException, ConfigurationException { + // For super columns, the componentIndex is 1 because the ColumnDefinition applies to the column component. return new ColumnDefinition(ByteBufferUtil.clone(thriftColumnDef.name), TypeParser.parse(thriftColumnDef.validation_class), thriftColumnDef.index_type, thriftColumnDef.index_options, thriftColumnDef.index_name, - null); + isSuper ? 1 : null); } - public static Map fromThrift(List thriftDefs) throws SyntaxException, ConfigurationException + public static Map fromThrift(List thriftDefs, boolean isSuper) throws SyntaxException, ConfigurationException { if (thriftDefs == null) return new HashMap(); Map cds = new TreeMap(); for (ColumnDef thriftColumnDef : thriftDefs) - cds.put(ByteBufferUtil.clone(thriftColumnDef.name), fromThrift(thriftColumnDef)); + cds.put(ByteBufferUtil.clone(thriftColumnDef.name), fromThrift(thriftColumnDef, isSuper)); return cds; } @@ -224,6 +224,9 @@ public class ColumnDefinition index_name = result.getString("index_name"); if (result.has("component_index")) componentIndex = result.getInt("component_index"); + // A ColumnDefinition for super columns applies to the column component + else if (cfm.isSuper()) + componentIndex = 1; cds.add(new ColumnDefinition(cfm.getColumnDefinitionComparator(componentIndex).fromString(result.getString("column_name")), TypeParser.parse(result.getString("validator")), @@ -246,7 +249,6 @@ public class ColumnDefinition DecoratedKey key = StorageService.getPartitioner().decorateKey(SystemTable.getSchemaKSKey(ksName)); ColumnFamilyStore columnsStore = SystemTable.schemaCFS(SystemTable.SCHEMA_COLUMNS_CF); ColumnFamily cf = columnsStore.getColumnFamily(key, - new QueryPath(SystemTable.SCHEMA_COLUMNS_CF), DefsTable.searchComposite(cfName, true), DefsTable.searchComposite(cfName, false), false, diff --git a/src/java/org/apache/cassandra/config/KSMetaData.java b/src/java/org/apache/cassandra/config/KSMetaData.java index e5b349a084..03ef6f589c 100644 --- a/src/java/org/apache/cassandra/config/KSMetaData.java +++ b/src/java/org/apache/cassandra/config/KSMetaData.java @@ -27,7 +27,6 @@ import org.apache.cassandra.auth.Auth; import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.cql3.UntypedResultSet; import org.apache.cassandra.db.*; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.locator.*; import org.apache.cassandra.service.StorageService; @@ -234,9 +233,9 @@ public final class KSMetaData public RowMutation dropFromSchema(long timestamp) { RowMutation rm = new RowMutation(Table.SYSTEM_KS, SystemTable.getSchemaKSKey(name)); - rm.delete(new QueryPath(SystemTable.SCHEMA_KEYSPACES_CF), timestamp); - rm.delete(new QueryPath(SystemTable.SCHEMA_COLUMNFAMILIES_CF), timestamp); - rm.delete(new QueryPath(SystemTable.SCHEMA_COLUMNS_CF), timestamp); + rm.delete(SystemTable.SCHEMA_KEYSPACES_CF, timestamp); + rm.delete(SystemTable.SCHEMA_COLUMNFAMILIES_CF, timestamp); + rm.delete(SystemTable.SCHEMA_COLUMNS_CF, timestamp); return rm; } diff --git a/src/java/org/apache/cassandra/config/Schema.java b/src/java/org/apache/cassandra/config/Schema.java index fa3ff241b0..23b0f11a01 100644 --- a/src/java/org/apache/cassandra/config/Schema.java +++ b/src/java/org/apache/cassandra/config/Schema.java @@ -235,20 +235,6 @@ public class Schema return cfmd.comparator; } - /** - * Get subComparator of the ColumnFamily - * - * @param ksName The keyspace name - * @param cfName The ColumnFamily name - * - * @return The subComparator of the ColumnFamily - */ - public AbstractType getSubComparator(String ksName, String cfName) - { - assert ksName != null; - return getCFMetaData(ksName, cfName).subcolumnComparator; - } - /** * Get value validator for specific column * diff --git a/src/java/org/apache/cassandra/cql/DeleteStatement.java b/src/java/org/apache/cassandra/cql/DeleteStatement.java index 87f48aa562..0a1f90c2b0 100644 --- a/src/java/org/apache/cassandra/cql/DeleteStatement.java +++ b/src/java/org/apache/cassandra/cql/DeleteStatement.java @@ -26,7 +26,6 @@ import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.Schema; import org.apache.cassandra.db.IMutation; import org.apache.cassandra.db.RowMutation; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.exceptions.UnauthorizedException; @@ -93,21 +92,19 @@ public class DeleteStatement extends AbstractModification QueryProcessor.validateKeyAlias(metadata, keyName); - AbstractType comparator = metadata.getComparatorFor(null); - if (columns.size() < 1) { // No columns, delete the row - rm.delete(new QueryPath(columnFamily), (timestamp == null) ? getTimestamp(clientState) : timestamp); + rm.delete(columnFamily, (timestamp == null) ? getTimestamp(clientState) : timestamp); } else { // Delete specific columns for (Term column : columns) { - ByteBuffer columnName = column.getByteBuffer(comparator, variables); + ByteBuffer columnName = column.getByteBuffer(metadata.comparator, variables); validateColumnName(columnName); - rm.delete(new QueryPath(columnFamily, null, columnName), (timestamp == null) ? getTimestamp(clientState) : timestamp); + rm.delete(columnFamily, columnName, (timestamp == null) ? getTimestamp(clientState) : timestamp); } } diff --git a/src/java/org/apache/cassandra/cql/QueryProcessor.java b/src/java/org/apache/cassandra/cql/QueryProcessor.java index ec07761a23..c54a4ebefe 100644 --- a/src/java/org/apache/cassandra/cql/QueryProcessor.java +++ b/src/java/org/apache/cassandra/cql/QueryProcessor.java @@ -76,13 +76,12 @@ public class QueryProcessor private static List getSlice(CFMetaData metadata, SelectStatement select, List variables) throws InvalidRequestException, ReadTimeoutException, UnavailableException, IsBootstrappingException { - QueryPath queryPath = new QueryPath(select.getColumnFamily()); List commands = new ArrayList(); // ...of a list of column names if (!select.isColumnRange()) { - Collection columnNames = getColumnNames(select, metadata, variables); + SortedSet columnNames = getColumnNames(select, metadata, variables); validateColumnNames(columnNames); for (Term rawKey: select.getKeys()) @@ -90,7 +89,7 @@ public class QueryProcessor ByteBuffer key = rawKey.getByteBuffer(metadata.getKeyValidator(),variables); validateKey(key); - commands.add(new SliceByNamesReadCommand(metadata.ksName, key, queryPath, columnNames)); + commands.add(new SliceByNamesReadCommand(metadata.ksName, key, select.getColumnFamily(), new NamesQueryFilter(columnNames))); } } // ...a range (slice) of column names @@ -108,11 +107,8 @@ public class QueryProcessor validateSliceFilter(metadata, start, finish, select.isColumnsReversed()); commands.add(new SliceFromReadCommand(metadata.ksName, key, - queryPath, - start, - finish, - select.isColumnsReversed(), - select.getColumnsLimit())); + select.getColumnFamily(), + new SliceQueryFilter(start, finish, select.isColumnsReversed(), select.getColumnsLimit()))); } } @@ -191,7 +187,6 @@ public class QueryProcessor { rows = StorageProxy.getRangeSlice(new RangeSliceCommand(metadata.ksName, select.getColumnFamily(), - null, columnFilter, bounds, expressions, @@ -300,10 +295,10 @@ public class QueryProcessor { for (ByteBuffer name : columns) { - if (name.remaining() > IColumn.MAX_NAME_LENGTH) + if (name.remaining() > org.apache.cassandra.db.Column.MAX_NAME_LENGTH) throw new InvalidRequestException(String.format("column name is too long (%s > %s)", name.remaining(), - IColumn.MAX_NAME_LENGTH)); + org.apache.cassandra.db.Column.MAX_NAME_LENGTH)); if (name.remaining() == 0) throw new InvalidRequestException("zero-length column name"); } @@ -352,7 +347,7 @@ public class QueryProcessor private static void validateSliceFilter(CFMetaData metadata, ByteBuffer start, ByteBuffer finish, boolean reversed) throws InvalidRequestException { - AbstractType comparator = metadata.getComparatorFor(null); + AbstractType comparator = metadata.comparator; Comparator orderedComparator = reversed ? comparator.reverseComparator: comparator; if (start.remaining() > 0 && finish.remaining() > 0 && orderedComparator.compare(start, finish) > 0) throw new InvalidRequestException("range finish must come after start in traversal order"); @@ -456,7 +451,7 @@ public class QueryProcessor // preserve comparator order if (row.cf != null) { - for (IColumn c : row.cf.getSortedColumns()) + for (org.apache.cassandra.db.Column c : row.cf.getSortedColumns()) { if (c.isMarkedForDelete()) continue; @@ -502,7 +497,7 @@ public class QueryProcessor ColumnDefinition cd = metadata.getColumnDefinitionFromColumnName(name); if (cd != null) result.schema.value_types.put(name, TypeParser.getShortName(cd.getValidator())); - IColumn c = row.cf.getColumn(name); + org.apache.cassandra.db.Column c = row.cf.getColumn(name); if (c == null || c.isMarkedForDelete()) thriftColumns.add(new Column().setName(name)); else @@ -833,7 +828,7 @@ public class QueryProcessor return cql.hashCode(); } - private static Column thriftify(IColumn c) + private static Column thriftify(org.apache.cassandra.db.Column c) { ByteBuffer value = (c instanceof CounterColumn) ? ByteBufferUtil.bytes(CounterContext.instance().total(c.value())) diff --git a/src/java/org/apache/cassandra/cql/UpdateStatement.java b/src/java/org/apache/cassandra/cql/UpdateStatement.java index 3470bca1f7..0e1250f61f 100644 --- a/src/java/org/apache/cassandra/cql/UpdateStatement.java +++ b/src/java/org/apache/cassandra/cql/UpdateStatement.java @@ -27,7 +27,6 @@ import org.apache.cassandra.db.CounterMutation; import org.apache.cassandra.db.ConsistencyLevel; import org.apache.cassandra.db.IMutation; import org.apache.cassandra.db.RowMutation; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.exceptions.UnauthorizedException; @@ -197,7 +196,8 @@ public class UpdateStatement extends AbstractModification ByteBuffer colValue = op.a.getByteBuffer(getValueValidator(keyspace, colName),variables); validateColumn(metadata, colName, colValue); - rm.add(new QueryPath(columnFamily, null, colName), + rm.add(columnFamily, + colName, colValue, (timestamp == null) ? getTimestamp(clientState) : timestamp, getTimeToLive()); @@ -221,7 +221,7 @@ public class UpdateStatement extends AbstractModification op.b.getText())); } - rm.addCounter(new QueryPath(columnFamily, null, colName), value); + rm.addCounter(columnFamily, colName, value); } } diff --git a/src/java/org/apache/cassandra/cql3/CFDefinition.java b/src/java/org/apache/cassandra/cql3/CFDefinition.java index 670fdb4c6e..14576ba541 100644 --- a/src/java/org/apache/cassandra/cql3/CFDefinition.java +++ b/src/java/org/apache/cassandra/cql3/CFDefinition.java @@ -90,6 +90,7 @@ public class CFDefinition implements Iterable * We are a "sparse" composite, i.e. a non-compact one, if either: * - the last type of the composite is a ColumnToCollectionType * - or we have one less alias than of composite types and the last type is UTF8Type. + * - some metadata are defined * * Note that this is not perfect: if someone upgrading from thrift "renames" all but * the last column alias, the cf will be considered "sparse" and he will be stuck with @@ -98,7 +99,8 @@ public class CFDefinition implements Iterable */ int last = composite.types.size() - 1; AbstractType lastType = composite.types.get(last); - if (lastType instanceof ColumnToCollectionType + if (!cfm.getColumn_metadata().isEmpty() + || lastType instanceof ColumnToCollectionType || (cfm.getColumnAliases().size() == last && lastType instanceof UTF8Type)) { // "sparse" composite diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java b/src/java/org/apache/cassandra/cql3/QueryProcessor.java index fec45e6cee..b675cda912 100644 --- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java +++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java @@ -85,10 +85,10 @@ public class QueryProcessor { for (ByteBuffer name : columns) { - if (name.remaining() > IColumn.MAX_NAME_LENGTH) + if (name.remaining() > Column.MAX_NAME_LENGTH) throw new InvalidRequestException(String.format("column name is too long (%s > %s)", name.remaining(), - IColumn.MAX_NAME_LENGTH)); + Column.MAX_NAME_LENGTH)); if (name.remaining() == 0) throw new InvalidRequestException("zero-length column name"); } @@ -114,8 +114,7 @@ public class QueryProcessor { try { - AbstractType comparator = metadata.getComparatorFor(null); - ColumnSlice.validate(range.slices, comparator, range.reversed); + ColumnSlice.validate(range.slices, metadata.comparator, range.reversed); } catch (IllegalArgumentException e) { diff --git a/src/java/org/apache/cassandra/cql3/operations/ColumnOperation.java b/src/java/org/apache/cassandra/cql3/operations/ColumnOperation.java index 224829ff26..c5f5b44389 100644 --- a/src/java/org/apache/cassandra/cql3/operations/ColumnOperation.java +++ b/src/java/org/apache/cassandra/cql3/operations/ColumnOperation.java @@ -23,8 +23,7 @@ import java.util.List; import org.apache.cassandra.cql3.*; import org.apache.cassandra.db.ColumnFamily; -import org.apache.cassandra.db.IColumn; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.CollectionType; import org.apache.cassandra.db.marshal.ListType; @@ -63,7 +62,7 @@ public class ColumnOperation implements Operation ColumnNameBuilder builder, AbstractType validator, UpdateParameters params, - List> list) throws InvalidRequestException + List> list) throws InvalidRequestException { switch (kind) { @@ -109,7 +108,7 @@ public class ColumnOperation implements Operation val = -val; } - cf.addCounter(new QueryPath(cf.metadata().cfName, null, builder.build()), val); + cf.addCounter(builder.build(), val); } public void addBoundNames(ColumnSpecification column, ColumnSpecification[] boundNames) throws InvalidRequestException diff --git a/src/java/org/apache/cassandra/cql3/operations/ListOperation.java b/src/java/org/apache/cassandra/cql3/operations/ListOperation.java index 1e09195aaf..5416c85f9a 100644 --- a/src/java/org/apache/cassandra/cql3/operations/ListOperation.java +++ b/src/java/org/apache/cassandra/cql3/operations/ListOperation.java @@ -30,7 +30,7 @@ import org.apache.cassandra.cql3.ColumnSpecification; import org.apache.cassandra.cql3.Term; import org.apache.cassandra.cql3.UpdateParameters; import org.apache.cassandra.db.ColumnFamily; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.CollectionType; import org.apache.cassandra.db.marshal.Int32Type; @@ -99,7 +99,7 @@ public class ListOperation implements Operation ColumnNameBuilder builder, AbstractType validator, UpdateParameters params, - List> list) throws InvalidRequestException + List> list) throws InvalidRequestException { if (!(validator instanceof ListType || (kind == Kind.SET_IDX && validator instanceof MapType))) throw new InvalidRequestException("List operations are only supported on List typed columns, but " + validator + " given."); @@ -198,7 +198,7 @@ public class ListOperation implements Operation } } - public static void doDiscardFromPrepared(ColumnFamily cf, ColumnNameBuilder builder, ListType validator, Term values, UpdateParameters params, List> list) throws InvalidRequestException + public static void doDiscardFromPrepared(ColumnFamily cf, ColumnNameBuilder builder, ListType validator, Term values, UpdateParameters params, List> list) throws InvalidRequestException { if (!values.isBindMarker()) throw new InvalidRequestException("Can't apply operation on column with " + validator + " type."); @@ -214,9 +214,9 @@ public class ListOperation implements Operation for (Object elt : l) toDiscard.add(validator.valueComparator().decompose(elt)); - for (Pair p : list) + for (Pair p : list) { - IColumn c = p.right; + Column c = p.right; if (toDiscard.contains(c.value())) cf.addColumn(params.makeTombstone(c.name())); } @@ -227,7 +227,7 @@ public class ListOperation implements Operation } } - private void doSet(ColumnFamily cf, ColumnNameBuilder builder, UpdateParameters params, CollectionType validator, List> list) throws InvalidRequestException + private void doSet(ColumnFamily cf, ColumnNameBuilder builder, UpdateParameters params, CollectionType validator, List> list) throws InvalidRequestException { int idx = validateListIdx(values.get(0), list); Term value = values.get(1); @@ -261,7 +261,7 @@ public class ListOperation implements Operation } } - private void doDiscard(ColumnFamily cf, CollectionType validator, UpdateParameters params, List> list) throws InvalidRequestException + private void doDiscard(ColumnFamily cf, CollectionType validator, UpdateParameters params, List> list) throws InvalidRequestException { if (list == null) return; @@ -271,15 +271,15 @@ public class ListOperation implements Operation for (Term value : values) toDiscard.add(value.getByteBuffer(validator.valueComparator(), params.variables)); - for (Pair p : list) + for (Pair p : list) { - IColumn c = p.right; + Column c = p.right; if (toDiscard.contains(c.value())) cf.addColumn(params.makeTombstone(c.name())); } } - private void doDiscardIdx(ColumnFamily cf, UpdateParameters params, List> list) throws InvalidRequestException + private void doDiscardIdx(ColumnFamily cf, UpdateParameters params, List> list) throws InvalidRequestException { int idx = validateListIdx(values.get(0), list); cf.addColumn(params.makeTombstone(list.get(idx).right.name())); @@ -381,7 +381,7 @@ public class ListOperation implements Operation return "ListOperation(" + kind + ", " + values + ")"; } - private int validateListIdx(Term value, List> list) throws InvalidRequestException + private int validateListIdx(Term value, List> list) throws InvalidRequestException { try { diff --git a/src/java/org/apache/cassandra/cql3/operations/MapOperation.java b/src/java/org/apache/cassandra/cql3/operations/MapOperation.java index ddded47d74..77101546c1 100644 --- a/src/java/org/apache/cassandra/cql3/operations/MapOperation.java +++ b/src/java/org/apache/cassandra/cql3/operations/MapOperation.java @@ -29,7 +29,7 @@ import org.apache.cassandra.cql3.ColumnSpecification; import org.apache.cassandra.cql3.Term; import org.apache.cassandra.cql3.UpdateParameters; import org.apache.cassandra.db.ColumnFamily; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.CollectionType; import org.apache.cassandra.db.marshal.MapType; @@ -63,7 +63,7 @@ public class MapOperation implements Operation ColumnNameBuilder builder, AbstractType validator, UpdateParameters params, - List> list) throws InvalidRequestException + List> list) throws InvalidRequestException { if (!(validator instanceof MapType)) throw new InvalidRequestException("Map operations are only supported on Map typed columns, but " + validator + " given."); diff --git a/src/java/org/apache/cassandra/cql3/operations/Operation.java b/src/java/org/apache/cassandra/cql3/operations/Operation.java index 6c30f7c4e6..052c3be83c 100644 --- a/src/java/org/apache/cassandra/cql3/operations/Operation.java +++ b/src/java/org/apache/cassandra/cql3/operations/Operation.java @@ -25,7 +25,7 @@ import org.apache.cassandra.cql3.ColumnSpecification; import org.apache.cassandra.cql3.Term; import org.apache.cassandra.cql3.UpdateParameters; import org.apache.cassandra.db.ColumnFamily; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.CollectionType; import org.apache.cassandra.exceptions.InvalidRequestException; @@ -39,7 +39,7 @@ public interface Operation ColumnNameBuilder builder, AbstractType validator, UpdateParameters params, - List> list) throws InvalidRequestException; + List> list) throws InvalidRequestException; public void addBoundNames(ColumnSpecification column, ColumnSpecification[] boundNames) throws InvalidRequestException; diff --git a/src/java/org/apache/cassandra/cql3/operations/PreparedOperation.java b/src/java/org/apache/cassandra/cql3/operations/PreparedOperation.java index 969e63cd61..0e7cb1b0f2 100644 --- a/src/java/org/apache/cassandra/cql3/operations/PreparedOperation.java +++ b/src/java/org/apache/cassandra/cql3/operations/PreparedOperation.java @@ -23,7 +23,7 @@ import java.util.List; import org.apache.cassandra.cql3.*; import org.apache.cassandra.db.ColumnFamily; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.CollectionType; import org.apache.cassandra.db.marshal.ListType; @@ -50,7 +50,7 @@ public class PreparedOperation implements Operation ColumnNameBuilder builder, AbstractType validator, UpdateParameters params, - List> list) throws InvalidRequestException + List> list) throws InvalidRequestException { if (validator instanceof CollectionType) { diff --git a/src/java/org/apache/cassandra/cql3/operations/SetOperation.java b/src/java/org/apache/cassandra/cql3/operations/SetOperation.java index e7f01c6224..657a2ca4e2 100644 --- a/src/java/org/apache/cassandra/cql3/operations/SetOperation.java +++ b/src/java/org/apache/cassandra/cql3/operations/SetOperation.java @@ -27,7 +27,7 @@ import org.apache.cassandra.cql3.ColumnSpecification; import org.apache.cassandra.cql3.Term; import org.apache.cassandra.cql3.UpdateParameters; import org.apache.cassandra.db.ColumnFamily; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.CollectionType; import org.apache.cassandra.db.marshal.MarshalException; @@ -53,7 +53,7 @@ public class SetOperation implements Operation ColumnNameBuilder builder, AbstractType validator, UpdateParameters params, - List> list) throws InvalidRequestException + List> list) throws InvalidRequestException { if (!(validator instanceof SetType)) throw new InvalidRequestException("Set operations are only supported on Set typed columns, but " + validator + " given."); diff --git a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java index ee8c98740f..e9f5425703 100644 --- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java @@ -93,6 +93,8 @@ public class AlterTableStatement extends SchemaAlteringStatement { if (!cfDef.isComposite) throw new InvalidRequestException("Cannot use collection types with non-composite PRIMARY KEY"); + if (cfDef.cfm.isSuper()) + throw new InvalidRequestException("Cannot use collection types with Super column family"); componentIndex--; diff --git a/src/java/org/apache/cassandra/cql3/statements/ColumnGroupMap.java b/src/java/org/apache/cassandra/cql3/statements/ColumnGroupMap.java index 2625feffcb..20fa3bd9c5 100644 --- a/src/java/org/apache/cassandra/cql3/statements/ColumnGroupMap.java +++ b/src/java/org/apache/cassandra/cql3/statements/ColumnGroupMap.java @@ -24,7 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.utils.Pair; @@ -38,7 +38,7 @@ public class ColumnGroupMap this.fullPath = fullPath; } - private void add(ByteBuffer[] fullName, int idx, IColumn column) + private void add(ByteBuffer[] fullName, int idx, Column column) { ByteBuffer columnName = fullName[idx]; if (fullName.length == idx + 2) @@ -66,7 +66,7 @@ public class ColumnGroupMap return fullPath[pos]; } - public IColumn getSimple(ByteBuffer key) + public Column getSimple(ByteBuffer key) { Value v = map.get(key); if (v == null) @@ -76,29 +76,29 @@ public class ColumnGroupMap return ((Simple)v).column; } - public List> getCollection(ByteBuffer key) + public List> getCollection(ByteBuffer key) { Value v = map.get(key); if (v == null) return null; assert v instanceof Collection; - return (List>)v; + return (List>)v; } private interface Value {}; private static class Simple implements Value { - public final IColumn column; + public final Column column; - Simple(IColumn column) + Simple(Column column) { this.column = column; } } - private static class Collection extends ArrayList> implements Value {} + private static class Collection extends ArrayList> implements Value {} public static class Builder { @@ -115,7 +115,7 @@ public class ColumnGroupMap this.idx = composite.types.size() - (hasCollections ? 2 : 1); } - public void add(IColumn c) + public void add(Column c) { if (c.isMarkedForDelete()) return; diff --git a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java index 4af27ba401..ad4f11a42c 100644 --- a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java @@ -26,7 +26,6 @@ import org.apache.cassandra.auth.Permission; import org.apache.cassandra.cql3.*; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.ColumnSlice; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.filter.SliceQueryFilter; import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.exceptions.*; @@ -165,7 +164,7 @@ public abstract class ModificationStatement extends CFStatement implements CQLSt for (ByteBuffer key : keys) commands.add(new SliceFromReadCommand(keyspace(), key, - new QueryPath(columnFamily()), + columnFamily(), new SliceQueryFilter(slices, false, Integer.MAX_VALUE))); try @@ -181,7 +180,7 @@ public abstract class ModificationStatement extends CFStatement implements CQLSt continue; ColumnGroupMap.Builder groupBuilder = new ColumnGroupMap.Builder(composite, true); - for (IColumn column : row.cf) + for (Column column : row.cf) groupBuilder.add(column); List groups = groupBuilder.groups(); diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java index b41659c1e4..73b54ada6a 100644 --- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java @@ -198,7 +198,6 @@ public class SelectStatement implements CQLStatement private List getSliceCommands(List variables) throws RequestValidationException { - QueryPath queryPath = new QueryPath(columnFamily()); Collection keys = getKeys(variables); List commands = new ArrayList(keys.size()); @@ -214,7 +213,7 @@ public class SelectStatement implements CQLStatement // Note that we should not share the slice filter amongst the command, due to SliceQueryFilter not // being immutable due to its columnCounter used by the lastCounted() method // (this is fairly ugly and we should change that but that's probably not a tiny refactor to do that cleanly) - commands.add(new SliceFromReadCommand(keyspace(), key, queryPath, (SliceQueryFilter)makeFilter(variables))); + commands.add(new SliceFromReadCommand(keyspace(), key, columnFamily(), (SliceQueryFilter)makeFilter(variables))); } } // ...of a list of column names @@ -225,7 +224,7 @@ public class SelectStatement implements CQLStatement for (ByteBuffer key: keys) { QueryProcessor.validateKey(key); - commands.add(new SliceByNamesReadCommand(keyspace(), key, queryPath, (NamesQueryFilter)filter)); + commands.add(new SliceByNamesReadCommand(keyspace(), key, columnFamily(), (NamesQueryFilter)filter)); } } return commands; @@ -239,7 +238,6 @@ public class SelectStatement implements CQLStatement // We want to have getRangeSlice to count the number of columns, not the number of keys. return new RangeSliceCommand(keyspace(), columnFamily(), - null, filter, getKeyBounds(variables), expressions, @@ -476,9 +474,9 @@ public class SelectStatement implements CQLStatement // We need to query the selected column as well as the marker // column (for the case where the row exists but has no columns outside the PK) - // One exception is "static CF" (non-composite non-compact CF) that - // don't have marker and for which we must query all columns instead - if (cfDef.isComposite) + // Two exceptions are "static CF" (non-composite non-compact CF) and "super CF" + // that don't have marker and for which we must query all columns instead + if (cfDef.isComposite && !cfDef.cfm.isSuper()) { // marker columns.add(builder.copy().add(ByteBufferUtil.EMPTY_BYTE_BUFFER).build()); @@ -606,14 +604,14 @@ public class SelectStatement implements CQLStatement } } - private ByteBuffer value(IColumn c) + private ByteBuffer value(Column c) { return (c instanceof CounterColumn) ? ByteBufferUtil.bytes(CounterContext.instance().total(c.value())) : c.value(); } - private void addReturnValue(ResultSet cqlRows, Selector s, IColumn c) + private void addReturnValue(ResultSet cqlRows, Selector s, Column c) { if (c == null || c.isMarkedForDelete()) { @@ -672,7 +670,7 @@ public class SelectStatement implements CQLStatement return new ResultSet(names); } - private Iterable columnsInOrder(final ColumnFamily cf, final List variables) throws InvalidRequestException + private Iterable columnsInOrder(final ColumnFamily cf, final List variables) throws InvalidRequestException { // If the restriction for the last column alias is an IN, respect // requested order @@ -693,18 +691,18 @@ public class SelectStatement implements CQLStatement requested.add(b.add(t, Relation.Type.EQ, variables).build()); } - return new Iterable() + return new Iterable() { - public Iterator iterator() + public Iterator iterator() { - return new AbstractIterator() + return new AbstractIterator() { Iterator iter = requested.iterator(); - public IColumn computeNext() + public Column computeNext() { if (!iter.hasNext()) return endOfData(); - IColumn column = cf.getColumn(iter.next()); + Column column = cf.getColumn(iter.next()); return column == null ? computeNext() : column; } }; @@ -736,7 +734,7 @@ public class SelectStatement implements CQLStatement if (cfDef.isCompact) { // One cqlRow per column - for (IColumn c : columnsInOrder(row.cf, variables)) + for (Column c : columnsInOrder(row.cf, variables)) { if (c.isMarkedForDelete()) continue; @@ -797,7 +795,7 @@ public class SelectStatement implements CQLStatement ColumnGroupMap.Builder builder = new ColumnGroupMap.Builder(composite, cfDef.hasCollections); - for (IColumn c : row.cf) + for (Column c : row.cf) { if (c.isMarkedForDelete()) continue; @@ -825,7 +823,7 @@ public class SelectStatement implements CQLStatement continue; } - IColumn c = row.cf.getColumn(name.name.key); + Column c = row.cf.getColumn(name.name.key); addReturnValue(cqlRows, selector, c); } } @@ -936,14 +934,14 @@ public class SelectStatement implements CQLStatement case COLUMN_METADATA: if (name.type.isCollection()) { - List> collection = columns.getCollection(name.name.key); + List> collection = columns.getCollection(name.name.key); if (collection == null) cqlRows.addColumnValue(null); else cqlRows.addColumnValue(((CollectionType)name.type).serialize(collection)); break; } - IColumn c = columns.getSimple(name.name.key); + Column c = columns.getSimple(name.name.key); addReturnValue(cqlRows, selector, c); break; default: diff --git a/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java b/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java index 014555deda..b159b7d15c 100644 --- a/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java @@ -220,7 +220,9 @@ public class UpdateStatement extends ModificationStatement // The last query should return one row (but with c == null). Adding // the marker with the insert make sure the semantic is correct (while making sure a // 'DELETE FROM t WHERE k = 1' does remove the row entirely) - if (cfDef.isComposite && !cfDef.isCompact) + // + // We never insert markers for Super CF as this would confuse the thrift side. + if (cfDef.isComposite && !cfDef.isCompact && !cfDef.cfm.isSuper()) { ByteBuffer name = builder.copy().add(ByteBufferUtil.EMPTY_BYTE_BUFFER).build(); cf.addColumn(params.makeColumn(name, ByteBufferUtil.EMPTY_BYTE_BUFFER)); diff --git a/src/java/org/apache/cassandra/db/AbstractColumnContainer.java b/src/java/org/apache/cassandra/db/AbstractColumnContainer.java index 09d0a38bd4..1a38e4b000 100644 --- a/src/java/org/apache/cassandra/db/AbstractColumnContainer.java +++ b/src/java/org/apache/cassandra/db/AbstractColumnContainer.java @@ -32,7 +32,7 @@ import org.apache.cassandra.io.util.IIterableColumns; import org.apache.cassandra.utils.Allocator; import org.apache.cassandra.utils.HeapAllocator; -public abstract class AbstractColumnContainer implements IColumnContainer, IIterableColumns +public abstract class AbstractColumnContainer implements IIterableColumns { protected final ISortedColumns columns; @@ -84,37 +84,37 @@ public abstract class AbstractColumnContainer implements IColumnContainer, IIter columns.maybeResetDeletionTimes(gcBefore); } - public long addAllWithSizeDelta(AbstractColumnContainer cc, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer) + public long addAllWithSizeDelta(AbstractColumnContainer cc, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer) { return columns.addAllWithSizeDelta(cc.columns, allocator, transformation, indexer); } - public void addAll(AbstractColumnContainer cc, Allocator allocator, Function transformation) + public void addAll(AbstractColumnContainer cc, Allocator allocator, Function transformation) { columns.addAll(cc.columns, allocator, transformation); } public void addAll(AbstractColumnContainer cc, Allocator allocator) { - addAll(cc, allocator, Functions.identity()); + addAll(cc, allocator, Functions.identity()); } - public void addColumn(IColumn column) + public void addColumn(Column column) { addColumn(column, HeapAllocator.instance); } - public void addColumn(IColumn column, Allocator allocator) + public void addColumn(Column column, Allocator allocator) { columns.addColumn(column, allocator); } - public IColumn getColumn(ByteBuffer name) + public Column getColumn(ByteBuffer name) { return columns.getColumn(name); } - public boolean replace(IColumn oldColumn, IColumn newColumn) + public boolean replace(Column oldColumn, Column newColumn) { return columns.replace(oldColumn, newColumn); } @@ -129,12 +129,12 @@ public abstract class AbstractColumnContainer implements IColumnContainer, IIter return columns.getColumnNames(); } - public Collection getSortedColumns() + public Collection getSortedColumns() { return columns.getSortedColumns(); } - public Collection getReverseSortedColumns() + public Collection getReverseSortedColumns() { return columns.getReverseSortedColumns(); } @@ -166,7 +166,7 @@ public abstract class AbstractColumnContainer implements IColumnContainer, IIter public boolean hasOnlyTombstones() { - for (IColumn column : columns) + for (Column column : columns) { if (column.isLive()) return false; @@ -174,17 +174,17 @@ public abstract class AbstractColumnContainer implements IColumnContainer, IIter return true; } - public Iterator iterator() + public Iterator iterator() { return columns.iterator(); } - public Iterator iterator(ColumnSlice[] slices) + public Iterator iterator(ColumnSlice[] slices) { return columns.iterator(slices); } - public Iterator reverseIterator(ColumnSlice[] slices) + public Iterator reverseIterator(ColumnSlice[] slices) { return columns.reverseIterator(slices); } @@ -196,7 +196,7 @@ public abstract class AbstractColumnContainer implements IColumnContainer, IIter return true; // Do we have colums that are either deleted by the container or gcable tombstone? - for (IColumn column : columns) + for (Column column : columns) if (deletionInfo().isDeleted(column) || column.hasIrrelevantData(gcBefore)) return true; diff --git a/src/java/org/apache/cassandra/db/AbstractThreadUnsafeSortedColumns.java b/src/java/org/apache/cassandra/db/AbstractThreadUnsafeSortedColumns.java index a4e5eb7475..aa153e145a 100644 --- a/src/java/org/apache/cassandra/db/AbstractThreadUnsafeSortedColumns.java +++ b/src/java/org/apache/cassandra/db/AbstractThreadUnsafeSortedColumns.java @@ -52,21 +52,16 @@ public abstract class AbstractThreadUnsafeSortedColumns implements ISortedColumn public void retainAll(ISortedColumns columns) { - Iterator iter = iterator(); - Iterator toRetain = columns.iterator(); - IColumn current = iter.hasNext() ? iter.next() : null; - IColumn retain = toRetain.hasNext() ? toRetain.next() : null; + Iterator iter = iterator(); + Iterator toRetain = columns.iterator(); + Column current = iter.hasNext() ? iter.next() : null; + Column retain = toRetain.hasNext() ? toRetain.next() : null; AbstractType comparator = getComparator(); while (current != null && retain != null) { int c = comparator.compare(current.name(), retain.name()); if (c == 0) { - if (current instanceof SuperColumn) - { - assert retain instanceof SuperColumn; - ((SuperColumn)current).retainAll((SuperColumn)retain); - } current = iter.hasNext() ? iter.next() : null; retain = toRetain.hasNext() ? toRetain.next() : null; } diff --git a/src/java/org/apache/cassandra/db/ArrayBackedSortedColumns.java b/src/java/org/apache/cassandra/db/ArrayBackedSortedColumns.java index 8d813a3be5..863e8f53dc 100644 --- a/src/java/org/apache/cassandra/db/ArrayBackedSortedColumns.java +++ b/src/java/org/apache/cassandra/db/ArrayBackedSortedColumns.java @@ -40,7 +40,7 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns { private final AbstractType comparator; private final boolean reversed; - private final ArrayList columns; + private final ArrayList columns; public static final ISortedColumns.Factory factory = new Factory() { @@ -49,7 +49,7 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns return new ArrayBackedSortedColumns(comparator, insertReversed); } - public ISortedColumns fromSorted(SortedMap sortedMap, boolean insertReversed) + public ISortedColumns fromSorted(SortedMap sortedMap, boolean insertReversed) { return new ArrayBackedSortedColumns(sortedMap.values(), (AbstractType)sortedMap.comparator(), insertReversed); } @@ -65,14 +65,14 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns super(); this.comparator = comparator; this.reversed = reversed; - this.columns = new ArrayList(); + this.columns = new ArrayList(); } - private ArrayBackedSortedColumns(Collection columns, AbstractType comparator, boolean reversed) + private ArrayBackedSortedColumns(Collection columns, AbstractType comparator, boolean reversed) { this.comparator = comparator; this.reversed = reversed; - this.columns = new ArrayList(columns); + this.columns = new ArrayList(columns); } public ISortedColumns.Factory getFactory() @@ -100,7 +100,7 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns return reversed ? comparator.reverseComparator : comparator; } - public IColumn getColumn(ByteBuffer name) + public Column getColumn(ByteBuffer name) { int pos = binarySearch(name); return pos >= 0 ? columns.get(pos) : null; @@ -116,7 +116,7 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns * without knowing about (we can revisit that decision later if we have * use cases where most insert are in sorted order but a few are not). */ - public void addColumn(IColumn column, Allocator allocator) + public void addColumn(Column column, Allocator allocator) { if (columns.isEmpty()) { @@ -154,21 +154,13 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns * Resolve against element at position i. * Assume that i is a valid position. */ - private void resolveAgainst(int i, IColumn column, Allocator allocator) + private void resolveAgainst(int i, Column column, Allocator allocator) { - IColumn oldColumn = columns.get(i); - if (oldColumn instanceof SuperColumn) - { - // Delegated to SuperColumn - assert column instanceof SuperColumn; - ((SuperColumn) oldColumn).putColumn((SuperColumn)column, allocator); - } - else - { - // calculate reconciled col from old (existing) col and new col - IColumn reconciledColumn = column.reconcile(oldColumn, allocator); - columns.set(i, reconciledColumn); - } + Column oldColumn = columns.get(i); + + // calculate reconciled col from old (existing) col and new col + Column reconciledColumn = column.reconcile(oldColumn, allocator); + columns.set(i, reconciledColumn); } private int binarySearch(ByteBuffer name) @@ -180,9 +172,9 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns * Simple binary search for a given column name. * The return value has the exact same meaning that the one of Collections.binarySearch(). * (We don't use Collections.binarySearch() directly because it would require us to create - * a fake IColumn (as well as an IColumn comparator) to do the search, which is ugly. + * a fake Column (as well as an Column comparator) to do the search, which is ugly. */ - private static int binarySearch(List columns, Comparator comparator, ByteBuffer name, int start) + private static int binarySearch(List columns, Comparator comparator, ByteBuffer name, int start) { int low = start; int mid = columns.size(); @@ -207,21 +199,21 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns return -mid - (result < 0 ? 1 : 2); } - public long addAllWithSizeDelta(ISortedColumns cm, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer) + public long addAllWithSizeDelta(ISortedColumns cm, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer) { throw new UnsupportedOperationException(); } - public void addAll(ISortedColumns cm, Allocator allocator, Function transformation) + public void addAll(ISortedColumns cm, Allocator allocator, Function transformation) { delete(cm.getDeletionInfo()); if (cm.isEmpty()) return; - IColumn[] copy = columns.toArray(new IColumn[size()]); + Column[] copy = columns.toArray(new Column[size()]); int idx = 0; - Iterator other = reversed ? cm.reverseIterator(ColumnSlice.ALL_COLUMNS_ARRAY) : cm.iterator(); - IColumn otherColumn = other.next(); + Iterator other = reversed ? cm.reverseIterator(ColumnSlice.ALL_COLUMNS_ARRAY) : cm.iterator(); + Column otherColumn = other.next(); columns.clear(); @@ -257,7 +249,7 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns } } - public boolean replace(IColumn oldColumn, IColumn newColumn) + public boolean replace(Column oldColumn, Column newColumn) { if (!oldColumn.name().equals(newColumn.name())) throw new IllegalArgumentException(); @@ -271,12 +263,12 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns return pos >= 0; } - public Collection getSortedColumns() + public Collection getSortedColumns() { return reversed ? new ReverseSortedCollection() : columns; } - public Collection getReverseSortedColumns() + public Collection getReverseSortedColumns() { // If reversed, the element are sorted reversely, so we could expect // to return *this*, but *this* redefine the iterator to be in sorted @@ -307,39 +299,39 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns return new ColumnNamesSet(); } - public Iterator iterator() + public Iterator iterator() { return reversed ? Lists.reverse(columns).iterator() : columns.iterator(); } - public Iterator iterator(ColumnSlice[] slices) + public Iterator iterator(ColumnSlice[] slices) { return new SlicesIterator(columns, comparator, slices, reversed); } - public Iterator reverseIterator(ColumnSlice[] slices) + public Iterator reverseIterator(ColumnSlice[] slices) { return new SlicesIterator(columns, comparator, slices, !reversed); } - private static class SlicesIterator extends AbstractIterator + private static class SlicesIterator extends AbstractIterator { - private final List list; + private final List list; private final ColumnSlice[] slices; private final Comparator comparator; private int idx = 0; private int previousSliceEnd = 0; - private Iterator currentSlice; + private Iterator currentSlice; - public SlicesIterator(List list, AbstractType comparator, ColumnSlice[] slices, boolean reversed) + public SlicesIterator(List list, AbstractType comparator, ColumnSlice[] slices, boolean reversed) { this.list = reversed ? Lists.reverse(list) : list; this.slices = slices; this.comparator = reversed ? comparator.reverseComparator : comparator; } - protected IColumn computeNext() + protected Column computeNext() { if (currentSlice == null) { @@ -375,16 +367,16 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns } } - private class ReverseSortedCollection extends AbstractCollection + private class ReverseSortedCollection extends AbstractCollection { public int size() { return columns.size(); } - public Iterator iterator() + public Iterator iterator() { - return new Iterator() + return new Iterator() { int idx = size() - 1; @@ -393,7 +385,7 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns return idx >= 0; } - public IColumn next() + public Column next() { return columns.get(idx--); } @@ -406,14 +398,14 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns } } - private class ForwardSortedCollection extends AbstractCollection + private class ForwardSortedCollection extends AbstractCollection { public int size() { return columns.size(); } - public Iterator iterator() + public Iterator iterator() { return columns.iterator(); } @@ -428,7 +420,7 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns public Iterator iterator() { - final Iterator outerIterator = ArrayBackedSortedColumns.this.iterator(); // handles reversed + final Iterator outerIterator = ArrayBackedSortedColumns.this.iterator(); // handles reversed return new Iterator() { public boolean hasNext() diff --git a/src/java/org/apache/cassandra/db/AtomicSortedColumns.java b/src/java/org/apache/cassandra/db/AtomicSortedColumns.java index 83aabea13c..fbfcd7580a 100644 --- a/src/java/org/apache/cassandra/db/AtomicSortedColumns.java +++ b/src/java/org/apache/cassandra/db/AtomicSortedColumns.java @@ -58,7 +58,7 @@ public class AtomicSortedColumns implements ISortedColumns return new AtomicSortedColumns(comparator); } - public ISortedColumns fromSorted(SortedMap sortedMap, boolean insertReversed) + public ISortedColumns fromSorted(SortedMap sortedMap, boolean insertReversed) { return new AtomicSortedColumns(sortedMap); } @@ -74,7 +74,7 @@ public class AtomicSortedColumns implements ISortedColumns this(new Holder(comparator)); } - private AtomicSortedColumns(SortedMap columns) + private AtomicSortedColumns(SortedMap columns) { this(new Holder(columns)); } @@ -144,7 +144,7 @@ public class AtomicSortedColumns implements ISortedColumns while (!ref.compareAndSet(current, modified)); } - public void addColumn(IColumn column, Allocator allocator) + public void addColumn(Column column, Allocator allocator) { Holder current, modified; do @@ -156,12 +156,12 @@ public class AtomicSortedColumns implements ISortedColumns while (!ref.compareAndSet(current, modified)); } - public void addAll(ISortedColumns cm, Allocator allocator, Function transformation) + public void addAll(ISortedColumns cm, Allocator allocator, Function transformation) { addAllWithSizeDelta(cm, allocator, transformation, SecondaryIndexManager.nullUpdater); } - public long addAllWithSizeDelta(ISortedColumns cm, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer) + public long addAllWithSizeDelta(ISortedColumns cm, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer) { /* * This operation needs to atomicity and isolation. To that end, we @@ -185,7 +185,7 @@ public class AtomicSortedColumns implements ISortedColumns DeletionInfo newDelInfo = current.deletionInfo.add(cm.getDeletionInfo()); modified = new Holder(current.map.clone(), newDelInfo); - for (IColumn column : cm.getSortedColumns()) + for (Column column : cm.getSortedColumns()) { sizeDelta += modified.addColumn(transformation.apply(column), allocator, indexer); // bail early if we know we've been beaten @@ -198,7 +198,7 @@ public class AtomicSortedColumns implements ISortedColumns return sizeDelta; } - public boolean replace(IColumn oldColumn, IColumn newColumn) + public boolean replace(Column oldColumn, Column newColumn) { if (!oldColumn.name().equals(newColumn.name())) throw new IllegalArgumentException(); @@ -238,7 +238,7 @@ public class AtomicSortedColumns implements ISortedColumns while (!ref.compareAndSet(current, modified)); } - public IColumn getColumn(ByteBuffer name) + public Column getColumn(ByteBuffer name) { return ref.get().map.get(name); } @@ -248,12 +248,12 @@ public class AtomicSortedColumns implements ISortedColumns return ref.get().map.keySet(); } - public Collection getSortedColumns() + public Collection getSortedColumns() { return ref.get().map.values(); } - public Collection getReverseSortedColumns() + public Collection getReverseSortedColumns() { return ref.get().map.descendingMap().values(); } @@ -273,17 +273,17 @@ public class AtomicSortedColumns implements ISortedColumns return ref.get().map.isEmpty(); } - public Iterator iterator() + public Iterator iterator() { return getSortedColumns().iterator(); } - public Iterator iterator(ColumnSlice[] slices) + public Iterator iterator(ColumnSlice[] slices) { return new ColumnSlice.NavigableMapIterator(ref.get().map, slices); } - public Iterator reverseIterator(ColumnSlice[] slices) + public Iterator reverseIterator(ColumnSlice[] slices) { return new ColumnSlice.NavigableMapIterator(ref.get().map.descendingMap(), slices); } @@ -295,20 +295,20 @@ public class AtomicSortedColumns implements ISortedColumns private static class Holder { - final SnapTreeMap map; + final SnapTreeMap map; final DeletionInfo deletionInfo; Holder(AbstractType comparator) { - this(new SnapTreeMap(comparator), DeletionInfo.LIVE); + this(new SnapTreeMap(comparator), DeletionInfo.LIVE); } - Holder(SortedMap columns) + Holder(SortedMap columns) { - this(new SnapTreeMap(columns), DeletionInfo.LIVE); + this(new SnapTreeMap(columns), DeletionInfo.LIVE); } - Holder(SnapTreeMap map, DeletionInfo deletionInfo) + Holder(SnapTreeMap map, DeletionInfo deletionInfo) { this.map = map; this.deletionInfo = deletionInfo; @@ -324,7 +324,7 @@ public class AtomicSortedColumns implements ISortedColumns return new Holder(map, info); } - Holder with(SnapTreeMap newMap) + Holder with(SnapTreeMap newMap) { return new Holder(newMap, deletionInfo); } @@ -333,64 +333,49 @@ public class AtomicSortedColumns implements ISortedColumns // afterwards. Holder clear() { - return new Holder(new SnapTreeMap(map.comparator()), deletionInfo); + return new Holder(new SnapTreeMap(map.comparator()), deletionInfo); } - long addColumn(IColumn column, Allocator allocator, SecondaryIndexManager.Updater indexer) + long addColumn(Column column, Allocator allocator, SecondaryIndexManager.Updater indexer) { ByteBuffer name = column.name(); while (true) { - IColumn oldColumn = map.putIfAbsent(name, column); + Column oldColumn = map.putIfAbsent(name, column); if (oldColumn == null) { indexer.insert(column); return column.dataSize(); } - if (oldColumn instanceof SuperColumn) + Column reconciledColumn = column.reconcile(oldColumn, allocator); + if (map.replace(name, oldColumn, reconciledColumn)) { - assert column instanceof SuperColumn; - long previousSize = oldColumn.dataSize(); - ((SuperColumn) oldColumn).putColumn((SuperColumn)column, allocator); - return oldColumn.dataSize() - previousSize; - } - else - { - IColumn reconciledColumn = column.reconcile(oldColumn, allocator); - if (map.replace(name, oldColumn, reconciledColumn)) - { - // for memtable updates we only care about oldcolumn, reconciledcolumn, but when compacting - // we need to make sure we update indexes no matter the order we merge - if (reconciledColumn == column) - indexer.update(oldColumn, reconciledColumn); - else - indexer.update(column, reconciledColumn); - return reconciledColumn.dataSize() - oldColumn.dataSize(); - } - // We failed to replace column due to a concurrent update or a concurrent removal. Keep trying. - // (Currently, concurrent removal should not happen (only updates), but let us support that anyway.) + // for memtable updates we only care about oldcolumn, reconciledcolumn, but when compacting + // we need to make sure we update indexes no matter the order we merge + if (reconciledColumn == column) + indexer.update(oldColumn, reconciledColumn); + else + indexer.update(column, reconciledColumn); + return reconciledColumn.dataSize() - oldColumn.dataSize(); } + // We failed to replace column due to a concurrent update or a concurrent removal. Keep trying. + // (Currently, concurrent removal should not happen (only updates), but let us support that anyway.) } } void retainAll(ISortedColumns columns) { - Iterator iter = map.values().iterator(); - Iterator toRetain = columns.iterator(); - IColumn current = iter.hasNext() ? iter.next() : null; - IColumn retain = toRetain.hasNext() ? toRetain.next() : null; + Iterator iter = map.values().iterator(); + Iterator toRetain = columns.iterator(); + Column current = iter.hasNext() ? iter.next() : null; + Column retain = toRetain.hasNext() ? toRetain.next() : null; Comparator comparator = map.comparator(); while (current != null && retain != null) { int c = comparator.compare(current.name(), retain.name()); if (c == 0) { - if (current instanceof SuperColumn) - { - assert retain instanceof SuperColumn; - ((SuperColumn)current).retainAll((SuperColumn)retain); - } current = iter.hasNext() ? iter.next() : null; retain = toRetain.hasNext() ? toRetain.next() : null; } diff --git a/src/java/org/apache/cassandra/db/BatchlogManager.java b/src/java/org/apache/cassandra/db/BatchlogManager.java index 843cf44e47..fcbfa9b2ed 100644 --- a/src/java/org/apache/cassandra/db/BatchlogManager.java +++ b/src/java/org/apache/cassandra/db/BatchlogManager.java @@ -40,7 +40,6 @@ import org.apache.cassandra.db.compaction.CompactionManager; 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.QueryPath; import org.apache.cassandra.db.marshal.LongType; import org.apache.cassandra.db.marshal.UTF8Type; import org.apache.cassandra.db.marshal.UUIDType; @@ -177,7 +176,7 @@ public class BatchlogManager implements BatchlogManagerMBean if (row.cf == null || row.cf.isMarkedForDelete()) continue; - IColumn writtenAt = row.cf.getColumn(WRITTEN_AT); + Column writtenAt = row.cf.getColumn(WRITTEN_AT); if (writtenAt == null || System.currentTimeMillis() > LongType.instance.compose(writtenAt.value()) + TIMEOUT) replayBatch(row.key); } @@ -199,13 +198,13 @@ public class BatchlogManager implements BatchlogManagerMBean logger.debug("Replaying batch {}", uuid); ColumnFamilyStore store = Table.open(Table.SYSTEM_KS).getColumnFamilyStore(SystemTable.BATCHLOG_CF); - QueryFilter filter = QueryFilter.getIdentityFilter(key, new QueryPath(SystemTable.BATCHLOG_CF)); + QueryFilter filter = QueryFilter.getIdentityFilter(key, SystemTable.BATCHLOG_CF); ColumnFamily batch = store.getColumnFamily(filter); if (batch == null || batch.isMarkedForDelete()) return; - IColumn dataColumn = batch.getColumn(DATA); + Column dataColumn = batch.getColumn(DATA); try { if (dataColumn != null) @@ -246,7 +245,7 @@ public class BatchlogManager implements BatchlogManagerMBean private static void deleteBatch(DecoratedKey key) { RowMutation rm = new RowMutation(Table.SYSTEM_KS, key.key); - rm.delete(new QueryPath(SystemTable.BATCHLOG_CF), FBUtilities.timestampMicros()); + rm.delete(SystemTable.BATCHLOG_CF, FBUtilities.timestampMicros()); rm.apply(); } @@ -262,7 +261,7 @@ public class BatchlogManager implements BatchlogManagerMBean IPartitioner partitioner = StorageService.getPartitioner(); RowPosition minPosition = partitioner.getMinimumToken().minKeyBound(); AbstractBounds range = new Range(minPosition, minPosition, partitioner); - return store.getRangeSlice(null, range, Integer.MAX_VALUE, columnFilter, null); + return store.getRangeSlice(range, Integer.MAX_VALUE, columnFilter, null); } /** force flush + compaction to reclaim space from replayed batches */ diff --git a/src/java/org/apache/cassandra/db/CollationController.java b/src/java/org/apache/cassandra/db/CollationController.java index 8c1a939a82..3e659cb628 100644 --- a/src/java/org/apache/cassandra/db/CollationController.java +++ b/src/java/org/apache/cassandra/db/CollationController.java @@ -54,16 +54,14 @@ public class CollationController this.filter = filter; this.gcBefore = gcBefore; - // AtomicSortedColumns doesn't work for super columns (see #3821) this.factory = mutableColumns - ? cfs.metadata.cfType == ColumnFamilyType.Super ? ThreadSafeSortedColumns.factory() : AtomicSortedColumns.factory() + ? AtomicSortedColumns.factory() : ArrayBackedSortedColumns.factory(); } public ColumnFamily getTopLevelColumns() { return filter.filter instanceof NamesQueryFilter - && (cfs.metadata.cfType == ColumnFamilyType.Standard || filter.path.superColumnName != null) && cfs.metadata.getDefaultValidator() != CounterColumnType.instance ? collectTimeOrderedData() : collectAllData(); @@ -110,7 +108,7 @@ public class CollationController // (reduceNameFilter removes columns that are known to be irrelevant) NamesQueryFilter namesFilter = (NamesQueryFilter) filter.filter; TreeSet filterColumns = new TreeSet(namesFilter.columns); - QueryFilter reducedFilter = new QueryFilter(filter.key, filter.path, namesFilter.withUpdatedColumns(filterColumns)); + QueryFilter reducedFilter = new QueryFilter(filter.key, filter.cfName, namesFilter.withUpdatedColumns(filterColumns)); /* add the SSTables on disk */ Collections.sort(view.sstables, SSTable.maxTimestampComparator); @@ -161,7 +159,7 @@ public class CollationController final ColumnFamily c2 = container; CloseableIterator toCollate = new SimpleAbstractColumnIterator() { - final Iterator iter = c2.iterator(); + final Iterator iter = c2.iterator(); protected OnDiskAtom computeNext() { @@ -205,13 +203,10 @@ public class CollationController } /** - * remove columns from @param filter where we already have data in @param returnCF newer than @param sstableTimestamp + * remove columns from @param filter where we already have data in @param container newer than @param sstableTimestamp */ - private void reduceNameFilter(QueryFilter filter, ColumnFamily returnCF, long sstableTimestamp) + private void reduceNameFilter(QueryFilter filter, ColumnFamily container, long sstableTimestamp) { - AbstractColumnContainer container = filter.path.superColumnName == null - ? returnCF - : (SuperColumn) returnCF.getColumn(filter.path.superColumnName); // MIN_VALUE means we don't know any information if (container == null || sstableTimestamp == Long.MIN_VALUE) return; @@ -219,7 +214,7 @@ public class CollationController for (Iterator iterator = ((NamesQueryFilter) filter.filter).columns.iterator(); iterator.hasNext(); ) { ByteBuffer filterColumn = iterator.next(); - IColumn column = container.getColumn(filterColumn); + Column column = container.getColumn(filterColumn); if (column != null && column.timestamp() > sstableTimestamp) iterator.remove(); } diff --git a/src/java/org/apache/cassandra/db/Column.java b/src/java/org/apache/cassandra/db/Column.java index ebfb9f56c6..4efcfbd227 100644 --- a/src/java/org/apache/cassandra/db/Column.java +++ b/src/java/org/apache/cassandra/db/Column.java @@ -17,31 +17,34 @@ */ package org.apache.cassandra.db; +import java.io.DataInput; +import java.io.IOError; import java.io.IOException; import java.net.InetAddress; import java.nio.ByteBuffer; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.db.marshal.*; +import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.util.DataOutputBuffer; import org.apache.cassandra.utils.Allocator; import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.HeapAllocator; /** * Column is immutable, which prevents all kinds of confusion in a multithreaded environment. - * (TODO: look at making SuperColumn immutable too. This is trickier but is probably doable - * with something like PCollections -- http://code.google.com */ - -public class Column implements IColumn +public class Column implements OnDiskAtom { + public static final int MAX_NAME_LENGTH = FBUtilities.MAX_UNSIGNED_SHORT; + private static final ColumnSerializer serializer = new ColumnSerializer(); - private static final OnDiskAtom.Serializer onDiskSerializer = new OnDiskAtom.Serializer(serializer); public static ColumnSerializer serializer() { @@ -50,7 +53,38 @@ public class Column implements IColumn public static OnDiskAtom.Serializer onDiskSerializer() { - return onDiskSerializer; + return OnDiskAtom.Serializer.instance; + } + + public static Iterator onDiskIterator(final DataInput dis, final int count, final ColumnSerializer.Flag flag, final int expireBefore, final Descriptor.Version version) + { + return new Iterator() + { + int i = 0; + + public boolean hasNext() + { + return i < count; + } + + public OnDiskAtom next() + { + ++i; + try + { + return onDiskSerializer().deserializeFromSSTable(dis, flag, expireBefore, version); + } + catch (IOException e) + { + throw new IOError(e); + } + } + + public void remove() + { + throw new UnsupportedOperationException(); + } + }; } protected final ByteBuffer name; @@ -71,32 +105,27 @@ public class Column implements IColumn { assert name != null; assert value != null; - assert name.remaining() <= IColumn.MAX_NAME_LENGTH; + assert name.remaining() <= Column.MAX_NAME_LENGTH; this.name = name; this.value = value; this.timestamp = timestamp; } + public Column withUpdatedName(ByteBuffer newName) + { + return new Column(newName, value, timestamp); + } + public ByteBuffer name() { return name; } - public Column getSubColumn(ByteBuffer columnName) - { - throw new UnsupportedOperationException("This operation is unsupported on simple columns."); - } - public ByteBuffer value() { return value; } - public Collection getSubColumns() - { - throw new UnsupportedOperationException("This operation is unsupported on simple columns."); - } - public long timestamp() { return timestamp; @@ -162,17 +191,7 @@ public class Column implements IColumn return 0; } - public void addColumn(IColumn column) - { - addColumn(null, null); - } - - public void addColumn(IColumn column, Allocator allocator) - { - throw new UnsupportedOperationException("This operation is not supported for simple columns."); - } - - public IColumn diff(IColumn column) + public Column diff(Column column) { if (timestamp() < column.timestamp()) { @@ -204,12 +223,12 @@ public class Column implements IColumn return Integer.MAX_VALUE; } - public IColumn reconcile(IColumn column) + public Column reconcile(Column column) { return reconcile(column, HeapAllocator.instance); } - public IColumn reconcile(IColumn column, Allocator allocator) + public Column reconcile(Column column, Allocator allocator) { // tombstones take precedence. (if both are tombstones, then it doesn't matter which one we use.) if (isMarkedForDelete()) @@ -250,12 +269,12 @@ public class Column implements IColumn return result; } - public IColumn localCopy(ColumnFamilyStore cfs) + public Column localCopy(ColumnFamilyStore cfs) { return localCopy(cfs, HeapAllocator.instance); } - public IColumn localCopy(ColumnFamilyStore cfs, Allocator allocator) + public Column localCopy(ColumnFamilyStore cfs, Allocator allocator) { return new Column(cfs.internOrCopy(name, allocator), allocator.clone(value), timestamp); } @@ -280,8 +299,7 @@ public class Column implements IColumn protected void validateName(CFMetaData metadata) throws MarshalException { - AbstractType nameValidator = metadata.cfType == ColumnFamilyType.Super ? metadata.subcolumnComparator : metadata.comparator; - nameValidator.validate(name()); + metadata.comparator.validate(name()); } public void validateFields(CFMetaData metadata) throws MarshalException diff --git a/src/java/org/apache/cassandra/db/ColumnFamily.java b/src/java/org/apache/cassandra/db/ColumnFamily.java index 28621d796a..fd255d3646 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamily.java +++ b/src/java/org/apache/cassandra/db/ColumnFamily.java @@ -17,6 +17,7 @@ */ package org.apache.cassandra.db; +import java.io.DataInput; import java.nio.ByteBuffer; import java.security.MessageDigest; import java.util.UUID; @@ -29,10 +30,9 @@ import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.cassandra.cache.IRowCacheEntry; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.Schema; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.MarshalException; -import org.apache.cassandra.io.IColumnSerializer; +import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.sstable.ColumnStats; public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEntry @@ -90,12 +90,6 @@ public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEn return cloneMeShallow(columns.getFactory(), columns.isInsertReversed()); } - public AbstractType getSubComparator() - { - IColumnSerializer s = getColumnSerializer(); - return (s instanceof SuperColumnSerializer) ? ((SuperColumnSerializer) s).getComparator() : null; - } - public ColumnFamilyType getType() { return cfm.cfType; @@ -121,98 +115,38 @@ public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEn return cfm; } - public IColumnSerializer getColumnSerializer() + public void addColumn(ByteBuffer name, ByteBuffer value, long timestamp) { - return cfm.getColumnSerializer(); + addColumn(name, value, timestamp, 0); } - public OnDiskAtom.Serializer getOnDiskSerializer() + public void addColumn(ByteBuffer name, ByteBuffer value, long timestamp, int timeToLive) { - return cfm.getOnDiskSerializer(); - } - - public boolean isSuper() - { - return getType() == ColumnFamilyType.Super; - } - - /** - * Same as addAll() but do a cloneMe of SuperColumn if necessary to - * avoid keeping references to the structure (see #3957). - */ - public void addAllWithSCCopy(ColumnFamily cf, Allocator allocator) - { - if (cf.isSuper()) - { - for (IColumn c : cf) - { - columns.addColumn(((SuperColumn)c).cloneMe(), allocator); - } - delete(cf); - } - else - { - addAll(cf, allocator); - } - } - - public void addColumn(QueryPath path, ByteBuffer value, long timestamp) - { - addColumn(path, value, timestamp, 0); - } - - public void addColumn(QueryPath path, ByteBuffer value, long timestamp, int timeToLive) - { - assert path.columnName != null : path; assert !metadata().getDefaultValidator().isCommutative(); - Column column = Column.create(path.columnName, value, timestamp, timeToLive, metadata()); - addColumn(path.superColumnName, column); + Column column = Column.create(name, value, timestamp, timeToLive, metadata()); + addColumn(column); } - public void addCounter(QueryPath path, long value) + public void addCounter(ByteBuffer name, long value) { - assert path.columnName != null : path; - addColumn(path.superColumnName, new CounterUpdateColumn(path.columnName, value, System.currentTimeMillis())); + addColumn(new CounterUpdateColumn(name, value, System.currentTimeMillis())); } - public void addTombstone(QueryPath path, ByteBuffer localDeletionTime, long timestamp) + public void addTombstone(ByteBuffer name, ByteBuffer localDeletionTime, long timestamp) { - assert path.columnName != null : path; - addColumn(path.superColumnName, new DeletedColumn(path.columnName, localDeletionTime, timestamp)); - } - - public void addTombstone(QueryPath path, int localDeletionTime, long timestamp) - { - assert path.columnName != null : path; - addColumn(path.superColumnName, new DeletedColumn(path.columnName, localDeletionTime, timestamp)); + addColumn(new DeletedColumn(name, localDeletionTime, timestamp)); } public void addTombstone(ByteBuffer name, int localDeletionTime, long timestamp) { - addColumn(null, new DeletedColumn(name, localDeletionTime, timestamp)); - } - - public void addColumn(ByteBuffer superColumnName, Column column) - { - IColumn c; - if (superColumnName == null) - { - c = column; - } - else - { - assert isSuper(); - c = new SuperColumn(superColumnName, getSubComparator()); - c.addColumn(column); // checks subcolumn name - } - addColumn(c); + addColumn(new DeletedColumn(name, localDeletionTime, timestamp)); } public void addAtom(OnDiskAtom atom) { - if (atom instanceof IColumn) + if (atom instanceof Column) { - addColumn((IColumn)atom); + addColumn((Column)atom); } else { @@ -236,20 +170,20 @@ public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEn ColumnFamily cfDiff = ColumnFamily.create(cfm); cfDiff.delete(cfComposite.deletionInfo()); - // (don't need to worry about cfNew containing IColumns that are shadowed by + // (don't need to worry about cfNew containing Columns that are shadowed by // the delete tombstone, since cfNew was generated by CF.resolve, which // takes care of those for us.) - for (IColumn columnExternal : cfComposite) + for (Column columnExternal : cfComposite) { ByteBuffer cName = columnExternal.name(); - IColumn columnInternal = this.columns.getColumn(cName); + Column columnInternal = this.columns.getColumn(cName); if (columnInternal == null) { cfDiff.addColumn(columnExternal); } else { - IColumn columnDiff = columnInternal.diff(columnExternal); + Column columnDiff = columnInternal.diff(columnExternal); if (columnDiff != null) { cfDiff.addColumn(columnDiff); @@ -266,7 +200,7 @@ public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEn int dataSize() { int size = deletionInfo().dataSize(); - for (IColumn column : columns) + for (Column column : columns) { size += column.dataSize(); } @@ -276,7 +210,7 @@ public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEn public long maxTimestamp() { long maxTimestamp = deletionInfo().maxTimestamp(); - for (IColumn column : columns) + for (Column column : columns) maxTimestamp = Math.max(maxTimestamp, column.maxTimestamp()); return maxTimestamp; } @@ -329,17 +263,10 @@ public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEn public void updateDigest(MessageDigest digest) { - for (IColumn column : columns) + for (Column column : columns) column.updateDigest(digest); } - public static AbstractType getComparatorFor(String table, String columnFamilyName, ByteBuffer superColumnName) - { - return superColumnName == null - ? Schema.instance.getComparator(table, columnFamilyName) - : Schema.instance.getSubComparator(table, columnFamilyName); - } - public static ColumnFamily diff(ColumnFamily cf1, ColumnFamily cf2) { if (cf1 == null) @@ -368,7 +295,7 @@ public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEn public void validateColumnFields() throws MarshalException { CFMetaData metadata = metadata(); - for (IColumn column : this) + for (Column column : this) { column.validateFields(metadata); } @@ -380,7 +307,7 @@ public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEn long maxTimestampSeen = deletionInfo().maxTimestamp(); StreamingHistogram tombstones = new StreamingHistogram(SSTable.TOMBSTONE_HISTOGRAM_BIN_SIZE); - for (IColumn column : columns) + for (Column column : columns) { minTimestampSeen = Math.min(minTimestampSeen, column.minTimestamp()); maxTimestampSeen = Math.max(maxTimestampSeen, column.maxTimestamp()); diff --git a/src/java/org/apache/cassandra/db/ColumnFamilySerializer.java b/src/java/org/apache/cassandra/db/ColumnFamilySerializer.java index bac1e8b797..2b3b5989cf 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilySerializer.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilySerializer.java @@ -20,10 +20,10 @@ package org.apache.cassandra.db; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.util.Iterator; import java.util.UUID; import org.apache.cassandra.config.Schema; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.ISSTableSerializer; import org.apache.cassandra.io.IVersionedSerializer; import org.apache.cassandra.io.sstable.Descriptor; @@ -62,13 +62,18 @@ public class ColumnFamilySerializer implements IVersionedSerializer iter = cf.metadata().getOnDiskIterator(dis, size, flag, expireBefore, version); + while (iter.hasNext()) + cf.addAtom(iter.next()); } - public void deserializeFromSSTable(DataInput dis, ColumnFamily cf, IColumnSerializer.Flag flag, Descriptor.Version version) throws IOException + public void deserializeFromSSTable(DataInput dis, ColumnFamily cf, ColumnSerializer.Flag flag, Descriptor.Version version) throws IOException { cf.delete(DeletionInfo.serializer().deserializeFromSSTable(dis, version)); int size = dis.readInt(); diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 88719e3b12..9aa0d6d320 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -54,7 +54,6 @@ import org.apache.cassandra.db.compaction.OperationType; import org.apache.cassandra.db.filter.ExtendedFilter; import org.apache.cassandra.db.filter.IDiskAtomFilter; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.index.SecondaryIndex; import org.apache.cassandra.db.index.SecondaryIndexManager; import org.apache.cassandra.db.marshal.AbstractType; @@ -752,10 +751,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean if (cachedRow instanceof RowCacheSentinel) invalidateCachedRow(cacheKey); else - // columnFamily is what is written in the commit log. Because of the PeriodicCommitLog, this can be done in concurrency - // with this. So columnFamily shouldn't be modified and if it contains super columns, neither should they. So for super - // columns, we must make sure to clone them when adding to the cache. That's what addAllWithSCCopy does (see #3957) - ((ColumnFamily) cachedRow).addAllWithSCCopy(columnFamily, HeapAllocator.instance); + ((ColumnFamily) cachedRow).addAll(columnFamily, HeapAllocator.instance); } } @@ -820,23 +816,10 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean private static void removeDeletedColumnsOnly(ColumnFamily cf, int gcBefore, SecondaryIndexManager.Updater indexer) { - if (cf.isSuper()) - removeDeletedSuper(cf, gcBefore); - else - removeDeletedStandard(cf, gcBefore, indexer); - } - - public static void removeDeletedColumnsOnly(ColumnFamily cf, int gcBefore) - { - removeDeletedColumnsOnly(cf, gcBefore, SecondaryIndexManager.nullUpdater); - } - - private static void removeDeletedStandard(ColumnFamily cf, int gcBefore, SecondaryIndexManager.Updater indexer) - { - Iterator iter = cf.iterator(); + Iterator iter = cf.iterator(); while (iter.hasNext()) { - IColumn c = iter.next(); + Column c = iter.next(); // remove columns if // (a) the column itself is gcable or // (b) the column is shadowed by a CF tombstone @@ -848,36 +831,9 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean } } - private static void removeDeletedSuper(ColumnFamily cf, int gcBefore) + public static void removeDeletedColumnsOnly(ColumnFamily cf, int gcBefore) { - // TODO assume deletion means "most are deleted?" and add to clone, instead of remove from original? - // this could be improved by having compaction, or possibly even removeDeleted, r/m the tombstone - // once gcBefore has passed, so if new stuff is added in it doesn't used the wrong algorithm forever - Iterator iter = cf.iterator(); - while (iter.hasNext()) - { - SuperColumn c = (SuperColumn)iter.next(); - Iterator subIter = c.getSubColumns().iterator(); - while (subIter.hasNext()) - { - IColumn subColumn = subIter.next(); - // remove subcolumns if - // (a) the subcolumn itself is gcable or - // (b) the supercolumn is shadowed by the CF and the column is not newer - // (b) the subcolumn is shadowed by the supercolumn - if (subColumn.getLocalDeletionTime() < gcBefore - || cf.deletionInfo().isDeleted(c.name(), subColumn.timestamp()) - || c.deletionInfo().isDeleted(subColumn)) - { - subIter.remove(); - } - } - c.maybeResetDeletionTimes(gcBefore); - if (c.getSubColumns().isEmpty() && !c.isMarkedForDelete()) - { - iter.remove(); - } - } + removeDeletedColumnsOnly(cf, gcBefore, SecondaryIndexManager.nullUpdater); } /** @@ -1139,9 +1095,9 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean return metric.writeLatency.recentLatencyHistogram.getBuckets(true); } - public ColumnFamily getColumnFamily(DecoratedKey key, QueryPath path, ByteBuffer start, ByteBuffer finish, boolean reversed, int limit) + public ColumnFamily getColumnFamily(DecoratedKey key, ByteBuffer start, ByteBuffer finish, boolean reversed, int limit) { - return getColumnFamily(QueryFilter.getSliceFilter(key, path, start, finish, reversed, limit)); + return getColumnFamily(QueryFilter.getSliceFilter(key, name, start, finish, reversed, limit)); } /** @@ -1195,7 +1151,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean try { - ColumnFamily data = getTopLevelColumns(QueryFilter.getIdentityFilter(filter.key, new QueryPath(name)), + ColumnFamily data = getTopLevelColumns(QueryFilter.getIdentityFilter(filter.key, name), Integer.MIN_VALUE, true); if (sentinelSuccess && data != null) @@ -1244,9 +1200,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean if (cf == null) return null; - // TODO this is necessary because when we collate supercolumns together, we don't check - // their subcolumns for relevance, so we need to do a second prune post facto here. - result = cf.isSuper() ? removeDeleted(cf, gcBefore) : removeDeletedCF(cf, gcBefore); + result = removeDeletedCF(cf, gcBefore); } } @@ -1268,9 +1222,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean ColumnFamily cf = cached.cloneMeShallow(ArrayBackedSortedColumns.factory(), filter.filter.isReversed()); OnDiskAtomIterator ci = filter.getMemtableColumnIterator(cached, null); filter.collateOnDiskAtom(cf, Collections.singletonList(ci), gcBefore); - // TODO this is necessary because when we collate supercolumns together, we don't check - // their subcolumns for relevance, so we need to do a second prune post facto here. - return cf.isSuper() ? removeDeleted(cf, gcBefore) : removeDeletedCF(cf, gcBefore); + return removeDeletedCF(cf, gcBefore); } /** @@ -1402,14 +1354,14 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean * @param range Either a Bounds, which includes start key, or a Range, which does not. * @param columnFilter description of the columns we're interested in for each row */ - public AbstractScanIterator getSequentialIterator(ByteBuffer superColumn, final AbstractBounds range, IDiskAtomFilter columnFilter) + public AbstractScanIterator getSequentialIterator(final AbstractBounds range, IDiskAtomFilter columnFilter) { assert !(range instanceof Range) || !((Range)range).isWrapAround() || range.right.isMinimum() : range; final RowPosition startWith = range.left; final RowPosition stopAt = range.right; - QueryFilter filter = new QueryFilter(null, new QueryPath(name, superColumn, null), columnFilter); + QueryFilter filter = new QueryFilter(null, name, columnFilter); final ViewFragment view = markReferenced(startWith, stopAt); Tracing.trace("Executing seq scan across {} sstables for {}", view.sstables.size(), range.getString(metadata.getKeyValidator())); @@ -1439,11 +1391,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean logger.trace("scanned {}", key); - // TODO this is necessary because when we collate supercolumns together, we don't check - // their subcolumns for relevance, so we need to do a second prune post facto here. - return current.cf != null && current.cf.isSuper() - ? new Row(current.key, removeDeleted(current.cf, gcBefore)) - : current; + return current; } public void close() throws IOException @@ -1461,14 +1409,14 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean } } - public List getRangeSlice(ByteBuffer superColumn, final AbstractBounds range, int maxResults, IDiskAtomFilter columnFilter, List rowFilter) + public List getRangeSlice(final AbstractBounds range, int maxResults, IDiskAtomFilter columnFilter, List rowFilter) { - return getRangeSlice(superColumn, range, maxResults, columnFilter, rowFilter, false, false); + return getRangeSlice(range, maxResults, columnFilter, rowFilter, false, false); } - public List getRangeSlice(ByteBuffer superColumn, final AbstractBounds range, int maxResults, IDiskAtomFilter columnFilter, List rowFilter, boolean countCQL3Rows, boolean isPaging) + public List getRangeSlice(final AbstractBounds range, int maxResults, IDiskAtomFilter columnFilter, List rowFilter, boolean countCQL3Rows, boolean isPaging) { - return filter(getSequentialIterator(superColumn, range, columnFilter), ExtendedFilter.create(this, columnFilter, rowFilter, maxResults, countCQL3Rows, isPaging)); + return filter(getSequentialIterator(range, columnFilter), ExtendedFilter.create(this, columnFilter, rowFilter, maxResults, countCQL3Rows, isPaging)); } public List search(List clause, AbstractBounds range, int maxResults, IDiskAtomFilter dataFilter) @@ -1503,8 +1451,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean IDiskAtomFilter extraFilter = filter.getExtraFilter(data); if (extraFilter != null) { - QueryPath path = new QueryPath(name); - ColumnFamily cf = filter.cfs.getColumnFamily(new QueryFilter(rawRow.key, path, extraFilter)); + ColumnFamily cf = filter.cfs.getColumnFamily(new QueryFilter(rawRow.key, name, extraFilter)); if (cf != null) data.addAll(cf, HeapAllocator.instance); } diff --git a/src/java/org/apache/cassandra/db/ColumnIndex.java b/src/java/org/apache/cassandra/db/ColumnIndex.java index bd1c35ae97..b72638be74 100644 --- a/src/java/org/apache/cassandra/db/ColumnIndex.java +++ b/src/java/org/apache/cassandra/db/ColumnIndex.java @@ -52,6 +52,8 @@ public class ColumnIndex */ public static class Builder { + private static final OnDiskAtom.Serializer atomSerializer = Column.onDiskSerializer(); + private final ColumnIndex result; private final long indexOffset; private long startPosition = -1; @@ -62,7 +64,6 @@ public class ColumnIndex private OnDiskAtom lastBlockClosing; private final DataOutput output; private final RangeTombstone.Tracker tombstoneTracker; - private final OnDiskAtom.Serializer atomSerializer; private int atomCount; public Builder(ColumnFamily cf, @@ -73,7 +74,6 @@ public class ColumnIndex this.indexOffset = rowHeaderSize(key, cf.deletionInfo()); this.result = new ColumnIndex(estimatedColumnCount); this.output = output; - this.atomSerializer = cf.getOnDiskSerializer(); this.tombstoneTracker = new RangeTombstone.Tracker(cf.getComparator()); } @@ -116,7 +116,7 @@ public class ColumnIndex RangeTombstone tombstone = rangeIter.hasNext() ? rangeIter.next() : null; Comparator comparator = cf.getComparator(); - for (IColumn c : cf) + for (Column c : cf) { while (tombstone != null && comparator.compare(c.name(), tombstone.min) >= 0) { @@ -146,7 +146,7 @@ public class ColumnIndex { atomCount++; - if (column instanceof IColumn) + if (column instanceof Column) result.bloomFilter.add(column.name()); if (firstColumn == null) diff --git a/src/java/org/apache/cassandra/db/ColumnSerializer.java b/src/java/org/apache/cassandra/db/ColumnSerializer.java index d4a3e64563..bc1d788828 100644 --- a/src/java/org/apache/cassandra/db/ColumnSerializer.java +++ b/src/java/org/apache/cassandra/db/ColumnSerializer.java @@ -22,12 +22,12 @@ import java.io.DataOutput; import java.io.IOException; import java.nio.ByteBuffer; +import org.apache.cassandra.io.ISerializer; import org.apache.cassandra.io.FSReadError; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.util.FileDataInput; import org.apache.cassandra.utils.ByteBufferUtil; -public class ColumnSerializer implements IColumnSerializer +public class ColumnSerializer implements ISerializer { public final static int DELETION_MASK = 0x01; public final static int EXPIRATION_MASK = 0x02; @@ -35,7 +35,23 @@ public class ColumnSerializer implements IColumnSerializer public final static int COUNTER_UPDATE_MASK = 0x08; public final static int RANGE_TOMBSTONE_MASK = 0x10; - public void serialize(IColumn column, DataOutput dos) throws IOException + /** + * Flag affecting deserialization behavior. + * - LOCAL: for deserialization of local data (Expired columns are + * converted to tombstones (to gain disk space)). + * - FROM_REMOTE: for deserialization of data received from remote hosts + * (Expired columns are converted to tombstone and counters have + * their delta cleared) + * - PRESERVE_SIZE: used when no transformation must be performed, i.e, + * when we must ensure that deserializing and reserializing the + * result yield the exact same bytes. Streaming uses this. + */ + public static enum Flag + { + LOCAL, FROM_REMOTE, PRESERVE_SIZE; + } + + public void serialize(Column column, DataOutput dos) throws IOException { assert column.name().remaining() > 0; ByteBufferUtil.writeWithShortLength(column.name(), dos); @@ -70,12 +86,12 @@ public class ColumnSerializer implements IColumnSerializer * deserialize comes from a remote host. If it does, then we must clear * the delta. */ - public Column deserialize(DataInput dis, IColumnSerializer.Flag flag) throws IOException + public Column deserialize(DataInput dis, ColumnSerializer.Flag flag) throws IOException { return deserialize(dis, flag, (int) (System.currentTimeMillis() / 1000)); } - public Column deserialize(DataInput dis, IColumnSerializer.Flag flag, int expireBefore) throws IOException + public Column deserialize(DataInput dis, ColumnSerializer.Flag flag, int expireBefore) throws IOException { ByteBuffer name = ByteBufferUtil.readWithShortLength(dis); if (name.remaining() <= 0) @@ -85,7 +101,7 @@ public class ColumnSerializer implements IColumnSerializer return deserializeColumnBody(dis, name, b, flag, expireBefore); } - Column deserializeColumnBody(DataInput dis, ByteBuffer name, int mask, IColumnSerializer.Flag flag, int expireBefore) throws IOException + Column deserializeColumnBody(DataInput dis, ByteBuffer name, int mask, ColumnSerializer.Flag flag, int expireBefore) throws IOException { if ((mask & COUNTER_MASK) != 0) { @@ -114,7 +130,7 @@ public class ColumnSerializer implements IColumnSerializer } } - public long serializedSize(IColumn column, TypeSizes type) + public long serializedSize(Column column, TypeSizes type) { return column.serializedSize(type); } diff --git a/src/java/org/apache/cassandra/db/CounterColumn.java b/src/java/org/apache/cassandra/db/CounterColumn.java index a10cb5732e..a24687b0d7 100644 --- a/src/java/org/apache/cassandra/db/CounterColumn.java +++ b/src/java/org/apache/cassandra/db/CounterColumn.java @@ -36,7 +36,6 @@ import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.MarshalException; import org.apache.cassandra.exceptions.OverloadedException; import org.apache.cassandra.exceptions.RequestExecutionException; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.util.DataOutputBuffer; import org.apache.cassandra.utils.Allocator; import org.apache.cassandra.service.AbstractWriteResponseHandler; @@ -75,15 +74,21 @@ public class CounterColumn extends Column this.timestampOfLastDelete = timestampOfLastDelete; } - public static CounterColumn create(ByteBuffer name, ByteBuffer value, long timestamp, long timestampOfLastDelete, IColumnSerializer.Flag flag) + public static CounterColumn create(ByteBuffer name, ByteBuffer value, long timestamp, long timestampOfLastDelete, ColumnSerializer.Flag flag) { // #elt being negative means we have to clean delta short count = value.getShort(value.position()); - if (flag == IColumnSerializer.Flag.FROM_REMOTE || (flag == IColumnSerializer.Flag.LOCAL && count < 0)) + if (flag == ColumnSerializer.Flag.FROM_REMOTE || (flag == ColumnSerializer.Flag.LOCAL && count < 0)) value = CounterContext.instance().clearAllDelta(value); return new CounterColumn(name, value, timestamp, timestampOfLastDelete); } + @Override + public Column withUpdatedName(ByteBuffer newName) + { + return new CounterColumn(newName, value, timestamp, timestampOfLastDelete); + } + public long timestampOfLastDelete() { return timestampOfLastDelete; @@ -111,7 +116,7 @@ public class CounterColumn extends Column } @Override - public IColumn diff(IColumn column) + public Column diff(Column column) { assert (column instanceof CounterColumn) || (column instanceof DeletedColumn) : "Wrong class type: " + column.getClass(); @@ -160,7 +165,7 @@ public class CounterColumn extends Column } @Override - public IColumn reconcile(IColumn column, Allocator allocator) + public Column reconcile(Column column, Allocator allocator) { assert (column instanceof CounterColumn) || (column instanceof DeletedColumn) : "Wrong class type: " + column.getClass(); @@ -208,13 +213,13 @@ public class CounterColumn extends Column } @Override - public IColumn localCopy(ColumnFamilyStore cfs) + public Column localCopy(ColumnFamilyStore cfs) { return new CounterColumn(cfs.internOrCopy(name, HeapAllocator.instance), ByteBufferUtil.clone(value), timestamp, timestampOfLastDelete); } @Override - public IColumn localCopy(ColumnFamilyStore cfs, Allocator allocator) + public Column localCopy(ColumnFamilyStore cfs, Allocator allocator) { return new CounterColumn(cfs.internOrCopy(name, allocator), allocator.clone(value), timestamp, timestampOfLastDelete); } @@ -299,52 +304,25 @@ public class CounterColumn extends Column public static void mergeAndRemoveOldShards(DecoratedKey key, ColumnFamily cf, int gcBefore, int mergeBefore, boolean sendToOtherReplica) { ColumnFamily remoteMerger = null; - if (!cf.isSuper()) + + for (Column c : cf) { - for (IColumn c : cf) + if (!(c instanceof CounterColumn)) + continue; + CounterColumn cc = (CounterColumn) c; + CounterColumn shardMerger = cc.computeOldShardMerger(mergeBefore); + CounterColumn merged = cc; + if (shardMerger != null) { - if (!(c instanceof CounterColumn)) - continue; - CounterColumn cc = (CounterColumn) c; - CounterColumn shardMerger = cc.computeOldShardMerger(mergeBefore); - CounterColumn merged = cc; - if (shardMerger != null) - { - merged = (CounterColumn) cc.reconcile(shardMerger); - if (remoteMerger == null) - remoteMerger = cf.cloneMeShallow(); - remoteMerger.addColumn(merged); - } - CounterColumn cleaned = merged.removeOldShards(gcBefore); - if (cleaned != cc) - { - cf.replace(cc, cleaned); - } + merged = (CounterColumn) cc.reconcile(shardMerger); + if (remoteMerger == null) + remoteMerger = cf.cloneMeShallow(); + remoteMerger.addColumn(merged); } - } - else - { - for (IColumn col : cf) + CounterColumn cleaned = merged.removeOldShards(gcBefore); + if (cleaned != cc) { - SuperColumn c = (SuperColumn)col; - for (IColumn subColumn : c.getSubColumns()) - { - if (!(subColumn instanceof CounterColumn)) - continue; - CounterColumn cc = (CounterColumn) subColumn; - CounterColumn shardMerger = cc.computeOldShardMerger(mergeBefore); - CounterColumn merged = cc; - if (shardMerger != null) - { - merged = (CounterColumn) cc.reconcile(shardMerger); - if (remoteMerger == null) - remoteMerger = cf.cloneMeShallow(); - remoteMerger.addColumn(c.name(), merged); - } - CounterColumn cleaned = merged.removeOldShards(gcBefore); - if (cleaned != subColumn) - c.replace(subColumn, cleaned); - } + cf.replace(cc, cleaned); } } @@ -361,7 +339,7 @@ public class CounterColumn extends Column } } - public IColumn markDeltaToBeCleared() + public Column markDeltaToBeCleared() { return new CounterColumn(name, contextManager.markDeltaToBeCleared(value), timestamp, timestampOfLastDelete); } diff --git a/src/java/org/apache/cassandra/db/CounterMutation.java b/src/java/org/apache/cassandra/db/CounterMutation.java index d06df33dec..dfc491880f 100644 --- a/src/java/org/apache/cassandra/db/CounterMutation.java +++ b/src/java/org/apache/cassandra/db/CounterMutation.java @@ -24,9 +24,11 @@ import java.nio.ByteBuffer; import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.UUID; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.filter.NamesQueryFilter; import org.apache.cassandra.io.IVersionedSerializer; import org.apache.cassandra.net.MessageOut; import org.apache.cassandra.net.MessagingService; @@ -92,8 +94,6 @@ public class CounterMutation implements IMutation continue; ColumnFamily cf = row.cf; - if (cf.isSuper()) - cf.retainAll(rowMutation.getColumnFamily(cf.metadata().cfId)); replicationMutation.add(cf); } return replicationMutation; @@ -101,8 +101,9 @@ public class CounterMutation implements IMutation private void addReadCommandFromColumnFamily(String table, ByteBuffer key, ColumnFamily columnFamily, List commands) { - QueryPath queryPath = new QueryPath(columnFamily.metadata().cfName); - commands.add(new SliceByNamesReadCommand(table, key, queryPath, columnFamily.getColumnNames())); + SortedSet s = new TreeSet(columnFamily.metadata().comparator); + s.addAll(columnFamily.getColumnNames()); + commands.add(new SliceByNamesReadCommand(table, key, columnFamily.metadata().cfName, new NamesQueryFilter(s))); } public MessageOut makeMutationMessage() throws IOException @@ -128,7 +129,7 @@ public class CounterMutation implements IMutation { ColumnFamily cf = cf_.cloneMeShallow(); ColumnFamilyStore cfs = table.getColumnFamilyStore(cf.id()); - for (IColumn column : cf_) + for (Column column : cf_) { cf.addColumn(column.localCopy(cfs), HeapAllocator.instance); } diff --git a/src/java/org/apache/cassandra/db/CounterUpdateColumn.java b/src/java/org/apache/cassandra/db/CounterUpdateColumn.java index 58241c01ff..9d9530e182 100644 --- a/src/java/org/apache/cassandra/db/CounterUpdateColumn.java +++ b/src/java/org/apache/cassandra/db/CounterUpdateColumn.java @@ -49,14 +49,14 @@ public class CounterUpdateColumn extends Column } @Override - public IColumn diff(IColumn column) + public Column diff(Column column) { // Diff is used during reads, but we should never read those columns throw new UnsupportedOperationException("This operation is unsupported on CounterUpdateColumn."); } @Override - public IColumn reconcile(IColumn column, Allocator allocator) + public Column reconcile(Column column, Allocator allocator) { // The only time this could happen is if a batchAdd ships two // increment for the same column. Hence we simply sums the delta. @@ -88,7 +88,7 @@ public class CounterUpdateColumn extends Column } @Override - public IColumn localCopy(ColumnFamilyStore cfs, Allocator allocator) + public Column localCopy(ColumnFamilyStore cfs, Allocator allocator) { return new CounterColumn(cfs.internOrCopy(name, allocator), CounterContext.instance().create(delta(), allocator), diff --git a/src/java/org/apache/cassandra/db/DefsTable.java b/src/java/org/apache/cassandra/db/DefsTable.java index 94d19583ea..7fd51642d2 100644 --- a/src/java/org/apache/cassandra/db/DefsTable.java +++ b/src/java/org/apache/cassandra/db/DefsTable.java @@ -37,7 +37,6 @@ import org.apache.avro.specific.SpecificRecord; import org.apache.cassandra.config.*; import org.apache.cassandra.db.compaction.CompactionManager; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.AsciiType; import org.apache.cassandra.db.marshal.UTF8Type; import org.apache.cassandra.db.migration.avro.KsDef; @@ -181,7 +180,7 @@ public class DefsTable if (Schema.invalidSchemaRow(row)) continue; - for (IColumn column : row.cf.columns) + for (Column column : row.cf.columns) { Date columnDate = new Date(column.timestamp()); @@ -233,10 +232,10 @@ public class DefsTable RowMutation mutation = new RowMutation(Table.SYSTEM_KS, row.key.key); - for (IColumn column : row.cf.columns) + for (Column column : row.cf.columns) { if (column.isLive()) - mutation.add(new QueryPath(columnFamily, null, column.name()), column.value(), microTimestamp); + mutation.add(columnFamily, column.name(), column.value(), microTimestamp); } mutation.apply(); @@ -272,7 +271,7 @@ public class DefsTable private static Row serializedColumnFamilies(DecoratedKey ksNameKey) { ColumnFamilyStore cfsStore = SystemTable.schemaCFS(SystemTable.SCHEMA_COLUMNFAMILIES_CF); - return new Row(ksNameKey, cfsStore.getColumnFamily(QueryFilter.getIdentityFilter(ksNameKey, new QueryPath(SystemTable.SCHEMA_COLUMNFAMILIES_CF)))); + return new Row(ksNameKey, cfsStore.getColumnFamily(QueryFilter.getIdentityFilter(ksNameKey, SystemTable.SCHEMA_COLUMNFAMILIES_CF))); } /** @@ -290,8 +289,8 @@ public class DefsTable DecoratedKey vkey = StorageService.getPartitioner().decorateKey(toUTF8Bytes(version)); Table defs = Table.open(Table.SYSTEM_KS); ColumnFamilyStore cfStore = defs.getColumnFamilyStore(OLD_SCHEMA_CF); - ColumnFamily cf = cfStore.getColumnFamily(QueryFilter.getIdentityFilter(vkey, new QueryPath(OLD_SCHEMA_CF))); - IColumn avroschema = cf.getColumn(DEFINITION_SCHEMA_COLUMN_NAME); + ColumnFamily cf = cfStore.getColumnFamily(QueryFilter.getIdentityFilter(vkey, OLD_SCHEMA_CF)); + Column avroschema = cf.getColumn(DEFINITION_SCHEMA_COLUMN_NAME); Collection keyspaces = Collections.emptyList(); @@ -301,10 +300,10 @@ public class DefsTable org.apache.avro.Schema schema = org.apache.avro.Schema.parse(ByteBufferUtil.string(value)); // deserialize keyspaces using schema - Collection columns = cf.getSortedColumns(); + Collection columns = cf.getSortedColumns(); keyspaces = new ArrayList(columns.size()); - for (IColumn column : columns) + for (Column column : columns) { if (column.name().equals(DEFINITION_SCHEMA_COLUMN_NAME)) continue; diff --git a/src/java/org/apache/cassandra/db/DeletedColumn.java b/src/java/org/apache/cassandra/db/DeletedColumn.java index 18faeef012..c1ca18c5b2 100644 --- a/src/java/org/apache/cassandra/db/DeletedColumn.java +++ b/src/java/org/apache/cassandra/db/DeletedColumn.java @@ -37,6 +37,12 @@ public class DeletedColumn extends Column super(name, value, timestamp); } + @Override + public Column withUpdatedName(ByteBuffer newName) + { + return new DeletedColumn(newName, value, timestamp); + } + @Override public boolean isMarkedForDelete() { @@ -58,7 +64,7 @@ public class DeletedColumn extends Column } @Override - public IColumn reconcile(IColumn column, Allocator allocator) + public Column reconcile(Column column, Allocator allocator) { if (column instanceof DeletedColumn) return super.reconcile(column, allocator); @@ -66,13 +72,13 @@ public class DeletedColumn extends Column } @Override - public IColumn localCopy(ColumnFamilyStore cfs) + public Column localCopy(ColumnFamilyStore cfs) { return new DeletedColumn(cfs.internOrCopy(name, HeapAllocator.instance), ByteBufferUtil.clone(value), timestamp); } @Override - public IColumn localCopy(ColumnFamilyStore cfs, Allocator allocator) + public Column localCopy(ColumnFamilyStore cfs, Allocator allocator) { return new DeletedColumn(cfs.internOrCopy(name, allocator), allocator.clone(value), timestamp); } diff --git a/src/java/org/apache/cassandra/db/DeletionInfo.java b/src/java/org/apache/cassandra/db/DeletionInfo.java index be64224d37..eab9f37b26 100644 --- a/src/java/org/apache/cassandra/db/DeletionInfo.java +++ b/src/java/org/apache/cassandra/db/DeletionInfo.java @@ -51,8 +51,12 @@ public class DeletionInfo { // Pre-1.1 node may return MIN_VALUE for non-deleted container, but the new default is MAX_VALUE // (see CASSANDRA-3872) - this(new DeletionTime(markedForDeleteAt, localDeletionTime == Integer.MIN_VALUE ? Integer.MAX_VALUE : localDeletionTime), - IntervalTree.emptyTree()); + this(new DeletionTime(markedForDeleteAt, localDeletionTime == Integer.MIN_VALUE ? Integer.MAX_VALUE : localDeletionTime)); + } + + public DeletionInfo(DeletionTime topLevel) + { + this(topLevel, IntervalTree.emptyTree()); } public DeletionInfo(ByteBuffer start, ByteBuffer end, Comparator comparator, long markedForDeleteAt, int localDeletionTime) @@ -94,7 +98,7 @@ public class DeletionInfo * @param column the column to check. * @return true if the column is deleted, false otherwise */ - public boolean isDeleted(IColumn column) + public boolean isDeleted(Column column) { return isDeleted(column.name(), column.mostRecentLiveChangeAt()); } @@ -211,6 +215,11 @@ public class DeletionInfo return ranges.iterator(); } + public List rangeCovering(ByteBuffer name) + { + return ranges.search(name); + } + public int dataSize() { int size = TypeSizes.NATIVE.sizeof(topLevel.markedForDeleteAt); @@ -331,7 +340,7 @@ public class DeletionInfo public DeletionInfo deserialize(DataInput in, int version, Comparator comparator) throws IOException { - assert comparator != null; + assert version < MessagingService.VERSION_12 || comparator != null; DeletionTime topLevel = DeletionTime.serializer.deserialize(in); if (version < MessagingService.VERSION_12) return new DeletionInfo(topLevel, IntervalTree.emptyTree()); diff --git a/src/java/org/apache/cassandra/db/DeletionTime.java b/src/java/org/apache/cassandra/db/DeletionTime.java index 2b9efcd064..c28b93677b 100644 --- a/src/java/org/apache/cassandra/db/DeletionTime.java +++ b/src/java/org/apache/cassandra/db/DeletionTime.java @@ -80,7 +80,7 @@ public class DeletionTime implements Comparable return localDeletionTime < gcBefore; } - public boolean isDeleted(IColumn column) + public boolean isDeleted(Column column) { return column.isMarkedForDelete() && column.getMarkedForDeleteAt() <= markedForDeleteAt; } diff --git a/src/java/org/apache/cassandra/db/ExpiringColumn.java b/src/java/org/apache/cassandra/db/ExpiringColumn.java index 1d52182527..fa21d27e43 100644 --- a/src/java/org/apache/cassandra/db/ExpiringColumn.java +++ b/src/java/org/apache/cassandra/db/ExpiringColumn.java @@ -24,7 +24,6 @@ import java.security.MessageDigest; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.MarshalException; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.util.DataOutputBuffer; import org.apache.cassandra.utils.Allocator; import org.apache.cassandra.utils.ByteBufferUtil; @@ -62,9 +61,9 @@ public class ExpiringColumn extends Column } /** @return Either a DeletedColumn, or an ExpiringColumn. */ - public static Column create(ByteBuffer name, ByteBuffer value, long timestamp, int timeToLive, int localExpirationTime, int expireBefore, IColumnSerializer.Flag flag) + public static Column create(ByteBuffer name, ByteBuffer value, long timestamp, int timeToLive, int localExpirationTime, int expireBefore, ColumnSerializer.Flag flag) { - if (localExpirationTime >= expireBefore || flag == IColumnSerializer.Flag.PRESERVE_SIZE) + if (localExpirationTime >= expireBefore || flag == ColumnSerializer.Flag.PRESERVE_SIZE) return new ExpiringColumn(name, value, timestamp, timeToLive, localExpirationTime); // the column is now expired, we can safely return a simple tombstone return new DeletedColumn(name, localExpirationTime, timestamp); @@ -75,6 +74,12 @@ public class ExpiringColumn extends Column return timeToLive; } + @Override + public Column withUpdatedName(ByteBuffer newName) + { + return new ExpiringColumn(newName, value, timestamp, timeToLive, localExpirationTime); + } + @Override public int dataSize() { @@ -119,13 +124,13 @@ public class ExpiringColumn extends Column } @Override - public IColumn localCopy(ColumnFamilyStore cfs) + public Column localCopy(ColumnFamilyStore cfs) { return new ExpiringColumn(cfs.internOrCopy(name, HeapAllocator.instance), ByteBufferUtil.clone(value), timestamp, timeToLive, localExpirationTime); } @Override - public IColumn localCopy(ColumnFamilyStore cfs, Allocator allocator) + public Column localCopy(ColumnFamilyStore cfs, Allocator allocator) { ByteBuffer clonedName = cfs.maybeIntern(name); if (clonedName == null) diff --git a/src/java/org/apache/cassandra/db/HintedHandOffManager.java b/src/java/org/apache/cassandra/db/HintedHandOffManager.java index 476af88010..3d726a0f4d 100644 --- a/src/java/org/apache/cassandra/db/HintedHandOffManager.java +++ b/src/java/org/apache/cassandra/db/HintedHandOffManager.java @@ -129,7 +129,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean private static void deleteHint(ByteBuffer tokenBytes, ByteBuffer columnName, long timestamp) throws IOException { RowMutation rm = new RowMutation(Table.SYSTEM_KS, tokenBytes); - rm.delete(new QueryPath(SystemTable.HINTS_CF, null, columnName), timestamp); + rm.delete(SystemTable.HINTS_CF, columnName, timestamp); rm.applyUnsafe(); // don't bother with commitlog since we're going to flush as soon as we're done with delivery } @@ -155,7 +155,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean UUID hostId = StorageService.instance.getTokenMetadata().getHostId(endpoint); ByteBuffer hostIdBytes = ByteBuffer.wrap(UUIDGen.decompose(hostId)); final RowMutation rm = new RowMutation(Table.SYSTEM_KS, hostIdBytes); - rm.delete(new QueryPath(SystemTable.HINTS_CF), System.currentTimeMillis()); + rm.delete(SystemTable.HINTS_CF, System.currentTimeMillis()); // execute asynchronously to avoid blocking caller (which may be processing gossip) Runnable runnable = new Runnable() @@ -303,7 +303,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean while (true) { - QueryFilter filter = QueryFilter.getSliceFilter(epkey, new QueryPath(SystemTable.HINTS_CF), startColumn, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, pageSize); + QueryFilter filter = QueryFilter.getSliceFilter(epkey, SystemTable.HINTS_CF, startColumn, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, pageSize); ColumnFamily hintsPage = ColumnFamilyStore.removeDeleted(hintStore.getColumnFamily(filter), (int)(System.currentTimeMillis() / 1000)); if (pagingFinished(hintsPage, startColumn)) { @@ -322,7 +322,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean } - for (final IColumn hint : hintsPage.getSortedColumns()) + for (final Column hint : hintsPage.getSortedColumns()) { // Skip tombstones: // if we iterate quickly enough, it's possible that we could request a new page in the same millisecond @@ -400,7 +400,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean RowPosition minPos = p.getMinimumToken().minKeyBound(); Range range = new Range(minPos, minPos, p); IDiskAtomFilter filter = new NamesQueryFilter(ImmutableSortedSet.of()); - List rows = hintStore.getRangeSlice(null, range, Integer.MAX_VALUE, filter, null); + List rows = hintStore.getRangeSlice(range, Integer.MAX_VALUE, filter, null); for (Row row : rows) { UUID hostId = UUIDGen.getUUID(row.key.key); @@ -473,9 +473,6 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean private List getHintsSlice(int columnCount) { - // ColumnParent for HintsCF... - ColumnParent parent = new ColumnParent(SystemTable.HINTS_CF); - // Get count # of columns... SliceQueryFilter predicate = new SliceQueryFilter(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, @@ -491,7 +488,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean List rows; try { - rows = StorageProxy.getRangeSlice(new RangeSliceCommand(Table.SYSTEM_KS, parent, predicate, range, null, LARGE_NUMBER), ConsistencyLevel.ONE); + rows = StorageProxy.getRangeSlice(new RangeSliceCommand(Table.SYSTEM_KS, SystemTable.HINTS_CF, predicate, range, null, LARGE_NUMBER), ConsistencyLevel.ONE); } catch (Exception e) { diff --git a/src/java/org/apache/cassandra/db/IColumn.java b/src/java/org/apache/cassandra/db/IColumn.java deleted file mode 100644 index 0a7fe7adab..0000000000 --- a/src/java/org/apache/cassandra/db/IColumn.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.db; - -import java.nio.ByteBuffer; -import java.util.Collection; - -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.db.marshal.AbstractType; -import org.apache.cassandra.db.marshal.MarshalException; -import org.apache.cassandra.utils.Allocator; -import org.apache.cassandra.utils.FBUtilities; - -/** TODO: rename */ -public interface IColumn extends OnDiskAtom -{ - public static final int MAX_NAME_LENGTH = FBUtilities.MAX_UNSIGNED_SHORT; - - /** - * @return true if the column has been deleted (is a tombstone). This depends on comparing the server clock - * with getLocalDeletionTime, so it can change during a single request if you're not careful. - */ - public boolean isMarkedForDelete(); - - public long getMarkedForDeleteAt(); - public long mostRecentLiveChangeAt(); - public long mostRecentNonGCableChangeAt(int gcbefore); - /** the size of user-provided data, not including internal overhead */ - public int dataSize(); - public int serializationFlags(); - public long timestamp(); - public ByteBuffer value(); - public Collection getSubColumns(); - public IColumn getSubColumn(ByteBuffer columnName); - public void addColumn(IColumn column); - public void addColumn(IColumn column, Allocator allocator); - public IColumn diff(IColumn column); - public IColumn reconcile(IColumn column); - public IColumn reconcile(IColumn column, Allocator allocator); - public String getString(AbstractType comparator); - public void validateFields(CFMetaData metadata) throws MarshalException; - - /** clones the column for the row cache, interning column names and making copies of other underlying byte buffers */ - IColumn localCopy(ColumnFamilyStore cfs); - - /** - * clones the column for the memtable, interning column names and making copies of other underlying byte buffers. - * Unlike the other localCopy, this uses Allocator to allocate values in contiguous memory regions, - * which helps avoid heap fragmentation. - */ - IColumn localCopy(ColumnFamilyStore cfs, Allocator allocator); - - /** - * For a simple column, live == !isMarkedForDelete. - * For a supercolumn, live means it has at least one subcolumn whose timestamp is greater than the - * supercolumn deleted-at time. - */ - boolean isLive(); - - /** - * For a standard column, this is the same as timestamp(). - * For a super column, this is the max column timestamp of the sub columns. - */ - public long maxTimestamp(); - - /** - * @return true if the column or any its subcolumns is no longer relevant after @param gcBefore - */ - public boolean hasIrrelevantData(int gcBefore); -} diff --git a/src/java/org/apache/cassandra/db/IColumnContainer.java b/src/java/org/apache/cassandra/db/IColumnContainer.java deleted file mode 100644 index a3bd210ac3..0000000000 --- a/src/java/org/apache/cassandra/db/IColumnContainer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.db; - -import java.nio.ByteBuffer; -import java.util.Collection; - -import org.apache.cassandra.db.marshal.AbstractType; -import org.apache.cassandra.utils.Allocator; - -public interface IColumnContainer -{ - public void addColumn(IColumn column); - public void addColumn(IColumn column, Allocator allocator); - public void remove(ByteBuffer columnName); - - /** - * Replace oldColumn if represent by newColumn. - * Returns true if oldColumn was present (and thus replaced) - * oldColumn and newColumn should have the same name. - * !NOTE! This should only be used if you know this is what you need. To - * add a column such that it use the usual column resolution rules in a - * thread safe manner, use addColumn. - */ - public boolean replace(IColumn oldColumn, IColumn newColumn); - - public boolean isMarkedForDelete(); - public DeletionInfo deletionInfo(); - public boolean hasIrrelevantData(int gcBefore); - - public AbstractType getComparator(); - - public Collection getSortedColumns(); -} diff --git a/src/java/org/apache/cassandra/db/ISortedColumns.java b/src/java/org/apache/cassandra/db/ISortedColumns.java index 5ccba1940e..df288aa1dc 100644 --- a/src/java/org/apache/cassandra/db/ISortedColumns.java +++ b/src/java/org/apache/cassandra/db/ISortedColumns.java @@ -62,7 +62,7 @@ public interface ISortedColumns extends IIterableColumns * If a column with the same name is already present in the map, it will * be replaced by the newly added column. */ - public void addColumn(IColumn column, Allocator allocator); + public void addColumn(Column column, Allocator allocator); /** * Adds all the columns of a given column map to this column map. @@ -75,19 +75,19 @@ public interface ISortedColumns extends IIterableColumns * * @return the difference in size seen after merging the given columns */ - public long addAllWithSizeDelta(ISortedColumns cm, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer); + public long addAllWithSizeDelta(ISortedColumns cm, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer); /** * Adds the columns without necessarily computing the size delta */ - public void addAll(ISortedColumns cm, Allocator allocator, Function transformation); + public void addAll(ISortedColumns cm, Allocator allocator, Function transformation); /** * Replace oldColumn if present by newColumn. * Returns true if oldColumn was present and thus replaced. * oldColumn and newColumn should have the same name. */ - public boolean replace(IColumn oldColumn, IColumn newColumn); + public boolean replace(Column oldColumn, Column newColumn); /** * Remove if present a column by name. @@ -103,7 +103,7 @@ public interface ISortedColumns extends IIterableColumns * Get a column given its name, returning null if the column is not * present. */ - public IColumn getColumn(ByteBuffer name); + public Column getColumn(ByteBuffer name); /** * Returns a set with the names of columns in this column map. @@ -117,14 +117,14 @@ public interface ISortedColumns extends IIterableColumns * The columns in the returned collection should be sorted as the columns * in this map. */ - public Collection getSortedColumns(); + public Collection getSortedColumns(); /** * Returns the columns of this column map as a collection. * The columns in the returned collection should be sorted in reverse * order of the columns in this map. */ - public Collection getReverseSortedColumns(); + public Collection getReverseSortedColumns(); /** * Returns the number of columns in this map. @@ -140,13 +140,13 @@ public interface ISortedColumns extends IIterableColumns * Returns an iterator over the columns of this map that returns only the matching @param slices. * The provided slices must be in order and must be non-overlapping. */ - public Iterator iterator(ColumnSlice[] slices); + public Iterator iterator(ColumnSlice[] slices); /** * Returns a reversed iterator over the columns of this map that returns only the matching @param slices. * The provided slices must be in reversed order and must be non-overlapping. */ - public Iterator reverseIterator(ColumnSlice[] slices); + public Iterator reverseIterator(ColumnSlice[] slices); /** * Returns if this map only support inserts in reverse order. @@ -171,6 +171,6 @@ public interface ISortedColumns extends IIterableColumns * columns in the provided sorted map. * See {@code create} for the description of {@code insertReversed} */ - public ISortedColumns fromSorted(SortedMap sm, boolean insertReversed); + public ISortedColumns fromSorted(SortedMap sm, boolean insertReversed); } } diff --git a/src/java/org/apache/cassandra/db/Memtable.java b/src/java/org/apache/cassandra/db/Memtable.java index 6b708d510b..32e6852034 100644 --- a/src/java/org/apache/cassandra/db/Memtable.java +++ b/src/java/org/apache/cassandra/db/Memtable.java @@ -93,9 +93,9 @@ public class Memtable private final SlabAllocator allocator = new SlabAllocator(); // We really only need one column by allocator but one by memtable is not a big waste and avoids needing allocators to know about CFS - private final Function localCopyFunction = new Function() + private final Function localCopyFunction = new Function() { - public IColumn apply(IColumn c) + public Column apply(Column c) { return c.localCopy(cfs, allocator); }; @@ -226,7 +226,7 @@ public class Memtable if (previous == null) { // AtomicSortedColumns doesn't work for super columns (see #3821) - ColumnFamily empty = cf.cloneMeShallow(cf.isSuper() ? ThreadSafeSortedColumns.factory() : AtomicSortedColumns.factory(), false); + ColumnFamily empty = cf.cloneMeShallow(AtomicSortedColumns.factory(), false); // We'll add the columns later. This avoids wasting works if we get beaten in the putIfAbsent previous = columnFamilies.putIfAbsent(new DecoratedKey(key.token, allocator.clone(key.key)), empty); if (previous == null) @@ -316,7 +316,7 @@ public class Memtable public static OnDiskAtomIterator getSliceIterator(final DecoratedKey key, final ColumnFamily cf, SliceQueryFilter filter) { assert cf != null; - final Iterator filteredIter = filter.reversed ? cf.reverseIterator(filter.slices) : cf.iterator(filter.slices); + final Iterator filteredIter = filter.reversed ? cf.reverseIterator(filter.slices) : cf.iterator(filter.slices); return new AbstractColumnIterator() { @@ -345,7 +345,6 @@ public class Memtable public static OnDiskAtomIterator getNamesIterator(final DecoratedKey key, final ColumnFamily cf, final NamesQueryFilter filter) { assert cf != null; - final boolean isStandard = !cf.isSuper(); return new SimpleAbstractColumnIterator() { @@ -366,10 +365,9 @@ public class Memtable while (iter.hasNext()) { ByteBuffer current = iter.next(); - IColumn column = cf.getColumn(current); + Column column = cf.getColumn(current); if (column != null) - // clone supercolumns so caller can freely removeDeleted or otherwise mutate it - return isStandard ? column : ((SuperColumn)column).cloneMe(); + return column; } return endOfData(); } diff --git a/src/java/org/apache/cassandra/db/OnDiskAtom.java b/src/java/org/apache/cassandra/db/OnDiskAtom.java index 7501d835cd..cc997ca45c 100644 --- a/src/java/org/apache/cassandra/db/OnDiskAtom.java +++ b/src/java/org/apache/cassandra/db/OnDiskAtom.java @@ -23,7 +23,6 @@ import java.security.MessageDigest; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.db.marshal.MarshalException; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.ISSTableSerializer; import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.utils.ByteBufferUtil; @@ -48,18 +47,15 @@ public interface OnDiskAtom public static class Serializer implements ISSTableSerializer { - private final IColumnSerializer columnSerializer; + public static Serializer instance = new Serializer(); - public Serializer(IColumnSerializer columnSerializer) - { - this.columnSerializer = columnSerializer; - } + private Serializer() {} public void serializeForSSTable(OnDiskAtom atom, DataOutput dos) throws IOException { - if (atom instanceof IColumn) + if (atom instanceof Column) { - columnSerializer.serialize((IColumn)atom, dos); + Column.serializer().serialize((Column)atom, dos); } else { @@ -70,27 +66,20 @@ public interface OnDiskAtom public OnDiskAtom deserializeFromSSTable(DataInput dis, Descriptor.Version version) throws IOException { - return deserializeFromSSTable(dis, IColumnSerializer.Flag.LOCAL, (int)(System.currentTimeMillis() / 1000), version); + return deserializeFromSSTable(dis, ColumnSerializer.Flag.LOCAL, (int)(System.currentTimeMillis() / 1000), version); } - public OnDiskAtom deserializeFromSSTable(DataInput dis, IColumnSerializer.Flag flag, int expireBefore, Descriptor.Version version) throws IOException + public OnDiskAtom deserializeFromSSTable(DataInput dis, ColumnSerializer.Flag flag, int expireBefore, Descriptor.Version version) throws IOException { - if (columnSerializer instanceof SuperColumnSerializer) - { - return columnSerializer.deserialize(dis, flag, expireBefore); - } - else - { - ByteBuffer name = ByteBufferUtil.readWithShortLength(dis); - if (name.remaining() <= 0) - throw ColumnSerializer.CorruptColumnException.create(dis, name); + ByteBuffer name = ByteBufferUtil.readWithShortLength(dis); + if (name.remaining() <= 0) + throw ColumnSerializer.CorruptColumnException.create(dis, name); - int b = dis.readUnsignedByte(); - if ((b & ColumnSerializer.RANGE_TOMBSTONE_MASK) != 0) - return RangeTombstone.serializer.deserializeBody(dis, name, version); - else - return ((ColumnSerializer)columnSerializer).deserializeColumnBody(dis, name, b, flag, expireBefore); - } + int b = dis.readUnsignedByte(); + if ((b & ColumnSerializer.RANGE_TOMBSTONE_MASK) != 0) + return RangeTombstone.serializer.deserializeBody(dis, name, version); + else + return Column.serializer().deserializeColumnBody(dis, name, b, flag, expireBefore); } } } diff --git a/src/java/org/apache/cassandra/db/RangeSliceCommand.java b/src/java/org/apache/cassandra/db/RangeSliceCommand.java index 1748abd9d0..e365b00cae 100644 --- a/src/java/org/apache/cassandra/db/RangeSliceCommand.java +++ b/src/java/org/apache/cassandra/db/RangeSliceCommand.java @@ -49,13 +49,13 @@ import org.apache.cassandra.db.filter.IDiskAtomFilter; import org.apache.cassandra.db.filter.NamesQueryFilter; import org.apache.cassandra.db.filter.SliceQueryFilter; import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.dht.AbstractBounds; import org.apache.cassandra.exceptions.*; import org.apache.cassandra.io.IVersionedSerializer; import org.apache.cassandra.net.MessageOut; import org.apache.cassandra.net.MessagingService; import org.apache.cassandra.service.IReadCommand; -import org.apache.cassandra.thrift.ColumnParent; import org.apache.cassandra.thrift.IndexClause; import org.apache.cassandra.thrift.IndexExpression; import org.apache.cassandra.thrift.IndexOperator; @@ -76,7 +76,6 @@ public class RangeSliceCommand implements IReadCommand public final String keyspace; public final String column_family; - public final ByteBuffer super_column; public final IDiskAtomFilter predicate; public final List row_filter; @@ -86,26 +85,20 @@ public class RangeSliceCommand implements IReadCommand public final boolean countCQL3Rows; public final boolean isPaging; - public RangeSliceCommand(String keyspace, String column_family, ByteBuffer super_column, IDiskAtomFilter predicate, AbstractBounds range, int maxResults) + public RangeSliceCommand(String keyspace, String column_family, IDiskAtomFilter predicate, AbstractBounds range, int maxResults) { - this(keyspace, column_family, super_column, predicate, range, null, maxResults, false, false); + this(keyspace, column_family, predicate, range, null, maxResults, false, false); } - public RangeSliceCommand(String keyspace, ColumnParent column_parent, IDiskAtomFilter predicate, AbstractBounds range, List row_filter, int maxResults) + public RangeSliceCommand(String keyspace, String column_family, IDiskAtomFilter predicate, AbstractBounds range, List row_filter, int maxResults) { - this(keyspace, column_parent.getColumn_family(), column_parent.super_column, predicate, range, row_filter, maxResults, false, false); + this(keyspace, column_family, predicate, range, row_filter, maxResults, false, false); } - public RangeSliceCommand(String keyspace, String column_family, ByteBuffer super_column, IDiskAtomFilter predicate, AbstractBounds range, List row_filter, int maxResults) - { - this(keyspace, column_family, super_column, predicate, range, row_filter, maxResults, false, false); - } - - public RangeSliceCommand(String keyspace, String column_family, ByteBuffer super_column, IDiskAtomFilter predicate, AbstractBounds range, List row_filter, int maxResults, boolean countCQL3Rows, boolean isPaging) + public RangeSliceCommand(String keyspace, String column_family, IDiskAtomFilter predicate, AbstractBounds range, List row_filter, int maxResults, boolean countCQL3Rows, boolean isPaging) { this.keyspace = keyspace; this.column_family = column_family; - this.super_column = super_column; this.predicate = predicate; this.range = range; this.row_filter = row_filter; @@ -125,7 +118,6 @@ public class RangeSliceCommand implements IReadCommand return "RangeSliceCommand{" + "keyspace='" + keyspace + '\'' + ", column_family='" + column_family + '\'' + - ", super_column=" + super_column + ", predicate=" + predicate + ", range=" + range + ", row_filter =" + row_filter + @@ -198,10 +190,26 @@ class RangeSliceCommandSerializer implements IVersionedSerializer 0) - { - byte[] buf = new byte[scLength]; - dis.readFully(buf); - superColumn = ByteBuffer.wrap(buf); - } + CFMetaData metadata = Schema.instance.getCFMetaData(keyspace, columnFamily); IDiskAtomFilter predicate; - AbstractType comparator = ColumnFamily.getComparatorFor(keyspace, columnFamily, superColumn); - if (version < MessagingService.VERSION_12) + if (version < MessagingService.VERSION_20) { - SlicePredicate pred = new SlicePredicate(); - FBUtilities.deserialize(new TDeserializer(new TBinaryProtocol.Factory()), pred, dis); - predicate = ThriftValidation.asIFilter(pred, comparator); + int scLength = dis.readInt(); + ByteBuffer superColumn = null; + if (scLength > 0) + { + byte[] buf = new byte[scLength]; + dis.readFully(buf); + superColumn = ByteBuffer.wrap(buf); + } + + AbstractType comparator; + if (metadata.cfType == ColumnFamilyType.Super) + { + CompositeType type = (CompositeType)metadata.comparator; + comparator = superColumn == null ? type.types.get(0) : type.types.get(1); + } + else + { + comparator = metadata.comparator; + } + + if (version < MessagingService.VERSION_12) + { + SlicePredicate pred = new SlicePredicate(); + FBUtilities.deserialize(new TDeserializer(new TBinaryProtocol.Factory()), pred, dis); + predicate = ThriftValidation.asIFilter(pred, metadata, superColumn); + } + else + { + predicate = IDiskAtomFilter.Serializer.instance.deserialize(dis, version, comparator); + } + + if (metadata.cfType == ColumnFamilyType.Super) + predicate = SuperColumns.fromSCFilter((CompositeType)metadata.comparator, superColumn, predicate); } else { - predicate = IDiskAtomFilter.Serializer.instance.deserialize(dis, version, comparator); + predicate = IDiskAtomFilter.Serializer.instance.deserialize(dis, version, metadata.comparator); } List rowFilter = null; @@ -304,7 +334,7 @@ class RangeSliceCommandSerializer implements IVersionedSerializer= MessagingService.VERSION_11) diff --git a/src/java/org/apache/cassandra/db/RangeTombstone.java b/src/java/org/apache/cassandra/db/RangeTombstone.java index 1d472c37de..bcddfea094 100644 --- a/src/java/org/apache/cassandra/db/RangeTombstone.java +++ b/src/java/org/apache/cassandra/db/RangeTombstone.java @@ -83,9 +83,8 @@ public class RangeTombstone extends Interval implement public void validateFields(CFMetaData metadata) throws MarshalException { - AbstractType nameValidator = metadata.cfType == ColumnFamilyType.Super ? metadata.subcolumnComparator : metadata.comparator; - nameValidator.validate(min); - nameValidator.validate(max); + metadata.comparator.validate(min); + metadata.comparator.validate(max); } public void updateDigest(MessageDigest digest) @@ -192,7 +191,7 @@ public class RangeTombstone extends Interval implement /** * Update this tracker given an {@code atom}. - * If column is a IColumn, check if any tracked range is useless and + * If column is a Column, check if any tracked range is useless and * can be removed. If it is a RangeTombstone, add it to this tracker. */ public void update(OnDiskAtom atom) @@ -219,7 +218,7 @@ public class RangeTombstone extends Interval implement } else { - assert atom instanceof IColumn; + assert atom instanceof Column; Iterator iter = maxOrderingSet.iterator(); while (iter.hasNext()) { @@ -240,7 +239,7 @@ public class RangeTombstone extends Interval implement } } - public boolean isDeleted(IColumn column) + public boolean isDeleted(Column column) { for (RangeTombstone tombstone : ranges) { diff --git a/src/java/org/apache/cassandra/db/ReadCommand.java b/src/java/org/apache/cassandra/db/ReadCommand.java index f3494e5435..8b68d5b45b 100644 --- a/src/java/org/apache/cassandra/db/ReadCommand.java +++ b/src/java/org/apache/cassandra/db/ReadCommand.java @@ -24,10 +24,14 @@ import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; +import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.config.Schema; import org.apache.cassandra.db.filter.IDiskAtomFilter; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.filter.NamesQueryFilter; +import org.apache.cassandra.db.filter.SliceQueryFilter; import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.io.IVersionedSerializer; import org.apache.cassandra.net.MessageOut; import org.apache.cassandra.net.MessagingService; @@ -38,8 +42,22 @@ import org.apache.cassandra.utils.IFilter; public abstract class ReadCommand implements IReadCommand { - public static final byte CMD_TYPE_GET_SLICE_BY_NAMES = 1; - public static final byte CMD_TYPE_GET_SLICE = 2; + public enum Type { + GET_BY_NAMES((byte)1), + GET_SLICES((byte)2); + + public final byte serializedValue; + + private Type(byte b) + { + this.serializedValue = b; + } + + public static Type fromSerializedValue(byte b) + { + return b == 1 ? GET_BY_NAMES : GET_SLICES; + } + } public static final ReadCommandSerializer serializer = new ReadCommandSerializer(); @@ -48,20 +66,28 @@ public abstract class ReadCommand implements IReadCommand return new MessageOut(MessagingService.Verb.READ, this, serializer); } - public final QueryPath queryPath; public final String table; + public final String cfName; public final ByteBuffer key; private boolean isDigestQuery = false; - protected final byte commandType; + protected final Type commandType; - protected ReadCommand(String table, ByteBuffer key, QueryPath queryPath, byte cmdType) + protected ReadCommand(String table, ByteBuffer key, String cfName, Type cmdType) { this.table = table; this.key = key; - this.queryPath = queryPath; + this.cfName = cfName; this.commandType = cmdType; } + public static ReadCommand create(String table, ByteBuffer key, String cfName, IDiskAtomFilter filter) + { + if (filter instanceof SliceQueryFilter) + return new SliceFromReadCommand(table, key, cfName, (SliceQueryFilter)filter); + else + return new SliceByNamesReadCommand(table, key, cfName, (NamesQueryFilter)filter); + } + public boolean isDigestQuery() { return isDigestQuery; @@ -74,7 +100,7 @@ public abstract class ReadCommand implements IReadCommand public String getColumnFamilyName() { - return queryPath.columnFamilyName; + return cfName; } public abstract ReadCommand copy(); @@ -83,11 +109,6 @@ public abstract class ReadCommand implements IReadCommand public abstract IDiskAtomFilter filter(); - protected AbstractType getComparator() - { - return ColumnFamily.getComparatorFor(table, getColumnFamilyName(), queryPath.superColumnName); - } - public String getKeyspace() { return table; @@ -113,28 +134,77 @@ public abstract class ReadCommand implements IReadCommand class ReadCommandSerializer implements IVersionedSerializer { - private static final Map> CMD_SERIALIZER_MAP = new HashMap>(); - static - { - CMD_SERIALIZER_MAP.put(ReadCommand.CMD_TYPE_GET_SLICE_BY_NAMES, new SliceByNamesReadCommandSerializer()); - CMD_SERIALIZER_MAP.put(ReadCommand.CMD_TYPE_GET_SLICE, new SliceFromReadCommandSerializer()); - } - - public void serialize(ReadCommand command, DataOutput dos, int version) throws IOException { - dos.writeByte(command.commandType); - CMD_SERIALIZER_MAP.get(command.commandType).serialize(command, dos, version); + // For super columns, when talking to an older node, we need to translate the filter used. + // That translation can change the filter type (names -> slice), and so change the command type. + // Hence we need to detect that early on, before we've written the command type. + ReadCommand newCommand = command; + ByteBuffer superColumn = null; + if (version < MessagingService.VERSION_20) + { + CFMetaData metadata = Schema.instance.getCFMetaData(command.table, command.cfName); + if (metadata.cfType == ColumnFamilyType.Super) + { + SuperColumns.SCFilter scFilter = SuperColumns.filterToSC((CompositeType)metadata.comparator, command.filter()); + newCommand = ReadCommand.create(command.table, command.key, command.cfName, scFilter.updatedFilter); + newCommand.setDigestQuery(command.isDigestQuery()); + superColumn = scFilter.scName; + } + } + + dos.writeByte(newCommand.commandType.serializedValue); + switch (command.commandType) + { + case GET_BY_NAMES: + SliceByNamesReadCommand.serializer.serialize(newCommand, superColumn, dos, version); + break; + case GET_SLICES: + SliceFromReadCommand.serializer.serialize(newCommand, superColumn, dos, version); + break; + default: + throw new AssertionError(); + } } public ReadCommand deserialize(DataInput dis, int version) throws IOException { - byte msgType = dis.readByte(); - return CMD_SERIALIZER_MAP.get(msgType).deserialize(dis, version); + ReadCommand.Type msgType = ReadCommand.Type.fromSerializedValue(dis.readByte()); + switch (msgType) + { + case GET_BY_NAMES: + return SliceByNamesReadCommand.serializer.deserialize(dis, version); + case GET_SLICES: + return SliceFromReadCommand.serializer.deserialize(dis, version); + default: + throw new AssertionError(); + } } public long serializedSize(ReadCommand command, int version) { - return 1 + CMD_SERIALIZER_MAP.get(command.commandType).serializedSize(command, version); + ReadCommand newCommand = command; + ByteBuffer superColumn = null; + if (version < MessagingService.VERSION_20) + { + CFMetaData metadata = Schema.instance.getCFMetaData(command.table, command.cfName); + if (metadata.cfType == ColumnFamilyType.Super) + { + SuperColumns.SCFilter scFilter = SuperColumns.filterToSC((CompositeType)metadata.comparator, command.filter()); + newCommand = ReadCommand.create(command.table, command.key, command.cfName, scFilter.updatedFilter); + newCommand.setDigestQuery(command.isDigestQuery()); + superColumn = scFilter.scName; + } + } + + switch (command.commandType) + { + case GET_BY_NAMES: + return 1 + SliceByNamesReadCommand.serializer.serializedSize(newCommand, superColumn, version); + case GET_SLICES: + return 1 + SliceFromReadCommand.serializer.serializedSize(newCommand, superColumn, version); + default: + throw new AssertionError(); + } } } diff --git a/src/java/org/apache/cassandra/db/ReadResponse.java b/src/java/org/apache/cassandra/db/ReadResponse.java index 1f21006f45..95f36e32da 100644 --- a/src/java/org/apache/cassandra/db/ReadResponse.java +++ b/src/java/org/apache/cassandra/db/ReadResponse.java @@ -20,7 +20,6 @@ package org.apache.cassandra.db; import java.io.*; import java.nio.ByteBuffer; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.IVersionedSerializer; import org.apache.cassandra.utils.ByteBufferUtil; @@ -94,7 +93,7 @@ class ReadResponseSerializer implements IVersionedSerializer if (!isDigest) { // This is coming from a remote host - row = Row.serializer.deserialize(dis, version, IColumnSerializer.Flag.FROM_REMOTE, ArrayBackedSortedColumns.factory()); + row = Row.serializer.deserialize(dis, version, ColumnSerializer.Flag.FROM_REMOTE, ArrayBackedSortedColumns.factory()); } return isDigest ? new ReadResponse(ByteBuffer.wrap(digest)) : new ReadResponse(row); diff --git a/src/java/org/apache/cassandra/db/RetriedSliceFromReadCommand.java b/src/java/org/apache/cassandra/db/RetriedSliceFromReadCommand.java index e7e99feba4..b9484607b7 100644 --- a/src/java/org/apache/cassandra/db/RetriedSliceFromReadCommand.java +++ b/src/java/org/apache/cassandra/db/RetriedSliceFromReadCommand.java @@ -29,21 +29,16 @@ public class RetriedSliceFromReadCommand extends SliceFromReadCommand static final Logger logger = LoggerFactory.getLogger(RetriedSliceFromReadCommand.class); public final int originalCount; - public RetriedSliceFromReadCommand(String table, ByteBuffer key, ColumnParent column_parent, SliceQueryFilter filter, int originalCount) + public RetriedSliceFromReadCommand(String table, ByteBuffer key, String cfName, SliceQueryFilter filter, int originalCount) { - this(table, key, new QueryPath(column_parent), filter, originalCount); - } - - public RetriedSliceFromReadCommand(String table, ByteBuffer key, QueryPath path, SliceQueryFilter filter, int originalCount) - { - super(table, key, path, filter); + super(table, key, cfName, filter); this.originalCount = originalCount; } @Override public ReadCommand copy() { - ReadCommand readCommand = new RetriedSliceFromReadCommand(table, key, queryPath, filter, originalCount); + ReadCommand readCommand = new RetriedSliceFromReadCommand(table, key, cfName, filter, originalCount); readCommand.setDigestQuery(isDigestQuery()); return readCommand; } diff --git a/src/java/org/apache/cassandra/db/Row.java b/src/java/org/apache/cassandra/db/Row.java index 74cd906106..54c5efe382 100644 --- a/src/java/org/apache/cassandra/db/Row.java +++ b/src/java/org/apache/cassandra/db/Row.java @@ -20,7 +20,6 @@ package org.apache.cassandra.db; import java.io.*; import org.apache.cassandra.db.filter.IDiskAtomFilter; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.IVersionedSerializer; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.ByteBufferUtil; @@ -62,7 +61,7 @@ public class Row ColumnFamily.serializer.serialize(row.cf, dos, version); } - public Row deserialize(DataInput dis, int version, IColumnSerializer.Flag flag, ISortedColumns.Factory factory) throws IOException + public Row deserialize(DataInput dis, int version, ColumnSerializer.Flag flag, ISortedColumns.Factory factory) throws IOException { return new Row(StorageService.getPartitioner().decorateKey(ByteBufferUtil.readWithShortLength(dis)), ColumnFamily.serializer.deserialize(dis, flag, factory, version)); @@ -70,7 +69,7 @@ public class Row public Row deserialize(DataInput dis, int version) throws IOException { - return deserialize(dis, version, IColumnSerializer.Flag.LOCAL, TreeMapBackedSortedColumns.factory()); + return deserialize(dis, version, ColumnSerializer.Flag.LOCAL, TreeMapBackedSortedColumns.factory()); } public long serializedSize(Row row, int version) diff --git a/src/java/org/apache/cassandra/db/RowIteratorFactory.java b/src/java/org/apache/cassandra/db/RowIteratorFactory.java index 937c496e63..38d0fc14d1 100644 --- a/src/java/org/apache/cassandra/db/RowIteratorFactory.java +++ b/src/java/org/apache/cassandra/db/RowIteratorFactory.java @@ -107,7 +107,7 @@ public class RowIteratorFactory } else { - QueryFilter keyFilter = new QueryFilter(key, filter.path, filter.filter); + QueryFilter keyFilter = new QueryFilter(key, filter.cfName, filter.filter); returnCF = cfs.filterColumnFamily(cached, keyFilter, gcBefore); } diff --git a/src/java/org/apache/cassandra/db/RowMutation.java b/src/java/org/apache/cassandra/db/RowMutation.java index b4666b5869..7ad31005e9 100644 --- a/src/java/org/apache/cassandra/db/RowMutation.java +++ b/src/java/org/apache/cassandra/db/RowMutation.java @@ -29,9 +29,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.KSMetaData; import org.apache.cassandra.config.Schema; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.UUIDType; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.IVersionedSerializer; import org.apache.cassandra.io.util.FastByteArrayInputStream; import org.apache.cassandra.net.MessageOut; @@ -115,8 +113,9 @@ public class RowMutation implements IMutation ttl = Math.min(ttl, cf.metadata().getGcGraceSeconds()); // serialize the hint with id and version as a composite column name - QueryPath path = new QueryPath(SystemTable.HINTS_CF, null, HintedHandOffManager.comparator.decompose(hintId, MessagingService.current_version)); - rm.add(path, ByteBuffer.wrap(mutation.getSerializedBuffer(MessagingService.current_version)), System.currentTimeMillis(), ttl); + ByteBuffer name = HintedHandOffManager.comparator.decompose(hintId, MessagingService.current_version); + ByteBuffer value = ByteBuffer.wrap(mutation.getSerializedBuffer(MessagingService.current_version)); + rm.add(SystemTable.HINTS_CF, name, value, System.currentTimeMillis(), ttl); return rm; } @@ -156,81 +155,37 @@ public class RowMutation implements IMutation return modifications.isEmpty(); } - /* - * Specify a column name and a corresponding value for - * the column. Column name is specified as :column. - * This will result in a ColumnFamily associated with - * as name and a Column with - * as name. The column can be further broken up - * as super column name : columnname in case of super columns - * - * param @ cf - column name as : - * param @ value - value associated with the column - * param @ timestamp - timestamp associated with this data. - * param @ timeToLive - ttl for the column, 0 for standard (non expiring) columns - * - * @Deprecated this tends to be low-performance; we're doing two hash lookups, - * one of which instantiates a Pair, and callers tend to instantiate new QP objects - * for each call as well. Use the add(ColumnFamily) overload instead. - */ - public void add(QueryPath path, ByteBuffer value, long timestamp, int timeToLive) + public void add(String cfName, ByteBuffer name, ByteBuffer value, long timestamp, int timeToLive) { - UUID id = Schema.instance.getId(table, path.columnFamilyName); - ColumnFamily columnFamily = modifications.get(id); - - if (columnFamily == null) - { - columnFamily = ColumnFamily.create(table, path.columnFamilyName); - modifications.put(id, columnFamily); - } - columnFamily.addColumn(path, value, timestamp, timeToLive); + addOrGet(cfName).addColumn(name, value, timestamp, timeToLive); } - public void addCounter(QueryPath path, long value) + public void addCounter(String cfName, ByteBuffer name, long value) { - UUID id = Schema.instance.getId(table, path.columnFamilyName); - ColumnFamily columnFamily = modifications.get(id); - - if (columnFamily == null) - { - columnFamily = ColumnFamily.create(table, path.columnFamilyName); - modifications.put(id, columnFamily); - } - columnFamily.addCounter(path, value); + addOrGet(cfName).addCounter(name, value); } - public void add(QueryPath path, ByteBuffer value, long timestamp) + public void add(String cfName, ByteBuffer name, ByteBuffer value, long timestamp) { - add(path, value, timestamp, 0); + add(cfName, name, value, timestamp, 0); } - public void delete(QueryPath path, long timestamp) + public void delete(String cfName, long timestamp) { - UUID id = Schema.instance.getId(table, path.columnFamilyName); - int localDeleteTime = (int) (System.currentTimeMillis() / 1000); + addOrGet(cfName).delete(new DeletionInfo(timestamp, localDeleteTime)); + } - ColumnFamily columnFamily = modifications.get(id); - if (columnFamily == null) - { - columnFamily = ColumnFamily.create(table, path.columnFamilyName); - modifications.put(id, columnFamily); - } + public void delete(String cfName, ByteBuffer name, long timestamp) + { + int localDeleteTime = (int) (System.currentTimeMillis() / 1000); + addOrGet(cfName).addTombstone(name, localDeleteTime, timestamp); + } - if (path.superColumnName == null && path.columnName == null) - { - columnFamily.delete(new DeletionInfo(timestamp, localDeleteTime)); - } - else if (path.columnName == null) - { - SuperColumn sc = new SuperColumn(path.superColumnName, columnFamily.getSubComparator()); - sc.delete(new DeletionInfo(timestamp, localDeleteTime)); - columnFamily.addColumn(sc); - } - else - { - columnFamily.addTombstone(path, localDeleteTime, timestamp); - } + public void deleteRange(String cfName, ByteBuffer start, ByteBuffer end, long timestamp) + { + int localDeleteTime = (int) (System.currentTimeMillis() / 1000); + addOrGet(cfName).addAtom(new RangeTombstone(start, end, timestamp, localDeleteTime)); } public void addAll(IMutation m) @@ -314,49 +269,6 @@ public class RowMutation implements IMutation return buff.append("])").toString(); } - public void addColumnOrSuperColumn(String cfName, ColumnOrSuperColumn cosc) - { - if (cosc.super_column != null) - { - for (org.apache.cassandra.thrift.Column column : cosc.super_column.columns) - { - add(new QueryPath(cfName, cosc.super_column.name, column.name), column.value, column.timestamp, column.ttl); - } - } - else if (cosc.column != null) - { - add(new QueryPath(cfName, null, cosc.column.name), cosc.column.value, cosc.column.timestamp, cosc.column.ttl); - } - else if (cosc.counter_super_column != null) - { - for (org.apache.cassandra.thrift.CounterColumn column : cosc.counter_super_column.columns) - { - addCounter(new QueryPath(cfName, cosc.counter_super_column.name, column.name), column.value); - } - } - else // cosc.counter_column != null - { - addCounter(new QueryPath(cfName, null, cosc.counter_column.name), cosc.counter_column.value); - } - } - - public void deleteColumnOrSuperColumn(String cfName, Deletion del) - { - if (del.predicate != null && del.predicate.column_names != null) - { - for(ByteBuffer c : del.predicate.column_names) - { - if (del.super_column == null && Schema.instance.getColumnFamilyType(table, cfName) == ColumnFamilyType.Super) - delete(new QueryPath(cfName, c), del.timestamp); - else - delete(new QueryPath(cfName, del.super_column, c), del.timestamp); - } - } - else - { - delete(new QueryPath(cfName, del.super_column), del.timestamp); - } - } public static RowMutation fromBytes(byte[] raw, int version) throws IOException { @@ -396,7 +308,7 @@ public class RowMutation implements IMutation } } - public RowMutation deserialize(DataInput dis, int version, IColumnSerializer.Flag flag) throws IOException + public RowMutation deserialize(DataInput dis, int version, ColumnSerializer.Flag flag) throws IOException { String table = dis.readUTF(); ByteBuffer key = ByteBufferUtil.readWithShortLength(dis); @@ -417,7 +329,7 @@ public class RowMutation implements IMutation public RowMutation deserialize(DataInput dis, int version) throws IOException { - return deserialize(dis, version, IColumnSerializer.Flag.FROM_REMOTE); + return deserialize(dis, version, ColumnSerializer.Flag.FROM_REMOTE); } public long serializedSize(RowMutation rm, int version) diff --git a/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java b/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java index 2b3b0b12ec..0273cbc92d 100644 --- a/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java +++ b/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java @@ -21,39 +21,31 @@ import java.io.*; import java.nio.ByteBuffer; import java.util.*; +import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.config.Schema; import org.apache.cassandra.db.filter.*; import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.io.IVersionedSerializer; +import org.apache.cassandra.net.MessagingService; import org.apache.cassandra.service.StorageService; -import org.apache.cassandra.thrift.ColumnParent; import org.apache.cassandra.utils.ByteBufferUtil; public class SliceByNamesReadCommand extends ReadCommand { + static final SliceByNamesReadCommandSerializer serializer = new SliceByNamesReadCommandSerializer(); + public final NamesQueryFilter filter; - public SliceByNamesReadCommand(String table, ByteBuffer key, ColumnParent column_parent, Collection columnNames) + public SliceByNamesReadCommand(String table, ByteBuffer key, String cfName, NamesQueryFilter filter) { - this(table, key, new QueryPath(column_parent), columnNames); - } - - public SliceByNamesReadCommand(String table, ByteBuffer key, QueryPath path, Collection columnNames) - { - super(table, key, path, CMD_TYPE_GET_SLICE_BY_NAMES); - SortedSet s = new TreeSet(getComparator()); - s.addAll(columnNames); - this.filter = new NamesQueryFilter(s); - } - - public SliceByNamesReadCommand(String table, ByteBuffer key, QueryPath path, NamesQueryFilter filter) - { - super(table, key, path, CMD_TYPE_GET_SLICE_BY_NAMES); + super(table, key, cfName, Type.GET_BY_NAMES); this.filter = filter; } public ReadCommand copy() { - ReadCommand readCommand= new SliceByNamesReadCommand(table, key, queryPath, filter); + ReadCommand readCommand= new SliceByNamesReadCommand(table, key, cfName, filter); readCommand.setDigestQuery(isDigestQuery()); return readCommand; } @@ -61,7 +53,7 @@ public class SliceByNamesReadCommand extends ReadCommand public Row getRow(Table table) throws IOException { DecoratedKey dk = StorageService.getPartitioner().decorateKey(key); - return table.getRow(new QueryFilter(dk, queryPath, filter)); + return table.getRow(new QueryFilter(dk, cfName, filter)); } @Override @@ -70,7 +62,7 @@ public class SliceByNamesReadCommand extends ReadCommand return "SliceByNamesReadCommand(" + "table='" + table + '\'' + ", key=" + ByteBufferUtil.bytesToHex(key) + - ", columnParent='" + queryPath + '\'' + + ", cfName='" + cfName + '\'' + ", filter=" + filter + ')'; } @@ -84,30 +76,86 @@ public class SliceByNamesReadCommand extends ReadCommand class SliceByNamesReadCommandSerializer implements IVersionedSerializer { public void serialize(ReadCommand cmd, DataOutput dos, int version) throws IOException + { + serialize(cmd, null, dos, version); + } + + public void serialize(ReadCommand cmd, ByteBuffer superColumn, DataOutput dos, int version) throws IOException { SliceByNamesReadCommand command = (SliceByNamesReadCommand) cmd; dos.writeBoolean(command.isDigestQuery()); dos.writeUTF(command.table); ByteBufferUtil.writeWithShortLength(command.key, dos); - command.queryPath.serialize(dos); + + if (version < MessagingService.VERSION_20) + new QueryPath(command.cfName, superColumn).serialize(dos); + else + dos.writeUTF(command.cfName); + NamesQueryFilter.serializer.serialize(command.filter, dos, version); } - public SliceByNamesReadCommand deserialize(DataInput dis, int version) throws IOException + public ReadCommand deserialize(DataInput dis, int version) throws IOException { boolean isDigest = dis.readBoolean(); String table = dis.readUTF(); ByteBuffer key = ByteBufferUtil.readWithShortLength(dis); - QueryPath columnParent = QueryPath.deserialize(dis); - AbstractType comparator = ColumnFamily.getComparatorFor(table, columnParent.columnFamilyName, columnParent.superColumnName); - NamesQueryFilter filter = NamesQueryFilter.serializer.deserialize(dis, version, comparator); - SliceByNamesReadCommand command = new SliceByNamesReadCommand(table, key, columnParent, filter); + String cfName; + ByteBuffer sc = null; + if (version < MessagingService.VERSION_20) + { + QueryPath path = QueryPath.deserialize(dis); + cfName = path.columnFamilyName; + sc = path.superColumnName; + } + else + { + cfName = dis.readUTF(); + } + + CFMetaData metadata = Schema.instance.getCFMetaData(table, cfName); + ReadCommand command; + if (version < MessagingService.VERSION_20) + { + AbstractType comparator; + if (metadata.cfType == ColumnFamilyType.Super) + { + CompositeType type = (CompositeType)metadata.comparator; + comparator = sc == null ? type.types.get(0) : type.types.get(1); + } + else + { + comparator = metadata.comparator; + } + + IDiskAtomFilter filter = NamesQueryFilter.serializer.deserialize(dis, version, comparator); + + if (metadata.cfType == ColumnFamilyType.Super) + filter = SuperColumns.fromSCFilter((CompositeType)metadata.comparator, sc, filter); + + // Due to SC compat, it's possible we get back a slice filter at this point + if (filter instanceof NamesQueryFilter) + command = new SliceByNamesReadCommand(table, key, cfName, (NamesQueryFilter)filter); + else + command = new SliceFromReadCommand(table, key, cfName, (SliceQueryFilter)filter); + } + else + { + NamesQueryFilter filter = NamesQueryFilter.serializer.deserialize(dis, version, metadata.comparator); + command = new SliceByNamesReadCommand(table, key, cfName, filter); + } + command.setDigestQuery(isDigest); return command; } public long serializedSize(ReadCommand cmd, int version) + { + return serializedSize(cmd, null, version); + } + + public long serializedSize(ReadCommand cmd, ByteBuffer superColumn, int version) { TypeSizes sizes = TypeSizes.NATIVE; SliceByNamesReadCommand command = (SliceByNamesReadCommand) cmd; @@ -116,7 +164,16 @@ class SliceByNamesReadCommandSerializer implements IVersionedSerializer { public void serialize(ReadCommand rm, DataOutput dos, int version) throws IOException + { + serialize(rm, null, dos, version); + } + + public void serialize(ReadCommand rm, ByteBuffer superColumn, DataOutput dos, int version) throws IOException { SliceFromReadCommand realRM = (SliceFromReadCommand)rm; dos.writeBoolean(realRM.isDigestQuery()); dos.writeUTF(realRM.table); ByteBufferUtil.writeWithShortLength(realRM.key, dos); - realRM.queryPath.serialize(dos); + + if (version < MessagingService.VERSION_20) + new QueryPath(realRM.cfName, superColumn).serialize(dos); + else + dos.writeUTF(realRM.cfName); + SliceQueryFilter.serializer.serialize(realRM.filter, dos, version); } @@ -150,14 +156,45 @@ class SliceFromReadCommandSerializer implements IVersionedSerializer if (exhausted) return null; - QueryPath path = new QueryPath(cfs.name); SliceQueryFilter sliceFilter = new SliceQueryFilter(slices, false, DEFAULT_PAGE_SIZE); - QueryFilter filter = new QueryFilter(key, path, sliceFilter); + QueryFilter filter = new QueryFilter(key, cfs.name, sliceFilter); ColumnFamily cf = cfs.getColumnFamily(filter); if (cf == null || sliceFilter.getLiveCount(cf) < DEFAULT_PAGE_SIZE) { @@ -61,8 +60,8 @@ public class SliceQueryPager implements Iterator } else { - Iterator iter = cf.getReverseSortedColumns().iterator(); - IColumn lastColumn = iter.next(); + Iterator iter = cf.getReverseSortedColumns().iterator(); + Column lastColumn = iter.next(); while (lastColumn.isMarkedForDelete()) lastColumn = iter.next(); diff --git a/src/java/org/apache/cassandra/db/SuperColumn.java b/src/java/org/apache/cassandra/db/SuperColumn.java deleted file mode 100644 index 57e87c4ede..0000000000 --- a/src/java/org/apache/cassandra/db/SuperColumn.java +++ /dev/null @@ -1,432 +0,0 @@ -/* - * 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.db; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.security.MessageDigest; -import java.util.Collection; -import java.util.Comparator; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; - -import org.apache.cassandra.config.CFMetaData; -import org.apache.cassandra.db.marshal.AbstractType; -import org.apache.cassandra.db.marshal.MarshalException; -import org.apache.cassandra.io.IColumnSerializer; -import org.apache.cassandra.io.util.ColumnSortedMap; -import org.apache.cassandra.io.util.DataOutputBuffer; -import org.apache.cassandra.net.MessagingService; -import org.apache.cassandra.utils.Allocator; -import org.apache.cassandra.utils.ByteBufferUtil; -import org.apache.cassandra.utils.HeapAllocator; -import org.cliffc.high_scale_lib.NonBlockingHashMap; - -public class SuperColumn extends AbstractColumnContainer implements IColumn -{ - private static final NonBlockingHashMap serializers = new NonBlockingHashMap(); - public static SuperColumnSerializer serializer(AbstractType comparator) - { - SuperColumnSerializer serializer = serializers.get(comparator); - if (serializer == null) - { - serializer = new SuperColumnSerializer(comparator); - serializers.put(comparator, serializer); - } - return serializer; - } - - public static OnDiskAtom.Serializer onDiskSerializer(AbstractType comparator) - { - return new OnDiskAtom.Serializer(serializer(comparator)); - } - - private final ByteBuffer name; - - public SuperColumn(ByteBuffer name, AbstractType comparator) - { - this(name, AtomicSortedColumns.factory().create(comparator, false)); - } - - SuperColumn(ByteBuffer name, ISortedColumns columns) - { - super(columns); - assert name != null; - assert name.remaining() <= IColumn.MAX_NAME_LENGTH; - this.name = name; - } - - public SuperColumn cloneMeShallow() - { - SuperColumn sc = new SuperColumn(name, getComparator()); - sc.delete(this); - return sc; - } - - public IColumn cloneMe() - { - SuperColumn sc = new SuperColumn(name, columns.cloneMe()); - sc.delete(this); - return sc; - } - - public ByteBuffer name() - { - return name; - } - - public Collection getSubColumns() - { - return getSortedColumns(); - } - - public IColumn getSubColumn(ByteBuffer columnName) - { - IColumn column = columns.getColumn(columnName); - assert column == null || column instanceof Column; - return column; - } - - /** - * This calculates the exact size of the sub columns on the fly - */ - public int dataSize() - { - int size = TypeSizes.NATIVE.sizeof(getMarkedForDeleteAt()); - for (IColumn subColumn : getSubColumns()) - size += subColumn.dataSize(); - return size; - } - - /** - * This returns the size of the super-column when serialized. - * @see org.apache.cassandra.db.IColumn#serializedSize(TypeSizes) - */ - public int serializedSize(TypeSizes typeSizes) - { - /* - * We need to keep the way we are calculating the column size in sync with the - * way we are calculating the size for the column family serializer. - * - * 2 bytes for name size - * n bytes for the name - * 4 bytes for getLocalDeletionTime - * 8 bytes for getMarkedForDeleteAt - * 4 bytes for the subcolumns size - * size(constantSize) of subcolumns. - */ - int nameSize = name.remaining(); - int subColumnsSize = 0; - for (IColumn subColumn : getSubColumns()) - subColumnsSize += subColumn.serializedSize(typeSizes); - int size = typeSizes.sizeof((short) nameSize) + nameSize - + typeSizes.sizeof(getLocalDeletionTime()) - + typeSizes.sizeof(getMarkedForDeleteAt()) - + typeSizes.sizeof(subColumnsSize) + subColumnsSize; - return size; - } - - public long serializedSizeForSSTable() - { - return serializedSize(TypeSizes.NATIVE); - } - - public long timestamp() - { - throw new UnsupportedOperationException("This operation is not supported for Super Columns."); - } - - public long minTimestamp() - { - long minTimestamp = getMarkedForDeleteAt(); - for (IColumn subColumn : getSubColumns()) - minTimestamp = Math.min(minTimestamp, subColumn.minTimestamp()); - return minTimestamp; - } - - public long maxTimestamp() - { - long maxTimestamp = getMarkedForDeleteAt(); - for (IColumn subColumn : getSubColumns()) - maxTimestamp = Math.max(maxTimestamp, subColumn.maxTimestamp()); - return maxTimestamp; - } - - public long mostRecentLiveChangeAt() - { - long max = Long.MIN_VALUE; - for (IColumn column : getSubColumns()) - { - if (!column.isMarkedForDelete() && column.timestamp() > max) - { - max = column.timestamp(); - } - } - return max; - } - - public long getMarkedForDeleteAt() - { - return deletionInfo().getTopLevelDeletion().markedForDeleteAt; - } - - public int getLocalDeletionTime() - { - return deletionInfo().getTopLevelDeletion().localDeletionTime; - } - - public long mostRecentNonGCableChangeAt(int gcbefore) - { - long max = Long.MIN_VALUE; - for (IColumn column : getSubColumns()) - { - if (column.getLocalDeletionTime() >= gcbefore && column.timestamp() > max) - { - max = column.timestamp(); - } - } - return max; - } - - public ByteBuffer value() - { - throw new UnsupportedOperationException("This operation is not supported for Super Columns."); - } - - @Override - public void addColumn(IColumn column, Allocator allocator) - { - assert column instanceof Column : "A super column can only contain simple columns"; - super.addColumn(column, allocator); - } - - /* - * Go through each sub column if it exists then as it to resolve itself - * if the column does not exist then create it. - */ - void putColumn(SuperColumn column, Allocator allocator) - { - for (IColumn subColumn : column.getSubColumns()) - { - addColumn(subColumn, allocator); - } - delete(column); - } - - public IColumn diff(IColumn columnNew) - { - IColumn columnDiff = new SuperColumn(columnNew.name(), ((SuperColumn)columnNew).getComparator()); - ((SuperColumn)columnDiff).delete(((SuperColumn)columnNew).deletionInfo()); - - // (don't need to worry about columnNew containing subColumns that are shadowed by - // the delete tombstone, since columnNew was generated by CF.resolve, which - // takes care of those for us.) - for (IColumn subColumn : columnNew.getSubColumns()) - { - IColumn columnInternal = columns.getColumn(subColumn.name()); - if(columnInternal == null ) - { - columnDiff.addColumn(subColumn); - } - else - { - IColumn subColumnDiff = columnInternal.diff(subColumn); - if(subColumnDiff != null) - { - columnDiff.addColumn(subColumnDiff); - } - } - } - - if (!columnDiff.getSubColumns().isEmpty() || columnNew.isMarkedForDelete()) - return columnDiff; - else - return null; - } - - public void updateDigest(MessageDigest digest) - { - assert name != null; - digest.update(name.duplicate()); - DataOutputBuffer buffer = new DataOutputBuffer(); - try - { - buffer.writeLong(getMarkedForDeleteAt()); - } - catch (IOException e) - { - throw new RuntimeException(e); - } - digest.update(buffer.getData(), 0, buffer.getLength()); - for (IColumn column : getSubColumns()) - { - column.updateDigest(digest); - } - } - - public String getString(AbstractType comparator) - { - StringBuilder sb = new StringBuilder(); - sb.append("SuperColumn("); - sb.append(comparator.getString(name)); - - if (isMarkedForDelete()) { - sb.append(" -delete at ").append(getMarkedForDeleteAt()).append("-"); - } - - sb.append(" ["); - sb.append(getComparator().getColumnsString(getSubColumns())); - sb.append("])"); - - return sb.toString(); - } - - public boolean isLive() - { - return mostRecentLiveChangeAt() > getMarkedForDeleteAt(); - } - - public IColumn localCopy(ColumnFamilyStore cfs) - { - return localCopy(cfs, HeapAllocator.instance); - } - - public IColumn localCopy(ColumnFamilyStore cfs, Allocator allocator) - { - // we don't try to intern supercolumn names, because if we're using Cassandra correctly it's almost - // certainly just going to pollute our interning map with unique, dynamic values - SuperColumn sc = new SuperColumn(allocator.clone(name), this.getComparator()); - sc.delete(this); - - for(IColumn c : columns) - { - sc.addColumn(c.localCopy(cfs, allocator)); - } - - return sc; - } - - public IColumn reconcile(IColumn c) - { - return reconcile(null, null); - } - - public IColumn reconcile(IColumn c, Allocator allocator) - { - throw new UnsupportedOperationException("This operation is unsupported on super columns."); - } - - public int serializationFlags() - { - throw new UnsupportedOperationException("Super columns don't have a serialization mask"); - } - - public void validateFields(CFMetaData metadata) throws MarshalException - { - metadata.comparator.validate(name()); - for (IColumn column : getSubColumns()) - { - column.validateFields(metadata); - } - } - - @Override - public boolean equals(Object o) - { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - SuperColumn sc = (SuperColumn)o; - - if (!name.equals(sc.name)) - return false; - if (getMarkedForDeleteAt() != sc.getMarkedForDeleteAt()) - return false; - if (getLocalDeletionTime() != sc.getLocalDeletionTime()) - return false; - return Iterables.elementsEqual(columns, sc.columns); - } - - @Override - public int hashCode() - { - return Objects.hashCode(name, getMarkedForDeleteAt(), getLocalDeletionTime(), columns); - } -} - -class SuperColumnSerializer implements IColumnSerializer -{ - private final AbstractType comparator; - - public SuperColumnSerializer(AbstractType comparator) - { - this.comparator = comparator; - } - - public AbstractType getComparator() - { - return comparator; - } - - public void serialize(IColumn column, DataOutput dos) throws IOException - { - SuperColumn superColumn = (SuperColumn)column; - ByteBufferUtil.writeWithShortLength(superColumn.name(), dos); - DeletionInfo.serializer().serialize(superColumn.deletionInfo(), dos, MessagingService.VERSION_10); - Collection columns = superColumn.getSubColumns(); - dos.writeInt(columns.size()); - for (IColumn subColumn : columns) - { - Column.serializer().serialize(subColumn, dos); - } - } - - public IColumn deserialize(DataInput dis) throws IOException - { - return deserialize(dis, IColumnSerializer.Flag.LOCAL); - } - - public IColumn deserialize(DataInput dis, IColumnSerializer.Flag flag) throws IOException - { - return deserialize(dis, flag, (int)(System.currentTimeMillis() / 1000)); - } - - public IColumn deserialize(DataInput dis, IColumnSerializer.Flag flag, int expireBefore) throws IOException - { - ByteBuffer name = ByteBufferUtil.readWithShortLength(dis); - DeletionInfo delInfo = DeletionInfo.serializer().deserialize(dis, MessagingService.VERSION_10, comparator); - - /* read the number of columns */ - int size = dis.readInt(); - ColumnSerializer serializer = Column.serializer(); - ColumnSortedMap preSortedMap = new ColumnSortedMap(comparator, serializer, dis, size, flag, expireBefore); - SuperColumn superColumn = new SuperColumn(name, AtomicSortedColumns.factory().fromSorted(preSortedMap, false)); - superColumn.delete(delInfo); - return superColumn; - } - - public long serializedSize(IColumn object, TypeSizes typeSizes) - { - return object.serializedSize(typeSizes); - } -} diff --git a/src/java/org/apache/cassandra/db/SuperColumns.java b/src/java/org/apache/cassandra/db/SuperColumns.java new file mode 100644 index 0000000000..c45f9f47f9 --- /dev/null +++ b/src/java/org/apache/cassandra/db/SuperColumns.java @@ -0,0 +1,442 @@ +/* + * 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.db; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOError; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.db.filter.*; +import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.CompositeType; +import org.apache.cassandra.io.sstable.Descriptor; +import org.apache.cassandra.net.MessagingService; +import org.apache.cassandra.utils.ByteBufferUtil; + +public class SuperColumns +{ + public static Iterator onDiskIterator(DataInput dis, int superColumnCount, ColumnSerializer.Flag flag, int expireBefore) + { + return new SCIterator(dis, superColumnCount, flag, expireBefore); + } + + public static void serializeSuperColumnFamily(ColumnFamily scf, DataOutput dos, int version) throws IOException + { + /* + * There is 2 complications: + * 1) We need to know the number of super columns in the column + * family to write in the header (so we do a first pass to group + * columns before serializing). + * 2) For deletion infos, we need to figure out which are top-level + * deletions and which are super columns deletions (i.e. the + * subcolumns range deletions). + */ + DeletionInfo delInfo = scf.deletionInfo(); + Map> scMap = groupSuperColumns(scf); + + // Actually Serialize + DeletionInfo.serializer().serialize(new DeletionInfo(delInfo.getTopLevelDeletion()), dos, version); + dos.writeInt(scMap.size()); + + for (Map.Entry> entry : scMap.entrySet()) + { + ByteBufferUtil.writeWithShortLength(entry.getKey(), dos); + + List delTimes = delInfo.rangeCovering(entry.getKey()); + assert delTimes.size() <= 1; // We're supposed to have either no deletion, or a full SC deletion. + DeletionInfo scDelInfo = delTimes.isEmpty() ? DeletionInfo.LIVE : new DeletionInfo(delTimes.get(0)); + DeletionInfo.serializer().serialize(scDelInfo, dos, MessagingService.VERSION_10); + + dos.writeInt(entry.getValue().size()); + for (Column subColumn : entry.getValue()) + Column.serializer().serialize(subColumn, dos); + } + } + + private static Map> groupSuperColumns(ColumnFamily scf) + { + CompositeType type = (CompositeType)scf.getComparator(); + // The order of insertion matters! + Map> scMap = new LinkedHashMap>(); + + ByteBuffer scName = null; + List subColumns = null; + for (Column column : scf) + { + ByteBuffer newScName = scName(column.name()); + ByteBuffer newSubName = subName(column.name()); + + if (scName == null || type.types.get(0).compare(scName, newScName) != 0) + { + // new super column + scName = newScName; + subColumns = new ArrayList(); + scMap.put(scName, subColumns); + } + + subColumns.add(((Column)column).withUpdatedName(newSubName)); + } + return scMap; + } + + public static void deserializerSuperColumnFamily(DataInput dis, ColumnFamily cf, ColumnSerializer.Flag flag, int expireBefore, int version) throws IOException + { + // Note that there was no way to insert a range tombstone in a SCF in 1.2 + cf.delete(DeletionInfo.serializer().deserialize(dis, version, cf.getComparator())); + assert !cf.deletionInfo().rangeIterator().hasNext(); + + Iterator iter = onDiskIterator(dis, dis.readInt(), flag, expireBefore); + while (iter.hasNext()) + cf.addAtom(iter.next()); + } + + public static long serializedSize(ColumnFamily scf, TypeSizes typeSizes, int version) + { + Map> scMap = groupSuperColumns(scf); + DeletionInfo delInfo = scf.deletionInfo(); + + // Actually Serialize + long size = DeletionInfo.serializer().serializedSize(new DeletionInfo(delInfo.getTopLevelDeletion()), version); + for (Map.Entry> entry : scMap.entrySet()) + { + int nameSize = entry.getKey().remaining(); + size += typeSizes.sizeof((short) nameSize) + nameSize; + + List delTimes = delInfo.rangeCovering(entry.getKey()); + assert delTimes.size() <= 1; // We're supposed to have either no deletion, or a full SC deletion. + DeletionInfo scDelInfo = delTimes.isEmpty() ? DeletionInfo.LIVE : new DeletionInfo(delTimes.get(0)); + size += DeletionInfo.serializer().serializedSize(scDelInfo, MessagingService.VERSION_10); + + size += typeSizes.sizeof(entry.getValue().size()); + for (Column subColumn : entry.getValue()) + size += Column.serializer().serializedSize(subColumn, typeSizes); + } + return size; + } + + private static class SCIterator implements Iterator + { + private final DataInput dis; + private final int scCount; + + private final ColumnSerializer.Flag flag; + private final int expireBefore; + + private int read; + private ByteBuffer scName; + private Iterator subColumnsIterator; + + private SCIterator(DataInput dis, int superColumnCount, ColumnSerializer.Flag flag, int expireBefore) + { + this.dis = dis; + this.scCount = superColumnCount; + this.flag = flag; + this.expireBefore = expireBefore; + } + + public boolean hasNext() + { + return (subColumnsIterator != null && subColumnsIterator.hasNext()) || read < scCount; + } + + public OnDiskAtom next() + { + try + { + if (subColumnsIterator != null && subColumnsIterator.hasNext()) + { + Column c = subColumnsIterator.next(); + return c.withUpdatedName(CompositeType.build(scName, c.name())); + } + + // Read one more super column + ++read; + + scName = ByteBufferUtil.readWithShortLength(dis); + DeletionInfo delInfo = DeletionInfo.serializer().deserialize(dis, MessagingService.VERSION_10, null); + assert !delInfo.rangeIterator().hasNext(); // We assume no range tombstone (there was no way to insert some in a SCF in 1.2) + + /* read the number of columns */ + int size = dis.readInt(); + List subColumns = new ArrayList(size); + + for (int i = 0; i < size; ++i) + subColumns.add(Column.serializer().deserialize(dis, flag, expireBefore)); + + subColumnsIterator = subColumns.iterator(); + + // If the SC was deleted, return that first, otherwise return the first subcolumn + DeletionTime dtime = delInfo.getTopLevelDeletion(); + if (!dtime.equals(DeletionTime.LIVE)) + return new RangeTombstone(startOf(scName), endOf(scName), dtime); + + return next(); + } + catch (IOException e) + { + throw new IOError(e); + } + } + + public void remove() + { + throw new UnsupportedOperationException(); + } + } + + public static AbstractType getComparatorFor(CFMetaData metadata, ByteBuffer superColumn) + { + return getComparatorFor(metadata, superColumn != null); + } + + public static AbstractType getComparatorFor(CFMetaData metadata, boolean subColumn) + { + return metadata.isSuper() + ? ((CompositeType)metadata.comparator).types.get(subColumn ? 1 : 0) + : metadata.comparator; + } + + // Extract the first component of a columnName, i.e. the super column name + public static ByteBuffer scName(ByteBuffer columnName) + { + return CompositeType.extractComponent(columnName, 0); + } + + // Extract the 2nd component of a columnName, i.e. the sub-column name + public static ByteBuffer subName(ByteBuffer columnName) + { + return CompositeType.extractComponent(columnName, 1); + } + + // We don't use CompositeType.Builder mostly because we want to avoid having to provide the comparator. + public static ByteBuffer startOf(ByteBuffer scName) + { + int length = scName.remaining(); + ByteBuffer bb = ByteBuffer.allocate(2 + length + 1); + + bb.put((byte) ((length >> 8) & 0xFF)); + bb.put((byte) (length & 0xFF)); + bb.put(scName.duplicate()); + bb.put((byte) 0); + bb.flip(); + return bb; + } + + public static ByteBuffer endOf(ByteBuffer scName) + { + ByteBuffer bb = startOf(scName); + bb.put(bb.remaining() - 1, (byte)1); + return bb; + } + + public static SCFilter filterToSC(CompositeType type, IDiskAtomFilter filter) + { + if (filter instanceof NamesQueryFilter) + return namesFilterToSC(type, (NamesQueryFilter)filter); + else + return sliceFilterToSC(type, (SliceQueryFilter)filter); + } + + public static SCFilter namesFilterToSC(CompositeType type, NamesQueryFilter filter) + { + ByteBuffer scName = null; + SortedSet newColumns = new TreeSet(filter.columns.comparator()); + for (ByteBuffer name : filter.columns) + { + ByteBuffer newScName = scName(name); + + if (scName == null) + { + scName = newScName; + } + else if (type.types.get(0).compare(scName, newScName) != 0) + { + // If we're selecting column across multiple SC, it's not something we can translate for an old node + throw new RuntimeException("Cannot convert filter to old super column format. Update all nodes to Cassandra 2.0 first."); + } + + newColumns.add(subName(name)); + } + return new SCFilter(scName, new NamesQueryFilter(newColumns)); + } + + public static SCFilter sliceFilterToSC(CompositeType type, SliceQueryFilter filter) + { + /* + * There is 3 main cases that we can translate back into super column + * queries: + * 1) We have only one slice where the first component of start and + * finish is the same, we translate as a slice query on one SC. + * 2) We have only one slice, neither the start and finish have a 2nd + * component, and end has the 'end of component' set, we translate + * as a slice of SCs. + * 3) Each slice has the same first component for start and finish, no + * 2nd component and each finish has the 'end of component' set, we + * translate as a names query of SCs (the filter must then not be reversed). + * Otherwise, we can't do much. + */ + + boolean reversed = filter.reversed; + if (filter.slices.length == 1) + { + ByteBuffer start = filter.slices[0].start; + ByteBuffer finish = filter.slices[0].start; + + if (filter.compositesToGroup == 1) + { + // Note: all the resulting filter must have compositeToGroup == 0 because this + // make no sense for super column on the destination node otherwise + if (start.remaining() == 0) + { + if (finish.remaining() == 0) + // An 'IdentityFilter', keep as is (except for the compositeToGroup) + return new SCFilter(null, new SliceQueryFilter(filter.start(), filter.finish(), reversed, filter.count)); + + if (subName(finish) == null + && ((!reversed && !firstEndOfComponent(finish)) || (reversed && firstEndOfComponent(finish)))) + return new SCFilter(null, new SliceQueryFilter(ByteBufferUtil.EMPTY_BYTE_BUFFER, scName(finish), reversed, filter.count)); + } + else if (finish.remaining() == 0) + { + if (subName(start) == null + && ((!reversed && firstEndOfComponent(start)) || (reversed && !firstEndOfComponent(start)))) + return new SCFilter(null, new SliceQueryFilter(scName(start), ByteBufferUtil.EMPTY_BYTE_BUFFER, reversed, filter.count)); + } + else if (subName(start) == null && subName(finish) == null + && (( reversed && !firstEndOfComponent(start) && firstEndOfComponent(finish)) + || (!reversed && firstEndOfComponent(start) && !firstEndOfComponent(finish)))) + { + // A slice of supercolumns + return new SCFilter(null, new SliceQueryFilter(scName(start), scName(finish), reversed, filter.count)); + } + } + else if (filter.compositesToGroup == 0 && type.types.get(0).compare(scName(start), scName(finish)) == 0) + { + // A slice of subcolumns + return new SCFilter(scName(start), filter.withUpdatedSlice(subName(start), subName(finish))); + } + } + else if (!reversed) + { + SortedSet columns = new TreeSet(type.types.get(0)); + for (int i = 0; i < filter.slices.length; ++i) + { + ByteBuffer start = filter.slices[i].start; + ByteBuffer finish = filter.slices[i].finish; + + if (subName(start) != null || subName(finish) != null + || type.types.get(0).compare(scName(start), scName(finish)) != 0 + || firstEndOfComponent(start) || !firstEndOfComponent(finish)) + throw new RuntimeException("Cannot convert filter to old super column format. Update all nodes to Cassandra 2.0 first."); + + columns.add(scName(start)); + } + return new SCFilter(null, new NamesQueryFilter(columns)); + } + throw new RuntimeException("Cannot convert filter to old super column format. Update all nodes to Cassandra 2.0 first."); + } + + public static IDiskAtomFilter fromSCFilter(CompositeType type, ByteBuffer scName, IDiskAtomFilter filter) + { + if (filter instanceof NamesQueryFilter) + return fromSCNamesFilter(type, scName, (NamesQueryFilter)filter); + else + return fromSCSliceFilter(type, scName, (SliceQueryFilter)filter); + } + + public static IDiskAtomFilter fromSCNamesFilter(CompositeType type, ByteBuffer scName, NamesQueryFilter filter) + { + if (scName == null) + { + ColumnSlice[] slices = new ColumnSlice[filter.columns.size()]; + int i = 0; + for (ByteBuffer bb : filter.columns) + { + CompositeType.Builder builder = type.builder().add(bb); + slices[i++] = new ColumnSlice(builder.build(), builder.buildAsEndOfRange()); + } + return new SliceQueryFilter(slices, false, slices.length, 1, 1); + } + else + { + SortedSet newColumns = new TreeSet(type); + for (ByteBuffer c : filter.columns) + newColumns.add(CompositeType.build(scName, c)); + return filter.withUpdatedColumns(newColumns); + } + } + + public static SliceQueryFilter fromSCSliceFilter(CompositeType type, ByteBuffer scName, SliceQueryFilter filter) + { + assert filter.slices.length == 1; + if (scName == null) + { + ByteBuffer start = filter.start().remaining() == 0 + ? filter.start() + : (filter.reversed ? type.builder().add(filter.start()).buildAsEndOfRange() + : type.builder().add(filter.start()).build()); + ByteBuffer finish = filter.finish().remaining() == 0 + ? filter.finish() + : (filter.reversed ? type.builder().add(filter.finish()).build() + : type.builder().add(filter.finish()).buildAsEndOfRange()); + return new SliceQueryFilter(start, finish, filter.reversed, filter.count, 1); + } + else + { + CompositeType.Builder builder = type.builder().add(scName); + ByteBuffer start = filter.start().remaining() == 0 + ? filter.reversed ? builder.buildAsEndOfRange() : builder.build() + : builder.copy().add(filter.start()).build(); + ByteBuffer end = filter.finish().remaining() == 0 + ? filter.reversed ? builder.build() : builder.buildAsEndOfRange() + : builder.add(filter.finish()).build(); + return new SliceQueryFilter(start, end, filter.reversed, filter.count); + } + } + + private static boolean firstEndOfComponent(ByteBuffer bb) + { + bb = bb.duplicate(); + int length = (bb.get() & 0xFF) << 8; + length |= (bb.get() & 0xFF); + + return bb.get(length + 2) == 1; + } + + public static class SCFilter + { + public final ByteBuffer scName; + public final IDiskAtomFilter updatedFilter; + + public SCFilter(ByteBuffer scName, IDiskAtomFilter updatedFilter) + { + this.scName = scName; + this.updatedFilter = updatedFilter; + } + } +} diff --git a/src/java/org/apache/cassandra/db/SystemTable.java b/src/java/org/apache/cassandra/db/SystemTable.java index 8f60904ea7..940300cb67 100644 --- a/src/java/org/apache/cassandra/db/SystemTable.java +++ b/src/java/org/apache/cassandra/db/SystemTable.java @@ -43,7 +43,6 @@ import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.cql3.UntypedResultSet; import org.apache.cassandra.db.columniterator.IdentityQueryFilter; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.AsciiType; import org.apache.cassandra.db.marshal.BytesType; import org.apache.cassandra.db.marshal.UTF8Type; @@ -156,9 +155,9 @@ public class SystemTable SortedSet cols = new TreeSet(BytesType.instance); cols.add(ByteBufferUtil.bytes("ClusterName")); cols.add(ByteBufferUtil.bytes("Token")); - QueryFilter filter = QueryFilter.getNamesFilter(decorate(ByteBufferUtil.bytes("L")), new QueryPath(OLD_STATUS_CF), cols); + QueryFilter filter = QueryFilter.getNamesFilter(decorate(ByteBufferUtil.bytes("L")), OLD_STATUS_CF, cols); ColumnFamily oldCf = oldStatusCfs.getColumnFamily(filter); - Iterator oldColumns = oldCf.columns.iterator(); + Iterator oldColumns = oldCf.columns.iterator(); String clusterName = null; try @@ -514,7 +513,7 @@ public class SystemTable { ColumnFamilyStore cfs = Table.open(Table.SYSTEM_KS).getColumnFamilyStore(INDEX_CF); QueryFilter filter = QueryFilter.getNamesFilter(decorate(ByteBufferUtil.bytes(table)), - new QueryPath(INDEX_CF), + INDEX_CF, ByteBufferUtil.bytes(indexName)); return ColumnFamilyStore.removeDeleted(cfs.getColumnFamily(filter), Integer.MAX_VALUE) != null; } @@ -532,7 +531,7 @@ public class SystemTable public static void setIndexRemoved(String table, String indexName) { RowMutation rm = new RowMutation(Table.SYSTEM_KS, ByteBufferUtil.bytes(table)); - rm.delete(new QueryPath(INDEX_CF, null, ByteBufferUtil.bytes(indexName)), FBUtilities.timestampMicros()); + rm.delete(INDEX_CF, ByteBufferUtil.bytes(indexName), FBUtilities.timestampMicros()); rm.apply(); forceBlockingFlush(INDEX_CF); } @@ -573,7 +572,7 @@ public class SystemTable // Get the last CounterId (since CounterId are timeuuid is thus ordered from the older to the newer one) QueryFilter filter = QueryFilter.getSliceFilter(decorate(ALL_LOCAL_NODE_ID_KEY), - new QueryPath(COUNTER_ID_CF), + COUNTER_ID_CF, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, @@ -611,11 +610,11 @@ public class SystemTable List l = new ArrayList(); Table table = Table.open(Table.SYSTEM_KS); - QueryFilter filter = QueryFilter.getIdentityFilter(decorate(ALL_LOCAL_NODE_ID_KEY), new QueryPath(COUNTER_ID_CF)); + QueryFilter filter = QueryFilter.getIdentityFilter(decorate(ALL_LOCAL_NODE_ID_KEY), COUNTER_ID_CF); ColumnFamily cf = table.getColumnFamilyStore(COUNTER_ID_CF).getColumnFamily(filter); CounterId previous = null; - for (IColumn c : cf) + for (Column c : cf) { if (previous != null) l.add(new CounterId.CounterIdRecord(previous, c.timestamp())); @@ -655,8 +654,7 @@ public class SystemTable { Token minToken = StorageService.getPartitioner().getMinimumToken(); - return schemaCFS(schemaCfName).getRangeSlice(null, - new Range(minToken.minKeyBound(), + return schemaCFS(schemaCfName).getRangeSlice(new Range(minToken.minKeyBound(), minToken.maxKeyBound()), Integer.MAX_VALUE, new IdentityQueryFilter(), @@ -713,7 +711,7 @@ public class SystemTable DecoratedKey key = StorageService.getPartitioner().decorateKey(getSchemaKSKey(ksName)); ColumnFamilyStore schemaCFS = SystemTable.schemaCFS(SCHEMA_KEYSPACES_CF); - ColumnFamily result = schemaCFS.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(SCHEMA_KEYSPACES_CF))); + ColumnFamily result = schemaCFS.getColumnFamily(QueryFilter.getIdentityFilter(key, SCHEMA_KEYSPACES_CF)); return new Row(key, result); } @@ -724,7 +722,6 @@ public class SystemTable ColumnFamilyStore schemaCFS = SystemTable.schemaCFS(SCHEMA_COLUMNFAMILIES_CF); ColumnFamily result = schemaCFS.getColumnFamily(key, - new QueryPath(SCHEMA_COLUMNFAMILIES_CF), DefsTable.searchComposite(cfName, true), DefsTable.searchComposite(cfName, false), false, diff --git a/src/java/org/apache/cassandra/db/Table.java b/src/java/org/apache/cassandra/db/Table.java index 786ed43c68..361e3b23b5 100644 --- a/src/java/org/apache/cassandra/db/Table.java +++ b/src/java/org/apache/cassandra/db/Table.java @@ -425,7 +425,7 @@ public class Table { ColumnFamily cf = pager.next(); ColumnFamily cf2 = cf.cloneMeShallow(); - for (IColumn column : cf) + for (Column column : cf) { if (cfs.indexManager.indexes(column.name(), indexes)) cf2.addColumn(column); diff --git a/src/java/org/apache/cassandra/db/ThreadSafeSortedColumns.java b/src/java/org/apache/cassandra/db/ThreadSafeSortedColumns.java index 6aa19f01ef..776e5439c2 100644 --- a/src/java/org/apache/cassandra/db/ThreadSafeSortedColumns.java +++ b/src/java/org/apache/cassandra/db/ThreadSafeSortedColumns.java @@ -33,7 +33,7 @@ import org.apache.cassandra.utils.Allocator; public class ThreadSafeSortedColumns extends AbstractThreadUnsafeSortedColumns implements ISortedColumns { - private final ConcurrentSkipListMap map; + private final ConcurrentSkipListMap map; public static final ISortedColumns.Factory factory = new Factory() { @@ -42,7 +42,7 @@ public class ThreadSafeSortedColumns extends AbstractThreadUnsafeSortedColumns i return new ThreadSafeSortedColumns(comparator); } - public ISortedColumns fromSorted(SortedMap sortedMap, boolean insertReversed) + public ISortedColumns fromSorted(SortedMap sortedMap, boolean insertReversed) { return new ThreadSafeSortedColumns(sortedMap); } @@ -60,12 +60,12 @@ public class ThreadSafeSortedColumns extends AbstractThreadUnsafeSortedColumns i private ThreadSafeSortedColumns(AbstractType comparator) { - this.map = new ConcurrentSkipListMap(comparator); + this.map = new ConcurrentSkipListMap(comparator); } - private ThreadSafeSortedColumns(SortedMap columns) + private ThreadSafeSortedColumns(SortedMap columns) { - this.map = new ConcurrentSkipListMap(columns); + this.map = new ConcurrentSkipListMap(columns); } public ISortedColumns.Factory getFactory() @@ -87,59 +87,49 @@ public class ThreadSafeSortedColumns extends AbstractThreadUnsafeSortedColumns i * If we find an old column that has the same name * the ask it to resolve itself else add the new column */ - public void addColumn(IColumn column, Allocator allocator) + public void addColumn(Column column, Allocator allocator) { addColumnInternal(column, allocator); } - private long addColumnInternal(IColumn column, Allocator allocator) + private long addColumnInternal(Column column, Allocator allocator) { ByteBuffer name = column.name(); while (true) { - IColumn oldColumn = map.putIfAbsent(name, column); + Column oldColumn = map.putIfAbsent(name, column); if (oldColumn == null) return column.dataSize(); - if (oldColumn instanceof SuperColumn) - { - assert column instanceof SuperColumn; - long previousSize = oldColumn.dataSize(); - ((SuperColumn) oldColumn).putColumn((SuperColumn)column, allocator); - return oldColumn.dataSize() - previousSize; - } - else - { - // calculate reconciled col from old (existing) col and new col - IColumn reconciledColumn = column.reconcile(oldColumn, allocator); - if (map.replace(name, oldColumn, reconciledColumn)) - return reconciledColumn.dataSize() - oldColumn.dataSize(); + // calculate reconciled col from old (existing) col and new col + Column reconciledColumn = column.reconcile(oldColumn, allocator); + if (map.replace(name, oldColumn, reconciledColumn)) + return reconciledColumn.dataSize() - oldColumn.dataSize(); - // We failed to replace column due to a concurrent update or a concurrent removal. Keep trying. - // (Currently, concurrent removal should not happen (only updates), but let us support that anyway.) - } + // We failed to replace column due to a concurrent update or a concurrent removal. Keep trying. + // (Currently, concurrent removal should not happen (only updates), but let us support that anyway.) } } /** * We need to go through each column in the column container and resolve it before adding */ - public void addAll(ISortedColumns cm, Allocator allocator, Function transformation) + public void addAll(ISortedColumns cm, Allocator allocator, Function transformation) { addAllWithSizeDelta(cm, allocator, transformation, null); } @Override - public long addAllWithSizeDelta(ISortedColumns cm, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer) + public long addAllWithSizeDelta(ISortedColumns cm, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer) { delete(cm.getDeletionInfo()); long sizeDelta = 0; - for (IColumn column : cm.getSortedColumns()) + for (Column column : cm.getSortedColumns()) sizeDelta += addColumnInternal(transformation.apply(column), allocator); return sizeDelta; } - public boolean replace(IColumn oldColumn, IColumn newColumn) + public boolean replace(Column oldColumn, Column newColumn) { if (!oldColumn.name().equals(newColumn.name())) throw new IllegalArgumentException(); @@ -147,7 +137,7 @@ public class ThreadSafeSortedColumns extends AbstractThreadUnsafeSortedColumns i return map.replace(oldColumn.name(), oldColumn, newColumn); } - public IColumn getColumn(ByteBuffer name) + public Column getColumn(ByteBuffer name) { return map.get(name); } @@ -167,12 +157,12 @@ public class ThreadSafeSortedColumns extends AbstractThreadUnsafeSortedColumns i return map.size(); } - public Collection getSortedColumns() + public Collection getSortedColumns() { return map.values(); } - public Collection getReverseSortedColumns() + public Collection getReverseSortedColumns() { return map.descendingMap().values(); } @@ -182,17 +172,17 @@ public class ThreadSafeSortedColumns extends AbstractThreadUnsafeSortedColumns i return map.navigableKeySet(); } - public Iterator iterator() + public Iterator iterator() { return map.values().iterator(); } - public Iterator iterator(ColumnSlice[] slices) + public Iterator iterator(ColumnSlice[] slices) { return new ColumnSlice.NavigableMapIterator(map, slices); } - public Iterator reverseIterator(ColumnSlice[] slices) + public Iterator reverseIterator(ColumnSlice[] slices) { return new ColumnSlice.NavigableMapIterator(map.descendingMap(), slices); } diff --git a/src/java/org/apache/cassandra/db/TreeMapBackedSortedColumns.java b/src/java/org/apache/cassandra/db/TreeMapBackedSortedColumns.java index c4ec52f24f..20cbd900bb 100644 --- a/src/java/org/apache/cassandra/db/TreeMapBackedSortedColumns.java +++ b/src/java/org/apache/cassandra/db/TreeMapBackedSortedColumns.java @@ -33,7 +33,7 @@ import org.apache.cassandra.utils.Allocator; public class TreeMapBackedSortedColumns extends AbstractThreadUnsafeSortedColumns implements ISortedColumns { - private final TreeMap map; + private final TreeMap map; public static final ISortedColumns.Factory factory = new Factory() { @@ -42,7 +42,7 @@ public class TreeMapBackedSortedColumns extends AbstractThreadUnsafeSortedColumn return new TreeMapBackedSortedColumns(comparator); } - public ISortedColumns fromSorted(SortedMap sortedMap, boolean insertReversed) + public ISortedColumns fromSorted(SortedMap sortedMap, boolean insertReversed) { return new TreeMapBackedSortedColumns(sortedMap); } @@ -60,12 +60,12 @@ public class TreeMapBackedSortedColumns extends AbstractThreadUnsafeSortedColumn private TreeMapBackedSortedColumns(AbstractType comparator) { - this.map = new TreeMap(comparator); + this.map = new TreeMap(comparator); } - private TreeMapBackedSortedColumns(SortedMap columns) + private TreeMapBackedSortedColumns(SortedMap columns) { - this.map = new TreeMap(columns); + this.map = new TreeMap(columns); } public ISortedColumns.Factory getFactory() @@ -83,7 +83,7 @@ public class TreeMapBackedSortedColumns extends AbstractThreadUnsafeSortedColumn return false; } - public void addColumn(IColumn column, Allocator allocator) + public void addColumn(Column column, Allocator allocator) { addColumn(column, allocator, SecondaryIndexManager.nullUpdater); } @@ -92,47 +92,33 @@ public class TreeMapBackedSortedColumns extends AbstractThreadUnsafeSortedColumn * If we find an old column that has the same name * the ask it to resolve itself else add the new column */ - public long addColumn(IColumn column, Allocator allocator, SecondaryIndexManager.Updater indexer) + public long addColumn(Column column, Allocator allocator, SecondaryIndexManager.Updater indexer) { ByteBuffer name = column.name(); // this is a slightly unusual way to structure this; a more natural way is shown in ThreadSafeSortedColumns, // but TreeMap lacks putAbsent. Rather than split it into a "get, then put" check, we do it as follows, // which saves the extra "get" in the no-conflict case [for both normal and super columns], // in exchange for a re-put in the SuperColumn case. - IColumn oldColumn = map.put(name, column); + Column oldColumn = map.put(name, column); if (oldColumn == null) return column.dataSize(); - if (oldColumn instanceof SuperColumn) - { - assert column instanceof SuperColumn; - long previousSize = oldColumn.dataSize(); - // since oldColumn is where we've been accumulating results, it's usually going to be faster to - // add the new one to the old, then place old back in the Map, rather than copy the old contents - // into the new Map entry. - ((SuperColumn) oldColumn).putColumn((SuperColumn)column, allocator); - map.put(name, oldColumn); - return oldColumn.dataSize() - previousSize; - } + // calculate reconciled col from old (existing) col and new col + Column reconciledColumn = column.reconcile(oldColumn, allocator); + map.put(name, reconciledColumn); + // for memtable updates we only care about oldcolumn, reconciledcolumn, but when compacting + // we need to make sure we update indexes no matter the order we merge + if (reconciledColumn == column) + indexer.update(oldColumn, reconciledColumn); else - { - // calculate reconciled col from old (existing) col and new col - IColumn reconciledColumn = column.reconcile(oldColumn, allocator); - map.put(name, reconciledColumn); - // for memtable updates we only care about oldcolumn, reconciledcolumn, but when compacting - // we need to make sure we update indexes no matter the order we merge - if (reconciledColumn == column) - indexer.update(oldColumn, reconciledColumn); - else - indexer.update(column, reconciledColumn); - return reconciledColumn.dataSize() - oldColumn.dataSize(); - } + indexer.update(column, reconciledColumn); + return reconciledColumn.dataSize() - oldColumn.dataSize(); } - public long addAllWithSizeDelta(ISortedColumns cm, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer) + public long addAllWithSizeDelta(ISortedColumns cm, Allocator allocator, Function transformation, SecondaryIndexManager.Updater indexer) { delete(cm.getDeletionInfo()); - for (IColumn column : cm.getSortedColumns()) + for (Column column : cm.getSortedColumns()) addColumn(transformation.apply(column), allocator, indexer); // we don't use this for memtables, so we don't bother computing size @@ -142,12 +128,12 @@ public class TreeMapBackedSortedColumns extends AbstractThreadUnsafeSortedColumn /** * We need to go through each column in the column container and resolve it before adding */ - public void addAll(ISortedColumns cm, Allocator allocator, Function transformation) + public void addAll(ISortedColumns cm, Allocator allocator, Function transformation) { addAllWithSizeDelta(cm, allocator, transformation, SecondaryIndexManager.nullUpdater); } - public boolean replace(IColumn oldColumn, IColumn newColumn) + public boolean replace(Column oldColumn, Column newColumn) { if (!oldColumn.name().equals(newColumn.name())) throw new IllegalArgumentException(); @@ -156,7 +142,7 @@ public class TreeMapBackedSortedColumns extends AbstractThreadUnsafeSortedColumn // column or the column was not equal to oldColumn (to be coherent // with other implementation). We optimize for the common case where // oldColumn do is present though. - IColumn previous = map.put(oldColumn.name(), newColumn); + Column previous = map.put(oldColumn.name(), newColumn); if (previous == null) { map.remove(oldColumn.name()); @@ -170,7 +156,7 @@ public class TreeMapBackedSortedColumns extends AbstractThreadUnsafeSortedColumn return true; } - public IColumn getColumn(ByteBuffer name) + public Column getColumn(ByteBuffer name) { return map.get(name); } @@ -190,12 +176,12 @@ public class TreeMapBackedSortedColumns extends AbstractThreadUnsafeSortedColumn return map.size(); } - public Collection getSortedColumns() + public Collection getSortedColumns() { return map.values(); } - public Collection getReverseSortedColumns() + public Collection getReverseSortedColumns() { return map.descendingMap().values(); } @@ -205,17 +191,17 @@ public class TreeMapBackedSortedColumns extends AbstractThreadUnsafeSortedColumn return map.navigableKeySet(); } - public Iterator iterator() + public Iterator iterator() { return map.values().iterator(); } - public Iterator iterator(ColumnSlice[] slices) + public Iterator iterator(ColumnSlice[] slices) { return new ColumnSlice.NavigableMapIterator(map, slices); } - public Iterator reverseIterator(ColumnSlice[] slices) + public Iterator reverseIterator(ColumnSlice[] slices) { return new ColumnSlice.NavigableMapIterator(map.descendingMap(), slices); } diff --git a/src/java/org/apache/cassandra/db/columniterator/IdentityQueryFilter.java b/src/java/org/apache/cassandra/db/columniterator/IdentityQueryFilter.java index 9c9682fd45..9697335cd6 100644 --- a/src/java/org/apache/cassandra/db/columniterator/IdentityQueryFilter.java +++ b/src/java/org/apache/cassandra/db/columniterator/IdentityQueryFilter.java @@ -17,7 +17,6 @@ */ package org.apache.cassandra.db.columniterator; -import org.apache.cassandra.db.SuperColumn; import org.apache.cassandra.db.filter.SliceQueryFilter; import org.apache.cassandra.utils.ByteBufferUtil; @@ -30,10 +29,4 @@ public class IdentityQueryFilter extends SliceQueryFilter { super(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, Integer.MAX_VALUE); } - - public SuperColumn filterSuperColumn(SuperColumn superColumn, int gcBefore) - { - // no filtering done, deliberately - return superColumn; - } } diff --git a/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java b/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java index db0130e519..ac03583aee 100644 --- a/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java +++ b/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayDeque; import java.util.Deque; +import java.util.Iterator; import java.util.List; import com.google.common.collect.AbstractIterator; @@ -352,7 +353,9 @@ class IndexedSliceReader extends AbstractIterator implements OnDiskA if (file == null) file = originalInput == null ? sstable.getFileDataInput(positionToSeek) : originalInput; - OnDiskAtom.Serializer atomSerializer = emptyColumnFamily.getOnDiskSerializer(); + // Give a bogus atom count since we'll deserialize as long as we're + // within the index block but we don't know how much atom is there + Iterator atomIterator = emptyColumnFamily.metadata().getOnDiskIterator(file, Integer.MAX_VALUE, sstable.descriptor.version); file.seek(positionToSeek); FileMark mark = file.mark(); @@ -365,7 +368,7 @@ class IndexedSliceReader extends AbstractIterator implements OnDiskA { // Only fetch a new column if we haven't dealt with the previous one. if (column == null) - column = atomSerializer.deserializeFromSSTable(file, sstable.descriptor.version); + column = atomIterator.next(); // col is before slice // (If in slice, don't bother checking that until we change slice) @@ -434,12 +437,10 @@ class IndexedSliceReader extends AbstractIterator implements OnDiskA // We remenber when we are whithin a slice to avoid some comparison boolean inSlice = false; - OnDiskAtom.Serializer atomSerializer = emptyColumnFamily.getOnDiskSerializer(); - int columns = file.readInt(); - - for (int i = 0; i < columns; i++) + Iterator atomIterator = emptyColumnFamily.metadata().getOnDiskIterator(file, file.readInt(), sstable.descriptor.version); + while (atomIterator.hasNext()) { - OnDiskAtom column = atomSerializer.deserializeFromSSTable(file, sstable.descriptor.version); + OnDiskAtom column = atomIterator.next(); // col is before slice // (If in slice, don't bother checking that until we change slice) diff --git a/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java b/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java index da4631df53..389fbb265a 100644 --- a/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java +++ b/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java @@ -26,7 +26,7 @@ import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.ColumnFamilySerializer; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.DeletionInfo; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.RowIndexEntry; import org.apache.cassandra.db.OnDiskAtom; import org.apache.cassandra.db.marshal.AbstractType; @@ -196,13 +196,12 @@ public class SSTableNamesIterator extends SimpleAbstractColumnIterator implement private void readSimpleColumns(FileDataInput file, SortedSet columnNames, List filteredColumnNames, List result) throws IOException { - OnDiskAtom.Serializer atomSerializer = cf.getOnDiskSerializer(); - int columns = file.readInt(); + Iterator atomIterator = cf.metadata().getOnDiskIterator(file, file.readInt(), sstable.descriptor.version); int n = 0; - for (int i = 0; i < columns; i++) + while (atomIterator.hasNext()) { - OnDiskAtom column = atomSerializer.deserializeFromSSTable(file, sstable.descriptor.version); - if (column instanceof IColumn) + OnDiskAtom column = atomIterator.next(); + if (column instanceof Column) { if (columnNames.contains(column.name())) { @@ -255,15 +254,16 @@ public class SSTableNamesIterator extends SimpleAbstractColumnIterator implement if (file == null) file = createFileDataInput(positionToSeek); - OnDiskAtom.Serializer atomSerializer = cf.getOnDiskSerializer(); + // We'll read as much atom as there is in the index block, so provide a bogus atom count + Iterator atomIterator = cf.metadata().getOnDiskIterator(file, Integer.MAX_VALUE, sstable.descriptor.version); file.seek(positionToSeek); FileMark mark = file.mark(); // TODO only completely deserialize columns we are interested in while (file.bytesPastMark(mark) < indexInfo.width) { - OnDiskAtom column = atomSerializer.deserializeFromSSTable(file, sstable.descriptor.version); + OnDiskAtom column = atomIterator.next(); // we check vs the original Set, not the filtered List, for efficiency - if (!(column instanceof IColumn) || columnNames.contains(column.name())) + if (!(column instanceof Column) || columnNames.contains(column.name())) result.add(column); } } diff --git a/src/java/org/apache/cassandra/db/columniterator/SimpleSliceReader.java b/src/java/org/apache/cassandra/db/columniterator/SimpleSliceReader.java index d19e6a503f..652d60cf18 100644 --- a/src/java/org/apache/cassandra/db/columniterator/SimpleSliceReader.java +++ b/src/java/org/apache/cassandra/db/columniterator/SimpleSliceReader.java @@ -19,6 +19,7 @@ package org.apache.cassandra.db.columniterator; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.Iterator; import com.google.common.collect.AbstractIterator; @@ -43,10 +44,9 @@ class SimpleSliceReader extends AbstractIterator implements OnDiskAt private final ByteBuffer finishColumn; private final AbstractType comparator; private final ColumnFamily emptyColumnFamily; - private final int columns; private int i; private FileMark mark; - private final OnDiskAtom.Serializer atomSerializer; + private final Iterator atomIterator; public SimpleSliceReader(SSTableReader sstable, RowIndexEntry indexEntry, FileDataInput input, ByteBuffer finishColumn) { @@ -79,8 +79,7 @@ class SimpleSliceReader extends AbstractIterator implements OnDiskAt emptyColumnFamily = ColumnFamily.create(sstable.metadata); emptyColumnFamily.delete(DeletionInfo.serializer().deserializeFromSSTable(file, sstable.descriptor.version)); - atomSerializer = emptyColumnFamily.getOnDiskSerializer(); - columns = file.readInt(); + atomIterator = emptyColumnFamily.metadata().getOnDiskIterator(file, file.readInt(), sstable.descriptor.version); mark = file.mark(); } catch (IOException e) @@ -92,14 +91,14 @@ class SimpleSliceReader extends AbstractIterator implements OnDiskAt protected OnDiskAtom computeNext() { - if (i++ >= columns) + if (!atomIterator.hasNext()) return endOfData(); OnDiskAtom column; try { file.reset(mark); - column = atomSerializer.deserializeFromSSTable(file, sstable.descriptor.version); + column = atomIterator.next(); } catch (IOException e) { diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLogDescriptor.java b/src/java/org/apache/cassandra/db/commitlog/CommitLogDescriptor.java index 17f351940b..533219c89c 100644 --- a/src/java/org/apache/cassandra/db/commitlog/CommitLogDescriptor.java +++ b/src/java/org/apache/cassandra/db/commitlog/CommitLogDescriptor.java @@ -35,11 +35,12 @@ public class CommitLogDescriptor public static final int LEGACY_VERSION = 1; public static final int VERSION_12 = 2; + public static final int VERSION_20 = 3; /** * Increment this number if there is a changes in the commit log disc layout or MessagingVersion changes. * Note: make sure to handle {@link #getMessagingVersion()} */ - public static final int current_version = VERSION_12; + public static final int current_version = VERSION_20; private final int version; public final long id; @@ -75,13 +76,15 @@ public class CommitLogDescriptor public int getMessagingVersion() { - assert MessagingService.current_version == MessagingService.VERSION_12; + assert MessagingService.current_version == MessagingService.VERSION_20; switch (version) { case LEGACY_VERSION: return MessagingService.VERSION_11; case VERSION_12: return MessagingService.VERSION_12; + case VERSION_20: + return MessagingService.VERSION_20; default: throw new IllegalStateException("Unknown commitlog version " + version); } diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java b/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java index 9f949d030c..3ef369326b 100644 --- a/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java +++ b/src/java/org/apache/cassandra/db/commitlog/CommitLogReplayer.java @@ -36,7 +36,6 @@ import org.apache.cassandra.concurrent.Stage; import org.apache.cassandra.concurrent.StageManager; import org.apache.cassandra.config.Schema; import org.apache.cassandra.db.*; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.util.FastByteArrayInputStream; import org.apache.cassandra.io.util.FileUtils; import org.apache.cassandra.io.util.RandomAccessReader; @@ -201,7 +200,7 @@ public class CommitLogReplayer { // assuming version here. We've gone to lengths to make sure what gets written to the CL is in // the current version. so do make sure the CL is drained prior to upgrading a node. - rm = RowMutation.serializer.deserialize(new DataInputStream(bufIn), version, IColumnSerializer.Flag.LOCAL); + rm = RowMutation.serializer.deserialize(new DataInputStream(bufIn), version, ColumnSerializer.Flag.LOCAL); } catch (UnknownColumnFamilyException ex) { diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java index eec4b4ce06..e93fdc160c 100644 --- a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java +++ b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java @@ -603,7 +603,7 @@ public class CompactionManager implements CompactionManagerMBean SSTableScanner scanner = sstable.getDirectScanner(); long rowsRead = 0; - List indexedColumnsInRow = null; + List indexedColumnsInRow = null; CleanupInfo ci = new CleanupInfo(sstable, scanner); metrics.beginCompaction(ci); @@ -637,12 +637,12 @@ public class CompactionManager implements CompactionManagerMBean OnDiskAtom column = row.next(); if (column instanceof CounterColumn) renewer.maybeRenew((CounterColumn) column); - if (column instanceof IColumn && cfs.indexManager.indexes((IColumn)column)) + if (column instanceof Column && cfs.indexManager.indexes((Column)column)) { if (indexedColumnsInRow == null) - indexedColumnsInRow = new ArrayList(); + indexedColumnsInRow = new ArrayList(); - indexedColumnsInRow.add((IColumn)column); + indexedColumnsInRow.add((Column)column); } } diff --git a/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java b/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java index 7981d885d7..6ff9a50a24 100644 --- a/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java +++ b/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java @@ -252,7 +252,7 @@ public class LazilyCompactedRow extends AbstractCompactedRow implements Iterable } else { - IColumn column = (IColumn) current; + Column column = (Column) current; container.addColumn(column); if (container.getColumn(column.name()) != column) indexer.remove(column); @@ -284,7 +284,7 @@ public class LazilyCompactedRow extends AbstractCompactedRow implements Iterable container.clear(); return null; } - IColumn reduced = purged.iterator().next(); + Column reduced = purged.iterator().next(); container.clear(); // PrecompactedRow.removeDeletedAndOldShards have only checked the top-level CF deletion times, diff --git a/src/java/org/apache/cassandra/db/compaction/ParallelCompactionIterable.java b/src/java/org/apache/cassandra/db/compaction/ParallelCompactionIterable.java index 7e1983cdf0..58227f63c9 100644 --- a/src/java/org/apache/cassandra/db/compaction/ParallelCompactionIterable.java +++ b/src/java/org/apache/cassandra/db/compaction/ParallelCompactionIterable.java @@ -207,7 +207,7 @@ public class ParallelCompactionIterable extends AbstractCompactionIterable { // addAll is ok even if cf is an ArrayBackedSortedColumns SecondaryIndexManager.Updater indexer = controller.cfs.indexManager.updaterFor(row.key, false); - cf.addAllWithSizeDelta(thisCF, HeapAllocator.instance, Functions.identity(), indexer); + cf.addAllWithSizeDelta(thisCF, HeapAllocator.instance, Functions.identity(), indexer); } } @@ -218,7 +218,7 @@ public class ParallelCompactionIterable extends AbstractCompactionIterable private class DeserializedColumnIterator implements ICountableColumnIterator { private final Row row; - private Iterator iter; + private Iterator iter; public DeserializedColumnIterator(Row row) { diff --git a/src/java/org/apache/cassandra/db/compaction/PrecompactedRow.java b/src/java/org/apache/cassandra/db/compaction/PrecompactedRow.java index be4b20e7bd..213bb8e693 100644 --- a/src/java/org/apache/cassandra/db/compaction/PrecompactedRow.java +++ b/src/java/org/apache/cassandra/db/compaction/PrecompactedRow.java @@ -121,7 +121,7 @@ public class PrecompactedRow extends AbstractCompactedRow else { // addAll is ok even if cf is an ArrayBackedSortedColumns - cf.addAllWithSizeDelta(thisCF, HeapAllocator.instance, Functions.identity(), indexer); + cf.addAllWithSizeDelta(thisCF, HeapAllocator.instance, Functions.identity(), indexer); } } return cf; diff --git a/src/java/org/apache/cassandra/db/filter/ColumnCounter.java b/src/java/org/apache/cassandra/db/filter/ColumnCounter.java index ccf83d9a45..697ad02fef 100644 --- a/src/java/org/apache/cassandra/db/filter/ColumnCounter.java +++ b/src/java/org/apache/cassandra/db/filter/ColumnCounter.java @@ -22,8 +22,8 @@ package org.apache.cassandra.db.filter; import java.nio.ByteBuffer; -import org.apache.cassandra.db.IColumn; -import org.apache.cassandra.db.IColumnContainer; +import org.apache.cassandra.db.Column; +import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.utils.ByteBufferUtil; @@ -32,7 +32,7 @@ public class ColumnCounter protected int live; protected int ignored; - public void count(IColumn column, IColumnContainer container) + public void count(Column column, ColumnFamily container) { if (!isLive(column, container)) ignored++; @@ -40,7 +40,7 @@ public class ColumnCounter live++; } - protected static boolean isLive(IColumn column, IColumnContainer container) + protected static boolean isLive(Column column, ColumnFamily container) { return column.isLive() && (!container.deletionInfo().isDeleted(column)); } @@ -79,7 +79,7 @@ public class ColumnCounter assert toGroup == 0 || type != null; } - public void count(IColumn column, IColumnContainer container) + public void count(Column column, ColumnFamily container) { if (!isLive(column, container)) { diff --git a/src/java/org/apache/cassandra/db/filter/ColumnSlice.java b/src/java/org/apache/cassandra/db/filter/ColumnSlice.java index cdcdc17dc2..e62a436107 100644 --- a/src/java/org/apache/cassandra/db/filter/ColumnSlice.java +++ b/src/java/org/apache/cassandra/db/filter/ColumnSlice.java @@ -140,21 +140,21 @@ public class ColumnSlice } } - public static class NavigableMapIterator extends AbstractIterator + public static class NavigableMapIterator extends AbstractIterator { - private final NavigableMap map; + private final NavigableMap map; private final ColumnSlice[] slices; private int idx = 0; - private Iterator currentSlice; + private Iterator currentSlice; - public NavigableMapIterator(NavigableMap map, ColumnSlice[] slices) + public NavigableMapIterator(NavigableMap map, ColumnSlice[] slices) { this.map = map; this.slices = slices; } - protected IColumn computeNext() + protected Column computeNext() { if (currentSlice == null) { diff --git a/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java b/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java index 4772c53150..41f9d289f7 100644 --- a/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java +++ b/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java @@ -281,7 +281,7 @@ public abstract class ExtendedFilter { // check column data vs expression ByteBuffer colName = builder == null ? expression.column_name : builder.copy().add(expression.column_name).build(); - IColumn column = data.getColumn(colName); + Column column = data.getColumn(colName); if (column == null) return false; int v = data.metadata().getValueValidator(expression.column_name).compare(column.value(), expression.value); diff --git a/src/java/org/apache/cassandra/db/filter/IDiskAtomFilter.java b/src/java/org/apache/cassandra/db/filter/IDiskAtomFilter.java index f1d96112e1..5115e954bc 100644 --- a/src/java/org/apache/cassandra/db/filter/IDiskAtomFilter.java +++ b/src/java/org/apache/cassandra/db/filter/IDiskAtomFilter.java @@ -66,15 +66,9 @@ public interface IDiskAtomFilter * by the filter code, which should have some limit on the number of columns * to avoid running out of memory on large rows. */ - public void collectReducedColumns(IColumnContainer container, Iterator reducedColumns, int gcBefore); + public void collectReducedColumns(ColumnFamily container, Iterator reducedColumns, int gcBefore); - /** - * subcolumns of a supercolumn are unindexed, so to pick out parts of those we operate in-memory. - * @param superColumn may be modified by filtering op. - */ - public SuperColumn filterSuperColumn(SuperColumn superColumn, int gcBefore); - - public Comparator getColumnComparator(AbstractType comparator); + public Comparator getColumnComparator(AbstractType comparator); public boolean isReversed(); public void updateColumnsLimit(int newLimit); diff --git a/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java b/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java index 0581e12727..5d0bc491e5 100644 --- a/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java +++ b/src/java/org/apache/cassandra/db/filter/NamesQueryFilter.java @@ -86,29 +86,17 @@ public class NamesQueryFilter implements IDiskAtomFilter return new SSTableNamesIterator(sstable, file, key, columns, indexEntry); } - public SuperColumn filterSuperColumn(SuperColumn superColumn, int gcBefore) - { - for (IColumn column : superColumn.getSubColumns()) - { - if (!columns.contains(column.name()) || !QueryFilter.isRelevant(column, superColumn, gcBefore)) - { - superColumn.remove(column.name()); - } - } - return superColumn; - } - - public void collectReducedColumns(IColumnContainer container, Iterator reducedColumns, int gcBefore) + public void collectReducedColumns(ColumnFamily container, Iterator reducedColumns, int gcBefore) { while (reducedColumns.hasNext()) { - IColumn column = reducedColumns.next(); + Column column = reducedColumns.next(); if (QueryFilter.isRelevant(column, container, gcBefore)) container.addColumn(column); } } - public Comparator getColumnComparator(AbstractType comparator) + public Comparator getColumnComparator(AbstractType comparator) { return comparator.columnComparator; } @@ -136,7 +124,7 @@ public class NamesQueryFilter implements IDiskAtomFilter return cf.hasOnlyTombstones() ? 0 : 1; int count = 0; - for (IColumn column : cf) + for (Column column : cf) { if (column.isLive()) count++; diff --git a/src/java/org/apache/cassandra/db/filter/QueryFilter.java b/src/java/org/apache/cassandra/db/filter/QueryFilter.java index 31b9db7ae6..c6414fa8e9 100644 --- a/src/java/org/apache/cassandra/db/filter/QueryFilter.java +++ b/src/java/org/apache/cassandra/db/filter/QueryFilter.java @@ -33,16 +33,14 @@ import org.apache.cassandra.utils.MergeIterator; public class QueryFilter { public final DecoratedKey key; - public final QueryPath path; + public final String cfName; public final IDiskAtomFilter filter; - private final IDiskAtomFilter superFilter; - public QueryFilter(DecoratedKey key, QueryPath path, IDiskAtomFilter filter) + public QueryFilter(DecoratedKey key, String cfName, IDiskAtomFilter filter) { this.key = key; - this.path = path; + this.cfName = cfName; this.filter = filter; - superFilter = path.superColumnName == null ? null : new NamesQueryFilter(path.superColumnName); } public OnDiskAtomIterator getMemtableColumnIterator(Memtable memtable) @@ -56,95 +54,62 @@ public class QueryFilter public OnDiskAtomIterator getMemtableColumnIterator(ColumnFamily cf, DecoratedKey key) { assert cf != null; - if (path.superColumnName == null) - return filter.getMemtableColumnIterator(cf, key); - return superFilter.getMemtableColumnIterator(cf, key); + return filter.getMemtableColumnIterator(cf, key); } - // TODO move gcBefore into a field public ISSTableColumnIterator getSSTableColumnIterator(SSTableReader sstable) { - if (path.superColumnName == null) - return filter.getSSTableColumnIterator(sstable, key); - return superFilter.getSSTableColumnIterator(sstable, key); + return filter.getSSTableColumnIterator(sstable, key); } public ISSTableColumnIterator getSSTableColumnIterator(SSTableReader sstable, FileDataInput file, DecoratedKey key, RowIndexEntry indexEntry) { - if (path.superColumnName == null) - return filter.getSSTableColumnIterator(sstable, file, key, indexEntry); - return superFilter.getSSTableColumnIterator(sstable, file, key, indexEntry); + return filter.getSSTableColumnIterator(sstable, file, key, indexEntry); } public void collateOnDiskAtom(final ColumnFamily returnCF, List> toCollate, final int gcBefore) { - List> filteredIterators = new ArrayList>(toCollate.size()); + List> filteredIterators = new ArrayList>(toCollate.size()); for (CloseableIterator iter : toCollate) filteredIterators.add(gatherTombstones(returnCF, iter)); collateColumns(returnCF, filteredIterators, gcBefore); } - // TODO move gcBefore into a field - public void collateColumns(final ColumnFamily returnCF, List> toCollate, final int gcBefore) + public void collateColumns(final ColumnFamily returnCF, List> toCollate, final int gcBefore) { - IDiskAtomFilter topLevelFilter = (superFilter == null ? filter : superFilter); - - Comparator fcomp = topLevelFilter.getColumnComparator(returnCF.getComparator()); + Comparator fcomp = filter.getColumnComparator(returnCF.getComparator()); // define a 'reduced' iterator that merges columns w/ the same name, which // greatly simplifies computing liveColumns in the presence of tombstones. - MergeIterator.Reducer reducer = new MergeIterator.Reducer() + MergeIterator.Reducer reducer = new MergeIterator.Reducer() { ColumnFamily curCF = returnCF.cloneMeShallow(); - public void reduce(IColumn current) + public void reduce(Column current) { - if (curCF.isSuper() && curCF.isEmpty()) - { - // If it is the first super column we add, we must clone it since other super column may modify - // it otherwise and it could be aliased in a memtable somewhere. We'll also don't have to care about what - // consumers make of the result (for instance CFS.getColumnFamily() call removeDeleted() on the - // result which removes column; which shouldn't be done on the original super column). - assert current instanceof SuperColumn; - curCF.addColumn(((SuperColumn) current).cloneMe()); - } - else - { - curCF.addColumn(current); - } + curCF.addColumn(current); } - protected IColumn getReduced() + protected Column getReduced() { - IColumn c = curCF.iterator().next(); - if (superFilter != null) - { - // filterSuperColumn only looks at immediate parent (the supercolumn) when determining if a subcolumn - // is still live, i.e., not shadowed by the parent's tombstone. so, bump it up temporarily to the tombstone - // time of the cf, if that is greater. - DeletionInfo delInfo = ((SuperColumn) c).deletionInfo(); - ((SuperColumn) c).delete(returnCF.deletionInfo()); - c = filter.filterSuperColumn((SuperColumn) c, gcBefore); - ((SuperColumn) c).setDeletionInfo(delInfo); // reset sc tombstone time to what it should be - } + Column c = curCF.iterator().next(); curCF.clear(); - return c; } }; - Iterator reduced = MergeIterator.get(toCollate, fcomp, reducer); + Iterator reduced = MergeIterator.get(toCollate, fcomp, reducer); - topLevelFilter.collectReducedColumns(returnCF, reduced, gcBefore); + filter.collectReducedColumns(returnCF, reduced, gcBefore); } /** * Given an iterator of on disk atom, returns an iterator that filters the tombstone range * markers adding them to {@code returnCF} and returns the normal column. */ - public static CloseableIterator gatherTombstones(final ColumnFamily returnCF, final CloseableIterator iter) + public static CloseableIterator gatherTombstones(final ColumnFamily returnCF, final CloseableIterator iter) { - return new CloseableIterator() + return new CloseableIterator() { - private IColumn next; + private Column next; public boolean hasNext() { @@ -155,13 +120,13 @@ public class QueryFilter return next != null; } - public IColumn next() + public Column next() { if (next == null) getNext(); assert next != null; - IColumn toReturn = next; + Column toReturn = next; next = null; return toReturn; } @@ -172,9 +137,9 @@ public class QueryFilter { OnDiskAtom atom = iter.next(); - if (atom instanceof IColumn) + if (atom instanceof Column) { - next = (IColumn)atom; + next = (Column)atom; break; } else @@ -198,10 +163,10 @@ public class QueryFilter public String getColumnFamilyName() { - return path.columnFamilyName; + return cfName; } - public static boolean isRelevant(IColumn column, IColumnContainer container, int gcBefore) + public static boolean isRelevant(Column column, ColumnFamily container, int gcBefore) { // the column itself must be not gc-able (it is live, or a still relevant tombstone, or has live subcolumns), (1) // and if its container is deleted, the column must be changed more recently than the container tombstone (2) @@ -214,51 +179,48 @@ public class QueryFilter /** * @return a QueryFilter object to satisfy the given slice criteria: * @param key the row to slice - * @param path path to the level to slice at (CF or SuperColumn) + * @param cfName column family to query * @param start column to start slice at, inclusive; empty for "the first column" * @param finish column to stop slice at, inclusive; empty for "the last column" * @param reversed true to start with the largest column (as determined by configured sort order) instead of smallest * @param limit maximum number of non-deleted columns to return */ - public static QueryFilter getSliceFilter(DecoratedKey key, QueryPath path, ByteBuffer start, ByteBuffer finish, boolean reversed, int limit) + public static QueryFilter getSliceFilter(DecoratedKey key, String cfName, ByteBuffer start, ByteBuffer finish, boolean reversed, int limit) { - return new QueryFilter(key, path, new SliceQueryFilter(start, finish, reversed, limit)); + return new QueryFilter(key, cfName, new SliceQueryFilter(start, finish, reversed, limit)); } /** * return a QueryFilter object that includes every column in the row. * This is dangerous on large rows; avoid except for test code. */ - public static QueryFilter getIdentityFilter(DecoratedKey key, QueryPath path) + public static QueryFilter getIdentityFilter(DecoratedKey key, String cfName) { - return new QueryFilter(key, path, new IdentityQueryFilter()); + return new QueryFilter(key, cfName, new IdentityQueryFilter()); } /** * @return a QueryFilter object that will return columns matching the given names * @param key the row to slice - * @param path path to the level to slice at (CF or SuperColumn) + * @param cfName column family to query * @param columns the column names to restrict the results to, sorted in comparator order */ - public static QueryFilter getNamesFilter(DecoratedKey key, QueryPath path, SortedSet columns) + public static QueryFilter getNamesFilter(DecoratedKey key, String cfName, SortedSet columns) { - return new QueryFilter(key, path, new NamesQueryFilter(columns)); + return new QueryFilter(key, cfName, new NamesQueryFilter(columns)); } /** * convenience method for creating a name filter matching a single column */ - public static QueryFilter getNamesFilter(DecoratedKey key, QueryPath path, ByteBuffer column) + public static QueryFilter getNamesFilter(DecoratedKey key, String cfName, ByteBuffer column) { - return new QueryFilter(key, path, new NamesQueryFilter(column)); + return new QueryFilter(key, cfName, new NamesQueryFilter(column)); } @Override - public String toString() { - return getClass().getSimpleName() + "(key=" + key + - ", path=" + path + - (filter == null ? "" : ", filter=" + filter) + - (superFilter == null ? "" : ", superFilter=" + superFilter) + - ")"; + public String toString() + { + return getClass().getSimpleName() + "(key=" + key + ", cfName=" + cfName + (filter == null ? "" : ", filter=" + filter) + ")"; } } diff --git a/src/java/org/apache/cassandra/db/filter/QueryPath.java b/src/java/org/apache/cassandra/db/filter/QueryPath.java index 0bae441961..022631ea3d 100644 --- a/src/java/org/apache/cassandra/db/filter/QueryPath.java +++ b/src/java/org/apache/cassandra/db/filter/QueryPath.java @@ -21,10 +21,12 @@ import java.io.*; import java.nio.ByteBuffer; import org.apache.cassandra.db.TypeSizes; -import org.apache.cassandra.thrift.ColumnParent; -import org.apache.cassandra.thrift.ColumnPath; import org.apache.cassandra.utils.ByteBufferUtil; +/** + * This class is obsolete internally, but kept for wire compatibility with + * older nodes. I.e. we kept it only for the serialization part. + */ public class QueryPath { public final String columnFamilyName; @@ -38,31 +40,11 @@ public class QueryPath this.columnName = columnName; } - public QueryPath(ColumnParent columnParent) - { - this(columnParent.column_family, columnParent.super_column, null); - } - public QueryPath(String columnFamilyName, ByteBuffer superColumnName) { this(columnFamilyName, superColumnName, null); } - public QueryPath(String columnFamilyName) - { - this(columnFamilyName, null); - } - - public QueryPath(ColumnPath column_path) - { - this(column_path.column_family, column_path.super_column, column_path.column); - } - - public static QueryPath column(ByteBuffer columnName) - { - return new QueryPath(null, null, columnName); - } - @Override public String toString() { diff --git a/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java b/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java index 2971151913..25e70534c7 100644 --- a/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java +++ b/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java @@ -46,7 +46,7 @@ public class SliceQueryFilter implements IDiskAtomFilter public final ColumnSlice[] slices; public final boolean reversed; public volatile int count; - private final int compositesToGroup; + public final int compositesToGroup; // This is a hack to allow rolling upgrade with pre-1.2 nodes private final int countMutliplierForCompatibility; @@ -91,6 +91,11 @@ public class SliceQueryFilter implements IDiskAtomFilter return new SliceQueryFilter(newSlices, reversed, count, compositesToGroup, countMutliplierForCompatibility); } + public SliceQueryFilter withUpdatedSlice(ByteBuffer start, ByteBuffer finish) + { + return new SliceQueryFilter(new ColumnSlice[]{ new ColumnSlice(start, finish) }, reversed, count, compositesToGroup, countMutliplierForCompatibility); + } + public OnDiskAtomIterator getMemtableColumnIterator(ColumnFamily cf, DecoratedKey key) { return Memtable.getSliceIterator(key, cf, this); @@ -106,57 +111,18 @@ public class SliceQueryFilter implements IDiskAtomFilter return new SSTableSliceIterator(sstable, file, key, slices, reversed, indexEntry); } - public SuperColumn filterSuperColumn(SuperColumn superColumn, int gcBefore) - { - // we clone shallow, then add, under the theory that generally we're interested in a relatively small number of subcolumns. - // this may be a poor assumption. - SuperColumn scFiltered = superColumn.cloneMeShallow(); - final Iterator subcolumns; - if (reversed) - { - List columnsAsList = new ArrayList(superColumn.getSubColumns()); - subcolumns = Lists.reverse(columnsAsList).iterator(); - } - else - { - subcolumns = superColumn.getSubColumns().iterator(); - } - final Comparator comparator = reversed ? superColumn.getComparator().reverseComparator : superColumn.getComparator(); - Iterator results = new AbstractIterator() - { - protected IColumn computeNext() - { - while (subcolumns.hasNext()) - { - IColumn subcolumn = subcolumns.next(); - // iterate until we get to the "real" start column - if (comparator.compare(subcolumn.name(), start()) < 0) - continue; - // exit loop when columns are out of the range. - if (finish().remaining() > 0 && comparator.compare(subcolumn.name(), finish()) > 0) - break; - return subcolumn; - } - return endOfData(); - } - }; - // subcolumns is either empty now, or has been redefined in the loop above. either is ok. - collectReducedColumns(scFiltered, results, gcBefore); - return scFiltered; - } - - public Comparator getColumnComparator(AbstractType comparator) + public Comparator getColumnComparator(AbstractType comparator) { return reversed ? comparator.columnReverseComparator : comparator.columnComparator; } - public void collectReducedColumns(IColumnContainer container, Iterator reducedColumns, int gcBefore) + public void collectReducedColumns(ColumnFamily container, Iterator reducedColumns, int gcBefore) { columnCounter = getColumnCounter(container); while (reducedColumns.hasNext()) { - IColumn column = reducedColumns.next(); + Column column = reducedColumns.next(); if (logger.isTraceEnabled()) logger.trace(String.format("collecting %s of %s: %s", columnCounter.live(), count, column.getString(container.getComparator()))); @@ -177,12 +143,12 @@ public class SliceQueryFilter implements IDiskAtomFilter public int getLiveCount(ColumnFamily cf) { ColumnCounter counter = getColumnCounter(cf); - for (IColumn column : cf) + for (Column column : cf) counter.count(column, cf); return counter.live(); } - private ColumnCounter getColumnCounter(IColumnContainer container) + private ColumnCounter getColumnCounter(ColumnFamily container) { AbstractType comparator = container.getComparator(); if (compositesToGroup < 0) @@ -200,11 +166,11 @@ public class SliceQueryFilter implements IDiskAtomFilter Collection toRemove = null; boolean trimRemaining = false; - Collection columns = reversed - ? cf.getReverseSortedColumns() - : cf.getSortedColumns(); + Collection columns = reversed + ? cf.getReverseSortedColumns() + : cf.getSortedColumns(); - for (IColumn column : columns) + for (Column column : columns) { if (trimRemaining) { diff --git a/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java b/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java index 4bb14fc9b2..2f96ef8e6e 100644 --- a/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java +++ b/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java @@ -72,7 +72,7 @@ public abstract class AbstractSimplePerColumnSecondaryIndex extends PerColumnSec protected abstract void init(ColumnDefinition columnDef); - protected abstract ByteBuffer makeIndexColumnName(ByteBuffer rowKey, IColumn column); + protected abstract ByteBuffer makeIndexColumnName(ByteBuffer rowKey, Column column); protected abstract AbstractType getExpressionComparator(); @@ -86,7 +86,7 @@ public abstract class AbstractSimplePerColumnSecondaryIndex extends PerColumnSec } - public void delete(ByteBuffer rowKey, IColumn column) + public void delete(ByteBuffer rowKey, Column column) { if (column.isMarkedForDelete()) return; @@ -100,7 +100,7 @@ public abstract class AbstractSimplePerColumnSecondaryIndex extends PerColumnSec logger.debug("removed index entry for cleaned-up value {}:{}", valueKey, cfi); } - public void insert(ByteBuffer rowKey, IColumn column) + public void insert(ByteBuffer rowKey, Column column) { DecoratedKey valueKey = getIndexKeyFor(column.value()); ColumnFamily cfi = ColumnFamily.create(indexCfs.metadata); @@ -120,7 +120,7 @@ public abstract class AbstractSimplePerColumnSecondaryIndex extends PerColumnSec indexCfs.apply(valueKey, cfi, SecondaryIndexManager.nullUpdater); } - public void update(ByteBuffer rowKey, IColumn col) + public void update(ByteBuffer rowKey, Column col) { insert(rowKey, col); } diff --git a/src/java/org/apache/cassandra/db/index/PerColumnSecondaryIndex.java b/src/java/org/apache/cassandra/db/index/PerColumnSecondaryIndex.java index d2025781f8..991581dcbb 100644 --- a/src/java/org/apache/cassandra/db/index/PerColumnSecondaryIndex.java +++ b/src/java/org/apache/cassandra/db/index/PerColumnSecondaryIndex.java @@ -19,8 +19,7 @@ package org.apache.cassandra.db.index; import java.nio.ByteBuffer; -import org.apache.cassandra.db.IColumn; -import org.apache.cassandra.thrift.Column; +import org.apache.cassandra.db.Column; import org.apache.cassandra.utils.FBUtilities; /** @@ -35,7 +34,7 @@ public abstract class PerColumnSecondaryIndex extends SecondaryIndex * @param rowKey the underlying row key which is indexed * @param col all the column info */ - public abstract void delete(ByteBuffer rowKey, IColumn col); + public abstract void delete(ByteBuffer rowKey, Column col); /** * insert a column to the index @@ -43,7 +42,7 @@ public abstract class PerColumnSecondaryIndex extends SecondaryIndex * @param rowKey the underlying row key which is indexed * @param col all the column info */ - public abstract void insert(ByteBuffer rowKey, IColumn col); + public abstract void insert(ByteBuffer rowKey, Column col); /** * update a column from the index @@ -51,7 +50,7 @@ public abstract class PerColumnSecondaryIndex extends SecondaryIndex * @param rowKey the underlying row key which is indexed * @param col all the column info */ - public abstract void update(ByteBuffer rowKey, IColumn col); + public abstract void update(ByteBuffer rowKey, Column col); public String getNameForSystemTable(ByteBuffer column) { @@ -61,6 +60,6 @@ public abstract class PerColumnSecondaryIndex extends SecondaryIndex @Override public boolean validate(Column column) { - return column.value.remaining() < FBUtilities.MAX_UNSIGNED_SHORT; + return column.value().remaining() < FBUtilities.MAX_UNSIGNED_SHORT; } } diff --git a/src/java/org/apache/cassandra/db/index/PerRowSecondaryIndex.java b/src/java/org/apache/cassandra/db/index/PerRowSecondaryIndex.java index 0200667725..1dd2de7f67 100644 --- a/src/java/org/apache/cassandra/db/index/PerRowSecondaryIndex.java +++ b/src/java/org/apache/cassandra/db/index/PerRowSecondaryIndex.java @@ -20,9 +20,9 @@ package org.apache.cassandra.db.index; import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.DecoratedKey; -import org.apache.cassandra.thrift.Column; import org.apache.cassandra.utils.ByteBufferUtil; /** diff --git a/src/java/org/apache/cassandra/db/index/SecondaryIndex.java b/src/java/org/apache/cassandra/db/index/SecondaryIndex.java index c7af4f1fd6..f78061ca22 100644 --- a/src/java/org/apache/cassandra/db/index/SecondaryIndex.java +++ b/src/java/org/apache/cassandra/db/index/SecondaryIndex.java @@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.ColumnDefinition; import org.apache.cassandra.exceptions.ConfigurationException; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.SystemTable; @@ -41,7 +42,6 @@ import org.apache.cassandra.db.marshal.LocalByPartionerType; import org.apache.cassandra.dht.*; import org.apache.cassandra.io.sstable.ReducingKeyIterator; import org.apache.cassandra.io.sstable.SSTableReader; -import org.apache.cassandra.thrift.Column; import org.apache.cassandra.service.StorageService; /** diff --git a/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java b/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java index 1be04dd88c..0de43b3b08 100644 --- a/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java +++ b/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java @@ -36,7 +36,6 @@ import org.apache.cassandra.db.compaction.CompactionManager; import org.apache.cassandra.dht.AbstractBounds; import org.apache.cassandra.io.sstable.ReducingKeyIterator; import org.apache.cassandra.io.sstable.SSTableReader; -import org.apache.cassandra.thrift.Column; import org.apache.cassandra.thrift.IndexExpression; /** @@ -49,11 +48,11 @@ public class SecondaryIndexManager public static final Updater nullUpdater = new Updater() { - public void insert(IColumn column) { } + public void insert(Column column) { } - public void update(IColumn oldColumn, IColumn column) { } + public void update(Column oldColumn, Column column) { } - public void remove(IColumn current) { } + public void remove(Column current) { } }; /** @@ -172,7 +171,7 @@ public class SecondaryIndexManager return null; } - public boolean indexes(IColumn column) + public boolean indexes(Column column) { return indexes(column.name()); } @@ -434,7 +433,7 @@ public class SecondaryIndexManager } else { - for (IColumn column : cf) + for (Column column : cf) { if (index.indexes(column.name())) ((PerColumnSecondaryIndex) index).insert(key, column); @@ -449,12 +448,12 @@ public class SecondaryIndexManager * @param key the row key * @param indexedColumnsInRow all column names in row */ - public void deleteFromIndexes(DecoratedKey key, List indexedColumnsInRow) + public void deleteFromIndexes(DecoratedKey key, List indexedColumnsInRow) { // Update entire row only once per row level index Set> cleanedRowLevelIndexes = null; - for (IColumn column : indexedColumnsInRow) + for (Column column : indexedColumnsInRow) { SecondaryIndex index = indexesByColumn.get(column.name()); if (index == null) @@ -574,17 +573,17 @@ public class SecondaryIndexManager public boolean validate(Column column) { - SecondaryIndex index = getIndexForColumn(column.name); + SecondaryIndex index = getIndexForColumn(column.name()); return index != null ? index.validate(column) : true; } public static interface Updater { - public void insert(IColumn column); + public void insert(Column column); - public void update(IColumn oldColumn, IColumn column); + public void update(Column oldColumn, Column column); - public void remove(IColumn current); + public void remove(Column current); } private class PerColumnIndexUpdater implements Updater @@ -596,7 +595,7 @@ public class SecondaryIndexManager this.key = key; } - public void insert(IColumn column) + public void insert(Column column) { if (column.isMarkedForDelete()) return; @@ -608,7 +607,7 @@ public class SecondaryIndexManager ((PerColumnSecondaryIndex) index).insert(key.key, column); } - public void update(IColumn oldColumn, IColumn column) + public void update(Column oldColumn, Column column) { if (column.isMarkedForDelete()) return; @@ -621,7 +620,7 @@ public class SecondaryIndexManager ((PerColumnSecondaryIndex) index).insert(key.key, column); } - public void remove(IColumn column) + public void remove(Column column) { if (column.isMarkedForDelete()) return; @@ -644,7 +643,7 @@ public class SecondaryIndexManager this.key = key; } - public void insert(IColumn column) + public void insert(Column column) { if (column.isMarkedForDelete()) return; @@ -664,7 +663,7 @@ public class SecondaryIndexManager } } - public void update(IColumn oldColumn, IColumn column) + public void update(Column oldColumn, Column column) { if (column.isMarkedForDelete()) return; @@ -685,7 +684,7 @@ public class SecondaryIndexManager } } - public void remove(IColumn column) + public void remove(Column column) { if (column.isMarkedForDelete()) return; diff --git a/src/java/org/apache/cassandra/db/index/SecondaryIndexSearcher.java b/src/java/org/apache/cassandra/db/index/SecondaryIndexSearcher.java index a8c1dde3e8..3085f48a1e 100644 --- a/src/java/org/apache/cassandra/db/index/SecondaryIndexSearcher.java +++ b/src/java/org/apache/cassandra/db/index/SecondaryIndexSearcher.java @@ -47,7 +47,7 @@ public abstract class SecondaryIndexSearcher protected boolean isIndexValueStale(ColumnFamily liveData, ByteBuffer indexedColumnName, ByteBuffer indexedValue) { - IColumn liveColumn = liveData.getColumn(indexedColumnName); + Column liveColumn = liveData.getColumn(indexedColumnName); if (liveColumn == null || liveColumn.isMarkedForDelete()) return true; diff --git a/src/java/org/apache/cassandra/db/index/composites/CompositesIndex.java b/src/java/org/apache/cassandra/db/index/composites/CompositesIndex.java index f1aa4aa3cc..3d10ec585a 100644 --- a/src/java/org/apache/cassandra/db/index/composites/CompositesIndex.java +++ b/src/java/org/apache/cassandra/db/index/composites/CompositesIndex.java @@ -56,7 +56,7 @@ public class CompositesIndex extends AbstractSimplePerColumnSecondaryIndex indexComparator = (CompositeType)SecondaryIndex.getIndexComparator(baseCfs.metadata, columnDef); } - protected ByteBuffer makeIndexColumnName(ByteBuffer rowKey, IColumn column) + protected ByteBuffer makeIndexColumnName(ByteBuffer rowKey, Column column) { CompositeType baseComparator = (CompositeType)baseCfs.getComparator(); ByteBuffer[] components = baseComparator.split(column.name()); diff --git a/src/java/org/apache/cassandra/db/index/composites/CompositesSearcher.java b/src/java/org/apache/cassandra/db/index/composites/CompositesSearcher.java index 29333b1ca2..1f201db9f6 100644 --- a/src/java/org/apache/cassandra/db/index/composites/CompositesSearcher.java +++ b/src/java/org/apache/cassandra/db/index/composites/CompositesSearcher.java @@ -160,8 +160,7 @@ public class CompositesSearcher extends SecondaryIndexSearcher return new ColumnFamilyStore.AbstractScanIterator() { private ByteBuffer lastSeenPrefix = startPrefix; - private Deque indexColumns; - private final QueryPath path = new QueryPath(baseCfs.name); + private Deque indexColumns; private int columnsRead = Integer.MAX_VALUE; private final int meanColumns = Math.max(index.getIndexCfs().getMeanColumns(), 1); @@ -218,7 +217,7 @@ public class CompositesSearcher extends SecondaryIndexSearcher ((AbstractSimplePerColumnSecondaryIndex)index).expressionString(primary), indexComparator.getString(startPrefix)); QueryFilter indexFilter = QueryFilter.getSliceFilter(indexKey, - new QueryPath(index.getIndexCfs().name), + index.getIndexCfs().name, lastSeenPrefix, endPrefix, false, @@ -227,10 +226,10 @@ public class CompositesSearcher extends SecondaryIndexSearcher if (indexRow == null) return makeReturn(currentKey, data); - Collection sortedColumns = indexRow.getSortedColumns(); + Collection sortedColumns = indexRow.getSortedColumns(); columnsRead = sortedColumns.size(); indexColumns = new ArrayDeque(sortedColumns); - IColumn firstColumn = sortedColumns.iterator().next(); + Column firstColumn = sortedColumns.iterator().next(); // Paging is racy, so it is possible the first column of a page is not the last seen one. if (lastSeenPrefix != startPrefix && lastSeenPrefix.equals(firstColumn.name())) @@ -249,7 +248,7 @@ public class CompositesSearcher extends SecondaryIndexSearcher while (!indexColumns.isEmpty() && columnsCount <= limit) { - IColumn column = indexColumns.poll(); + Column column = indexColumns.poll(); lastSeenPrefix = column.name(); if (column.isMarkedForDelete()) { @@ -302,7 +301,7 @@ public class CompositesSearcher extends SecondaryIndexSearcher continue; SliceQueryFilter dataFilter = new SliceQueryFilter(start, builder.copy().buildAsEndOfRange(), false, Integer.MAX_VALUE, prefixSize); - ColumnFamily newData = baseCfs.getColumnFamily(new QueryFilter(dk, path, dataFilter)); + ColumnFamily newData = baseCfs.getColumnFamily(new QueryFilter(dk, baseCfs.name, dataFilter)); if (newData != null) { ByteBuffer baseColumnName = builder.copy().add(primary.column_name).build(); @@ -311,7 +310,7 @@ public class CompositesSearcher extends SecondaryIndexSearcher if (isIndexValueStale(newData, baseColumnName, indexedValue)) { // delete the index entry w/ its own timestamp - IColumn dummyColumn = new Column(baseColumnName, indexedValue, column.timestamp()); + Column dummyColumn = new Column(baseColumnName, indexedValue, column.timestamp()); ((PerColumnSecondaryIndex) index).delete(dk.key, dummyColumn); continue; } diff --git a/src/java/org/apache/cassandra/db/index/keys/KeysIndex.java b/src/java/org/apache/cassandra/db/index/keys/KeysIndex.java index 04c9946ee6..8d065ab6ae 100644 --- a/src/java/org/apache/cassandra/db/index/keys/KeysIndex.java +++ b/src/java/org/apache/cassandra/db/index/keys/KeysIndex.java @@ -21,7 +21,7 @@ import java.nio.ByteBuffer; import java.util.Set; import org.apache.cassandra.config.ColumnDefinition; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.index.AbstractSimplePerColumnSecondaryIndex; import org.apache.cassandra.db.index.SecondaryIndexSearcher; import org.apache.cassandra.db.marshal.AbstractType; @@ -38,7 +38,7 @@ public class KeysIndex extends AbstractSimplePerColumnSecondaryIndex // Nothing specific } - protected ByteBuffer makeIndexColumnName(ByteBuffer rowKey, IColumn column) + protected ByteBuffer makeIndexColumnName(ByteBuffer rowKey, Column column) { return rowKey; } diff --git a/src/java/org/apache/cassandra/db/index/keys/KeysSearcher.java b/src/java/org/apache/cassandra/db/index/keys/KeysSearcher.java index cc7773c1e4..62cdb7887f 100644 --- a/src/java/org/apache/cassandra/db/index/keys/KeysSearcher.java +++ b/src/java/org/apache/cassandra/db/index/keys/KeysSearcher.java @@ -108,8 +108,7 @@ public class KeysSearcher extends SecondaryIndexSearcher return new ColumnFamilyStore.AbstractScanIterator() { private ByteBuffer lastSeenKey = startKey; - private Iterator indexColumns; - private final QueryPath path = new QueryPath(baseCfs.name); + private Iterator indexColumns; private int columnsRead = Integer.MAX_VALUE; protected Row computeNext() @@ -132,7 +131,7 @@ public class KeysSearcher extends SecondaryIndexSearcher ((AbstractSimplePerColumnSecondaryIndex)index).expressionString(primary), index.getBaseCfs().metadata.getKeyValidator().getString(startKey)); QueryFilter indexFilter = QueryFilter.getSliceFilter(indexKey, - new QueryPath(index.getIndexCfs().name), + index.getIndexCfs().name, lastSeenKey, endKey, false, @@ -145,10 +144,10 @@ public class KeysSearcher extends SecondaryIndexSearcher return endOfData(); } - Collection sortedColumns = indexRow.getSortedColumns(); + Collection sortedColumns = indexRow.getSortedColumns(); columnsRead = sortedColumns.size(); indexColumns = sortedColumns.iterator(); - IColumn firstColumn = sortedColumns.iterator().next(); + Column firstColumn = sortedColumns.iterator().next(); // Paging is racy, so it is possible the first column of a page is not the last seen one. if (lastSeenKey != startKey && lastSeenKey.equals(firstColumn.name())) @@ -167,7 +166,7 @@ public class KeysSearcher extends SecondaryIndexSearcher while (indexColumns.hasNext()) { - IColumn column = indexColumns.next(); + Column column = indexColumns.next(); lastSeenKey = column.name(); if (column.isMarkedForDelete()) { @@ -188,7 +187,7 @@ public class KeysSearcher extends SecondaryIndexSearcher } logger.trace("Returning index hit for {}", dk); - ColumnFamily data = baseCfs.getColumnFamily(new QueryFilter(dk, path, filter.initialFilter())); + ColumnFamily data = baseCfs.getColumnFamily(new QueryFilter(dk, baseCfs.name, filter.initialFilter())); // While the column family we'll get in the end should contains the primary clause column, the initialFilter may not have found it and can thus be null if (data == null) data = ColumnFamily.create(baseCfs.metadata); @@ -198,7 +197,7 @@ public class KeysSearcher extends SecondaryIndexSearcher IDiskAtomFilter extraFilter = filter.getExtraFilter(data); if (extraFilter != null) { - ColumnFamily cf = baseCfs.getColumnFamily(new QueryFilter(dk, path, extraFilter)); + ColumnFamily cf = baseCfs.getColumnFamily(new QueryFilter(dk, baseCfs.name, extraFilter)); if (cf != null) data.addAll(cf, HeapAllocator.instance); } @@ -206,7 +205,7 @@ public class KeysSearcher extends SecondaryIndexSearcher if (isIndexValueStale(data, primary.column_name, indexKey.key)) { // delete the index entry w/ its own timestamp - IColumn dummyColumn = new Column(primary.column_name, indexKey.key, column.timestamp()); + Column dummyColumn = new Column(primary.column_name, indexKey.key, column.timestamp()); ((PerColumnSecondaryIndex)index).delete(dk.key, dummyColumn); continue; } diff --git a/src/java/org/apache/cassandra/db/marshal/AbstractType.java b/src/java/org/apache/cassandra/db/marshal/AbstractType.java index 5393c0cfa5..b3d158df59 100644 --- a/src/java/org/apache/cassandra/db/marshal/AbstractType.java +++ b/src/java/org/apache/cassandra/db/marshal/AbstractType.java @@ -23,7 +23,7 @@ import java.util.Comparator; import java.util.Map; import org.apache.cassandra.exceptions.SyntaxException; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.OnDiskAtom; import org.apache.cassandra.db.RangeTombstone; import static org.apache.cassandra.io.sstable.IndexHelper.IndexInfo; @@ -40,8 +40,8 @@ public abstract class AbstractType implements Comparator { public final Comparator indexComparator; public final Comparator indexReverseComparator; - public final Comparator columnComparator; - public final Comparator columnReverseComparator; + public final Comparator columnComparator; + public final Comparator columnReverseComparator; public final Comparator onDiskAtomComparator; public final Comparator reverseComparator; @@ -61,16 +61,16 @@ public abstract class AbstractType implements Comparator return AbstractType.this.compare(o1.firstName, o2.firstName); } }; - columnComparator = new Comparator() + columnComparator = new Comparator() { - public int compare(IColumn c1, IColumn c2) + public int compare(Column c1, Column c2) { return AbstractType.this.compare(c1.name(), c2.name()); } }; - columnReverseComparator = new Comparator() + columnReverseComparator = new Comparator() { - public int compare(IColumn c1, IColumn c2) + public int compare(Column c1, Column c2) { return AbstractType.this.compare(c2.name(), c1.name()); } @@ -159,10 +159,10 @@ public abstract class AbstractType implements Comparator } /* convenience method */ - public String getColumnsString(Collection columns) + public String getColumnsString(Collection columns) { StringBuilder builder = new StringBuilder(); - for (IColumn column : columns) + for (Column column : columns) { builder.append(column.getString(this)).append(","); } diff --git a/src/java/org/apache/cassandra/db/marshal/CollectionType.java b/src/java/org/apache/cassandra/db/marshal/CollectionType.java index a19912b778..621e5c3e31 100644 --- a/src/java/org/apache/cassandra/db/marshal/CollectionType.java +++ b/src/java/org/apache/cassandra/db/marshal/CollectionType.java @@ -20,7 +20,7 @@ package org.apache.cassandra.db.marshal; import java.nio.ByteBuffer; import java.util.List; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.Pair; @@ -49,7 +49,7 @@ public abstract class CollectionType extends AbstractType protected abstract void appendToStringBuilder(StringBuilder sb); - public abstract ByteBuffer serialize(List> columns); + public abstract ByteBuffer serialize(List> columns); @Override public String toString() diff --git a/src/java/org/apache/cassandra/db/marshal/CompositeType.java b/src/java/org/apache/cassandra/db/marshal/CompositeType.java index fb80906f49..d843f5a91f 100644 --- a/src/java/org/apache/cassandra/db/marshal/CompositeType.java +++ b/src/java/org/apache/cassandra/db/marshal/CompositeType.java @@ -68,6 +68,11 @@ public class CompositeType extends AbstractCompositeType return getInstance(parser.getTypeParameters()); } + public static CompositeType getInstance(AbstractType... types) + { + return getInstance(Arrays.>asList(types)); + } + public static synchronized CompositeType getInstance(List> types) { assert types != null && !types.isEmpty(); @@ -126,6 +131,23 @@ public class CompositeType extends AbstractCompositeType return build(serialized); } + // Extract component idx from bb. Return null if there is not enough component. + public static ByteBuffer extractComponent(ByteBuffer bb, int idx) + { + bb = bb.duplicate(); + int i = 0; + while (bb.remaining() > 0) + { + ByteBuffer c = getWithShortLength(bb); + if (i == idx) + return c; + + bb.get(); // skip end-of-component + ++i; + } + return null; + } + @Override public boolean isCompatibleWith(AbstractType previous) { @@ -190,7 +212,7 @@ public class CompositeType extends AbstractCompositeType return new Builder(this); } - public ByteBuffer build(ByteBuffer... buffers) + public static ByteBuffer build(ByteBuffer... buffers) { int totalLength = 0; for (ByteBuffer bb : buffers) @@ -200,7 +222,7 @@ public class CompositeType extends AbstractCompositeType for (ByteBuffer bb : buffers) { putShortLength(out, bb.remaining()); - out.put(bb); + out.put(bb.duplicate()); out.put((byte) 0); } out.flip(); diff --git a/src/java/org/apache/cassandra/db/marshal/ListType.java b/src/java/org/apache/cassandra/db/marshal/ListType.java index 589e29eb82..76cf748193 100644 --- a/src/java/org/apache/cassandra/db/marshal/ListType.java +++ b/src/java/org/apache/cassandra/db/marshal/ListType.java @@ -21,7 +21,7 @@ import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.util.*; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.SyntaxException; import org.apache.cassandra.utils.Pair; @@ -118,11 +118,11 @@ public class ListType extends CollectionType> sb.append(getClass().getName()).append(TypeParser.stringifyTypeParameters(Collections.>singletonList(elements))); } - public ByteBuffer serialize(List> columns) + public ByteBuffer serialize(List> columns) { List bbs = new ArrayList(columns.size()); int size = 0; - for (Pair p : columns) + for (Pair p : columns) { bbs.add(p.right.value()); size += 2 + p.right.value().remaining(); diff --git a/src/java/org/apache/cassandra/db/marshal/MapType.java b/src/java/org/apache/cassandra/db/marshal/MapType.java index 8364ea037a..820abfa499 100644 --- a/src/java/org/apache/cassandra/db/marshal/MapType.java +++ b/src/java/org/apache/cassandra/db/marshal/MapType.java @@ -21,7 +21,7 @@ import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.util.*; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.SyntaxException; import org.apache.cassandra.utils.Pair; @@ -135,11 +135,11 @@ public class MapType extends CollectionType> /** * Creates the same output than decompose, but from the internal representation. */ - public ByteBuffer serialize(List> columns) + public ByteBuffer serialize(List> columns) { List bbs = new ArrayList(2 * columns.size()); int size = 0; - for (Pair p : columns) + for (Pair p : columns) { bbs.add(p.left); bbs.add(p.right.value()); diff --git a/src/java/org/apache/cassandra/db/marshal/SetType.java b/src/java/org/apache/cassandra/db/marshal/SetType.java index bbfb46fc75..31afd66a7c 100644 --- a/src/java/org/apache/cassandra/db/marshal/SetType.java +++ b/src/java/org/apache/cassandra/db/marshal/SetType.java @@ -21,7 +21,7 @@ import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.util.*; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.SyntaxException; import org.apache.cassandra.utils.Pair; @@ -118,11 +118,11 @@ public class SetType extends CollectionType> sb.append(getClass().getName()).append(TypeParser.stringifyTypeParameters(Collections.>singletonList(elements))); } - public ByteBuffer serialize(List> columns) + public ByteBuffer serialize(List> columns) { List bbs = new ArrayList(columns.size()); int size = 0; - for (Pair p : columns) + for (Pair p : columns) { bbs.add(p.left); size += 2 + p.left.remaining(); diff --git a/src/java/org/apache/cassandra/hadoop/ColumnFamilyInputFormat.java b/src/java/org/apache/cassandra/hadoop/ColumnFamilyInputFormat.java index 057d46a754..a78a4ca97b 100644 --- a/src/java/org/apache/cassandra/hadoop/ColumnFamilyInputFormat.java +++ b/src/java/org/apache/cassandra/hadoop/ColumnFamilyInputFormat.java @@ -37,7 +37,7 @@ import org.apache.thrift.TApplicationException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.Range; import org.apache.cassandra.dht.Token; @@ -65,8 +65,8 @@ import org.apache.thrift.TException; * * The default split size is 64k rows. */ -public class ColumnFamilyInputFormat extends InputFormat> - implements org.apache.hadoop.mapred.InputFormat> +public class ColumnFamilyInputFormat extends InputFormat> + implements org.apache.hadoop.mapred.InputFormat> { private static final Logger logger = LoggerFactory.getLogger(ColumnFamilyInputFormat.class); @@ -313,7 +313,7 @@ public class ColumnFamilyInputFormat extends InputFormat> createRecordReader(InputSplit inputSplit, TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException + public RecordReader> createRecordReader(InputSplit inputSplit, TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException { return new ColumnFamilyRecordReader(); } @@ -332,7 +332,7 @@ public class ColumnFamilyInputFormat extends InputFormat> getRecordReader(org.apache.hadoop.mapred.InputSplit split, JobConf jobConf, final Reporter reporter) throws IOException + public org.apache.hadoop.mapred.RecordReader> getRecordReader(org.apache.hadoop.mapred.InputSplit split, JobConf jobConf, final Reporter reporter) throws IOException { TaskAttemptContext tac = new TaskAttemptContext(jobConf, TaskAttemptID.forName(jobConf.get(MAPRED_TASK_ID))) { diff --git a/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java b/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java index 07a54601a9..ea98cc94d5 100644 --- a/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java +++ b/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java @@ -30,11 +30,26 @@ import org.slf4j.LoggerFactory; import org.apache.cassandra.auth.IAuthenticator; import org.apache.cassandra.exceptions.ConfigurationException; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.db.marshal.TypeParser; import org.apache.cassandra.dht.IPartitioner; -import org.apache.cassandra.thrift.*; +import org.apache.cassandra.thrift.AuthenticationRequest; +import org.apache.cassandra.thrift.Cassandra; +import org.apache.cassandra.thrift.CfDef; +import org.apache.cassandra.thrift.ColumnOrSuperColumn; +import org.apache.cassandra.thrift.ColumnParent; +import org.apache.cassandra.thrift.ConsistencyLevel; +import org.apache.cassandra.thrift.CounterColumn; +import org.apache.cassandra.thrift.CounterSuperColumn; +import org.apache.cassandra.thrift.IndexExpression; +import org.apache.cassandra.thrift.KeyRange; +import org.apache.cassandra.thrift.KeySlice; +import org.apache.cassandra.thrift.KsDef; +import org.apache.cassandra.thrift.SlicePredicate; +import org.apache.cassandra.thrift.SuperColumn; +import org.apache.cassandra.thrift.TBinaryProtocol; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.Pair; @@ -45,8 +60,8 @@ import org.apache.hadoop.mapreduce.TaskAttemptContext; import org.apache.thrift.TException; import org.apache.thrift.transport.TSocket; -public class ColumnFamilyRecordReader extends RecordReader> - implements org.apache.hadoop.mapred.RecordReader> +public class ColumnFamilyRecordReader extends RecordReader> + implements org.apache.hadoop.mapred.RecordReader> { private static final Logger logger = LoggerFactory.getLogger(ColumnFamilyRecordReader.class); @@ -54,7 +69,7 @@ public class ColumnFamilyRecordReader extends RecordReader> currentRow; + private Pair> currentRow; private SlicePredicate predicate; private boolean isEmptyPredicate; private int totalRowCount; // total number of rows to fetch @@ -93,7 +108,7 @@ public class ColumnFamilyRecordReader extends RecordReader getCurrentValue() + public SortedMap getCurrentValue() { return currentRow.right; } @@ -219,10 +234,11 @@ public class ColumnFamilyRecordReader extends RecordReader>> + private abstract class RowIterator extends AbstractIterator>> { protected List rows; protected int totalRead = 0; + protected final boolean isSuper; protected final AbstractType comparator; protected final AbstractType subComparator; protected final IPartitioner partitioner; @@ -242,6 +258,7 @@ public class ColumnFamilyRecordReader extends RecordReader unthriftify(ColumnOrSuperColumn cosc) { if (cosc.counter_column != null) - return unthriftifyCounter(cosc.counter_column); + return Collections.singletonList(unthriftifyCounter(cosc.counter_column)); if (cosc.counter_super_column != null) return unthriftifySuperCounter(cosc.counter_super_column); if (cosc.super_column != null) return unthriftifySuper(cosc.super_column); assert cosc.column != null; - return unthriftifySimple(cosc.column); + return Collections.singletonList(unthriftifySimple(cosc.column)); } - private IColumn unthriftifySuper(SuperColumn super_column) + private List unthriftifySuper(SuperColumn super_column) { - org.apache.cassandra.db.SuperColumn sc = new org.apache.cassandra.db.SuperColumn(super_column.name, subComparator); - for (Column column : super_column.columns) + List columns = new ArrayList(super_column.columns.size()); + for (org.apache.cassandra.thrift.Column column : super_column.columns) { - sc.addColumn(unthriftifySimple(column)); + Column c = unthriftifySimple(column); + columns.add(c.withUpdatedName(CompositeType.build(super_column.name, c.name()))); } - return sc; + return columns; } - protected IColumn unthriftifySimple(Column column) + protected Column unthriftifySimple(org.apache.cassandra.thrift.Column column) { - return new org.apache.cassandra.db.Column(column.name, column.value, column.timestamp); + return new Column(column.name, column.value, column.timestamp); } - private IColumn unthriftifyCounter(CounterColumn column) + private Column unthriftifyCounter(CounterColumn column) { //CounterColumns read the counterID from the System table, so need the StorageService running and access //to cassandra.yaml. To avoid a Hadoop needing access to yaml return a regular Column. - return new org.apache.cassandra.db.Column(column.name, ByteBufferUtil.bytes(column.value), 0); + return new Column(column.name, ByteBufferUtil.bytes(column.value), 0); } - private IColumn unthriftifySuperCounter(CounterSuperColumn superColumn) + private List unthriftifySuperCounter(CounterSuperColumn super_column) { - org.apache.cassandra.db.SuperColumn sc = new org.apache.cassandra.db.SuperColumn(superColumn.name, subComparator); - for (CounterColumn column : superColumn.columns) - sc.addColumn(unthriftifyCounter(column)); - return sc; + List columns = new ArrayList(super_column.columns.size()); + for (CounterColumn column : super_column.columns) + { + Column c = unthriftifyCounter(column); + columns.add(c.withUpdatedName(CompositeType.build(super_column.name, c.name()))); + } + return columns; } } @@ -385,7 +406,7 @@ public class ColumnFamilyRecordReader extends RecordReader> computeNext() + protected Pair> computeNext() { maybeInit(); if (rows == null) @@ -393,11 +414,12 @@ public class ColumnFamilyRecordReader extends RecordReader map = new TreeMap(comparator); + SortedMap map = new TreeMap(comparator); for (ColumnOrSuperColumn cosc : ks.columns) { - IColumn column = unthriftify(cosc); - map.put(column.name(), column); + List columns = unthriftify(cosc); + for (Column column : columns) + map.put(column.name(), column); } return Pair.create(ks.key, map); } @@ -405,7 +427,7 @@ public class ColumnFamilyRecordReader extends RecordReader>> wideColumns; + private PeekingIterator>> wideColumns; private ByteBuffer lastColumn = ByteBufferUtil.EMPTY_BYTE_BUFFER; private ByteBuffer lastCountedKey = ByteBufferUtil.EMPTY_BYTE_BUFFER; @@ -454,13 +476,13 @@ public class ColumnFamilyRecordReader extends RecordReader> computeNext() + protected Pair> computeNext() { maybeInit(); if (rows == null) return endOfData(); - Pair> next = wideColumns.next(); + Pair> next = wideColumns.next(); lastColumn = next.right.values().iterator().next().name(); maybeIncreaseRowCounter(next); @@ -472,7 +494,7 @@ public class ColumnFamilyRecordReader extends RecordReader> next) + private void maybeIncreaseRowCounter(Pair> next) { ByteBuffer currentKey = next.left; if (!currentKey.equals(lastCountedKey)) @@ -482,7 +504,7 @@ public class ColumnFamilyRecordReader extends RecordReader>> + private class WideColumnIterator extends AbstractIterator>> { private final Iterator rows; private Iterator columns; @@ -503,16 +525,27 @@ public class ColumnFamilyRecordReader extends RecordReader> computeNext() + protected Pair> computeNext() { while (true) { if (columns.hasNext()) { ColumnOrSuperColumn cosc = columns.next(); - IColumn column = unthriftify(cosc); - ImmutableSortedMap map = ImmutableSortedMap.of(column.name(), column); - return Pair.>create(currentRow.key, map); + SortedMap map; + List columns = unthriftify(cosc); + if (columns.size() == 1) + { + map = ImmutableSortedMap.of(columns.get(0).name(), columns.get(0)); + } + else + { + assert isSuper; + map = new TreeMap(CompositeType.getInstance(comparator, subComparator)); + for (Column column : columns) + map.put(column.name(), column); + } + return Pair.>create(currentRow.key, map); } if (!rows.hasNext()) @@ -529,7 +562,7 @@ public class ColumnFamilyRecordReader extends RecordReader value) throws IOException + public boolean next(ByteBuffer key, SortedMap value) throws IOException { if (this.nextKeyValue()) { @@ -550,9 +583,9 @@ public class ColumnFamilyRecordReader extends RecordReader createValue() + public SortedMap createValue() { - return new TreeMap(); + return new TreeMap(); } public long getPos() throws IOException diff --git a/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java b/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java index 7c459b55a9..91174f309c 100644 --- a/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java +++ b/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java @@ -29,7 +29,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.cassandra.auth.IAuthenticator; import org.apache.cassandra.db.Column; -import org.apache.cassandra.db.IColumn; import org.apache.cassandra.db.marshal.*; import org.apache.cassandra.db.marshal.AbstractCompositeType.CompositeComponent; import org.apache.cassandra.hadoop.*; @@ -96,7 +95,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo private String storeSignature; private Configuration conf; - private RecordReader> reader; + private RecordReader> reader; private RecordWriter> writer; private String inputFormatClass; private String outputFormatClass; @@ -105,7 +104,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo private boolean usePartitionFilter = false; // wide row hacks private ByteBuffer lastKey; - private Map lastRow; + private Map lastRow; private boolean hasNext = true; public CassandraStorage() @@ -147,7 +146,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo key = (ByteBuffer)reader.getCurrentKey(); tuple.append(new DataByteArray(key.array(), key.position()+key.arrayOffset(), key.limit()+key.arrayOffset())); } - for (Map.Entry entry : lastRow.entrySet()) + for (Map.Entry entry : lastRow.entrySet()) { bag.add(columnToTuple(entry.getValue(), cfDef, parseType(cfDef.getComparator_type()))); } @@ -171,7 +170,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo { // read too much, hold on to it for next time lastKey = (ByteBuffer)reader.getCurrentKey(); - lastRow = (SortedMap)reader.getCurrentValue(); + lastRow = (SortedMap)reader.getCurrentValue(); // but return what we have so far tuple.append(bag); return tuple; @@ -182,28 +181,28 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo if (lastKey != null && !(key.equals(lastKey))) // last key only had one value { tuple.append(new DataByteArray(lastKey.array(), lastKey.position()+lastKey.arrayOffset(), lastKey.limit()+lastKey.arrayOffset())); - for (Map.Entry entry : lastRow.entrySet()) + for (Map.Entry entry : lastRow.entrySet()) { bag.add(columnToTuple(entry.getValue(), cfDef, parseType(cfDef.getComparator_type()))); } tuple.append(bag); lastKey = key; - lastRow = (SortedMap)reader.getCurrentValue(); + lastRow = (SortedMap)reader.getCurrentValue(); return tuple; } tuple.append(new DataByteArray(key.array(), key.position()+key.arrayOffset(), key.limit()+key.arrayOffset())); } - SortedMap row = (SortedMap)reader.getCurrentValue(); + SortedMap row = (SortedMap)reader.getCurrentValue(); if (lastRow != null) // prepend what was read last time { - for (Map.Entry entry : lastRow.entrySet()) + for (Map.Entry entry : lastRow.entrySet()) { bag.add(columnToTuple(entry.getValue(), cfDef, parseType(cfDef.getComparator_type()))); } lastKey = null; lastRow = null; } - for (Map.Entry entry : row.entrySet()) + for (Map.Entry entry : row.entrySet()) { bag.add(columnToTuple(entry.getValue(), cfDef, parseType(cfDef.getComparator_type()))); } @@ -228,7 +227,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo CfDef cfDef = getCfDef(loadSignature); ByteBuffer key = reader.getCurrentKey(); - Map cf = reader.getCurrentValue(); + Map cf = reader.getCurrentValue(); assert key != null && cf != null; // output tuple, will hold the key, each indexed column in a tuple, then a bag of the rest @@ -253,7 +252,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo added.put(cdef.name, true); } // now add all the other columns - for (Map.Entry entry : cf.entrySet()) + for (Map.Entry entry : cf.entrySet()) { if (!added.containsKey(entry.getKey())) bag.add(columnToTuple(entry.getValue(), cfDef, parseType(cfDef.getComparator_type()))); @@ -307,7 +306,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo return tuple; } - private Tuple columnToTuple(IColumn col, CfDef cfDef, AbstractType comparator) throws IOException + private Tuple columnToTuple(Column col, CfDef cfDef, AbstractType comparator) throws IOException { Tuple pair = TupleFactory.getInstance().newTuple(2); @@ -319,27 +318,14 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo { setTupleValue(pair, 0, comparator.compose(col.name())); } - if (col instanceof Column) - { - // standard - List marshallers = getDefaultMarshallers(cfDef); - Map validators = getValidatorMap(cfDef); - if (validators.get(col.name()) == null) - setTupleValue(pair, 1, marshallers.get(1).compose(col.value())); - else - setTupleValue(pair, 1, validators.get(col.name()).compose(col.value())); - return pair; - } + List marshallers = getDefaultMarshallers(cfDef); + Map validators = getValidatorMap(cfDef); + + if (validators.get(col.name()) == null) + setTupleValue(pair, 1, marshallers.get(1).compose(col.value())); else - { - // super - ArrayList subcols = new ArrayList(); - for (IColumn subcol : col.getSubColumns()) - subcols.add(columnToTuple(subcol, cfDef, parseType(cfDef.getSubcomparator_type()))); - - pair.set(1, new DefaultDataBag(subcols)); - } + setTupleValue(pair, 1, validators.get(col.name()).compose(col.value())); return pair; } diff --git a/src/java/org/apache/cassandra/io/IColumnSerializer.java b/src/java/org/apache/cassandra/io/IColumnSerializer.java deleted file mode 100644 index 580214063d..0000000000 --- a/src/java/org/apache/cassandra/io/IColumnSerializer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.io; - -import java.io.DataInput; -import java.io.IOException; - -import org.apache.cassandra.db.IColumn; - -public interface IColumnSerializer extends ISerializer -{ - /** - * Flag affecting deserialization behavior. - * - LOCAL: for deserialization of local data (Expired columns are - * converted to tombstones (to gain disk space)). - * - FROM_REMOTE: for deserialization of data received from remote hosts - * (Expired columns are converted to tombstone and counters have - * their delta cleared) - * - PRESERVE_SIZE: used when no transformation must be performed, i.e, - * when we must ensure that deserializing and reserializing the - * result yield the exact same bytes. Streaming uses this. - */ - public static enum Flag - { - LOCAL, FROM_REMOTE, PRESERVE_SIZE; - } - - public IColumn deserialize(DataInput in, Flag flag, int expireBefore) throws IOException; -} - diff --git a/src/java/org/apache/cassandra/io/sstable/AbstractSSTableSimpleWriter.java b/src/java/org/apache/cassandra/io/sstable/AbstractSSTableSimpleWriter.java index f3d097f7fd..63a6071061 100644 --- a/src/java/org/apache/cassandra/io/sstable/AbstractSSTableSimpleWriter.java +++ b/src/java/org/apache/cassandra/io/sstable/AbstractSSTableSimpleWriter.java @@ -28,6 +28,7 @@ import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.*; import org.apache.cassandra.db.context.CounterContext; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.utils.CounterId; import org.apache.cassandra.utils.Pair; @@ -38,7 +39,7 @@ public abstract class AbstractSSTableSimpleWriter protected final CFMetaData metadata; protected DecoratedKey currentKey; protected ColumnFamily columnFamily; - protected SuperColumn currentSuperColumn; + protected ByteBuffer currentSuperColumn; protected final CounterId counterid = CounterId.generate(); public AbstractSSTableSimpleWriter(File directory, CFMetaData metadata, IPartitioner partitioner) @@ -102,20 +103,22 @@ public abstract class AbstractSSTableSimpleWriter */ public void newSuperColumn(ByteBuffer name) { - if (!columnFamily.isSuper()) + if (!columnFamily.metadata().isSuper()) throw new IllegalStateException("Cannot add a super column to a standard column family"); - currentSuperColumn = new SuperColumn(name, metadata.subcolumnComparator); - columnFamily.addColumn(currentSuperColumn); + currentSuperColumn = name; } - private void addColumn(IColumn column) + private void addColumn(Column column) { - if (columnFamily.isSuper() && currentSuperColumn == null) - throw new IllegalStateException("Trying to add a column to a super column family, but no super column has been started."); + if (columnFamily.metadata().isSuper()) + { + if (currentSuperColumn == null) + throw new IllegalStateException("Trying to add a column to a super column family, but no super column has been started."); - IColumnContainer container = columnFamily.isSuper() ? currentSuperColumn : columnFamily; - container.addColumn(column); + column = column.withUpdatedName(CompositeType.build(currentSuperColumn, column.name())); + } + columnFamily.addColumn(column); } /** diff --git a/src/java/org/apache/cassandra/io/sstable/Descriptor.java b/src/java/org/apache/cassandra/io/sstable/Descriptor.java index cf1907ec1b..c96a336640 100644 --- a/src/java/org/apache/cassandra/io/sstable/Descriptor.java +++ b/src/java/org/apache/cassandra/io/sstable/Descriptor.java @@ -47,7 +47,7 @@ public class Descriptor public static class Version { // This needs to be at the begining for initialization sake - private static final String current_version = "ib"; + private static final String current_version = "ic"; public static final Version LEGACY = new Version("a"); // "pre-history" // b (0.7.0): added version to sstable filenames @@ -66,6 +66,10 @@ public class Descriptor // records estimated histogram of deletion times in tombstones // bloom filter (keys and columns) upgraded to Murmur3 // ib (1.2.1): tracks min client timestamp in metadata component + // ja (1.3.0): super columns are serialized as composites + // (note that there is no real format change, this is mostly a marker to know if we should expect super + // columns or not. We do need a major version bump however, because we should not allow streaming of + // super columns into this new format) public static final Version CURRENT = new Version(current_version); @@ -85,6 +89,7 @@ public class Descriptor public final boolean hasPromotedIndexes; public final FilterFactory.Type filterType; public final boolean hasAncestors; + public final boolean hasSuperColumns; public Version(String version) { @@ -108,6 +113,7 @@ public class Descriptor filterType = FilterFactory.Type.MURMUR2; else filterType = FilterFactory.Type.MURMUR3; + hasSuperColumns = version.compareTo("ib") < 0; } /** diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java b/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java index d9aabfbae0..d2839c8233 100644 --- a/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java +++ b/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java @@ -18,6 +18,7 @@ package org.apache.cassandra.io.sstable; import java.io.*; +import java.util.Iterator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,7 +27,6 @@ import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.db.*; import org.apache.cassandra.db.columniterator.ICountableColumnIterator; import org.apache.cassandra.db.marshal.MarshalException; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.util.RandomAccessReader; import org.apache.cassandra.utils.BytesReadTracker; @@ -38,13 +38,13 @@ public class SSTableIdentityIterator implements Comparable atomIterator; private final Descriptor.Version dataVersion; private final BytesReadTracker inputWithTracker; // tracks bytes read @@ -80,11 +80,11 @@ public class SSTableIdentityIterator implements Comparable -{ - private final ColumnSerializer serializer; - private final DataInput dis; - private final Comparator comparator; - private final int length; - private final IColumnSerializer.Flag flag; - private final int expireBefore; - - public ColumnSortedMap(Comparator comparator, ColumnSerializer serializer, DataInput dis, int length, IColumnSerializer.Flag flag, int expireBefore) - { - this.comparator = comparator; - this.serializer = serializer; - this.dis = dis; - this.length = length; - this.flag = flag; - this.expireBefore = expireBefore; - } - - public int size() - { - return length; - } - - public boolean isEmpty() - { - throw new UnsupportedOperationException(); - } - - public boolean containsKey(Object key) - { - throw new UnsupportedOperationException(); - } - - public boolean containsValue(Object value) - { - throw new UnsupportedOperationException(); - } - - public IColumn get(Object key) - { - throw new UnsupportedOperationException(); - } - - public IColumn put(ByteBuffer key, IColumn value) - { - throw new UnsupportedOperationException(); - } - - public IColumn remove(Object key) - { - throw new UnsupportedOperationException(); - } - - public void putAll(Map m) - { - throw new UnsupportedOperationException(); - } - - public void clear() - { - - } - - public Comparator comparator() - { - return comparator; - } - - public SortedMap subMap(ByteBuffer fromKey, ByteBuffer toKey) - { - throw new UnsupportedOperationException(); - } - - public SortedMap headMap(ByteBuffer toKey) - { - throw new UnsupportedOperationException(); - } - - public SortedMap tailMap(ByteBuffer fromKey) - { - throw new UnsupportedOperationException(); - } - - public ByteBuffer firstKey() - { - throw new UnsupportedOperationException(); - } - - public ByteBuffer lastKey() - { - throw new UnsupportedOperationException(); - } - - public Set keySet() - { - throw new UnsupportedOperationException(); - } - - public Collection values() - { - throw new UnsupportedOperationException(); - } - - public Set> entrySet() - { - return new ColumnSet(serializer, dis, length, flag, expireBefore); - } -} - -class ColumnSet implements Set> -{ - private final ColumnSerializer serializer; - private final DataInput dis; - private final int length; - private final IColumnSerializer.Flag flag; - private final int expireBefore; - - public ColumnSet(ColumnSerializer serializer, DataInput dis, int length, IColumnSerializer.Flag flag, int expireBefore) - { - this.serializer = serializer; - this.dis = dis; - this.length = length; - this.flag = flag; - this.expireBefore = expireBefore; - } - - public int size() - { - return length; - } - - public boolean isEmpty() - { - throw new UnsupportedOperationException(); - } - - public boolean contains(Object o) - { - throw new UnsupportedOperationException(); - } - - public Iterator> iterator() - { - return new ColumnIterator(serializer, dis, length, flag, expireBefore); - } - - public Object[] toArray() - { - throw new UnsupportedOperationException(); - } - - public T[] toArray(T[] a) - { - throw new UnsupportedOperationException(); - } - - public boolean add(Entry e) - { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) - { - throw new UnsupportedOperationException(); - } - - public boolean containsAll(Collection c) - { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) - { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) - { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) - { - throw new UnsupportedOperationException(); - } - - public void clear() - { - } -} - -class ColumnIterator implements Iterator> -{ - private final ColumnSerializer serializer; - private final DataInput dis; - private final int length; - private final IColumnSerializer.Flag flag; - private int count = 0; - private final int expireBefore; - - public ColumnIterator(ColumnSerializer serializer, DataInput dis, int length, IColumnSerializer.Flag flag, int expireBefore) - { - this.dis = dis; - this.serializer = serializer; - this.length = length; - this.flag = flag; - this.expireBefore = expireBefore; - } - - private IColumn deserializeNext() - { - try - { - count++; - return serializer.deserialize(dis, flag, expireBefore); - } - catch (IOException e) - { - throw new IOError(e); // can't throw more detailed error. can't rethrow IOException - Iterator interface next(). - } - } - - public boolean hasNext() - { - return count < length; - } - - public Entry next() - { - if (!hasNext()) - { - throw new IllegalStateException("end of column iterator"); - } - - final IColumn column = deserializeNext(); - return new Entry() - { - public IColumn setValue(IColumn value) - { - throw new UnsupportedOperationException(); - } - - public IColumn getValue() - { - return column; - } - - public ByteBuffer getKey() - { - return column.name(); - } - }; - } - - public void remove() - { - throw new UnsupportedOperationException(); - } -} diff --git a/src/java/org/apache/cassandra/io/util/IIterableColumns.java b/src/java/org/apache/cassandra/io/util/IIterableColumns.java index 030bef3f80..68c5645952 100644 --- a/src/java/org/apache/cassandra/io/util/IIterableColumns.java +++ b/src/java/org/apache/cassandra/io/util/IIterableColumns.java @@ -17,10 +17,10 @@ */ package org.apache.cassandra.io.util; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.marshal.AbstractType; -public interface IIterableColumns extends Iterable +public interface IIterableColumns extends Iterable { public int getEstimatedColumnCount(); diff --git a/src/java/org/apache/cassandra/net/MessagingService.java b/src/java/org/apache/cassandra/net/MessagingService.java index 98495be742..84438b9b3d 100644 --- a/src/java/org/apache/cassandra/net/MessagingService.java +++ b/src/java/org/apache/cassandra/net/MessagingService.java @@ -73,7 +73,8 @@ public final class MessagingService implements MessagingServiceMBean public static final int VERSION_11 = 4; public static final int VERSION_117 = 5; public static final int VERSION_12 = 6; - public static final int current_version = VERSION_12; + public static final int VERSION_20 = 7; + public static final int current_version = VERSION_20; /** * we preface every message with this number so the recipient can validate the sender is sane diff --git a/src/java/org/apache/cassandra/service/CacheService.java b/src/java/org/apache/cassandra/service/CacheService.java index 7e3aca8d1a..b0aa693038 100644 --- a/src/java/org/apache/cassandra/service/CacheService.java +++ b/src/java/org/apache/cassandra/service/CacheService.java @@ -48,7 +48,6 @@ import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.RowIndexEntry; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.io.sstable.SSTableReader.Operator; @@ -340,7 +339,7 @@ public class CacheService implements CacheServiceMBean public Pair call() throws Exception { DecoratedKey key = cfs.partitioner.decorateKey(buffer); - ColumnFamily data = cfs.getTopLevelColumns(QueryFilter.getIdentityFilter(key, new QueryPath(cfs.name)), Integer.MIN_VALUE, true); + ColumnFamily data = cfs.getTopLevelColumns(QueryFilter.getIdentityFilter(key, cfs.name), Integer.MIN_VALUE, true); return Pair.create(new RowCacheKey(cfs.metadata.cfId, key), (IRowCacheEntry) data); } }); @@ -351,7 +350,7 @@ public class CacheService implements CacheServiceMBean for (ByteBuffer key : buffers) { DecoratedKey dk = cfs.partitioner.decorateKey(key); - ColumnFamily data = cfs.getTopLevelColumns(QueryFilter.getIdentityFilter(dk, new QueryPath(cfs.name)), Integer.MIN_VALUE, true); + ColumnFamily data = cfs.getTopLevelColumns(QueryFilter.getIdentityFilter(dk, cfs.name), Integer.MIN_VALUE, true); rowCache.put(new RowCacheKey(cfs.metadata.cfId, dk), data); } } diff --git a/src/java/org/apache/cassandra/service/IndexScanVerbHandler.java b/src/java/org/apache/cassandra/service/IndexScanVerbHandler.java index 5bd98760ba..6d030092ea 100644 --- a/src/java/org/apache/cassandra/service/IndexScanVerbHandler.java +++ b/src/java/org/apache/cassandra/service/IndexScanVerbHandler.java @@ -43,7 +43,7 @@ public class IndexScanVerbHandler implements IVerbHandler List rows = cfs.search(command.index_clause.expressions, command.range, command.index_clause.count, - ThriftValidation.asIFilter(command.predicate, cfs.getComparator())); + ThriftValidation.asIFilter(command.predicate, cfs.metadata, null)); RangeSliceReply reply = new RangeSliceReply(rows); Tracing.trace("Enqueuing response to {}", message.from); MessagingService.instance().sendReply(reply.createMessage(), id, message.from); diff --git a/src/java/org/apache/cassandra/service/MigrationManager.java b/src/java/org/apache/cassandra/service/MigrationManager.java index 43fa8f7841..943e6ae59d 100644 --- a/src/java/org/apache/cassandra/service/MigrationManager.java +++ b/src/java/org/apache/cassandra/service/MigrationManager.java @@ -41,7 +41,6 @@ import org.apache.cassandra.config.KSMetaData; import org.apache.cassandra.config.Schema; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.exceptions.AlreadyExistsException; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.gms.*; @@ -391,7 +390,7 @@ public class MigrationManager implements IEndpointStateChangeSubscriber DecoratedKey dkey = StorageService.getPartitioner().decorateKey(LAST_MIGRATION_KEY); Table defs = Table.open(Table.SYSTEM_KS); ColumnFamilyStore cfStore = defs.getColumnFamilyStore(DefsTable.OLD_SCHEMA_CF); - QueryFilter filter = QueryFilter.getNamesFilter(dkey, new QueryPath(DefsTable.OLD_SCHEMA_CF), LAST_MIGRATION_KEY); + QueryFilter filter = QueryFilter.getNamesFilter(dkey, DefsTable.OLD_SCHEMA_CF, LAST_MIGRATION_KEY); ColumnFamily cf = cfStore.getColumnFamily(filter); if (cf == null || cf.getColumnNames().size() == 0) return null; diff --git a/src/java/org/apache/cassandra/service/RangeSliceVerbHandler.java b/src/java/org/apache/cassandra/service/RangeSliceVerbHandler.java index ba8283f9e0..d8588a8d7d 100644 --- a/src/java/org/apache/cassandra/service/RangeSliceVerbHandler.java +++ b/src/java/org/apache/cassandra/service/RangeSliceVerbHandler.java @@ -43,7 +43,7 @@ public class RangeSliceVerbHandler implements IVerbHandler if (cfs.indexManager.hasIndexFor(command.row_filter)) return cfs.search(command.row_filter, command.range, command.maxResults, command.predicate, command.countCQL3Rows); else - return cfs.getRangeSlice(command.super_column, command.range, command.maxResults, command.predicate, command.row_filter, command.countCQL3Rows, command.isPaging); + return cfs.getRangeSlice(command.range, command.maxResults, command.predicate, command.row_filter, command.countCQL3Rows, command.isPaging); } public void doVerb(MessageIn message, String id) diff --git a/src/java/org/apache/cassandra/service/RowRepairResolver.java b/src/java/org/apache/cassandra/service/RowRepairResolver.java index 21cf5ab2a0..45b9e2cd63 100644 --- a/src/java/org/apache/cassandra/service/RowRepairResolver.java +++ b/src/java/org/apache/cassandra/service/RowRepairResolver.java @@ -30,7 +30,6 @@ import org.apache.cassandra.db.*; import org.apache.cassandra.db.columniterator.IdentityQueryFilter; import org.apache.cassandra.db.filter.IDiskAtomFilter; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.filter.SliceQueryFilter; import org.apache.cassandra.net.IAsyncResult; import org.apache.cassandra.net.MessageIn; @@ -153,8 +152,8 @@ public class RowRepairResolver extends AbstractRowResolver // mimic the collectCollatedColumn + removeDeleted path that getColumnFamily takes. // this will handle removing columns and subcolumns that are supressed by a row or // supercolumn tombstone. - QueryFilter filter = new QueryFilter(null, new QueryPath(resolved.metadata().cfName), new IdentityQueryFilter()); - List> iters = new ArrayList>(); + QueryFilter filter = new QueryFilter(null, resolved.metadata().cfName, new IdentityQueryFilter()); + List> iters = new ArrayList>(); for (ColumnFamily version : versions) { if (version == null) diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index 6408c0b0bf..212765e10b 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -43,7 +43,6 @@ import org.apache.cassandra.db.*; import org.apache.cassandra.db.Table; import org.apache.cassandra.db.filter.ColumnSlice; import org.apache.cassandra.db.filter.IDiskAtomFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.filter.SliceQueryFilter; import org.apache.cassandra.db.marshal.UUIDType; import org.apache.cassandra.dht.AbstractBounds; @@ -322,7 +321,7 @@ public class StorageProxy implements StorageProxyMBean private static void asyncRemoveFromBatchlog(Collection endpoints, UUID uuid) { RowMutation rm = new RowMutation(Table.SYSTEM_KS, UUIDType.instance.decompose(uuid)); - rm.delete(new QueryPath(SystemTable.BATCHLOG_CF), FBUtilities.timestampMicros()); + rm.delete(SystemTable.BATCHLOG_CF, FBUtilities.timestampMicros()); AbstractWriteResponseHandler handler = new WriteResponseHandler(endpoints, Collections.emptyList(), ConsistencyLevel.ANY, Table.SYSTEM_KS, null, WriteType.SIMPLE); updateBatchlog(rm, endpoints, handler); } @@ -1099,7 +1098,6 @@ public class StorageProxy implements StorageProxyMBean { RangeSliceCommand nodeCmd = new RangeSliceCommand(command.keyspace, command.column_family, - command.super_column, commandPredicate, range, command.row_filter, diff --git a/src/java/org/apache/cassandra/streaming/IncomingStreamReader.java b/src/java/org/apache/cassandra/streaming/IncomingStreamReader.java index 656a99d5c2..547e7e94be 100644 --- a/src/java/org/apache/cassandra/streaming/IncomingStreamReader.java +++ b/src/java/org/apache/cassandra/streaming/IncomingStreamReader.java @@ -30,11 +30,11 @@ import org.slf4j.LoggerFactory; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.ColumnSerializer; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.Table; import org.apache.cassandra.db.compaction.CompactionController; import org.apache.cassandra.db.compaction.PrecompactedRow; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.sstable.*; import org.apache.cassandra.io.util.FileUtils; import org.apache.cassandra.metrics.StreamingMetrics; @@ -164,7 +164,7 @@ public class IncomingStreamReader { // need to update row cache // Note: Because we won't just echo the columns, there is no need to use the PRESERVE_SIZE flag, contrarily to what appendFromStream does below - SSTableIdentityIterator iter = new SSTableIdentityIterator(cfs.metadata, in, localFile.getFilename(), key, 0, dataSize, IColumnSerializer.Flag.FROM_REMOTE); + SSTableIdentityIterator iter = new SSTableIdentityIterator(cfs.metadata, in, localFile.getFilename(), key, 0, dataSize, ColumnSerializer.Flag.FROM_REMOTE); PrecompactedRow row = new PrecompactedRow(controller, Collections.singletonList(iter)); // We don't expire anything so the row shouldn't be empty assert !row.isEmpty(); diff --git a/src/java/org/apache/cassandra/thrift/CassandraServer.java b/src/java/org/apache/cassandra/thrift/CassandraServer.java index f25e093614..1e4c0ed0f2 100644 --- a/src/java/org/apache/cassandra/thrift/CassandraServer.java +++ b/src/java/org/apache/cassandra/thrift/CassandraServer.java @@ -42,8 +42,8 @@ import org.apache.cassandra.cql.CQLStatement; import org.apache.cassandra.cql.QueryProcessor; import org.apache.cassandra.db.*; import org.apache.cassandra.db.context.CounterContext; -import org.apache.cassandra.db.filter.IDiskAtomFilter; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.filter.*; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.db.marshal.MarshalException; import org.apache.cassandra.db.marshal.TimeUUIDType; import org.apache.cassandra.dht.*; @@ -121,7 +121,7 @@ public class CassandraServer implements Cassandra.Iface return columnFamilyKeyMap; } - public List thriftifySubColumns(Collection columns) + public List thriftifySubColumns(Collection columns) { if (columns == null || columns.isEmpty()) { @@ -129,7 +129,7 @@ public class CassandraServer implements Cassandra.Iface } ArrayList thriftColumns = new ArrayList(columns.size()); - for (IColumn column : columns) + for (org.apache.cassandra.db.Column column : columns) { if (column.isMarkedForDelete()) { @@ -146,7 +146,7 @@ public class CassandraServer implements Cassandra.Iface return thriftColumns; } - public List thriftifyCounterSubColumns(Collection columns) + public List thriftifyCounterSubColumns(Collection columns) { if (columns == null || columns.isEmpty()) { @@ -154,7 +154,7 @@ public class CassandraServer implements Cassandra.Iface } ArrayList thriftColumns = new ArrayList(columns.size()); - for (IColumn column : columns) + for (org.apache.cassandra.db.Column column : columns) { if (column.isMarkedForDelete()) { @@ -168,29 +168,15 @@ public class CassandraServer implements Cassandra.Iface return thriftColumns; } - public List thriftifyColumns(Collection columns, boolean reverseOrder) + public List thriftifyColumns(Collection columns, boolean reverseOrder) { ArrayList thriftColumns = new ArrayList(columns.size()); - for (IColumn column : columns) + for (org.apache.cassandra.db.Column column : columns) { if (column.isMarkedForDelete()) - { continue; - } - if (column instanceof org.apache.cassandra.db.CounterColumn) - { - CounterColumn thrift_column = new CounterColumn(column.name(), CounterContext.instance().total(column.value())); - thriftColumns.add(new ColumnOrSuperColumn().setCounter_column(thrift_column)); - } - else - { - Column thrift_column = new Column(column.name()).setValue(column.value()).setTimestamp(column.timestamp()); - if (column instanceof ExpiringColumn) - { - thrift_column.setTtl(((ExpiringColumn) column).getTimeToLive()); - } - thriftColumns.add(new ColumnOrSuperColumn().setColumn(thrift_column)); - } + + thriftColumns.add(thriftifyColumn(column)); } // we have to do the reversing here, since internally we pass results around in ColumnFamily @@ -201,26 +187,80 @@ public class CassandraServer implements Cassandra.Iface return thriftColumns; } - private List thriftifySuperColumns(Collection columns, boolean reverseOrder, boolean isCounterCF) + private ColumnOrSuperColumn thriftifyColumnWithName(org.apache.cassandra.db.Column column, ByteBuffer newName) { - if (isCounterCF) - return thriftifyCounterSuperColumns(columns, reverseOrder); + assert !column.isMarkedForDelete(); + + if (column instanceof org.apache.cassandra.db.CounterColumn) + return new ColumnOrSuperColumn().setCounter_column(thriftifySubCounter(column).setName(newName)); else - return thriftifySuperColumns(columns, reverseOrder); + return new ColumnOrSuperColumn().setColumn(thriftifySubColumn(column).setName(newName)); } - private List thriftifySuperColumns(Collection columns, boolean reverseOrder) + private ColumnOrSuperColumn thriftifyColumn(org.apache.cassandra.db.Column column) + { + return thriftifyColumnWithName(column, column.name()); + } + + private Column thriftifySubColumn(org.apache.cassandra.db.Column column) + { + assert !column.isMarkedForDelete() && !(column instanceof org.apache.cassandra.db.CounterColumn); + + Column thrift_column = new Column(column.name()).setValue(column.value()).setTimestamp(column.timestamp()); + if (column instanceof ExpiringColumn) + { + thrift_column.setTtl(((ExpiringColumn) column).getTimeToLive()); + } + return thrift_column; + } + + private CounterColumn thriftifySubCounter(org.apache.cassandra.db.Column column) + { + assert !column.isMarkedForDelete() && (column instanceof org.apache.cassandra.db.CounterColumn); + return new CounterColumn(column.name(), CounterContext.instance().total(column.value())); + } + + private List thriftifySuperColumns(Collection columns, boolean reverseOrder, boolean subcolumnsOnly, boolean isCounterCF) + { + if (subcolumnsOnly) + { + ArrayList thriftSuperColumns = new ArrayList(columns.size()); + for (org.apache.cassandra.db.Column column : columns) + { + if (column.isMarkedForDelete()) + continue; + + thriftSuperColumns.add(thriftifyColumnWithName(column, SuperColumns.subName(column.name()))); + } + if (reverseOrder) + Collections.reverse(thriftSuperColumns); + return thriftSuperColumns; + } + else + { + if (isCounterCF) + return thriftifyCounterSuperColumns(columns, reverseOrder); + else + return thriftifySuperColumns(columns, reverseOrder); + } + } + + private List thriftifySuperColumns(Collection columns, boolean reverseOrder) { ArrayList thriftSuperColumns = new ArrayList(columns.size()); - for (IColumn column : columns) + SuperColumn current = null; + for (org.apache.cassandra.db.Column column : columns) { - List subcolumns = thriftifySubColumns(column.getSubColumns()); - if (subcolumns.isEmpty()) - { + if (column.isMarkedForDelete()) continue; + + ByteBuffer scName = SuperColumns.scName(column.name()); + if (current == null || !scName.equals(current.bufferForName())) + { + current = new SuperColumn(scName, new ArrayList()); + thriftSuperColumns.add(new ColumnOrSuperColumn().setSuper_column(current)); } - SuperColumn superColumn = new SuperColumn(column.name(), subcolumns); - thriftSuperColumns.add(new ColumnOrSuperColumn().setSuper_column(superColumn)); + current.getColumns().add(thriftifySubColumn(column).setName(SuperColumns.subName(column.name()))); } if (reverseOrder) @@ -229,18 +269,22 @@ public class CassandraServer implements Cassandra.Iface return thriftSuperColumns; } - private List thriftifyCounterSuperColumns(Collection columns, boolean reverseOrder) + private List thriftifyCounterSuperColumns(Collection columns, boolean reverseOrder) { ArrayList thriftSuperColumns = new ArrayList(columns.size()); - for (IColumn column : columns) + CounterSuperColumn current = null; + for (org.apache.cassandra.db.Column column : columns) { - List subcolumns = thriftifyCounterSubColumns(column.getSubColumns()); - if (subcolumns.isEmpty()) - { + if (column.isMarkedForDelete()) continue; + + ByteBuffer scName = SuperColumns.scName(column.name()); + if (current == null || !scName.equals(current.bufferForName())) + { + current = new CounterSuperColumn(scName, new ArrayList()); + thriftSuperColumns.add(new ColumnOrSuperColumn().setCounter_super_column(current)); } - CounterSuperColumn superColumn = new CounterSuperColumn(column.name(), subcolumns); - thriftSuperColumns.add(new ColumnOrSuperColumn().setCounter_super_column(superColumn)); + current.getColumns().add(thriftifySubCounter(column).setName(SuperColumns.subName(column.name()))); } if (reverseOrder) @@ -249,7 +293,7 @@ public class CassandraServer implements Cassandra.Iface return thriftSuperColumns; } - private Map> getSlice(List commands, org.apache.cassandra.db.ConsistencyLevel consistency_level) + private Map> getSlice(List commands, boolean subColumnsOnly, org.apache.cassandra.db.ConsistencyLevel consistency_level) throws org.apache.cassandra.exceptions.InvalidRequestException, UnavailableException, TimedOutException { Map columnFamilies = readColumnFamily(commands, consistency_level); @@ -258,7 +302,7 @@ public class CassandraServer implements Cassandra.Iface { ColumnFamily cf = columnFamilies.get(StorageService.getPartitioner().decorateKey(command.key)); boolean reverseOrder = command instanceof SliceFromReadCommand && ((SliceFromReadCommand)command).filter.reversed; - List thriftifiedColumns = thriftifyColumnFamily(cf, command.queryPath.superColumnName != null, reverseOrder); + List thriftifiedColumns = thriftifyColumnFamily(cf, subColumnsOnly, reverseOrder); columnFamiliesMap.put(command.key, thriftifiedColumns); } @@ -269,19 +313,11 @@ public class CassandraServer implements Cassandra.Iface { if (cf == null || cf.isEmpty()) return EMPTY_COLUMNS; - if (subcolumnsOnly) - { - IColumn column = cf.iterator().next(); - Collection subcolumns = column.getSubColumns(); - if (subcolumns == null || subcolumns.isEmpty()) - return EMPTY_COLUMNS; - else - return thriftifyColumns(subcolumns, reverseOrder); - } - if (cf.isSuper()) + + if (cf.metadata().isSuper()) { boolean isCounterCF = cf.metadata().getDefaultValidator().isCommutative(); - return thriftifySuperColumns(cf.getSortedColumns(), reverseOrder, isCounterCF); + return thriftifySuperColumns(cf.getSortedColumns(), reverseOrder, subcolumnsOnly, isCounterCF); } else { @@ -369,25 +405,38 @@ public class CassandraServer implements Cassandra.Iface consistencyLevel.validateForRead(keyspace); List commands = new ArrayList(keys.size()); + IDiskAtomFilter filter; if (predicate.column_names != null) { - for (ByteBuffer key: keys) + if (metadata.isSuper()) { - ThriftValidation.validateKey(metadata, key); - commands.add(new SliceByNamesReadCommand(keyspace, key, column_parent, predicate.column_names)); + CompositeType type = (CompositeType)metadata.comparator; + SortedSet s = new TreeSet(column_parent.isSetSuper_column() ? type.types.get(1) : type.types.get(0)); + s.addAll(predicate.column_names); + filter = SuperColumns.fromSCNamesFilter(type, column_parent.bufferForSuper_column(), new NamesQueryFilter(s)); + } + else + { + SortedSet s = new TreeSet(metadata.comparator); + s.addAll(predicate.column_names); + filter = new NamesQueryFilter(s); } } else { SliceRange range = predicate.slice_range; - for (ByteBuffer key: keys) - { - ThriftValidation.validateKey(metadata, key); - commands.add(new SliceFromReadCommand(keyspace, key, column_parent, range.start, range.finish, range.reversed, range.count)); - } + filter = new SliceQueryFilter(range.start, range.finish, range.reversed, range.count); + if (metadata.isSuper()) + filter = SuperColumns.fromSCFilter((CompositeType)metadata.comparator, column_parent.bufferForSuper_column(), filter); } - return getSlice(commands, consistencyLevel); + for (ByteBuffer key: keys) + { + ThriftValidation.validateKey(metadata, key); + commands.add(ReadCommand.create(keyspace, key, column_parent.getColumn_family(), filter)); + } + + return getSlice(commands, column_parent.isSetSuper_column(), consistencyLevel); } private ColumnOrSuperColumn internal_get(ByteBuffer key, ColumnPath column_path, ConsistencyLevel consistency_level) @@ -402,10 +451,24 @@ public class CassandraServer implements Cassandra.Iface org.apache.cassandra.db.ConsistencyLevel consistencyLevel = ThriftConversion.fromThrift(consistency_level); consistencyLevel.validateForRead(keyspace); - QueryPath path = new QueryPath(column_path.column_family, column_path.column == null ? null : column_path.super_column); - List nameAsList = Arrays.asList(column_path.column == null ? column_path.super_column : column_path.column); ThriftValidation.validateKey(metadata, key); - ReadCommand command = new SliceByNamesReadCommand(keyspace, key, path, nameAsList); + + IDiskAtomFilter filter; + if (metadata.isSuper()) + { + CompositeType type = (CompositeType)metadata.comparator; + SortedSet names = new TreeSet(column_path.column == null ? type.types.get(0) : type.types.get(1)); + names.add(column_path.column == null ? column_path.super_column : column_path.column); + filter = SuperColumns.fromSCNamesFilter(type, column_path.column == null ? null : column_path.bufferForSuper_column(), new NamesQueryFilter(names)); + } + else + { + SortedSet names = new TreeSet(metadata.comparator); + names.add(column_path.column); + filter = new NamesQueryFilter(names); + } + + ReadCommand command = ReadCommand.create(keyspace, key, column_path.column_family, filter); Map cfamilies = readColumnFamily(Arrays.asList(command), consistencyLevel); @@ -413,7 +476,7 @@ public class CassandraServer implements Cassandra.Iface if (cf == null) throw new NotFoundException(); - List tcolumns = thriftifyColumnFamily(cf, command.queryPath.superColumnName != null, false); + List tcolumns = thriftifyColumnFamily(cf, metadata.isSuper() && column_path.column != null, false); if (tcolumns.isEmpty()) throw new NotFoundException(); assert tcolumns.size() == 1; @@ -613,7 +676,11 @@ public class CassandraServer implements Cassandra.Iface RowMutation rm = new RowMutation(cState.getKeyspace(), key); try { - rm.add(new QueryPath(column_parent.column_family, column_parent.super_column, column.name), column.value, column.timestamp, column.ttl); + ByteBuffer name = column.name; + if (metadata.isSuper()) + name = CompositeType.build(column_parent.super_column, name); + + rm.add(column_parent.column_family, name, column.value, column.timestamp, column.ttl); } catch (MarshalException e) { @@ -705,11 +772,11 @@ public class CassandraServer implements Cassandra.Iface if (mutation.deletion != null) { - rm.deleteColumnOrSuperColumn(cfName, mutation.deletion); + deleteColumnOrSuperColumn(rm, cfName, mutation.deletion); } if (mutation.column_or_supercolumn != null) { - rm.addColumnOrSuperColumn(cfName, mutation.column_or_supercolumn); + addColumnOrSuperColumn(rm, cfName, mutation.column_or_supercolumn); } } } @@ -728,6 +795,55 @@ public class CassandraServer implements Cassandra.Iface return rowMutations; } + private void addColumnOrSuperColumn(RowMutation rm, String cfName, ColumnOrSuperColumn cosc) + { + if (cosc.super_column != null) + { + for (Column column : cosc.super_column.columns) + { + rm.add(cfName, CompositeType.build(cosc.super_column.name, column.name), column.value, column.timestamp, column.ttl); + } + } + else if (cosc.column != null) + { + rm.add(cfName, cosc.column.name, cosc.column.value, cosc.column.timestamp, cosc.column.ttl); + } + else if (cosc.counter_super_column != null) + { + for (CounterColumn column : cosc.counter_super_column.columns) + { + rm.addCounter(cfName, CompositeType.build(cosc.counter_super_column.name, column.name), column.value); + } + } + else // cosc.counter_column != null + { + rm.addCounter(cfName, cosc.counter_column.name, cosc.counter_column.value); + } + } + + private void deleteColumnOrSuperColumn(RowMutation rm, String cfName, Deletion del) + { + if (del.predicate != null && del.predicate.column_names != null) + { + for(ByteBuffer c : del.predicate.column_names) + { + if (del.super_column == null && Schema.instance.getColumnFamilyType(rm.getTable(), cfName) == ColumnFamilyType.Super) + rm.deleteRange(cfName, SuperColumns.startOf(c), SuperColumns.endOf(c), del.timestamp); + else if (del.super_column != null) + rm.delete(cfName, CompositeType.build(del.super_column, c), del.timestamp); + else + rm.delete(cfName, c, del.timestamp); + } + } + else + { + if (del.super_column != null) + rm.deleteRange(cfName, SuperColumns.startOf(del.super_column), SuperColumns.endOf(del.super_column), del.timestamp); + else + rm.delete(cfName, del.timestamp); + } + } + public void batch_mutate(Map>> mutation_map, ConsistencyLevel consistency_level) throws InvalidRequestException, UnavailableException, TimedOutException { @@ -808,7 +924,14 @@ public class CassandraServer implements Cassandra.Iface ThriftConversion.fromThrift(consistency_level).validateCounterForWrite(metadata); RowMutation rm = new RowMutation(keyspace, key); - rm.delete(new QueryPath(column_path), timestamp); + if (column_path.super_column == null && column_path.column == null) + rm.delete(column_path.column_family, timestamp); + else if (column_path.super_column == null) + rm.delete(column_path.column_family, column_path.column, timestamp); + else if (column_path.column == null) + rm.deleteRange(column_path.column_family, SuperColumns.startOf(column_path.super_column), SuperColumns.endOf(column_path.super_column), timestamp); + else + rm.delete(column_path.column_family, CompositeType.build(column_path.super_column, column_path.column), timestamp); if (isCommutativeOp) doInsert(consistency_level, Arrays.asList(new CounterMutation(rm, ThriftConversion.fromThrift(consistency_level)))); @@ -942,8 +1065,8 @@ public class CassandraServer implements Cassandra.Iface schedule(DatabaseDescriptor.getRangeRpcTimeout()); try { - IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, metadata.getComparatorFor(column_parent.super_column)); - rows = StorageProxy.getRangeSlice(new RangeSliceCommand(keyspace, column_parent, filter, bounds, + IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, metadata, column_parent.super_column); + rows = StorageProxy.getRangeSlice(new RangeSliceCommand(keyspace, column_parent.column_family, filter, bounds, range.row_filter, range.count), consistencyLevel); } finally @@ -1030,8 +1153,8 @@ public class CassandraServer implements Cassandra.Iface schedule(DatabaseDescriptor.getRangeRpcTimeout()); try { - IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, metadata.comparator); - rows = StorageProxy.getRangeSlice(new RangeSliceCommand(keyspace, column_family, null, filter, + IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, metadata, null); + rows = StorageProxy.getRangeSlice(new RangeSliceCommand(keyspace, column_family, filter, bounds, range.row_filter, range.count, true, true), consistencyLevel); } finally @@ -1110,10 +1233,9 @@ public class CassandraServer implements Cassandra.Iface AbstractBounds bounds = new Bounds(RowPosition.forKey(index_clause.start_key, p), p.getMinimumToken().minKeyBound()); - IDiskAtomFilter filter = ThriftValidation.asIFilter(column_predicate, metadata.getComparatorFor(column_parent.super_column)); + IDiskAtomFilter filter = ThriftValidation.asIFilter(column_predicate, metadata, column_parent.super_column); RangeSliceCommand command = new RangeSliceCommand(keyspace, column_parent.column_family, - null, filter, bounds, index_clause.expressions, @@ -1528,7 +1650,10 @@ public class CassandraServer implements Cassandra.Iface RowMutation rm = new RowMutation(keyspace, key); try { - rm.addCounter(new QueryPath(column_parent.column_family, column_parent.super_column, column.name), column.value); + if (metadata.isSuper()) + rm.addCounter(column_parent.column_family, CompositeType.build(column_parent.super_column, column.name), column.value); + else + rm.addCounter(column_parent.column_family, column.name, column.value); } catch (MarshalException e) { diff --git a/src/java/org/apache/cassandra/thrift/ThriftValidation.java b/src/java/org/apache/cassandra/thrift/ThriftValidation.java index 6473acdb14..101102f97a 100644 --- a/src/java/org/apache/cassandra/thrift/ThriftValidation.java +++ b/src/java/org/apache/cassandra/thrift/ThriftValidation.java @@ -30,6 +30,7 @@ import org.apache.cassandra.db.filter.NamesQueryFilter; import org.apache.cassandra.db.filter.SliceQueryFilter; import org.apache.cassandra.db.index.SecondaryIndexManager; import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.db.marshal.MarshalException; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.RandomPartitioner; @@ -195,20 +196,22 @@ public class ThriftValidation private static void validateColumnNames(CFMetaData metadata, ByteBuffer superColumnName, Iterable column_names) throws org.apache.cassandra.exceptions.InvalidRequestException { + int maxNameLength = org.apache.cassandra.db.Column.MAX_NAME_LENGTH; + if (superColumnName != null) { - if (superColumnName.remaining() > IColumn.MAX_NAME_LENGTH) - throw new org.apache.cassandra.exceptions.InvalidRequestException("supercolumn name length must not be greater than " + IColumn.MAX_NAME_LENGTH); + if (superColumnName.remaining() > maxNameLength) + throw new org.apache.cassandra.exceptions.InvalidRequestException("supercolumn name length must not be greater than " + maxNameLength); if (superColumnName.remaining() == 0) throw new org.apache.cassandra.exceptions.InvalidRequestException("supercolumn name must not be empty"); if (metadata.cfType == ColumnFamilyType.Standard) throw new org.apache.cassandra.exceptions.InvalidRequestException("supercolumn specified to ColumnFamily " + metadata.cfName + " containing normal columns"); } - AbstractType comparator = metadata.getComparatorFor(superColumnName); + AbstractType comparator = SuperColumns.getComparatorFor(metadata, superColumnName); for (ByteBuffer name : column_names) { - if (name.remaining() > IColumn.MAX_NAME_LENGTH) - throw new org.apache.cassandra.exceptions.InvalidRequestException("column name length must not be greater than " + IColumn.MAX_NAME_LENGTH); + if (name.remaining() > maxNameLength) + throw new org.apache.cassandra.exceptions.InvalidRequestException("column name length must not be greater than " + maxNameLength); if (name.remaining() == 0) throw new org.apache.cassandra.exceptions.InvalidRequestException("column name must not be empty"); try @@ -229,7 +232,7 @@ public class ThriftValidation public static void validateRange(CFMetaData metadata, ColumnParent column_parent, SliceRange range) throws org.apache.cassandra.exceptions.InvalidRequestException { - AbstractType comparator = metadata.getComparatorFor(column_parent.super_column); + AbstractType comparator = SuperColumns.getComparatorFor(metadata, column_parent.super_column); try { comparator.validate(range.start); @@ -412,15 +415,16 @@ public class ThriftValidation { if (logger.isDebugEnabled()) logger.debug("rejecting invalid value " + ByteBufferUtil.bytesToHex(summarize(column.value))); + throw new org.apache.cassandra.exceptions.InvalidRequestException(String.format("(%s) [%s][%s][%s] failed validation", me.getMessage(), metadata.ksName, metadata.cfName, - (isSubColumn ? metadata.subcolumnComparator : metadata.comparator).getString(column.name))); + (SuperColumns.getComparatorFor(metadata, isSubColumn)).getString(column.name))); } // Indexed column values cannot be larger than 64K. See CASSANDRA-3057/4240 for more details - if (!Table.open(metadata.ksName).getColumnFamilyStore(metadata.cfName).indexManager.validate(column)) + if (!Table.open(metadata.ksName).getColumnFamilyStore(metadata.cfName).indexManager.validate(asDBColumn(column))) throw new org.apache.cassandra.exceptions.InvalidRequestException(String.format("Can't index column value of size %d for index %s in CF %s of KS %s", column.value.remaining(), columnDef.getIndexName(), @@ -428,6 +432,14 @@ public class ThriftValidation metadata.ksName)); } + private static org.apache.cassandra.db.Column asDBColumn(Column column) + { + if (column.ttl <= 0) + return new org.apache.cassandra.db.Column(column.name, column.value, column.timestamp); + else + return new org.apache.cassandra.db.ExpiringColumn(column.name, column.value, column.timestamp, column.ttl); + } + /** * Return, at most, the first 64K of the buffer. This avoids very large column values being * logged in their entirety. @@ -527,7 +539,7 @@ public class ThriftValidation return false; SecondaryIndexManager idxManager = Table.open(metadata.ksName).getColumnFamilyStore(metadata.cfName).indexManager; - AbstractType nameValidator = ColumnFamily.getComparatorFor(metadata.ksName, metadata.cfName, null); + AbstractType nameValidator = SuperColumns.getComparatorFor(metadata, null); boolean isIndexed = false; for (IndexExpression expression : index_clause) @@ -586,18 +598,26 @@ public class ThriftValidation throw new org.apache.cassandra.exceptions.InvalidRequestException("system keyspace is not user-modifiable"); } - public static IDiskAtomFilter asIFilter(SlicePredicate sp, AbstractType comparator) + public static IDiskAtomFilter asIFilter(SlicePredicate sp, CFMetaData metadata, ByteBuffer superColumn) { + AbstractType comparator = metadata.isSuper() + ? ((CompositeType)metadata.comparator).types.get(superColumn == null ? 0 : 1) + : metadata.comparator; SliceRange sr = sp.slice_range; + IDiskAtomFilter filter; if (sr == null) { SortedSet ss = new TreeSet(comparator); ss.addAll(sp.column_names); - return new NamesQueryFilter(ss); + filter = new NamesQueryFilter(ss); } else { - return new SliceQueryFilter(sr.start, sr.finish, sr.reversed, sr.count); + filter = new SliceQueryFilter(sr.start, sr.finish, sr.reversed, sr.count); } + + if (metadata.isSuper()) + filter = SuperColumns.fromSCFilter((CompositeType)metadata.comparator, superColumn, filter); + return filter; } } diff --git a/src/java/org/apache/cassandra/tools/SSTableExport.java b/src/java/org/apache/cassandra/tools/SSTableExport.java index fe7d6c0bb5..5085b529ae 100644 --- a/src/java/org/apache/cassandra/tools/SSTableExport.java +++ b/src/java/org/apache/cassandra/tools/SSTableExport.java @@ -51,10 +51,9 @@ import org.apache.cassandra.db.DeletedColumn; import org.apache.cassandra.db.DeletionInfo; import org.apache.cassandra.db.DeletionTime; import org.apache.cassandra.db.ExpiringColumn; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.OnDiskAtom; import org.apache.cassandra.db.RangeTombstone; -import org.apache.cassandra.db.SuperColumn; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.io.sstable.Descriptor; @@ -136,20 +135,6 @@ public class SSTableExport } return; } - - if (columnContainer instanceof SuperColumn) - { - SuperColumn superColumn = (SuperColumn) columnContainer; - DeletionInfo deletionInfo = new DeletionInfo(superColumn.getMarkedForDeleteAt(), - superColumn.getLocalDeletionTime()); - if (!deletionInfo.equals(DeletionInfo.LIVE)) - { - writeKey(out, "metadata"); - writeDeletionInfo(out, deletionInfo.getTopLevelDeletion()); - out.print(","); - } - return; - } } private static void writeDeletionInfo(PrintStream out, DeletionTime deletionTime) @@ -169,7 +154,18 @@ public class SSTableExport * @param comparator columns comparator * @param cfMetaData Column Family metadata (to get validator) */ - private static void serializeColumns(Iterator columns, PrintStream out, AbstractType comparator, CFMetaData cfMetaData) + private static void serializeAtoms(Iterator atoms, PrintStream out, AbstractType comparator, CFMetaData cfMetaData) + { + while (atoms.hasNext()) + { + writeJSON(out, serializeAtom(atoms.next(), comparator, cfMetaData)); + + if (atoms.hasNext()) + out.print(", "); + } + } + + private static void serializeColumns(Iterator columns, PrintStream out, AbstractType comparator, CFMetaData cfMetaData) { while (columns.hasNext()) { @@ -180,27 +176,16 @@ public class SSTableExport } } - private static void serializeIColumns(Iterator columns, PrintStream out, AbstractType comparator, CFMetaData cfMetaData) + private static List serializeAtom(OnDiskAtom atom, AbstractType comparator, CFMetaData cfMetaData) { - while (columns.hasNext()) + if (atom instanceof Column) { - writeJSON(out, serializeColumn(columns.next(), comparator, cfMetaData)); - - if (columns.hasNext()) - out.print(", "); - } - } - - private static List serializeColumn(OnDiskAtom column, AbstractType comparator, CFMetaData cfMetaData) - { - if (column instanceof IColumn) - { - return serializeColumn((IColumn)column, comparator, cfMetaData); + return serializeColumn((Column)atom, comparator, cfMetaData); } else { - assert column instanceof RangeTombstone; - RangeTombstone rt = (RangeTombstone)column; + assert atom instanceof RangeTombstone; + RangeTombstone rt = (RangeTombstone)atom; ArrayList serializedColumn = new ArrayList(); serializedColumn.add(comparator.getString(rt.min)); serializedColumn.add(comparator.getString(rt.max)); @@ -220,7 +205,7 @@ public class SSTableExport * * @return column as serialized list */ - private static List serializeColumn(IColumn column, AbstractType comparator, CFMetaData cfMetaData) + private static List serializeColumn(Column column, AbstractType comparator, CFMetaData cfMetaData) { ArrayList serializedColumn = new ArrayList(); @@ -267,7 +252,6 @@ public class SSTableExport private static void serializeRow(SSTableIdentityIterator row, DecoratedKey key, PrintStream out) { ColumnFamily columnFamily = row.getColumnFamily(); - boolean isSuperCF = columnFamily.isSuper(); CFMetaData cfMetaData = columnFamily.metadata(); AbstractType comparator = columnFamily.getComparator(); @@ -279,34 +263,11 @@ public class SSTableExport writeMeta(out, columnFamily); writeKey(out, "columns"); - out.print(isSuperCF ? "{" : "["); + out.print("["); - if (isSuperCF) - { - while (row.hasNext()) - { - SuperColumn scol = (SuperColumn)row.next(); - assert scol instanceof IColumn; - IColumn column = (IColumn)scol; - writeKey(out, comparator.getString(column.name())); - out.print("{"); - writeMeta(out, scol); - writeKey(out, "subColumns"); - out.print("["); - serializeIColumns(column.getSubColumns().iterator(), out, columnFamily.getSubComparator(), cfMetaData); - out.print("]"); - out.print("}"); + serializeAtoms(row, out, comparator, cfMetaData); - if (row.hasNext()) - out.print(", "); - } - } - else - { - serializeColumns(row, out, comparator, cfMetaData); - } - - out.print(isSuperCF ? "}" : "]"); + out.print("]"); out.print("}"); } diff --git a/src/java/org/apache/cassandra/tools/SSTableImport.java b/src/java/org/apache/cassandra/tools/SSTableImport.java index 74a86caacf..06ccaa72d6 100644 --- a/src/java/org/apache/cassandra/tools/SSTableImport.java +++ b/src/java/org/apache/cassandra/tools/SSTableImport.java @@ -46,10 +46,10 @@ import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.DeletionInfo; import org.apache.cassandra.db.ExpiringColumn; import org.apache.cassandra.db.RangeTombstone; -import org.apache.cassandra.db.SuperColumn; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.SuperColumns; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.BytesType; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.db.marshal.MarshalException; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.io.sstable.SSTableWriter; @@ -69,12 +69,14 @@ public class SSTableImport private static final String COLUMN_FAMILY_OPTION = "c"; private static final String KEY_COUNT_OPTION = "n"; private static final String IS_SORTED_OPTION = "s"; + private static final String OLD_SC_FORMAT_OPTION = "S"; private static final Options options = new Options(); private static CommandLine cmd; private Integer keyCountToImport; private final boolean isSorted; + private final boolean oldSCFormat; private static final JsonFactory factory = new MappingJsonFactory().configure( JsonParser.Feature.INTERN_FIELD_NAMES, false); @@ -91,6 +93,7 @@ public class SSTableImport options.addOption(new Option(KEY_COUNT_OPTION, true, "Number of keys to import (Optional).")); options.addOption(new Option(IS_SORTED_OPTION, false, "Assume JSON file as already sorted (e.g. created by sstable2json tool) (Optional).")); + options.addOption(new Option(OLD_SC_FORMAT_OPTION, false, "Assume JSON file use legacy super column format (Optional).")); } private static class JsonColumn @@ -107,11 +110,11 @@ public class SSTableImport // Counter columns private long timestampOfLastDelete; - public JsonColumn(T json, CFMetaData meta, boolean isSubColumn) + public JsonColumn(T json, CFMetaData meta, boolean oldSCFormat, boolean isSubColumn) { if (json instanceof List) { - AbstractType comparator = (isSubColumn) ? meta.subcolumnComparator : meta.comparator; + AbstractType comparator = oldSCFormat ? SuperColumns.getComparatorFor(meta, isSubColumn) : meta.comparator; List fields = (List) json; assert fields.size() >= 3 : "Column definition should have at least 3"; @@ -193,18 +196,24 @@ public class SSTableImport public SSTableImport() { - this(null, false); + this(null, false, false); } public SSTableImport(boolean isSorted) { - this(null, isSorted); + this(isSorted, false); } - public SSTableImport(Integer keyCountToImport, boolean isSorted) + public SSTableImport(boolean isSorted, boolean oldSCFormat) + { + this(null, isSorted, oldSCFormat); + } + + public SSTableImport(Integer keyCountToImport, boolean isSorted, boolean oldSCFormat) { this.keyCountToImport = keyCountToImport; this.isSorted = isSorted; + this.oldSCFormat = oldSCFormat; } private void addToStandardCF(List row, ColumnFamily cfamily) @@ -226,33 +235,34 @@ public class SSTableImport for (Object c : row) { - JsonColumn col = new JsonColumn((List) c, cfm, (superName != null)); - QueryPath path = new QueryPath(cfm.cfName, superName, col.getName()); + JsonColumn col = new JsonColumn((List) c, cfm, oldSCFormat, (superName != null)); + ByteBuffer cname = superName == null ? col.getName() : CompositeType.build(superName, col.getName()); if (col.isExpiring()) { - cfamily.addColumn(null, new ExpiringColumn(col.getName(), col.getValue(), col.timestamp, col.ttl, col.localExpirationTime)); + cfamily.addColumn(new ExpiringColumn(cname, col.getValue(), col.timestamp, col.ttl, col.localExpirationTime)); } else if (col.isCounter()) { - cfamily.addColumn(null, new CounterColumn(col.getName(), col.getValue(), col.timestamp, col.timestampOfLastDelete)); + cfamily.addColumn(new CounterColumn(cname, col.getValue(), col.timestamp, col.timestampOfLastDelete)); } else if (col.isDeleted()) { - cfamily.addTombstone(path, col.getValue(), col.timestamp); + cfamily.addTombstone(cname, col.getValue(), col.timestamp); } else if (col.isRangeTombstone()) { - cfamily.addAtom(new RangeTombstone(col.getName(), col.getValue(), col.timestamp, col.localExpirationTime)); + ByteBuffer end = superName == null ? col.getValue() : CompositeType.build(superName, col.getValue()); + cfamily.addAtom(new RangeTombstone(cname, end, col.timestamp, col.localExpirationTime)); } else { - cfamily.addColumn(path, col.getValue(), col.timestamp); + cfamily.addColumn(cname, col.getValue(), col.timestamp); } } } - private void parseMeta(Map map, AbstractColumnContainer columnContainer) + private void parseMeta(Map map, ColumnFamily cf, ByteBuffer superColumnName) { // deletionInfo is the only metadata we store for now @@ -262,7 +272,10 @@ public class SSTableImport Number number = (Number) unparsedDeletionInfo.get("markedForDeleteAt"); long markedForDeleteAt = number instanceof Long ? (Long) number : ((Integer) number).longValue(); int localDeletionTime = (Integer) unparsedDeletionInfo.get("localDeletionTime"); - columnContainer.setDeletionInfo(new DeletionInfo(markedForDeleteAt, localDeletionTime)); + if (superColumnName == null) + cf.setDeletionInfo(new DeletionInfo(markedForDeleteAt, localDeletionTime)); + else + cf.addAtom(new RangeTombstone(SuperColumns.startOf(superColumnName), SuperColumns.endOf(superColumnName), markedForDeleteAt, localDeletionTime)); } } @@ -284,13 +297,13 @@ public class SSTableImport { Map data = (Map) entry.getValue(); - ByteBuffer superName = stringAsType((String) entry.getKey(), comparator); + ByteBuffer superName = stringAsType((String) entry.getKey(), ((CompositeType)comparator).types.get(0)); addColumnsToCF((List) data.get("subColumns"), superName, cfamily); if (data.containsKey("metadata")) { - parseMeta((Map) data.get("metadata"), (SuperColumn) cfamily.getColumn(superName)); + parseMeta((Map) data.get("metadata"), cfamily, superName); } } } @@ -346,11 +359,11 @@ public class SSTableImport { if (row.getValue().containsKey("metadata")) { - parseMeta((Map) row.getValue().get("metadata"), columnFamily); + parseMeta((Map) row.getValue().get("metadata"), columnFamily, null); } Object columns = row.getValue().get("columns"); - if (columnFamily.getType() == ColumnFamilyType.Super) + if (columnFamily.getType() == ColumnFamilyType.Super && oldSCFormat) addToSuperCF((Map) columns, columnFamily); else addToStandardCF((List) columns, columnFamily); @@ -421,10 +434,9 @@ public class SSTableImport DecoratedKey currentKey = partitioner.decorateKey(hexToBytes((String) row.get("key"))); if (row.containsKey("metadata")) - parseMeta((Map) row.get("metadata"), columnFamily); + parseMeta((Map) row.get("metadata"), columnFamily, null); - - if (columnFamily.getType() == ColumnFamilyType.Super) + if (columnFamily.getType() == ColumnFamilyType.Super && oldSCFormat) addToSuperCF((Map)row.get("columns"), columnFamily); else addToStandardCF((List)row.get("columns"), columnFamily); @@ -511,6 +523,7 @@ public class SSTableImport Integer keyCountToImport = null; boolean isSorted = false; + boolean oldSCFormat = false; if (cmd.hasOption(KEY_COUNT_OPTION)) { @@ -522,6 +535,11 @@ public class SSTableImport isSorted = true; } + if (cmd.hasOption(OLD_SC_FORMAT_OPTION)) + { + oldSCFormat = true; + } + DatabaseDescriptor.loadSchemas(); if (Schema.instance.getNonSystemTables().size() < 1) { @@ -532,7 +550,7 @@ public class SSTableImport try { - new SSTableImport(keyCountToImport,isSorted).importJson(json, keyspace, cfamily, ssTable); + new SSTableImport(keyCountToImport, isSorted, oldSCFormat).importJson(json, keyspace, cfamily, ssTable); } catch (Exception e) { diff --git a/test/data/serialization/2.0/db.RangeSliceCommand.bin b/test/data/serialization/2.0/db.RangeSliceCommand.bin new file mode 100644 index 0000000000..e96746d77e Binary files /dev/null and b/test/data/serialization/2.0/db.RangeSliceCommand.bin differ diff --git a/test/data/serialization/2.0/db.Row.bin b/test/data/serialization/2.0/db.Row.bin new file mode 100644 index 0000000000..bfc671d903 Binary files /dev/null and b/test/data/serialization/2.0/db.Row.bin differ diff --git a/test/data/serialization/2.0/db.RowMutation.bin b/test/data/serialization/2.0/db.RowMutation.bin new file mode 100644 index 0000000000..0f024acc8c Binary files /dev/null and b/test/data/serialization/2.0/db.RowMutation.bin differ diff --git a/test/data/serialization/2.0/db.SliceByNamesReadCommand.bin b/test/data/serialization/2.0/db.SliceByNamesReadCommand.bin new file mode 100644 index 0000000000..0e143a6c62 Binary files /dev/null and b/test/data/serialization/2.0/db.SliceByNamesReadCommand.bin differ diff --git a/test/data/serialization/2.0/db.SliceFromReadCommand.bin b/test/data/serialization/2.0/db.SliceFromReadCommand.bin new file mode 100644 index 0000000000..7b357aa3fc Binary files /dev/null and b/test/data/serialization/2.0/db.SliceFromReadCommand.bin differ diff --git a/test/data/serialization/2.0/db.Truncation.bin b/test/data/serialization/2.0/db.Truncation.bin new file mode 100644 index 0000000000..ea679956a4 Binary files /dev/null and b/test/data/serialization/2.0/db.Truncation.bin differ diff --git a/test/data/serialization/2.0/db.WriteResponse.bin b/test/data/serialization/2.0/db.WriteResponse.bin new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/data/serialization/2.0/gms.EndpointState.bin b/test/data/serialization/2.0/gms.EndpointState.bin new file mode 100644 index 0000000000..ffbb00d19f Binary files /dev/null and b/test/data/serialization/2.0/gms.EndpointState.bin differ diff --git a/test/data/serialization/2.0/gms.Gossip.bin b/test/data/serialization/2.0/gms.Gossip.bin new file mode 100644 index 0000000000..af5ac57146 Binary files /dev/null and b/test/data/serialization/2.0/gms.Gossip.bin differ diff --git a/test/data/serialization/2.0/service.TreeRequest.bin b/test/data/serialization/2.0/service.TreeRequest.bin new file mode 100644 index 0000000000..b12a1b8018 Binary files /dev/null and b/test/data/serialization/2.0/service.TreeRequest.bin differ diff --git a/test/data/serialization/2.0/service.TreeResponse.bin b/test/data/serialization/2.0/service.TreeResponse.bin new file mode 100644 index 0000000000..4beb4102ef Binary files /dev/null and b/test/data/serialization/2.0/service.TreeResponse.bin differ diff --git a/test/data/serialization/2.0/streaming.PendingFile.bin b/test/data/serialization/2.0/streaming.PendingFile.bin new file mode 100644 index 0000000000..efc8f77369 Binary files /dev/null and b/test/data/serialization/2.0/streaming.PendingFile.bin differ diff --git a/test/data/serialization/2.0/streaming.StreamHeader.bin b/test/data/serialization/2.0/streaming.StreamHeader.bin new file mode 100644 index 0000000000..f7e5edc38f Binary files /dev/null and b/test/data/serialization/2.0/streaming.StreamHeader.bin differ diff --git a/test/data/serialization/2.0/streaming.StreamReply.bin b/test/data/serialization/2.0/streaming.StreamReply.bin new file mode 100644 index 0000000000..0094ecc806 Binary files /dev/null and b/test/data/serialization/2.0/streaming.StreamReply.bin differ diff --git a/test/data/serialization/2.0/streaming.StreamRequestMessage.bin b/test/data/serialization/2.0/streaming.StreamRequestMessage.bin new file mode 100644 index 0000000000..71aaf78926 Binary files /dev/null and b/test/data/serialization/2.0/streaming.StreamRequestMessage.bin differ diff --git a/test/data/serialization/2.0/utils.BloomFilter.bin b/test/data/serialization/2.0/utils.BloomFilter.bin new file mode 100644 index 0000000000..63e561a737 Binary files /dev/null and b/test/data/serialization/2.0/utils.BloomFilter.bin differ diff --git a/test/data/serialization/2.0/utils.EstimatedHistogram.bin b/test/data/serialization/2.0/utils.EstimatedHistogram.bin new file mode 100644 index 0000000000..bedd39bce6 Binary files /dev/null and b/test/data/serialization/2.0/utils.EstimatedHistogram.bin differ diff --git a/test/data/serialization/2.0/utils.LegacyBloomFilter.bin b/test/data/serialization/2.0/utils.LegacyBloomFilter.bin new file mode 100644 index 0000000000..faef1b8154 Binary files /dev/null and b/test/data/serialization/2.0/utils.LegacyBloomFilter.bin differ diff --git a/test/long/org/apache/cassandra/db/LongTableTest.java b/test/long/org/apache/cassandra/db/LongTableTest.java index 47ea23800b..a630fca55c 100644 --- a/test/long/org/apache/cassandra/db/LongTableTest.java +++ b/test/long/org/apache/cassandra/db/LongTableTest.java @@ -26,7 +26,6 @@ import org.apache.cassandra.utils.WrappedRunnable; import static org.apache.cassandra.Util.column; import org.apache.cassandra.Util; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.utils.ByteBufferUtil; @@ -57,7 +56,7 @@ public class LongTableTest extends SchemaLoader { for (int j = 0; j < i; j++) { - cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("key" + i), new QueryPath("Standard1"), ByteBufferUtil.bytes("c" + j))); + cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("key" + i), "Standard1", ByteBufferUtil.bytes("c" + j))); TableTest.assertColumns(cf, "c" + j); } } diff --git a/test/long/org/apache/cassandra/db/compaction/LongCompactionsTest.java b/test/long/org/apache/cassandra/db/compaction/LongCompactionsTest.java index de44468b40..65a8a17bcc 100644 --- a/test/long/org/apache/cassandra/db/compaction/LongCompactionsTest.java +++ b/test/long/org/apache/cassandra/db/compaction/LongCompactionsTest.java @@ -30,7 +30,6 @@ import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.db.*; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.io.sstable.SSTableUtils; import org.apache.cassandra.utils.ByteBufferUtil; @@ -83,7 +82,7 @@ public class LongCompactionsTest extends SchemaLoader for (int j = 0; j < rowsPerSSTable; j++) { String key = String.valueOf(j); - IColumn[] cols = new IColumn[colsPerRow]; + Column[] cols = new Column[colsPerRow]; for (int i = 0; i < colsPerRow; i++) { // last sstable has highest timestamps @@ -131,7 +130,7 @@ public class LongCompactionsTest extends SchemaLoader DecoratedKey key = Util.dk(String.valueOf(i % 2)); RowMutation rm = new RowMutation(TABLE1, key.key); long timestamp = j * ROWS_PER_SSTABLE + i; - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(String.valueOf(i / 2))), + rm.add("Standard1", ByteBufferUtil.bytes(String.valueOf(i / 2)), ByteBufferUtil.EMPTY_BYTE_BUFFER, timestamp); maxTimestampExpected = Math.max(timestamp, maxTimestampExpected); @@ -152,48 +151,6 @@ public class LongCompactionsTest extends SchemaLoader cfs.truncate(); } - @Test - public void testSuperColumnCompactions() throws IOException, ExecutionException, InterruptedException - { - Table table = Table.open(TABLE1); - ColumnFamilyStore cfs = table.getColumnFamilyStore("Super1"); - - final int ROWS_PER_SSTABLE = 10; - final int SSTABLES = cfs.metadata.getIndexInterval() * 3 / ROWS_PER_SSTABLE; - - //disable compaction while flushing - cfs.disableAutoCompaction(); - - long maxTimestampExpected = Long.MIN_VALUE; - Set inserted = new HashSet(); - ByteBuffer superColumn = ByteBufferUtil.bytes("TestSuperColumn"); - for (int j = 0; j < SSTABLES; j++) - { - for (int i = 0; i < ROWS_PER_SSTABLE; i++) - { - DecoratedKey key = Util.dk(String.valueOf(i % 2)); - RowMutation rm = new RowMutation(TABLE1, key.key); - long timestamp = j * ROWS_PER_SSTABLE + i; - rm.add(new QueryPath("Super1", superColumn, ByteBufferUtil.bytes((long)(i / 2))), - ByteBufferUtil.EMPTY_BYTE_BUFFER, - timestamp); - maxTimestampExpected = Math.max(timestamp, maxTimestampExpected); - rm.apply(); - inserted.add(key); - } - cfs.forceBlockingFlush(); - CompactionsTest.assertMaxTimestamp(cfs, maxTimestampExpected); - assertEquals(inserted.toString(), inserted.size(), Util.getRangeSlice(cfs, superColumn).size()); - } - - forceCompactions(cfs); - - assertEquals(inserted.size(), Util.getRangeSlice(cfs, superColumn).size()); - - // make sure max timestamp of compacted sstables is recorded properly after compaction. - CompactionsTest.assertMaxTimestamp(cfs, maxTimestampExpected); - } - private void forceCompactions(ColumnFamilyStore cfs) throws ExecutionException, InterruptedException { // re-enable compaction with thresholds low enough to force a few rounds diff --git a/test/long/org/apache/cassandra/db/compaction/LongLeveledCompactionStrategyTest.java b/test/long/org/apache/cassandra/db/compaction/LongLeveledCompactionStrategyTest.java index 0ba9d7c647..beae23dae4 100644 --- a/test/long/org/apache/cassandra/db/compaction/LongLeveledCompactionStrategyTest.java +++ b/test/long/org/apache/cassandra/db/compaction/LongLeveledCompactionStrategyTest.java @@ -31,7 +31,6 @@ import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.RowMutation; import org.apache.cassandra.db.Table; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.io.sstable.SSTable; import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.utils.ByteBufferUtil; @@ -63,7 +62,7 @@ public class LongLeveledCompactionStrategyTest extends SchemaLoader RowMutation rm = new RowMutation(ksname, key.key); for (int c = 0; c < columns; c++) { - rm.add(new QueryPath(cfname, null, ByteBufferUtil.bytes("column" + c)), value, 0); + rm.add(cfname, ByteBufferUtil.bytes("column" + c), value, 0); } rm.apply(); store.forceBlockingFlush(); diff --git a/test/system/__init__.py b/test/system/__init__.py index d9b88eec0c..6dd6be9463 100644 --- a/test/system/__init__.py +++ b/test/system/__init__.py @@ -132,6 +132,8 @@ class BaseTester(object): if not is_alive(spid): break slept += 0.5 + # Give time for cassandra to shutdown + time.sleep(1) if (slept > max_wait and is_alive(spid)): os.kill(spid, signal.SIGKILL) fpath = os.path.join(root, pid_fname) diff --git a/test/unit/org/apache/cassandra/AbstractSerializationsTester.java b/test/unit/org/apache/cassandra/AbstractSerializationsTester.java index aafe98b76b..807fd98d23 100644 --- a/test/unit/org/apache/cassandra/AbstractSerializationsTester.java +++ b/test/unit/org/apache/cassandra/AbstractSerializationsTester.java @@ -35,12 +35,13 @@ import java.util.Map; public class AbstractSerializationsTester extends SchemaLoader { - protected static final String CUR_VER = System.getProperty("cassandra.version", "1.2"); + protected static final String CUR_VER = System.getProperty("cassandra.version", "2.0"); protected static final Map VERSION_MAP = new HashMap () {{ put("0.7", 1); put("1.0", 3); put("1.2", MessagingService.VERSION_12); + put("2.0", MessagingService.VERSION_20); }}; // TODO ant doesn't pass this -D up to the test, so it's kind of useless diff --git a/test/unit/org/apache/cassandra/SchemaLoader.java b/test/unit/org/apache/cassandra/SchemaLoader.java index 48fbc04122..b7abacb1c9 100644 --- a/test/unit/org/apache/cassandra/SchemaLoader.java +++ b/test/unit/org/apache/cassandra/SchemaLoader.java @@ -33,7 +33,7 @@ import org.apache.cassandra.config.*; import org.apache.cassandra.db.*; import org.apache.cassandra.db.commitlog.CommitLog; import org.apache.cassandra.db.compaction.LeveledCompactionStrategy; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.filter.QueryFilter; import org.apache.cassandra.db.index.composites.CompositesIndex; import org.apache.cassandra.db.marshal.*; import org.apache.cassandra.exceptions.ConfigurationException; @@ -411,9 +411,7 @@ public class SchemaLoader { ByteBuffer key = ByteBufferUtil.bytes("key" + i); RowMutation rowMutation = new RowMutation(keyspace, key); - QueryPath path = new QueryPath(columnFamily, null, ByteBufferUtil.bytes("col" + i)); - - rowMutation.add(path, ByteBufferUtil.bytes("val" + i), System.currentTimeMillis()); + rowMutation.add(columnFamily, ByteBufferUtil.bytes("col" + i), ByteBufferUtil.bytes("val" + i), System.currentTimeMillis()); rowMutation.applyUnsafe(); } } @@ -425,9 +423,7 @@ public class SchemaLoader for (int i = offset; i < offset + numberOfRows; i++) { DecoratedKey key = Util.dk("key" + i); - QueryPath path = new QueryPath(columnFamily, null, ByteBufferUtil.bytes("col" + i)); - - store.getColumnFamily(key, path, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); + store.getColumnFamily(QueryFilter.getNamesFilter(key, columnFamily, ByteBufferUtil.bytes("col" + i))); } } diff --git a/test/unit/org/apache/cassandra/Util.java b/test/unit/org/apache/cassandra/Util.java index 1e9031e788..3df82671e9 100644 --- a/test/unit/org/apache/cassandra/Util.java +++ b/test/unit/org/apache/cassandra/Util.java @@ -37,8 +37,10 @@ import org.apache.cassandra.db.*; import org.apache.cassandra.db.compaction.CompactionManager; import org.apache.cassandra.db.compaction.CompactionTask; import org.apache.cassandra.db.columniterator.IdentityQueryFilter; +import org.apache.cassandra.db.filter.IDiskAtomFilter; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.filter.SliceQueryFilter; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.dht.*; import org.apache.cassandra.gms.ApplicationState; import org.apache.cassandra.gms.Gossiper; @@ -90,14 +92,6 @@ public class Util return new CounterUpdateColumn(ByteBufferUtil.bytes(name), value, timestamp); } - public static SuperColumn superColumn(ColumnFamily cf, String name, Column... columns) - { - SuperColumn sc = new SuperColumn(ByteBufferUtil.bytes(name), cf.metadata().comparator); - for (Column c : columns) - sc.addColumn(c); - return sc; - } - public static Token token(String key) { return StorageService.getPartitioner().getToken(ByteBufferUtil.bytes(key)); @@ -120,7 +114,10 @@ public class Util public static void addMutation(RowMutation rm, String columnFamilyName, String superColumnName, long columnName, String value, long timestamp) { - rm.add(new QueryPath(columnFamilyName, ByteBufferUtil.bytes(superColumnName), getBytes(columnName)), ByteBufferUtil.bytes(value), timestamp); + ByteBuffer cname = superColumnName == null + ? getBytes(columnName) + : CompositeType.build(ByteBufferUtil.bytes(superColumnName), getBytes(columnName)); + rm.add(columnFamilyName, cname, ByteBufferUtil.bytes(value), timestamp); } public static ByteBuffer getBytes(long v) @@ -148,11 +145,14 @@ public class Util public static List getRangeSlice(ColumnFamilyStore cfs, ByteBuffer superColumn) throws IOException, ExecutionException, InterruptedException { + IDiskAtomFilter filter = superColumn == null + ? new IdentityQueryFilter() + : new SliceQueryFilter(SuperColumns.startOf(superColumn), SuperColumns.endOf(superColumn), false, Integer.MAX_VALUE); + Token min = StorageService.getPartitioner().getMinimumToken(); - return cfs.getRangeSlice(superColumn, - new Bounds(min, min).toRowBounds(), + return cfs.getRangeSlice(new Bounds(min, min).toRowBounds(), 10000, - new IdentityQueryFilter(), + filter, null); } @@ -180,7 +180,7 @@ public class Util { ColumnFamilyStore cfStore = table.getColumnFamilyStore(cfName); assert cfStore != null : "Column family " + cfName + " has not been defined"; - return cfStore.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName))); + return cfStore.getColumnFamily(QueryFilter.getIdentityFilter(key, cfName)); } public static byte[] concatByteArrays(byte[] first, byte[]... remaining) diff --git a/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java b/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java index c7ba1df526..1e2ef9cb90 100644 --- a/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java +++ b/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java @@ -53,7 +53,7 @@ public class ColumnDefinitionTest protected void testSerializeDeserialize(ColumnDefinition cd) throws Exception { - ColumnDefinition newCd = ColumnDefinition.fromThrift(cd.toThrift()); + ColumnDefinition newCd = ColumnDefinition.fromThrift(cd.toThrift(), false); assert cd != newCd; assert cd.hashCode() == newCd.hashCode(); assert cd.equals(newCd); diff --git a/test/unit/org/apache/cassandra/config/DefsTest.java b/test/unit/org/apache/cassandra/config/DefsTest.java index 804cb29c8e..ef30668c87 100644 --- a/test/unit/org/apache/cassandra/config/DefsTest.java +++ b/test/unit/org/apache/cassandra/config/DefsTest.java @@ -28,7 +28,6 @@ import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.BytesType; import org.apache.cassandra.db.marshal.UTF8Type; import org.apache.cassandra.db.marshal.TimeUUIDType; @@ -66,8 +65,7 @@ public class DefsTest extends SchemaLoader CFMetaData cfm = new CFMetaData("Keyspace1", "TestApplyCFM_CF", ColumnFamilyType.Standard, - BytesType.instance, - null); + BytesType.instance); cfm.comment("No comment") .readRepairChance(0.5) @@ -188,15 +186,15 @@ public class DefsTest extends SchemaLoader // now read and write to it. DecoratedKey dk = Util.dk("key0"); RowMutation rm = new RowMutation(ks, dk.key); - rm.add(new QueryPath(cf, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L); + rm.add(cf, ByteBufferUtil.bytes("col0"), ByteBufferUtil.bytes("value0"), 1L); rm.apply(); ColumnFamilyStore store = Table.open(ks).getColumnFamilyStore(cf); assert store != null; store.forceBlockingFlush(); - ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(cf), ByteBufferUtil.bytes("col0"))); + ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, cf, ByteBufferUtil.bytes("col0"))); assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null; - IColumn col = cfam.getColumn(ByteBufferUtil.bytes("col0")); + Column col = cfam.getColumn(ByteBufferUtil.bytes("col0")); assert ByteBufferUtil.bytes("value0").equals(col.value()); } @@ -213,7 +211,7 @@ public class DefsTest extends SchemaLoader // write some data, force a flush, then verify that files exist on disk. RowMutation rm = new RowMutation(ks.name, dk.key); for (int i = 0; i < 100; i++) - rm.add(new QueryPath(cfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L); + rm.add(cfm.cfName, ByteBufferUtil.bytes(("col" + i)), ByteBufferUtil.bytes("anyvalue"), 1L); rm.apply(); ColumnFamilyStore store = Table.open(cfm.ksName).getColumnFamilyStore(cfm.cfName); assert store != null; @@ -229,7 +227,7 @@ public class DefsTest extends SchemaLoader boolean success = true; try { - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L); + rm.add("Standard1", ByteBufferUtil.bytes("col0"), ByteBufferUtil.bytes("value0"), 1L); rm.apply(); } catch (Throwable th) @@ -261,15 +259,15 @@ public class DefsTest extends SchemaLoader // test reads and writes. RowMutation rm = new RowMutation(newCf.ksName, dk.key); - rm.add(new QueryPath(newCf.cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L); + rm.add(newCf.cfName, ByteBufferUtil.bytes("col0"), ByteBufferUtil.bytes("value0"), 1L); rm.apply(); ColumnFamilyStore store = Table.open(newCf.ksName).getColumnFamilyStore(newCf.cfName); assert store != null; store.forceBlockingFlush(); - ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(newCf.cfName), ByteBufferUtil.bytes("col0"))); + ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, newCf.cfName, ByteBufferUtil.bytes("col0"))); assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null; - IColumn col = cfam.getColumn(ByteBufferUtil.bytes("col0")); + Column col = cfam.getColumn(ByteBufferUtil.bytes("col0")); assert ByteBufferUtil.bytes("value0").equals(col.value()); } @@ -286,7 +284,7 @@ public class DefsTest extends SchemaLoader // write some data, force a flush, then verify that files exist on disk. RowMutation rm = new RowMutation(ks.name, dk.key); for (int i = 0; i < 100; i++) - rm.add(new QueryPath(cfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L); + rm.add(cfm.cfName, ByteBufferUtil.bytes(("col" + i)), ByteBufferUtil.bytes("anyvalue"), 1L); rm.apply(); ColumnFamilyStore store = Table.open(cfm.ksName).getColumnFamilyStore(cfm.cfName); assert store != null; @@ -302,7 +300,7 @@ public class DefsTest extends SchemaLoader boolean success = true; try { - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L); + rm.add("Standard1", ByteBufferUtil.bytes("col0"), ByteBufferUtil.bytes("value0"), 1L); rm.apply(); } catch (Throwable th) @@ -337,7 +335,7 @@ public class DefsTest extends SchemaLoader // write some data RowMutation rm = new RowMutation(ks.name, dk.key); for (int i = 0; i < 100; i++) - rm.add(new QueryPath(cfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L); + rm.add(cfm.cfName, ByteBufferUtil.bytes(("col" + i)), ByteBufferUtil.bytes("anyvalue"), 1L); rm.apply(); MigrationManager.announceKeyspaceDrop(ks.name); @@ -369,15 +367,15 @@ public class DefsTest extends SchemaLoader // now read and write to it. DecoratedKey dk = Util.dk("key0"); RowMutation rm = new RowMutation(newKs.name, dk.key); - rm.add(new QueryPath(newCf.cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L); + rm.add(newCf.cfName, ByteBufferUtil.bytes("col0"), ByteBufferUtil.bytes("value0"), 1L); rm.apply(); ColumnFamilyStore store = Table.open(newKs.name).getColumnFamilyStore(newCf.cfName); assert store != null; store.forceBlockingFlush(); - ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(newCf.cfName), ByteBufferUtil.bytes("col0"))); + ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, newCf.cfName, ByteBufferUtil.bytes("col0"))); assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null; - IColumn col = cfam.getColumn(ByteBufferUtil.bytes("col0")); + Column col = cfam.getColumn(ByteBufferUtil.bytes("col0")); assert ByteBufferUtil.bytes("value0").equals(col.value()); } @@ -460,7 +458,7 @@ public class DefsTest extends SchemaLoader assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getDefaultValidator() == UTF8Type.instance; // Change cfId - newCfm = new CFMetaData(cf.ksName, cf.cfName, cf.cfType, cf.comparator, cf.subcolumnComparator, UUID.randomUUID()); + newCfm = new CFMetaData(cf.ksName, cf.cfName, cf.cfType, cf.comparator, UUID.randomUUID()); CFMetaData.copyOpts(newCfm, cf); try { @@ -470,7 +468,7 @@ public class DefsTest extends SchemaLoader catch (ConfigurationException expected) {} // Change cfName - newCfm = new CFMetaData(cf.ksName, cf.cfName + "_renamed", cf.cfType, cf.comparator, cf.subcolumnComparator); + newCfm = new CFMetaData(cf.ksName, cf.cfName + "_renamed", cf.cfType, cf.comparator); CFMetaData.copyOpts(newCfm, cf); try { @@ -480,7 +478,7 @@ public class DefsTest extends SchemaLoader catch (ConfigurationException expected) {} // Change ksName - newCfm = new CFMetaData(cf.ksName + "_renamed", cf.cfName, cf.cfType, cf.comparator, cf.subcolumnComparator); + newCfm = new CFMetaData(cf.ksName + "_renamed", cf.cfName, cf.cfType, cf.comparator); CFMetaData.copyOpts(newCfm, cf); try { @@ -490,7 +488,7 @@ public class DefsTest extends SchemaLoader catch (ConfigurationException expected) {} // Change cf type - newCfm = new CFMetaData(cf.ksName, cf.cfName, ColumnFamilyType.Super, cf.comparator, cf.subcolumnComparator); + newCfm = new CFMetaData(cf.ksName, cf.cfName, ColumnFamilyType.Super, cf.comparator); CFMetaData.copyOpts(newCfm, cf); try { @@ -500,7 +498,7 @@ public class DefsTest extends SchemaLoader catch (ConfigurationException expected) {} // Change comparator - newCfm = new CFMetaData(cf.ksName, cf.cfName, cf.cfType, TimeUUIDType.instance, cf.subcolumnComparator); + newCfm = new CFMetaData(cf.ksName, cf.cfName, cf.cfType, TimeUUIDType.instance); CFMetaData.copyOpts(newCfm, cf); try { @@ -518,8 +516,8 @@ public class DefsTest extends SchemaLoader // insert some data. save the sstable descriptor so we can make sure it's marked for delete after the drop RowMutation rm = new RowMutation("Keyspace6", ByteBufferUtil.bytes("k1")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(1L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("notbirthdate"), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 0); rm.apply(); ColumnFamilyStore cfs = Table.open("Keyspace6").getColumnFamilyStore("Indexed1"); cfs.forceBlockingFlush(); @@ -541,7 +539,7 @@ public class DefsTest extends SchemaLoader private CFMetaData addTestCF(String ks, String cf, String comment) { - CFMetaData newCFMD = new CFMetaData(ks, cf, ColumnFamilyType.Standard, UTF8Type.instance, null); + CFMetaData newCFMD = new CFMetaData(ks, cf, ColumnFamilyType.Standard, UTF8Type.instance); newCFMD.comment(comment) .readRepairChance(0.0); diff --git a/test/unit/org/apache/cassandra/db/ArrayBackedSortedColumnsTest.java b/test/unit/org/apache/cassandra/db/ArrayBackedSortedColumnsTest.java index 0ea4f71b25..f2184fe92d 100644 --- a/test/unit/org/apache/cassandra/db/ArrayBackedSortedColumnsTest.java +++ b/test/unit/org/apache/cassandra/db/ArrayBackedSortedColumnsTest.java @@ -52,7 +52,7 @@ public class ArrayBackedSortedColumnsTest for (int i = 0; i < values.length; ++i) map.addColumn(new Column(ByteBufferUtil.bytes(values[reversed ? values.length - 1 - i : i])), HeapAllocator.instance); - Iterator iter = map.iterator(); + Iterator iter = map.iterator(); assertEquals("1st column", 1, iter.next().name().getInt(0)); assertEquals("2nd column", 2, iter.next().name().getInt(0)); assertEquals("3rd column", 3, iter.next().name().getInt(0)); @@ -79,9 +79,9 @@ public class ArrayBackedSortedColumnsTest for (int i = 0; i < values2.length; ++i) map2.addColumn(new Column(ByteBufferUtil.bytes(values2[reversed ? values2.length - 1 - i : i])), HeapAllocator.instance); - map2.addAll(map, HeapAllocator.instance, Functions.identity()); + map2.addAll(map, HeapAllocator.instance, Functions.identity()); - Iterator iter = map2.iterator(); + Iterator iter = map2.iterator(); assertEquals("1st column", 1, iter.next().name().getInt(0)); assertEquals("2nd column", 2, iter.next().name().getInt(0)); assertEquals("3rd column", 3, iter.next().name().getInt(0)); @@ -102,10 +102,10 @@ public class ArrayBackedSortedColumnsTest ISortedColumns map = ArrayBackedSortedColumns.factory().create(BytesType.instance, reversed); int[] values = new int[]{ 1, 2, 3, 5, 9 }; - List sorted = new ArrayList(); + List sorted = new ArrayList(); for (int v : values) sorted.add(new Column(ByteBufferUtil.bytes(v))); - List reverseSorted = new ArrayList(sorted); + List reverseSorted = new ArrayList(sorted); Collections.reverse(reverseSorted); for (int i = 0; i < values.length; ++i) @@ -177,7 +177,7 @@ public class ArrayBackedSortedColumnsTest fail("The collection don't have the same size"); } - private void assertSame(int[] names, Iterator iter) + private void assertSame(int[] names, Iterator iter) { for (int name : names) { diff --git a/test/unit/org/apache/cassandra/db/CleanupTest.java b/test/unit/org/apache/cassandra/db/CleanupTest.java index 4de36ace4b..b4911d7bf9 100644 --- a/test/unit/org/apache/cassandra/db/CleanupTest.java +++ b/test/unit/org/apache/cassandra/db/CleanupTest.java @@ -33,7 +33,6 @@ import org.apache.cassandra.db.filter.IDiskAtomFilter; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.db.columniterator.IdentityQueryFilter; import org.apache.cassandra.db.compaction.CompactionManager; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.index.SecondaryIndex; import org.apache.cassandra.dht.BytesToken; import org.apache.cassandra.dht.IPartitioner; @@ -151,7 +150,7 @@ public class CleanupTest extends SchemaLoader // create a row and update the birthdate value, test that the index query fetches the new version RowMutation rm; rm = new RowMutation(TABLE1, ByteBufferUtil.bytes(key)); - rm.add(new QueryPath(cfs.name, null, COLUMN), VALUE, System.currentTimeMillis()); + rm.add(cfs.name, COLUMN, VALUE, System.currentTimeMillis()); rm.applyUnsafe(); } diff --git a/test/unit/org/apache/cassandra/db/CollationControllerTest.java b/test/unit/org/apache/cassandra/db/CollationControllerTest.java index 4a8e426081..4ef8d64980 100644 --- a/test/unit/org/apache/cassandra/db/CollationControllerTest.java +++ b/test/unit/org/apache/cassandra/db/CollationControllerTest.java @@ -26,7 +26,6 @@ import java.util.concurrent.ExecutionException; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.utils.ByteBufferUtil; import org.junit.Test; @@ -42,36 +41,35 @@ public class CollationControllerTest extends SchemaLoader ColumnFamilyStore store = table.getColumnFamilyStore("Standard1"); RowMutation rm; DecoratedKey dk = Util.dk("key1"); - QueryPath path = new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")); // add data rm = new RowMutation("Keyspace1", dk.key); - rm.add(path, ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdf"), 0); rm.apply(); store.forceBlockingFlush(); // remove rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Standard1"), 10); + rm.delete("Standard1", 10); rm.apply(); // add another mutation because sstable maxtimestamp isn't set // correctly during flush if the most recent mutation is a row delete rm = new RowMutation("Keyspace1", Util.dk("key2").key); - rm.add(path, ByteBufferUtil.bytes("zxcv"), 20); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("zxcv"), 20); rm.apply(); store.forceBlockingFlush(); // add yet one more mutation rm = new RowMutation("Keyspace1", dk.key); - rm.add(path, ByteBufferUtil.bytes("foobar"), 30); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("foobar"), 30); rm.apply(); store.forceBlockingFlush(); // A NamesQueryFilter goes down one code path (through collectTimeOrderedData()) // It should only iterate the last flushed sstable, since it probably contains the most recent value for Column1 - QueryFilter filter = QueryFilter.getNamesFilter(dk, path, ByteBufferUtil.bytes("Column1")); + QueryFilter filter = QueryFilter.getNamesFilter(dk, "Standard1", ByteBufferUtil.bytes("Column1")); CollationController controller = new CollationController(store, false, filter, Integer.MIN_VALUE); controller.getTopLevelColumns(); assertEquals(1, controller.getSstablesIterated()); @@ -79,7 +77,7 @@ public class CollationControllerTest extends SchemaLoader // SliceQueryFilter goes down another path (through collectAllData()) // We will read "only" the last sstable in that case, but because the 2nd sstable has a tombstone that is more // recent than the maxTimestamp of the very first sstable we flushed, we should only read the 2 first sstables. - filter = QueryFilter.getIdentityFilter(dk, path); + filter = QueryFilter.getIdentityFilter(dk, "Standard1"); controller = new CollationController(store, false, filter, Integer.MIN_VALUE); controller.getTopLevelColumns(); assertEquals(2, controller.getSstablesIterated()); diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java index b6f98170ac..e77277f6b8 100644 --- a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java +++ b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java @@ -32,6 +32,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Random; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -100,17 +102,17 @@ public class ColumnFamilyStoreTest extends SchemaLoader RowMutation rm; rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1")); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdf"), 0); rm.apply(); cfs.forceBlockingFlush(); rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1")); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 1); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdf"), 1); rm.apply(); cfs.forceBlockingFlush(); cfs.getRecentSSTablesPerReadHistogram(); // resets counts - cfs.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("key1"), new QueryPath("Standard1", null), ByteBufferUtil.bytes("Column1"))); + cfs.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("key1"), "Standard1", ByteBufferUtil.bytes("Column1"))); assertEquals(1, cfs.getRecentSSTablesPerReadHistogram()[0]); } @@ -124,15 +126,15 @@ public class ColumnFamilyStoreTest extends SchemaLoader List rms = new LinkedList(); RowMutation rm; rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1")); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column2")), ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column2"), ByteBufferUtil.bytes("asdf"), 0); rms.add(rm); Util.writeColumnFamily(rms); List ssTables = table.getAllSSTables(); assertEquals(1, ssTables.size()); ssTables.get(0).forceFilterFailures(); - ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("key2"), new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")))); + ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("key2"), "Standard1")); assertNull(cf); } @@ -144,19 +146,19 @@ public class ColumnFamilyStoreTest extends SchemaLoader RowMutation rm; rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1")); - rm.delete(new QueryPath("Standard2", null, null), System.currentTimeMillis()); + rm.delete("Standard2", System.currentTimeMillis()); rm.apply(); Runnable r = new WrappedRunnable() { public void runMayThrow() throws IOException { - QueryFilter sliceFilter = QueryFilter.getSliceFilter(Util.dk("key1"), new QueryPath("Standard2", null, null), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); + QueryFilter sliceFilter = QueryFilter.getSliceFilter(Util.dk("key1"), "Standard2", ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); ColumnFamily cf = store.getColumnFamily(sliceFilter); assert cf.isMarkedForDelete(); assert cf.isEmpty(); - QueryFilter namesFilter = QueryFilter.getNamesFilter(Util.dk("key1"), new QueryPath("Standard2", null, null), ByteBufferUtil.bytes("a")); + QueryFilter namesFilter = QueryFilter.getNamesFilter(Util.dk("key1"), "Standard2", ByteBufferUtil.bytes("a")); cf = store.getColumnFamily(namesFilter); assert cf.isMarkedForDelete(); assert cf.isEmpty(); @@ -172,8 +174,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader ColumnFamilyStore cfs = insertKey1Key2(); IPartitioner p = StorageService.getPartitioner(); - List result = cfs.getRangeSlice(ByteBufferUtil.EMPTY_BYTE_BUFFER, - Util.range(p, "key1", "key2"), + List result = cfs.getRangeSlice(Util.range(p, "key1", "key2"), 10, new NamesQueryFilter(ByteBufferUtil.bytes("asdf")), null); @@ -187,23 +188,23 @@ public class ColumnFamilyStoreTest extends SchemaLoader RowMutation rm; rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k1")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(1L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("notbirthdate"), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 0); rm.apply(); rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k2")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(2L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("notbirthdate"), ByteBufferUtil.bytes(2L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(2L), 0); rm.apply(); rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k3")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("notbirthdate"), ByteBufferUtil.bytes(2L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 0); rm.apply(); rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k4aaaa")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(3L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("notbirthdate"), ByteBufferUtil.bytes(2L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(3L), 0); rm.apply(); // basic single-expression query @@ -270,8 +271,8 @@ public class ColumnFamilyStoreTest extends SchemaLoader for (int i = 0; i < 100; i++) { rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key" + i)); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(34L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes((long) (i % 2)), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(34L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("notbirthdate"), ByteBufferUtil.bytes((long) (i % 2)), 0); rm.applyUnsafe(); } @@ -299,7 +300,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader RowMutation rm; rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 0); rm.apply(); IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(1L)); @@ -314,13 +315,13 @@ public class ColumnFamilyStoreTest extends SchemaLoader // delete the column directly rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1")); - rm.delete(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), 1); + rm.delete("Indexed1", ByteBufferUtil.bytes("birthdate"), 1); rm.apply(); rows = cfs.search(clause, range, 100, filter); assert rows.isEmpty(); // verify that it's not being indexed under the deletion column value either - IColumn deletion = rm.getColumnFamilies().iterator().next().iterator().next(); + Column deletion = rm.getColumnFamilies().iterator().next().iterator().next(); ByteBuffer deletionLong = ByteBufferUtil.bytes((long) ByteBufferUtil.toInt(deletion.value())); IndexExpression expr0 = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, deletionLong); List clause0 = Arrays.asList(expr0); @@ -329,7 +330,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // resurrect w/ a newer timestamp rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 2); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 2); rm.apply(); rows = cfs.search(clause, range, 100, filter); assert rows.size() == 1 : StringUtils.join(rows, ","); @@ -338,7 +339,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // verify that row and delete w/ older timestamp does nothing rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1")); - rm.delete(new QueryPath("Indexed1"), 1); + rm.delete("Indexed1", 1); rm.apply(); rows = cfs.search(clause, range, 100, filter); assert rows.size() == 1 : StringUtils.join(rows, ","); @@ -347,7 +348,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // similarly, column delete w/ older timestamp should do nothing rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1")); - rm.delete(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), 1); + rm.delete("Indexed1", ByteBufferUtil.bytes("birthdate"), 1); rm.apply(); rows = cfs.search(clause, range, 100, filter); assert rows.size() == 1 : StringUtils.join(rows, ","); @@ -356,30 +357,30 @@ public class ColumnFamilyStoreTest extends SchemaLoader // delete the entire row (w/ newer timestamp this time) rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1")); - rm.delete(new QueryPath("Indexed1"), 3); + rm.delete("Indexed1", 3); rm.apply(); rows = cfs.search(clause, range, 100, filter); assert rows.isEmpty() : StringUtils.join(rows, ","); // make sure obsolete mutations don't generate an index entry rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 3); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 3); rm.apply(); rows = cfs.search(clause, range, 100, filter); assert rows.isEmpty() : StringUtils.join(rows, ","); // try insert followed by row delete in the same mutation rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 1); - rm.delete(new QueryPath("Indexed1"), 2); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 1); + rm.delete("Indexed1", 2); rm.apply(); rows = cfs.search(clause, range, 100, filter); assert rows.isEmpty() : StringUtils.join(rows, ","); // try row delete followed by insert in the same mutation rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1")); - rm.delete(new QueryPath("Indexed1"), 3); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 4); + rm.delete("Indexed1", 3); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 4); rm.apply(); rows = cfs.search(clause, range, 100, filter); assert rows.size() == 1 : StringUtils.join(rows, ","); @@ -395,10 +396,10 @@ public class ColumnFamilyStoreTest extends SchemaLoader // create a row and update the birthdate value, test that the index query fetches the new version RowMutation rm; rm = new RowMutation("Keyspace2", ByteBufferUtil.bytes("k1")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 1); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 1); rm.apply(); rm = new RowMutation("Keyspace2", ByteBufferUtil.bytes("k1")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(2L), 2); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(2L), 2); rm.apply(); IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(1L)); @@ -417,7 +418,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // update the birthdate value with an OLDER timestamp, and test that the index ignores this rm = new RowMutation("Keyspace2", ByteBufferUtil.bytes("k1")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(3L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(3L), 0); rm.apply(); rows = table.getColumnFamilyStore("Indexed1").search(clause, range, 100, filter); @@ -444,7 +445,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // create a row and update the "birthdate" value, test that the index query fetches this version RowMutation rm; rm = new RowMutation(keySpace, rowKey); - rm.add(new QueryPath(cfName, null, colName), val1, 0); + rm.add(cfName, colName, val1, 0); rm.apply(); IndexExpression expr = new IndexExpression(colName, IndexOperator.EQ, val1); List clause = Arrays.asList(expr); @@ -458,7 +459,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // now apply another update, but force the index update to be skipped rm = new RowMutation(keySpace, rowKey); - rm.add(new QueryPath(cfName, null, colName), val2, 1); + rm.add(cfName, colName, val2, 1); table.apply(rm, true, false); // Now searching the index for either the old or new value should return 0 rows @@ -478,7 +479,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // now, reset back to the original value, still skipping the index update, to // make sure the value was expunged from the index when it was discovered to be inconsistent rm = new RowMutation(keySpace, rowKey); - rm.add(new QueryPath(cfName, null, colName), ByteBufferUtil.bytes(1L), 3); + rm.add(cfName, colName, ByteBufferUtil.bytes(1L), 3); table.apply(rm, true, false); expr = new IndexExpression(colName, IndexOperator.EQ, ByteBufferUtil.bytes(1L)); @@ -514,7 +515,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // create a row and update the author value RowMutation rm; rm = new RowMutation(keySpace, rowKey); - rm.add(new QueryPath(cfName, null , compositeName), val1, 0); + rm.add(cfName, compositeName, val1, 0); rm.apply(); // test that the index query fetches this version @@ -532,7 +533,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // now apply another update, but force the index update to be skipped rm = new RowMutation(keySpace, rowKey); - rm.add(new QueryPath(cfName, null, compositeName), val2, 1); + rm.add(cfName, compositeName, val2, 1); table.apply(rm, true, false); // Now searching the index for either the old or new value should return 0 rows @@ -552,7 +553,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // now, reset back to the original value, still skipping the index update, to // make sure the value was expunged from the index when it was discovered to be inconsistent rm = new RowMutation(keySpace, rowKey); - rm.add(new QueryPath(cfName, null , compositeName), val1, 2); + rm.add(cfName, compositeName, val1, 2); table.apply(rm, true, false); expr = new IndexExpression(colName, IndexOperator.EQ, val1); @@ -570,23 +571,23 @@ public class ColumnFamilyStoreTest extends SchemaLoader RowMutation rm; rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("kk1")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(1L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("notbirthdate"), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 0); rm.apply(); rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("kk2")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("notbirthdate"), ByteBufferUtil.bytes(2L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 0); rm.apply(); rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("kk3")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("notbirthdate"), ByteBufferUtil.bytes(2L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 0); rm.apply(); rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("kk4")); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("notbirthdate"), ByteBufferUtil.bytes(2L), 0); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 0); rm.apply(); // basic single-expression query @@ -610,7 +611,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader // create a row and update the birthdate value, test that the index query fetches the new version RowMutation rm; rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k1")); - rm.add(new QueryPath("Indexed2", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 1); + rm.add("Indexed2", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), 1); rm.apply(); ColumnFamilyStore cfs = table.getColumnFamilyStore("Indexed2"); @@ -651,8 +652,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader ColumnFamilyStore cfs = insertKey1Key2(); IPartitioner p = StorageService.getPartitioner(); - List result = cfs.getRangeSlice(ByteBufferUtil.EMPTY_BYTE_BUFFER, - Util.bounds("key1", "key2"), + List result = cfs.getRangeSlice(Util.bounds("key1", "key2"), 10, new NamesQueryFilter(ByteBufferUtil.bytes("asdf")), null); @@ -690,21 +690,21 @@ public class ColumnFamilyStoreTest extends SchemaLoader sp.getSlice_range().setStart(ArrayUtils.EMPTY_BYTE_ARRAY); sp.getSlice_range().setFinish(ArrayUtils.EMPTY_BYTE_ARRAY); - assertRowAndColCount(1, 6, scfName, false, cfs.getRangeSlice(scfName, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 6, scfName, false, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, scfName), null)); // deeleet. RowMutation rm = new RowMutation(table.getName(), key.key); - rm.delete(new QueryPath(cfName, scfName), 2); + rm.deleteRange(cfName, SuperColumns.startOf(scfName), SuperColumns.endOf(scfName), 2); rm.apply(); // verify delete. - assertRowAndColCount(1, 0, scfName, false, cfs.getRangeSlice(scfName, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 0, scfName, false, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, scfName), null)); // flush cfs.forceBlockingFlush(); // re-verify delete. - assertRowAndColCount(1, 0, scfName, false, cfs.getRangeSlice(scfName, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 0, scfName, false, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, scfName), null)); // late insert. putColsSuper(cfs, key, scfName, @@ -712,14 +712,14 @@ public class ColumnFamilyStoreTest extends SchemaLoader new Column(getBytes(7L), ByteBufferUtil.bytes("val7"), 1L)); // re-verify delete. - assertRowAndColCount(1, 0, scfName, false, cfs.getRangeSlice(scfName, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 0, scfName, false, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, scfName), null)); // make sure new writes are recognized. putColsSuper(cfs, key, scfName, new Column(getBytes(3L), ByteBufferUtil.bytes("val3"), 3), new Column(getBytes(8L), ByteBufferUtil.bytes("val8"), 3), new Column(getBytes(9L), ByteBufferUtil.bytes("val9"), 3)); - assertRowAndColCount(1, 3, scfName, false, cfs.getRangeSlice(scfName, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 3, scfName, false, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, scfName), null)); } private static void assertRowAndColCount(int rowCount, int colCount, ByteBuffer sc, boolean isDeleted, Collection rows) throws CharacterCodingException @@ -728,10 +728,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader for (Row row : rows) { assert row.cf != null : "cf was null"; - if (sc != null) - assert row.cf.getColumn(sc).getSubColumns().size() == colCount : row.cf.getColumn(sc).getSubColumns().size(); - else - assert row.cf.getColumnCount() == colCount : "colcount " + row.cf.getColumnCount() + "|" + str(row.cf); + assert row.cf.getColumnCount() == colCount : "colcount " + row.cf.getColumnCount() + "|" + str(row.cf); if (isDeleted) assert row.cf.isMarkedForDelete() : "cf not marked for delete"; } @@ -740,7 +737,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader private static String str(ColumnFamily cf) throws CharacterCodingException { StringBuilder sb = new StringBuilder(); - for (IColumn col : cf.getSortedColumns()) + for (Column col : cf.getSortedColumns()) sb.append(String.format("(%s,%s,%d),", ByteBufferUtil.string(col.name()), ByteBufferUtil.string(col.value()), col.timestamp())); return sb.toString(); } @@ -749,10 +746,8 @@ public class ColumnFamilyStoreTest extends SchemaLoader { RowMutation rm = new RowMutation(cfs.table.getName(), key.key); ColumnFamily cf = ColumnFamily.create(cfs.table.getName(), cfs.name); - SuperColumn sc = new SuperColumn(scfName, cfs.metadata.subcolumnComparator); for (Column col : cols) - sc.addColumn(col); - cf.addColumn(sc); + cf.addColumn(col.withUpdatedName(CompositeType.build(scfName, col.name()))); rm.add(cf); rm.apply(); } @@ -785,42 +780,42 @@ public class ColumnFamilyStoreTest extends SchemaLoader // insert putColsStandard(cfs, key, column("col1", "val1", 1), column("col2", "val2", 1)); - assertRowAndColCount(1, 2, null, false, cfs.getRangeSlice(null, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 2, null, false, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, null), null)); // flush. cfs.forceBlockingFlush(); // insert, don't flush putColsStandard(cfs, key, column("col3", "val3", 1), column("col4", "val4", 1)); - assertRowAndColCount(1, 4, null, false, cfs.getRangeSlice(null, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 4, null, false, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, null), null)); // delete (from sstable and memtable) RowMutation rm = new RowMutation(table.getName(), key.key); - rm.delete(new QueryPath(cfs.name, null, null), 2); + rm.delete(cfs.name, 2); rm.apply(); // verify delete - assertRowAndColCount(1, 0, null, true, cfs.getRangeSlice(null, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 0, null, true, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, null), null)); // flush cfs.forceBlockingFlush(); // re-verify delete. // first breakage is right here because of CASSANDRA-1837. - assertRowAndColCount(1, 0, null, true, cfs.getRangeSlice(null, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 0, null, true, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, null), null)); // simulate a 'late' insertion that gets put in after the deletion. should get inserted, but fail on read. putColsStandard(cfs, key, column("col5", "val5", 1), column("col2", "val2", 1)); // should still be nothing there because we deleted this row. 2nd breakage, but was undetected because of 1837. - assertRowAndColCount(1, 0, null, true, cfs.getRangeSlice(null, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 0, null, true, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, null), null)); // make sure that new writes are recognized. putColsStandard(cfs, key, column("col6", "val6", 3), column("col7", "val7", 3)); - assertRowAndColCount(1, 2, null, true, cfs.getRangeSlice(null, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 2, null, true, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, null), null)); // and it remains so after flush. (this wasn't failing before, but it's good to check.) cfs.forceBlockingFlush(); - assertRowAndColCount(1, 2, null, true, cfs.getRangeSlice(null, Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null)); + assertRowAndColCount(1, 2, null, true, cfs.getRangeSlice(Util.range("f", "g"), 100, ThriftValidation.asIFilter(sp, cfs.metadata, null), null)); } @@ -829,12 +824,12 @@ public class ColumnFamilyStoreTest extends SchemaLoader List rms = new LinkedList(); RowMutation rm; rm = new RowMutation("Keyspace2", ByteBufferUtil.bytes("key1")); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdf"), 0); rms.add(rm); Util.writeColumnFamily(rms); rm = new RowMutation("Keyspace2", ByteBufferUtil.bytes("key2")); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdf"), 0); rms.add(rm); return Util.writeColumnFamily(rms); } @@ -853,30 +848,6 @@ public class ColumnFamilyStoreTest extends SchemaLoader } } - @Test - public void testSuperSliceByNamesCommand() throws Throwable - { - String tableName = "Keyspace1"; - String cfName= "Super4"; - ByteBuffer superColName = ByteBufferUtil.bytes("HerpDerp"); - DecoratedKey key = Util.dk("multiget-slice-resurrection"); - Table table = Table.open(tableName); - ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName); - - // Initially create a SC with 1 subcolumn - putColsSuper(cfs, key, superColName, new Column(ByteBufferUtil.bytes("c1"), ByteBufferUtil.bytes("a"), 1)); - cfs.forceBlockingFlush(); - - // Add another column - putColsSuper(cfs, key, superColName, new Column(ByteBufferUtil.bytes("c2"), ByteBufferUtil.bytes("b"), 2)); - - // Test fetching the supercolumn by name - SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(tableName, key.key, new QueryPath(cfName), Collections.singletonList(superColName)); - ColumnFamily cf = cmd.getRow(table).cf; - SuperColumn superColumn = (SuperColumn) cf.getColumn(superColName); - assertColumns(superColumn, "c1", "c2"); - } - // CASSANDRA-3467. the key here is that supercolumn and subcolumn comparators are different @Test public void testSliceByNamesCommandOnUUIDTypeSCF() throws Throwable @@ -893,20 +864,20 @@ public class ColumnFamilyStoreTest extends SchemaLoader new Column(ByteBufferUtil.bytes("b"), ByteBufferUtil.bytes("B"), 1)); // Get the entire supercolumn like normal - IColumn columnGet = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName, superColName))).getColumn(superColName); - assertEquals(ByteBufferUtil.bytes("A"), columnGet.getSubColumn(ByteBufferUtil.bytes("a")).value()); - assertEquals(ByteBufferUtil.bytes("B"), columnGet.getSubColumn(ByteBufferUtil.bytes("b")).value()); + ColumnFamily cfGet = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, cfName)); + assertEquals(ByteBufferUtil.bytes("A"), cfGet.getColumn(CompositeType.build(superColName, ByteBufferUtil.bytes("a"))).value()); + assertEquals(ByteBufferUtil.bytes("B"), cfGet.getColumn(CompositeType.build(superColName, ByteBufferUtil.bytes("b"))).value()); // Now do the SliceByNamesCommand on the supercolumn, passing both subcolumns in as columns to get - ArrayList sliceColNames = new ArrayList(); - sliceColNames.add(ByteBufferUtil.bytes("a")); - sliceColNames.add(ByteBufferUtil.bytes("b")); - SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(tableName, key.key, new QueryPath(cfName, superColName), sliceColNames); - IColumn columnSliced = cmd.getRow(table).cf.getColumn(superColName); + SortedSet sliceColNames = new TreeSet(cfs.metadata.comparator); + sliceColNames.add(CompositeType.build(superColName, ByteBufferUtil.bytes("a"))); + sliceColNames.add(CompositeType.build(superColName, ByteBufferUtil.bytes("b"))); + SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(tableName, key.key, cfName, new NamesQueryFilter(sliceColNames)); + ColumnFamily cfSliced = cmd.getRow(table).cf; // Make sure the slice returns the same as the straight get - assertEquals(ByteBufferUtil.bytes("A"), columnSliced.getSubColumn(ByteBufferUtil.bytes("a")).value()); - assertEquals(ByteBufferUtil.bytes("B"), columnSliced.getSubColumn(ByteBufferUtil.bytes("b")).value()); + assertEquals(ByteBufferUtil.bytes("A"), cfSliced.getColumn(CompositeType.build(superColName, ByteBufferUtil.bytes("a"))).value()); + assertEquals(ByteBufferUtil.bytes("B"), cfSliced.getColumn(CompositeType.build(superColName, ByteBufferUtil.bytes("b"))).value()); } @Test @@ -937,7 +908,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader putColsStandard(cfs, key, new Column(cname, ByteBufferUtil.bytes("b"), 1)); // Test fetching the column by name returns the first column - SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(tableName, key.key, new QueryPath(cfName), Collections.singletonList(cname)); + SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(tableName, key.key, cfName, new NamesQueryFilter(cname)); ColumnFamily cf = cmd.getRow(table).cf; Column column = (Column) cf.getColumn(cname); assert column.value().equals(ByteBufferUtil.bytes("a")) : "expecting a, got " + ByteBufferUtil.string(column.value()); @@ -953,6 +924,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader assert columns == expectedCount : "Expected " + expectedCount + " live columns but got " + columns + ": " + rows; } + @Test public void testRangeSliceColumnsLimit() throws Throwable { @@ -977,11 +949,11 @@ public class ColumnFamilyStoreTest extends SchemaLoader sp.getSlice_range().setStart(ArrayUtils.EMPTY_BYTE_ARRAY); sp.getSlice_range().setFinish(ArrayUtils.EMPTY_BYTE_ARRAY); - assertTotalColCount(cfs.getRangeSlice(null, Util.range("", ""), 3, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, false), 3); - assertTotalColCount(cfs.getRangeSlice(null, Util.range("", ""), 5, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, false), 5); - assertTotalColCount(cfs.getRangeSlice(null, Util.range("", ""), 8, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, false), 8); - assertTotalColCount(cfs.getRangeSlice(null, Util.range("", ""), 10, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, false), 10); - assertTotalColCount(cfs.getRangeSlice(null, Util.range("", ""), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, false), 11); + assertTotalColCount(cfs.getRangeSlice(Util.range("", ""), 3, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, false), 3); + assertTotalColCount(cfs.getRangeSlice(Util.range("", ""), 5, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, false), 5); + assertTotalColCount(cfs.getRangeSlice(Util.range("", ""), 8, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, false), 8); + assertTotalColCount(cfs.getRangeSlice(Util.range("", ""), 10, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, false), 10); + assertTotalColCount(cfs.getRangeSlice(Util.range("", ""), 100, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, false), 11); // Check that when querying by name, we always include all names for a // gien row even if it means returning more columns than requested (this is necesseray for CQL) @@ -992,11 +964,11 @@ public class ColumnFamilyStoreTest extends SchemaLoader ByteBufferUtil.bytes("c2") )); - assertTotalColCount(cfs.getRangeSlice(null, Util.range("", ""), 1, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, false), 3); - assertTotalColCount(cfs.getRangeSlice(null, Util.range("", ""), 4, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, false), 5); - assertTotalColCount(cfs.getRangeSlice(null, Util.range("", ""), 5, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, false), 5); - assertTotalColCount(cfs.getRangeSlice(null, Util.range("", ""), 6, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, false), 8); - assertTotalColCount(cfs.getRangeSlice(null, Util.range("", ""), 100, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, false), 8); + assertTotalColCount(cfs.getRangeSlice(Util.range("", ""), 1, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, false), 3); + assertTotalColCount(cfs.getRangeSlice(Util.range("", ""), 4, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, false), 5); + assertTotalColCount(cfs.getRangeSlice(Util.range("", ""), 5, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, false), 5); + assertTotalColCount(cfs.getRangeSlice(Util.range("", ""), 6, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, false), 8); + assertTotalColCount(cfs.getRangeSlice(Util.range("", ""), 100, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, false), 8); } @Test @@ -1023,13 +995,13 @@ public class ColumnFamilyStoreTest extends SchemaLoader sp.getSlice_range().setStart(ArrayUtils.EMPTY_BYTE_ARRAY); sp.getSlice_range().setFinish(ArrayUtils.EMPTY_BYTE_ARRAY); - Collection rows = cfs.getRangeSlice(null, Util.range("", ""), 3, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, true); + Collection rows = cfs.getRangeSlice(Util.range("", ""), 3, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, true); assert rows.size() == 1 : "Expected 1 row, got " + rows; Row row = rows.iterator().next(); assertColumnNames(row, "c0", "c1", "c2"); sp.getSlice_range().setStart(ByteBufferUtil.getArray(ByteBufferUtil.bytes("c2"))); - rows = cfs.getRangeSlice(null, Util.range("", ""), 3, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, true); + rows = cfs.getRangeSlice(Util.range("", ""), 3, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, true); assert rows.size() == 2 : "Expected 2 rows, got " + rows; Iterator iter = rows.iterator(); Row row1 = iter.next(); @@ -1038,13 +1010,13 @@ public class ColumnFamilyStoreTest extends SchemaLoader assertColumnNames(row2, "c0"); sp.getSlice_range().setStart(ByteBufferUtil.getArray(ByteBufferUtil.bytes("c0"))); - rows = cfs.getRangeSlice(null, new Bounds(row2.key, Util.rp("")), 3, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, true); + rows = cfs.getRangeSlice(new Bounds(row2.key, Util.rp("")), 3, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, true); assert rows.size() == 1 : "Expected 1 row, got " + rows; row = rows.iterator().next(); assertColumnNames(row, "c0", "c1", "c2"); sp.getSlice_range().setStart(ByteBufferUtil.getArray(ByteBufferUtil.bytes("c2"))); - rows = cfs.getRangeSlice(null, new Bounds(row.key, Util.rp("")), 3, ThriftValidation.asIFilter(sp, cfs.getComparator()), null, true, true); + rows = cfs.getRangeSlice(new Bounds(row.key, Util.rp("")), 3, ThriftValidation.asIFilter(sp, cfs.metadata, null), null, true, true); assert rows.size() == 2 : "Expected 2 rows, got " + rows; iter = rows.iterator(); row1 = iter.next(); @@ -1058,12 +1030,12 @@ public class ColumnFamilyStoreTest extends SchemaLoader if (row == null || row.cf == null) throw new AssertionError("The row should not be empty"); - Iterator columns = row.cf.getSortedColumns().iterator(); + Iterator columns = row.cf.getSortedColumns().iterator(); Iterator names = Arrays.asList(columnNames).iterator(); while (columns.hasNext()) { - IColumn c = columns.next(); + Column c = columns.next(); assert names.hasNext() : "Got more columns that expected (first unexpected column: " + ByteBufferUtil.string(c.name()) + ")"; String n = names.next(); assert c.name().equals(ByteBufferUtil.bytes(n)) : "Expected " + n + ", got " + ByteBufferUtil.string(c.name()); @@ -1100,30 +1072,30 @@ public class ColumnFamilyStoreTest extends SchemaLoader sp.getSlice_range().setCount(1); sp.getSlice_range().setStart(ArrayUtils.EMPTY_BYTE_ARRAY); sp.getSlice_range().setFinish(ArrayUtils.EMPTY_BYTE_ARRAY); - IDiskAtomFilter qf = ThriftValidation.asIFilter(sp, cfs.getComparator()); + IDiskAtomFilter qf = ThriftValidation.asIFilter(sp, cfs.metadata, null); List rows; // Start and end inclusive - rows = cfs.getRangeSlice(null, new Bounds(rp("2"), rp("7")), 100, qf, null); + rows = cfs.getRangeSlice(new Bounds(rp("2"), rp("7")), 100, qf, null); assert rows.size() == 6; assert rows.get(0).key.equals(idk(2)); assert rows.get(rows.size() - 1).key.equals(idk(7)); // Start and end excluded - rows = cfs.getRangeSlice(null, new ExcludingBounds(rp("2"), rp("7")), 100, qf, null); + rows = cfs.getRangeSlice(new ExcludingBounds(rp("2"), rp("7")), 100, qf, null); assert rows.size() == 4; assert rows.get(0).key.equals(idk(3)); assert rows.get(rows.size() - 1).key.equals(idk(6)); // Start excluded, end included - rows = cfs.getRangeSlice(null, new Range(rp("2"), rp("7")), 100, qf, null); + rows = cfs.getRangeSlice(new Range(rp("2"), rp("7")), 100, qf, null); assert rows.size() == 5; assert rows.get(0).key.equals(idk(3)); assert rows.get(rows.size() - 1).key.equals(idk(7)); // Start included, end excluded - rows = cfs.getRangeSlice(null, new IncludingExcludingBounds(rp("2"), rp("7")), 100, qf, null); + rows = cfs.getRangeSlice(new IncludingExcludingBounds(rp("2"), rp("7")), 100, qf, null); assert rows.size() == 5; assert rows.get(0).key.equals(idk(2)); assert rows.get(rows.size() - 1).key.equals(idk(6)); @@ -1142,11 +1114,7 @@ public class ColumnFamilyStoreTest extends SchemaLoader { ByteBuffer key = ByteBufferUtil.bytes(String.valueOf("k" + i)); RowMutation rm = new RowMutation("Keyspace1", key); - - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), - LongType.instance.decompose(1L), - System.currentTimeMillis()); - + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), LongType.instance.decompose(1L), System.currentTimeMillis()); rm.apply(); } @@ -1482,16 +1450,16 @@ public class ColumnFamilyStoreTest extends SchemaLoader private void findRowGetSlicesAndAssertColsFound(ColumnFamilyStore cfs, SliceQueryFilter filter, String rowKey, String... colNames) { - List rows = cfs.getRangeSlice(null, new Bounds(rp(rowKey), rp(rowKey)), + List rows = cfs.getRangeSlice(new Bounds(rp(rowKey), rp(rowKey)), Integer.MAX_VALUE, filter, null, false, false); assertSame("unexpected number of rows ", 1, rows.size()); Row row = rows.get(0); - Collection cols = !filter.isReversed() ? row.cf.getSortedColumns() : row.cf.getReverseSortedColumns(); + Collection cols = !filter.isReversed() ? row.cf.getSortedColumns() : row.cf.getReverseSortedColumns(); // printRow(cfs, new String(row.key.key.array()), cols); - String[] returnedColsNames = Iterables.toArray(Iterables.transform(cols, new Function() + String[] returnedColsNames = Iterables.toArray(Iterables.transform(cols, new Function() { - public String apply(IColumn arg0) + public String apply(Column arg0) { return new String(arg0.name().array()); } @@ -1501,29 +1469,29 @@ public class ColumnFamilyStoreTest extends SchemaLoader "Columns did not match. Expected: " + Arrays.toString(colNames) + " but got:" + Arrays.toString(returnedColsNames), Arrays.equals(colNames, returnedColsNames)); int i = 0; - for (IColumn col : cols) + for (Column col : cols) { assertEquals(colNames[i++], new String(col.name().array())); } } - private void printRow(ColumnFamilyStore cfs, String rowKey, Collection cols) + private void printRow(ColumnFamilyStore cfs, String rowKey, Collection cols) { DecoratedKey ROW = Util.dk(rowKey); System.err.println("Original:"); - ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(ROW, new QueryPath("Standard1"))); + ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(ROW, "Standard1")); System.err.println("Row key: " + rowKey + " Cols: " - + Iterables.transform(cf.getSortedColumns(), new Function() + + Iterables.transform(cf.getSortedColumns(), new Function() { - public String apply(IColumn arg0) + public String apply(Column arg0) { return new String(arg0.name().array()); } })); System.err.println("Filtered:"); - Iterable transformed = Iterables.transform(cols, new Function() + Iterable transformed = Iterables.transform(cols, new Function() { - public String apply(IColumn arg0) + public String apply(Column arg0) { return new String(arg0.name().array()); } diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java b/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java index 1b41958515..21fa727a02 100644 --- a/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java +++ b/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java @@ -29,7 +29,6 @@ import org.junit.Test; import org.apache.cassandra.io.sstable.ColumnStats; import org.apache.cassandra.io.util.DataOutputBuffer; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.net.MessagingService; import static org.apache.cassandra.Util.column; import static org.junit.Assert.assertEquals; @@ -126,12 +125,11 @@ public class ColumnFamilyTest extends SchemaLoader ByteBuffer val = ByteBufferUtil.bytes("sample value"); ByteBuffer val2 = ByteBufferUtil.bytes("x value "); - // exercise addColumn(QueryPath, ...) - cf_new.addColumn(QueryPath.column(ByteBufferUtil.bytes("col1")), val, 3); - cf_new.addColumn(QueryPath.column(ByteBufferUtil.bytes("col2")), val, 4); + cf_new.addColumn(ByteBufferUtil.bytes("col1"), val, 3); + cf_new.addColumn(ByteBufferUtil.bytes("col2"), val, 4); - cf_old.addColumn(QueryPath.column(ByteBufferUtil.bytes("col2")), val2, 1); - cf_old.addColumn(QueryPath.column(ByteBufferUtil.bytes("col3")), val2, 2); + cf_old.addColumn(ByteBufferUtil.bytes("col2"), val2, 1); + cf_old.addColumn(ByteBufferUtil.bytes("col3"), val2, 2); cf_result.addAll(cf_new, HeapAllocator.instance); cf_result.addAll(cf_old, HeapAllocator.instance); @@ -143,46 +141,16 @@ public class ColumnFamilyTest extends SchemaLoader // check that tombstone wins timestamp ties cf_result.addTombstone(ByteBufferUtil.bytes("col1"), 0, 3); assert cf_result.getColumn(ByteBufferUtil.bytes("col1")).isMarkedForDelete(); - cf_result.addColumn(QueryPath.column(ByteBufferUtil.bytes("col1")), val2, 3); + cf_result.addColumn(ByteBufferUtil.bytes("col1"), val2, 3); assert cf_result.getColumn(ByteBufferUtil.bytes("col1")).isMarkedForDelete(); // check that column value wins timestamp ties in absence of tombstone - cf_result.addColumn(QueryPath.column(ByteBufferUtil.bytes("col3")), val, 2); + cf_result.addColumn(ByteBufferUtil.bytes("col3"), val, 2); assert cf_result.getColumn(ByteBufferUtil.bytes("col3")).value().equals(val2); - cf_result.addColumn(QueryPath.column(ByteBufferUtil.bytes("col3")), ByteBufferUtil.bytes("z"), 2); + cf_result.addColumn(ByteBufferUtil.bytes("col3"), ByteBufferUtil.bytes("z"), 2); assert cf_result.getColumn(ByteBufferUtil.bytes("col3")).value().equals(ByteBufferUtil.bytes("z")); } - private void testSuperColumnResolution(ISortedColumns.Factory factory) - { - ColumnFamilyStore cfs = Table.open("Keyspace1").getColumnFamilyStore("Super1"); - ColumnFamily cf = ColumnFamily.create(cfs.metadata, factory); - ByteBuffer superColumnName = ByteBufferUtil.bytes("sc"); - ByteBuffer subColumnName = ByteBufferUtil.bytes(1L); - - Column first = new Column(subColumnName, ByteBufferUtil.bytes("one"), 1L); - Column second = new Column(subColumnName, ByteBufferUtil.bytes("two"), 2L); - - cf.addColumn(superColumnName, first); - - // resolve older + new - cf.addColumn(superColumnName, second); - assertEquals(second, cf.getColumn(superColumnName).getSubColumn(subColumnName)); - - // resolve new + older - cf.addColumn(superColumnName, first); - assertEquals(second, cf.getColumn(superColumnName).getSubColumn(subColumnName)); - } - - @Test - public void testSuperColumnResolution() - { - testSuperColumnResolution(TreeMapBackedSortedColumns.factory()); - testSuperColumnResolution(AtomicSortedColumns.factory()); - // array-sorted does allow conflict resolution IF it is the last column. Bit of an edge case. - testSuperColumnResolution(ArrayBackedSortedColumns.factory()); - } - @Test public void testColumnStatsRecordsRowDeletesCorrectly() throws IOException { diff --git a/test/unit/org/apache/cassandra/db/CommitLogTest.java b/test/unit/org/apache/cassandra/db/CommitLogTest.java index ef58aedd0f..ee2e66316d 100644 --- a/test/unit/org/apache/cassandra/db/CommitLogTest.java +++ b/test/unit/org/apache/cassandra/db/CommitLogTest.java @@ -33,7 +33,6 @@ import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.commitlog.CommitLog; import org.apache.cassandra.db.commitlog.CommitLogDescriptor; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.net.MessagingService; import static org.apache.cassandra.utils.ByteBufferUtil.bytes; @@ -101,7 +100,7 @@ public class CommitLogTest extends SchemaLoader CommitLog.instance.resetUnsafe(); // Roughly 32 MB mutation RowMutation rm = new RowMutation("Keyspace1", bytes("k")); - rm.add(new QueryPath("Standard1", null, bytes("c1")), ByteBuffer.allocate(DatabaseDescriptor.getCommitLogSegmentSize()/4), 0); + rm.add("Standard1", bytes("c1"), ByteBuffer.allocate(DatabaseDescriptor.getCommitLogSegmentSize()/4), 0); // Adding it 5 times CommitLog.instance.add(rm); @@ -112,7 +111,7 @@ public class CommitLogTest extends SchemaLoader // Adding new mutation on another CF RowMutation rm2 = new RowMutation("Keyspace1", bytes("k")); - rm2.add(new QueryPath("Standard2", null, bytes("c1")), ByteBuffer.allocate(4), 0); + rm2.add("Standard2", bytes("c1"), ByteBuffer.allocate(4), 0); CommitLog.instance.add(rm2); assert CommitLog.instance.activeSegments() == 2 : "Expecting 2 segments, got " + CommitLog.instance.activeSegments(); @@ -130,7 +129,7 @@ public class CommitLogTest extends SchemaLoader CommitLog.instance.resetUnsafe(); // Roughly 32 MB mutation RowMutation rm = new RowMutation("Keyspace1", bytes("k")); - rm.add(new QueryPath("Standard1", null, bytes("c1")), ByteBuffer.allocate(DatabaseDescriptor.getCommitLogSegmentSize()/4), 0); + rm.add("Standard1", bytes("c1"), ByteBuffer.allocate(DatabaseDescriptor.getCommitLogSegmentSize()/4), 0); // Adding it twice (won't change segment) CommitLog.instance.add(rm); @@ -146,7 +145,7 @@ public class CommitLogTest extends SchemaLoader // Adding new mutation on another CF, large enough (including CL entry overhead) that a new segment is created RowMutation rm2 = new RowMutation("Keyspace1", bytes("k")); - rm2.add(new QueryPath("Standard2", null, bytes("c1")), ByteBuffer.allocate(DatabaseDescriptor.getCommitLogSegmentSize()/2), 0); + rm2.add("Standard2", bytes("c1"), ByteBuffer.allocate(DatabaseDescriptor.getCommitLogSegmentSize()/2), 0); CommitLog.instance.add(rm2); // also forces a new segment, since each entry-with-overhead is just over half the CL size CommitLog.instance.add(rm2); @@ -171,7 +170,7 @@ public class CommitLogTest extends SchemaLoader CommitLog.instance.resetUnsafe(); RowMutation rm = new RowMutation("Keyspace1", bytes("k")); - rm.add(new QueryPath("Standard1", null, bytes("c1")), ByteBuffer.allocate((DatabaseDescriptor.getCommitLogSegmentSize()) - 83), 0); + rm.add("Standard1", bytes("c1"), ByteBuffer.allocate((DatabaseDescriptor.getCommitLogSegmentSize()) - 83), 0); CommitLog.instance.add(rm); } diff --git a/test/unit/org/apache/cassandra/db/CounterColumnTest.java b/test/unit/org/apache/cassandra/db/CounterColumnTest.java index d627139620..c1926237b9 100644 --- a/test/unit/org/apache/cassandra/db/CounterColumnTest.java +++ b/test/unit/org/apache/cassandra/db/CounterColumnTest.java @@ -33,7 +33,6 @@ import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.db.context.CounterContext; import static org.apache.cassandra.db.context.CounterContext.ContextState; -import org.apache.cassandra.io.IColumnSerializer; import org.apache.cassandra.io.util.DataOutputBuffer; import org.apache.cassandra.utils.*; @@ -74,9 +73,9 @@ public class CounterColumnTest extends SchemaLoader @Test public void testReconcile() throws UnknownHostException { - IColumn left; - IColumn right; - IColumn reconciled; + Column left; + Column right; + Column reconciled; ByteBuffer context; @@ -286,7 +285,7 @@ public class CounterColumnTest extends SchemaLoader assert original.equals(deserialized); bufIn = new ByteArrayInputStream(serialized, 0, serialized.length); - CounterColumn deserializedOnRemote = (CounterColumn)Column.serializer().deserialize(new DataInputStream(bufIn), IColumnSerializer.Flag.FROM_REMOTE); + CounterColumn deserializedOnRemote = (CounterColumn)Column.serializer().deserialize(new DataInputStream(bufIn), ColumnSerializer.Flag.FROM_REMOTE); assert deserializedOnRemote.name().equals(original.name()); assert deserializedOnRemote.total() == original.total(); assert deserializedOnRemote.value().equals(cc.clearAllDelta(original.value())); diff --git a/test/unit/org/apache/cassandra/db/CounterMutationTest.java b/test/unit/org/apache/cassandra/db/CounterMutationTest.java index 10fafa5294..e65fd857cc 100644 --- a/test/unit/org/apache/cassandra/db/CounterMutationTest.java +++ b/test/unit/org/apache/cassandra/db/CounterMutationTest.java @@ -44,7 +44,7 @@ public class CounterMutationTest extends SchemaLoader CounterId id1 = CounterId.getLocalId(); rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1")); - rm.addCounter(new QueryPath("Counter1", null, ByteBufferUtil.bytes("Column1")), 3); + rm.addCounter("Counter1", ByteBufferUtil.bytes("Column1"), 3); cm = new CounterMutation(rm, ConsistencyLevel.ONE); cm.apply(); @@ -52,7 +52,7 @@ public class CounterMutationTest extends SchemaLoader CounterId id2 = CounterId.getLocalId(); rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1")); - rm.addCounter(new QueryPath("Counter1", null, ByteBufferUtil.bytes("Column1")), 4); + rm.addCounter("Counter1", ByteBufferUtil.bytes("Column1"), 4); cm = new CounterMutation(rm, ConsistencyLevel.ONE); cm.apply(); @@ -60,8 +60,8 @@ public class CounterMutationTest extends SchemaLoader CounterId id3 = CounterId.getLocalId(); rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1")); - rm.addCounter(new QueryPath("Counter1", null, ByteBufferUtil.bytes("Column1")), 5); - rm.addCounter(new QueryPath("Counter1", null, ByteBufferUtil.bytes("Column2")), 1); + rm.addCounter("Counter1", ByteBufferUtil.bytes("Column1"), 5); + rm.addCounter("Counter1", ByteBufferUtil.bytes("Column2"), 1); cm = new CounterMutation(rm, ConsistencyLevel.ONE); cm.apply(); @@ -71,7 +71,7 @@ public class CounterMutationTest extends SchemaLoader // First merges old shards CounterColumn.mergeAndRemoveOldShards(dk, cf, Integer.MIN_VALUE, Integer.MAX_VALUE, false); long now = System.currentTimeMillis(); - IColumn c = cf.getColumn(ByteBufferUtil.bytes("Column1")); + Column c = cf.getColumn(ByteBufferUtil.bytes("Column1")); assert c != null; assert c instanceof CounterColumn; assert ((CounterColumn)c).total() == 12L; @@ -100,40 +100,6 @@ public class CounterMutationTest extends SchemaLoader assert s.getCount() == 12L; } - @Test - public void testMutateSuperColumns() throws IOException - { - RowMutation rm; - CounterMutation cm; - - rm = new RowMutation("Keyspace1", bytes("key1")); - rm.addCounter(new QueryPath("SuperCounter1", bytes("sc1"), bytes("Column1")), 1); - rm.addCounter(new QueryPath("SuperCounter1", bytes("sc2"), bytes("Column1")), 1); - cm = new CounterMutation(rm, ConsistencyLevel.ONE); - cm.apply(); - - rm = new RowMutation("Keyspace1", bytes("key1")); - rm.addCounter(new QueryPath("SuperCounter1", bytes("sc1"), bytes("Column2")), 1); - rm.addCounter(new QueryPath("SuperCounter1", bytes("sc2"), bytes("Column2")), 1); - cm = new CounterMutation(rm, ConsistencyLevel.ONE); - cm.apply(); - - RowMutation reprm = cm.makeReplicationMutation(); - ColumnFamily cf = reprm.getColumnFamilies().iterator().next(); - - assert cf.getColumnCount() == 2; - - IColumn sc1 = cf.getColumn(bytes("sc1")); - assert sc1 != null && sc1 instanceof SuperColumn; - assert sc1.getSubColumns().size() == 1; - assert sc1.getSubColumn(bytes("Column2")) != null; - - IColumn sc2 = cf.getColumn(bytes("sc2")); - assert sc2 != null && sc2 instanceof SuperColumn; - assert sc2.getSubColumns().size() == 1; - assert sc2.getSubColumn(bytes("Column2")) != null; - } - @Test public void testGetOldShardFromSystemTable() throws IOException { diff --git a/test/unit/org/apache/cassandra/db/HintedHandOffTest.java b/test/unit/org/apache/cassandra/db/HintedHandOffTest.java index 0b042505dc..7fdfd3f82d 100644 --- a/test/unit/org/apache/cassandra/db/HintedHandOffTest.java +++ b/test/unit/org/apache/cassandra/db/HintedHandOffTest.java @@ -29,7 +29,6 @@ import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.db.compaction.CompactionManager; import org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; @@ -56,11 +55,7 @@ public class HintedHandOffTest extends SchemaLoader // insert 1 hint RowMutation rm = new RowMutation(TABLE4, ByteBufferUtil.bytes(1)); - rm.add(new QueryPath(STANDARD1_CF, - null, - ByteBufferUtil.bytes(String.valueOf(COLUMN1))), - ByteBufferUtil.EMPTY_BYTE_BUFFER, - System.currentTimeMillis()); + rm.add(STANDARD1_CF, ByteBufferUtil.bytes(String.valueOf(COLUMN1)), ByteBufferUtil.EMPTY_BYTE_BUFFER, System.currentTimeMillis()); RowMutation.hintFor(rm, UUID.randomUUID()).apply(); diff --git a/test/unit/org/apache/cassandra/db/KeyCacheTest.java b/test/unit/org/apache/cassandra/db/KeyCacheTest.java index 93f1fea99a..cc442f285f 100644 --- a/test/unit/org/apache/cassandra/db/KeyCacheTest.java +++ b/test/unit/org/apache/cassandra/db/KeyCacheTest.java @@ -35,7 +35,6 @@ import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.compaction.CompactionManager; import org.apache.cassandra.utils.ByteBufferUtil; import static junit.framework.Assert.assertEquals; @@ -106,10 +105,10 @@ public class KeyCacheTest extends SchemaLoader // inserts rm = new RowMutation(TABLE1, key1.key); - rm.add(new QueryPath(COLUMN_FAMILY1, null, ByteBufferUtil.bytes("1")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(COLUMN_FAMILY1, ByteBufferUtil.bytes("1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); rm.apply(); rm = new RowMutation(TABLE1, key2.key); - rm.add(new QueryPath(COLUMN_FAMILY1, null, ByteBufferUtil.bytes("2")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(COLUMN_FAMILY1, ByteBufferUtil.bytes("2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); rm.apply(); // to make sure we have SSTable @@ -117,14 +116,14 @@ public class KeyCacheTest extends SchemaLoader // reads to cache key position cfs.getColumnFamily(QueryFilter.getSliceFilter(key1, - new QueryPath(new ColumnParent(COLUMN_FAMILY1)), + COLUMN_FAMILY1, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 10)); cfs.getColumnFamily(QueryFilter.getSliceFilter(key2, - new QueryPath(new ColumnParent(COLUMN_FAMILY1)), + COLUMN_FAMILY1, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, @@ -140,14 +139,14 @@ public class KeyCacheTest extends SchemaLoader // re-read same keys to verify that key cache didn't grow further cfs.getColumnFamily(QueryFilter.getSliceFilter(key1, - new QueryPath(new ColumnParent(COLUMN_FAMILY1)), + COLUMN_FAMILY1, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 10)); cfs.getColumnFamily(QueryFilter.getSliceFilter(key2, - new QueryPath(new ColumnParent(COLUMN_FAMILY1)), + COLUMN_FAMILY1, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, diff --git a/test/unit/org/apache/cassandra/db/KeyCollisionTest.java b/test/unit/org/apache/cassandra/db/KeyCollisionTest.java index e152a5d67d..ab792d579e 100644 --- a/test/unit/org/apache/cassandra/db/KeyCollisionTest.java +++ b/test/unit/org/apache/cassandra/db/KeyCollisionTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.db.columniterator.IdentityQueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.dht.*; import org.apache.cassandra.config.*; import org.apache.cassandra.service.StorageService; @@ -70,7 +69,7 @@ public class KeyCollisionTest extends SchemaLoader insert("key1", "key2", "key3"); // token = 4 insert("longKey1", "longKey2"); // token = 8 - List rows = cfs.getRangeSlice(null, new Bounds(dk("k2"), dk("key2")), 10000, new IdentityQueryFilter(), null); + List rows = cfs.getRangeSlice(new Bounds(dk("k2"), dk("key2")), 10000, new IdentityQueryFilter(), null); assert rows.size() == 4 : "Expecting 4 keys, got " + rows.size(); assert rows.get(0).key.key.equals(ByteBufferUtil.bytes("k2")); assert rows.get(1).key.key.equals(ByteBufferUtil.bytes("k3")); @@ -88,7 +87,7 @@ public class KeyCollisionTest extends SchemaLoader { RowMutation rm; rm = new RowMutation(KEYSPACE, ByteBufferUtil.bytes(key)); - rm.add(new QueryPath(CF, null, ByteBufferUtil.bytes("column")), ByteBufferUtil.bytes("asdf"), 0); + rm.add(CF, ByteBufferUtil.bytes("column"), ByteBufferUtil.bytes("asdf"), 0); rm.apply(); } diff --git a/test/unit/org/apache/cassandra/db/NameSortTest.java b/test/unit/org/apache/cassandra/db/NameSortTest.java index 668a2e2127..97a4a8a5bc 100644 --- a/test/unit/org/apache/cassandra/db/NameSortTest.java +++ b/test/unit/org/apache/cassandra/db/NameSortTest.java @@ -27,7 +27,6 @@ import java.util.concurrent.ExecutionException; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.utils.ByteBufferUtil; import org.junit.Test; @@ -69,7 +68,7 @@ public class NameSortTest extends SchemaLoader { ByteBuffer bytes = j % 2 == 0 ? ByteBufferUtil.bytes("a") : ByteBufferUtil.bytes("b"); rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(("Column-" + j))), bytes, j); + rm.add("Standard1", ByteBufferUtil.bytes(("Column-" + j)), bytes, j); rm.applyUnsafe(); } @@ -101,32 +100,14 @@ public class NameSortTest extends SchemaLoader ColumnFamily cf; cf = Util.getColumnFamily(table, key, "Standard1"); - Collection columns = cf.getSortedColumns(); - for (IColumn column : columns) + Collection columns = cf.getSortedColumns(); + for (Column column : columns) { String name = ByteBufferUtil.string(column.name()); int j = Integer.valueOf(name.substring(name.length() - 1)); byte[] bytes = j % 2 == 0 ? "a".getBytes() : "b".getBytes(); assertEquals(new String(bytes), ByteBufferUtil.string(column.value())); } - - cf = Util.getColumnFamily(table, key, "Super1"); - assert cf != null : "key " + key + " is missing!"; - Collection superColumns = cf.getSortedColumns(); - assert superColumns.size() == 8 : cf; - for (IColumn superColumn : superColumns) - { - int j = Integer.valueOf(ByteBufferUtil.string(superColumn.name()).split("-")[1]); - Collection subColumns = superColumn.getSubColumns(); - assert subColumns.size() == 4; - for (IColumn subColumn : subColumns) - { - long k = subColumn.name().getLong(subColumn.name().position()); - byte[] bytes = (j + k) % 2 == 0 ? "a".getBytes() : "b".getBytes(); - assertEquals(new String(bytes), ByteBufferUtil.string(subColumn.value())); - } - } } } - } diff --git a/test/unit/org/apache/cassandra/db/RangeTombstoneTest.java b/test/unit/org/apache/cassandra/db/RangeTombstoneTest.java index 1bc846b2b6..ae147d4458 100644 --- a/test/unit/org/apache/cassandra/db/RangeTombstoneTest.java +++ b/test/unit/org/apache/cassandra/db/RangeTombstoneTest.java @@ -70,8 +70,6 @@ public class RangeTombstoneTest extends SchemaLoader rm.apply(); // We don't flush to test with both a range tomsbtone in memtable and in sstable - QueryPath path = new QueryPath(CFNAME); - // Queries by name int[] live = new int[]{ 4, 9, 11, 17, 28 }; int[] dead = new int[]{ 12, 19, 21, 24, 27 }; @@ -80,7 +78,7 @@ public class RangeTombstoneTest extends SchemaLoader columns.add(b(i)); for (int i : dead) columns.add(b(i)); - cf = cfs.getColumnFamily(QueryFilter.getNamesFilter(dk(key), path, columns)); + cf = cfs.getColumnFamily(QueryFilter.getNamesFilter(dk(key), CFNAME, columns)); for (int i : live) assert isLive(cf, cf.getColumn(b(i))) : "Column " + i + " should be live"; @@ -88,7 +86,7 @@ public class RangeTombstoneTest extends SchemaLoader assert !isLive(cf, cf.getColumn(b(i))) : "Column " + i + " shouldn't be live"; // Queries by slices - cf = cfs.getColumnFamily(QueryFilter.getSliceFilter(dk(key), path, b(7), b(30), false, Integer.MAX_VALUE)); + cf = cfs.getColumnFamily(QueryFilter.getSliceFilter(dk(key), CFNAME, b(7), b(30), false, Integer.MAX_VALUE)); for (int i : new int[]{ 7, 8, 9, 11, 13, 15, 17, 28, 29, 30 }) assert isLive(cf, cf.getColumn(b(i))) : "Column " + i + " should be live"; @@ -132,8 +130,7 @@ public class RangeTombstoneTest extends SchemaLoader rm.apply(); cfs.forceBlockingFlush(); - QueryPath path = new QueryPath(CFNAME); - cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(dk(key), path)); + cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(dk(key), CFNAME)); for (int i = 0; i < 5; i++) assert isLive(cf, cf.getColumn(b(i))) : "Column " + i + " should be live"; @@ -144,7 +141,7 @@ public class RangeTombstoneTest extends SchemaLoader // Compact everything and re-test CompactionManager.instance.performMaximal(cfs); - cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(dk(key), path)); + cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(dk(key), CFNAME)); for (int i = 0; i < 5; i++) assert isLive(cf, cf.getColumn(b(i))) : "Column " + i + " should be live"; @@ -154,7 +151,7 @@ public class RangeTombstoneTest extends SchemaLoader assert !isLive(cf, cf.getColumn(b(i))) : "Column " + i + " shouldn't be live"; } - private static boolean isLive(ColumnFamily cf, IColumn c) + private static boolean isLive(ColumnFamily cf, Column c) { return c != null && !c.isMarkedForDelete() && !cf.deletionInfo().isDeleted(c); } @@ -170,7 +167,7 @@ public class RangeTombstoneTest extends SchemaLoader private static void add(RowMutation rm, int value, long timestamp) { - rm.add(new QueryPath(CFNAME, null, b(value)), b(value), timestamp); + rm.add(CFNAME, b(value), b(value), timestamp); } private static void delete(ColumnFamily cf, int from, int to, long timestamp) diff --git a/test/unit/org/apache/cassandra/db/ReadMessageTest.java b/test/unit/org/apache/cassandra/db/ReadMessageTest.java index 4b56b96793..23aea675fa 100644 --- a/test/unit/org/apache/cassandra/db/ReadMessageTest.java +++ b/test/unit/org/apache/cassandra/db/ReadMessageTest.java @@ -24,13 +24,16 @@ import java.io.*; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; +import java.util.SortedSet; +import java.util.TreeSet; import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.config.DatabaseDescriptor; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.filter.NamesQueryFilter; +import org.apache.cassandra.db.filter.SliceQueryFilter; import org.apache.cassandra.io.util.DataOutputBuffer; import org.apache.cassandra.net.MessagingService; import org.apache.cassandra.utils.ByteBufferUtil; @@ -41,30 +44,30 @@ public class ReadMessageTest extends SchemaLoader @Test public void testMakeReadMessage() throws IOException { - ArrayList colList = new ArrayList(); + SortedSet colList = new TreeSet(); colList.add(ByteBufferUtil.bytes("col1")); colList.add(ByteBufferUtil.bytes("col2")); ReadCommand rm, rm2; DecoratedKey dk = Util.dk("row1"); - rm = new SliceByNamesReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), colList); + rm = new SliceByNamesReadCommand("Keyspace1", dk.key, "Standard1", new NamesQueryFilter(colList)); rm2 = serializeAndDeserializeReadMessage(rm); assert rm2.toString().equals(rm.toString()); - rm = new SliceFromReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2); + rm = new SliceFromReadCommand("Keyspace1", dk.key, "Standard1", new SliceQueryFilter(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2)); rm2 = serializeAndDeserializeReadMessage(rm); assert rm2.toString().equals(rm.toString()); - rm = new SliceFromReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), ByteBufferUtil.bytes("a"), ByteBufferUtil.bytes("z"), true, 5); + rm = new SliceFromReadCommand("Keyspace1", dk.key, "Standard1", new SliceQueryFilter(ByteBufferUtil.bytes("a"), ByteBufferUtil.bytes("z"), true, 5)); rm2 = serializeAndDeserializeReadMessage(rm); assertEquals(rm2.toString(), rm.toString()); - rm = new SliceFromReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2); + rm = new SliceFromReadCommand("Keyspace1", dk.key, "Standard1", new SliceQueryFilter(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2)); rm2 = serializeAndDeserializeReadMessage(rm); assert rm2.toString().equals(rm.toString()); - rm = new SliceFromReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), ByteBufferUtil.bytes("a"), ByteBufferUtil.bytes("z"), true, 5); + rm = new SliceFromReadCommand("Keyspace1", dk.key, "Standard1", new SliceQueryFilter(ByteBufferUtil.bytes("a"), ByteBufferUtil.bytes("z"), true, 5)); rm2 = serializeAndDeserializeReadMessage(rm); assertEquals(rm2.toString(), rm.toString()); } @@ -89,12 +92,12 @@ public class ReadMessageTest extends SchemaLoader // add data rm = new RowMutation("Keyspace1", dk.key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("abcd"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("abcd"), 0); rm.apply(); - ReadCommand command = new SliceByNamesReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), Arrays.asList(ByteBufferUtil.bytes("Column1"))); + ReadCommand command = new SliceByNamesReadCommand("Keyspace1", dk.key, "Standard1", new NamesQueryFilter(ByteBufferUtil.bytes("Column1"))); Row row = command.getRow(table); - IColumn col = row.cf.getColumn(ByteBufferUtil.bytes("Column1")); + Column col = row.cf.getColumn(ByteBufferUtil.bytes("Column1")); assertEquals(col.value(), ByteBuffer.wrap("abcd".getBytes())); } @@ -103,11 +106,11 @@ public class ReadMessageTest extends SchemaLoader { RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("row")); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("commit1")), ByteBufferUtil.bytes("abcd"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("commit1"), ByteBufferUtil.bytes("abcd"), 0); rm.apply(); rm = new RowMutation("NoCommitlogSpace", ByteBufferUtil.bytes("row")); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("commit2")), ByteBufferUtil.bytes("abcd"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("commit2"), ByteBufferUtil.bytes("abcd"), 0); rm.apply(); boolean commitLogMessageFound = false; diff --git a/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java b/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java index 68c0b37067..96889b879d 100644 --- a/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java +++ b/test/unit/org/apache/cassandra/db/RecoveryManagerTest.java @@ -96,7 +96,7 @@ public class RecoveryManagerTest extends SchemaLoader cf = Util.getColumnFamily(table1, dk, "Counter1"); assert cf.getColumnCount() == 1; - IColumn c = cf.getColumn(ByteBufferUtil.bytes("col")); + Column c = cf.getColumn(ByteBufferUtil.bytes("col")); assert c != null; assert ((CounterColumn)c).total() == 10L; diff --git a/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java b/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java index 843bbef402..6776e65cb4 100644 --- a/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java +++ b/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java @@ -29,7 +29,6 @@ import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.db.commitlog.CommitLog; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.junit.Test; import org.apache.cassandra.utils.ByteBufferUtil; @@ -66,7 +65,7 @@ public class RecoveryManagerTruncateTest extends SchemaLoader assertNull(getFromTable(table, "Standard1", "keymulti", "col1")); } - private IColumn getFromTable(Table table, String cfName, String keyName, String columnName) + private Column getFromTable(Table table, String cfName, String keyName, String columnName) { ColumnFamily cf; ColumnFamilyStore cfStore = table.getColumnFamilyStore(cfName); @@ -75,7 +74,7 @@ public class RecoveryManagerTruncateTest extends SchemaLoader return null; } cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter( - Util.dk(keyName), new QueryPath(cfName), ByteBufferUtil.bytes(columnName))); + Util.dk(keyName), cfName, ByteBufferUtil.bytes(columnName))); if (cf == null) { return null; diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java index 15369d654d..fb42361799 100644 --- a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java +++ b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java @@ -25,7 +25,6 @@ import org.junit.Test; import static junit.framework.Assert.assertNull; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; @@ -44,15 +43,15 @@ public class RemoveColumnFamilyTest extends SchemaLoader // add data rm = new RowMutation("Keyspace1", dk.key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdf"), 0); rm.apply(); // remove rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Standard1"), 1); + rm.delete("Standard1", 1); rm.apply(); - ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")))); + ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, "Standard1")); assert retrieved.isMarkedForDelete(); assertNull(retrieved.getColumn(ByteBufferUtil.bytes("Column1"))); assertNull(Util.cloneAndRemoveDeleted(retrieved, Integer.MAX_VALUE)); diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java index f724cb5233..b32b3a9ea4 100644 --- a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java +++ b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java @@ -25,7 +25,6 @@ import org.junit.Test; import static junit.framework.Assert.assertNull; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; @@ -44,17 +43,17 @@ public class RemoveColumnFamilyWithFlush1Test extends SchemaLoader // add data rm = new RowMutation("Keyspace1", dk.key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column2")), ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column2"), ByteBufferUtil.bytes("asdf"), 0); rm.apply(); store.forceBlockingFlush(); // remove rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Standard1"), 1); + rm.delete("Standard1", 1); rm.apply(); - ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Standard1"))); + ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, "Standard1")); assert retrieved.isMarkedForDelete(); assertNull(retrieved.getColumn(ByteBufferUtil.bytes("Column1"))); assertNull(Util.cloneAndRemoveDeleted(retrieved, Integer.MAX_VALUE)); diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java index 49585dc1f4..d59d09b88f 100644 --- a/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java +++ b/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java @@ -25,7 +25,6 @@ import org.junit.Test; import static junit.framework.Assert.assertNull; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; @@ -44,15 +43,15 @@ public class RemoveColumnFamilyWithFlush2Test extends SchemaLoader // add data rm = new RowMutation("Keyspace1", dk.key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdf"), 0); rm.apply(); // remove rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Standard1"), 1); + rm.delete("Standard1", 1); rm.apply(); store.forceBlockingFlush(); - ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")))); + ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, "Standard1")); assert retrieved.isMarkedForDelete(); assertNull(retrieved.getColumn(ByteBufferUtil.bytes("Column1"))); assertNull(Util.cloneAndRemoveDeleted(retrieved, Integer.MAX_VALUE)); diff --git a/test/unit/org/apache/cassandra/db/RemoveColumnTest.java b/test/unit/org/apache/cassandra/db/RemoveColumnTest.java index 06ce57d2d9..4c3f3aab16 100644 --- a/test/unit/org/apache/cassandra/db/RemoveColumnTest.java +++ b/test/unit/org/apache/cassandra/db/RemoveColumnTest.java @@ -27,7 +27,6 @@ import static junit.framework.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; @@ -46,19 +45,19 @@ public class RemoveColumnTest extends SchemaLoader // add data rm = new RowMutation("Keyspace1", dk.key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdf"), 0); rm.apply(); store.forceBlockingFlush(); // remove rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), 1); + rm.delete("Standard1", ByteBufferUtil.bytes("Column1"), 1); rm.apply(); - ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Standard1"), ByteBufferUtil.bytes("Column1"))); + ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getNamesFilter(dk, "Standard1", ByteBufferUtil.bytes("Column1"))); assert retrieved.getColumn(ByteBufferUtil.bytes("Column1")).isMarkedForDelete(); assertNull(Util.cloneAndRemoveDeleted(retrieved, Integer.MAX_VALUE)); - assertNull(Util.cloneAndRemoveDeleted(store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Standard1"))), Integer.MAX_VALUE)); + assertNull(Util.cloneAndRemoveDeleted(store.getColumnFamily(QueryFilter.getIdentityFilter(dk, "Standard1")), Integer.MAX_VALUE)); } @Test diff --git a/test/unit/org/apache/cassandra/db/RemoveSubColumnTest.java b/test/unit/org/apache/cassandra/db/RemoveSubColumnTest.java index 70cbaa2b04..47fbe80b31 100644 --- a/test/unit/org/apache/cassandra/db/RemoveSubColumnTest.java +++ b/test/unit/org/apache/cassandra/db/RemoveSubColumnTest.java @@ -18,6 +18,7 @@ */ package org.apache.cassandra.db; +import java.nio.ByteBuffer; import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -25,7 +26,7 @@ import org.junit.Test; import static junit.framework.Assert.assertNull; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.marshal.CompositeType; import static org.apache.cassandra.Util.getBytes; import org.apache.cassandra.Util; import org.apache.cassandra.SchemaLoader; @@ -48,13 +49,14 @@ public class RemoveSubColumnTest extends SchemaLoader rm.apply(); store.forceBlockingFlush(); + ByteBuffer cname = CompositeType.build(ByteBufferUtil.bytes("SC1"), getBytes(1L)); // remove rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Super1", ByteBufferUtil.bytes("SC1"), getBytes(1L)), 1); + rm.delete("Super1", cname, 1); rm.apply(); - ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Super1", ByteBufferUtil.bytes("SC1")))); - assert retrieved.getColumn(ByteBufferUtil.bytes("SC1")).getSubColumn(getBytes(1L)).isMarkedForDelete(); + ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, "Super1")); + assert retrieved.getColumn(cname).isMarkedForDelete(); assertNull(Util.cloneAndRemoveDeleted(retrieved, Integer.MAX_VALUE)); } @@ -73,8 +75,10 @@ public class RemoveSubColumnTest extends SchemaLoader store.forceBlockingFlush(); // remove the SC + ByteBuffer scName = ByteBufferUtil.bytes("SC1"); + ByteBuffer cname = CompositeType.build(scName, getBytes(1L)); rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Super1", ByteBufferUtil.bytes("SC1"), null), 1); + rm.deleteRange("Super1", SuperColumns.startOf(scName), SuperColumns.endOf(scName), 1); rm.apply(); // Mark current time and make sure the next insert happens at least @@ -84,11 +88,11 @@ public class RemoveSubColumnTest extends SchemaLoader // remove the column itself rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Super1", ByteBufferUtil.bytes("SC1"), getBytes(1)), 2); + rm.delete("Super1", cname, 2); rm.apply(); - ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Super1", ByteBufferUtil.bytes("SC1"))), gcbefore); - assert retrieved.getColumn(ByteBufferUtil.bytes("SC1")).getSubColumn(getBytes(1)).isMarkedForDelete(); + ColumnFamily retrieved = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, "Super1"), gcbefore); + assert retrieved.getColumn(cname).isMarkedForDelete(); assertNull(Util.cloneAndRemoveDeleted(retrieved, Integer.MAX_VALUE)); } } diff --git a/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java b/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java deleted file mode 100644 index b15b8c62b3..0000000000 --- a/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java +++ /dev/null @@ -1,200 +0,0 @@ -/* -* 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.db; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.Collection; - -import org.junit.Test; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertEquals; - -import org.apache.cassandra.Util; -import org.apache.cassandra.db.compaction.CompactionManager; -import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; -import static org.apache.cassandra.Util.addMutation; -import static org.apache.cassandra.Util.getBytes; - -import org.apache.cassandra.SchemaLoader; -import static junit.framework.Assert.assertNotNull; -import org.apache.cassandra.utils.ByteBufferUtil; - - -public class RemoveSuperColumnTest extends SchemaLoader -{ - @Test - public void testRemoveSuperColumn() throws IOException, ExecutionException, InterruptedException - { - ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super1"); - RowMutation rm; - DecoratedKey dk = Util.dk("key1"); - - // add data - rm = new RowMutation("Keyspace1", dk.key); - addMutation(rm, "Super1", "SC1", 1, "val1", 0); - rm.apply(); - store.forceBlockingFlush(); - - // remove - rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Super1", ByteBufferUtil.bytes("SC1")), 1); - rm.apply(); - - validateRemoveTwoSources(dk); - - store.forceBlockingFlush(); - validateRemoveTwoSources(dk); - - CompactionManager.instance.performMaximal(store); - assertEquals(1, store.getSSTables().size()); - validateRemoveCompacted(dk); - } - - @Test - public void testRemoveDeletedSubColumn() throws IOException, ExecutionException, InterruptedException - { - ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super3"); - RowMutation rm; - DecoratedKey dk = Util.dk("key1"); - - // add data - rm = new RowMutation("Keyspace1", dk.key); - addMutation(rm, "Super3", "SC1", 1, "val1", 0); - addMutation(rm, "Super3", "SC1", 2, "val1", 0); - rm.apply(); - store.forceBlockingFlush(); - - // remove - rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Super3", ByteBufferUtil.bytes("SC1"), Util.getBytes(1L)), 1); - rm.apply(); - - validateRemoveSubColumn(dk); - - store.forceBlockingFlush(); - validateRemoveSubColumn(dk); - } - - private void validateRemoveSubColumn(DecoratedKey dk) throws IOException - { - ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super3"); - ColumnFamily cf = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Super3", ByteBufferUtil.bytes("SC1")), Util.getBytes(1L))); - assertNull(Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE)); - cf = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Super3", ByteBufferUtil.bytes("SC1")), Util.getBytes(2L))); - assertNotNull(Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE)); - } - - private void validateRemoveTwoSources(DecoratedKey dk) throws IOException - { - ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super1"); - ColumnFamily cf = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Super1"), ByteBufferUtil.bytes("SC1"))); - assert cf.getSortedColumns().iterator().next().getMarkedForDeleteAt() == 1 : cf; - assert cf.getSortedColumns().iterator().next().getSubColumns().size() == 0 : cf; - assertNull(Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE)); - cf = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Super1"), ByteBufferUtil.bytes("SC1"))); - assertNull(Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE)); - cf = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Super1"))); - assertNull(Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE)); - assertNull(Util.cloneAndRemoveDeleted(store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Super1"))), Integer.MAX_VALUE)); - } - - private void validateRemoveCompacted(DecoratedKey dk) throws IOException - { - ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super1"); - ColumnFamily resolved = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Super1"), ByteBufferUtil.bytes("SC1"))); - assert resolved.getSortedColumns().iterator().next().getMarkedForDeleteAt() == 1; - Collection subColumns = resolved.getSortedColumns().iterator().next().getSubColumns(); - assert subColumns.size() == 0; - } - - @Test - public void testRemoveSuperColumnWithNewData() throws IOException, ExecutionException, InterruptedException - { - ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super2"); - RowMutation rm; - DecoratedKey dk = Util.dk("key1"); - - // add data - rm = new RowMutation("Keyspace1", dk.key); - addMutation(rm, "Super2", "SC1", 1, "val1", 0); - rm.apply(); - store.forceBlockingFlush(); - - // remove - rm = new RowMutation("Keyspace1", dk.key); - rm.delete(new QueryPath("Super2", ByteBufferUtil.bytes("SC1")), 1); - rm.apply(); - - // new data - rm = new RowMutation("Keyspace1", dk.key); - addMutation(rm, "Super2", "SC1", 2, "val2", 2); - rm.apply(); - - validateRemoveWithNewData(dk); - - store.forceBlockingFlush(); - validateRemoveWithNewData(dk); - - CompactionManager.instance.performMaximal(store); - assertEquals(1, store.getSSTables().size()); - validateRemoveWithNewData(dk); - } - - private void validateRemoveWithNewData(DecoratedKey dk) throws IOException - { - ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super2"); - ColumnFamily cf = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Super2", ByteBufferUtil.bytes("SC1")), getBytes(2L))); - Collection subColumns = cf.getSortedColumns().iterator().next().getSubColumns(); - assert subColumns.size() == 1; - assert subColumns.iterator().next().timestamp() == 2; - } - - @Test - public void testRemoveSuperColumnResurrection() throws IOException, ExecutionException, InterruptedException - { - ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super2"); - RowMutation rm; - DecoratedKey key = Util.dk("keyC"); - - // add data - rm = new RowMutation("Keyspace1", key.key); - addMutation(rm, "Super2", "SC1", 1, "val1", 0); - rm.apply(); - - // remove - rm = new RowMutation("Keyspace1", key.key); - rm.delete(new QueryPath("Super2", ByteBufferUtil.bytes("SC1")), 1); - rm.apply(); - assertNull(Util.cloneAndRemoveDeleted(store.getColumnFamily(QueryFilter.getNamesFilter(key, new QueryPath("Super2"), ByteBufferUtil.bytes("SC1"))), Integer.MAX_VALUE)); - - // resurrect - rm = new RowMutation("Keyspace1", key.key); - addMutation(rm, "Super2", "SC1", 1, "val2", 2); - rm.apply(); - - // validate - ColumnFamily cf = store.getColumnFamily(QueryFilter.getNamesFilter(key, new QueryPath("Super2"), ByteBufferUtil.bytes("SC1"))); - cf = Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE); - Collection subColumns = cf.getSortedColumns().iterator().next().getSubColumns(); - assert subColumns.size() == 1; - assert subColumns.iterator().next().timestamp() == 2; - } -} diff --git a/test/unit/org/apache/cassandra/db/RowCacheTest.java b/test/unit/org/apache/cassandra/db/RowCacheTest.java index 99b8cbc976..c75cbc73a9 100644 --- a/test/unit/org/apache/cassandra/db/RowCacheTest.java +++ b/test/unit/org/apache/cassandra/db/RowCacheTest.java @@ -28,7 +28,6 @@ import org.apache.cassandra.Util; import org.apache.cassandra.db.compaction.CompactionManager; import org.apache.cassandra.service.CacheService; import org.apache.cassandra.utils.ByteBufferUtil; -import org.apache.cassandra.db.filter.QueryPath; public class RowCacheTest extends SchemaLoader { @@ -62,17 +61,16 @@ public class RowCacheTest extends SchemaLoader for (int i = 0; i < 100; i++) { DecoratedKey key = Util.dk("key" + i); - QueryPath path = new QueryPath(COLUMN_FAMILY, null, ByteBufferUtil.bytes("col" + i)); - cachedStore.getColumnFamily(key, path, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); + cachedStore.getColumnFamily(key, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); assert CacheService.instance.rowCache.size() == i + 1; assert cachedStore.containsCachedRow(key); // current key should be stored in the cache // checking if column is read correctly after cache - ColumnFamily cf = cachedStore.getColumnFamily(key, path, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); - Collection columns = cf.getSortedColumns(); + ColumnFamily cf = cachedStore.getColumnFamily(key, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); + Collection columns = cf.getSortedColumns(); - IColumn column = columns.iterator().next(); + Column column = columns.iterator().next(); assert columns.size() == 1; assert column.name().equals(ByteBufferUtil.bytes("col" + i)); @@ -85,16 +83,15 @@ public class RowCacheTest extends SchemaLoader for (int i = 100; i < 110; i++) { DecoratedKey key = Util.dk("key" + i); - QueryPath path = new QueryPath(COLUMN_FAMILY, null, ByteBufferUtil.bytes("col" + i)); - cachedStore.getColumnFamily(key, path, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); + cachedStore.getColumnFamily(key, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); assert cachedStore.containsCachedRow(key); // cache should be populated with the latest rows read (old ones should be popped) // checking if column is read correctly after cache - ColumnFamily cf = cachedStore.getColumnFamily(key, path, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); - Collection columns = cf.getSortedColumns(); + ColumnFamily cf = cachedStore.getColumnFamily(key, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); + Collection columns = cf.getSortedColumns(); - IColumn column = columns.iterator().next(); + Column column = columns.iterator().next(); assert columns.size() == 1; assert column.name().equals(ByteBufferUtil.bytes("col" + i)); diff --git a/test/unit/org/apache/cassandra/db/RowIterationTest.java b/test/unit/org/apache/cassandra/db/RowIterationTest.java index 26f11c8e39..a6c04952b8 100644 --- a/test/unit/org/apache/cassandra/db/RowIterationTest.java +++ b/test/unit/org/apache/cassandra/db/RowIterationTest.java @@ -30,7 +30,7 @@ import org.apache.cassandra.Util; import org.junit.Test; import org.apache.cassandra.SchemaLoader; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.utils.FBUtilities; import static junit.framework.Assert.assertEquals; import org.apache.cassandra.utils.ByteBufferUtil; @@ -52,7 +52,7 @@ public class RowIterationTest extends SchemaLoader for (int i = 0; i < ROWS_PER_SSTABLE; i++) { DecoratedKey key = Util.dk(String.valueOf(i)); RowMutation rm = new RowMutation(TABLE1, key.key); - rm.add(new QueryPath("Super3", ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes(String.valueOf(i))), ByteBuffer.wrap(new byte[ROWS_PER_SSTABLE * 10 - i * 2]), i); + rm.add("Super3", CompositeType.build(ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes(String.valueOf(i))), ByteBuffer.wrap(new byte[ROWS_PER_SSTABLE * 10 - i * 2]), i); rm.apply(); inserted.add(key); } @@ -70,16 +70,16 @@ public class RowIterationTest extends SchemaLoader // Delete row in first sstable RowMutation rm = new RowMutation(TABLE1, key.key); - rm.delete(new QueryPath(CF_NAME, null, null), 0); - rm.add(new QueryPath(CF_NAME, null, ByteBufferUtil.bytes("c")), ByteBufferUtil.bytes("values"), 0L); + rm.delete(CF_NAME, 0); + rm.add(CF_NAME, ByteBufferUtil.bytes("c"), ByteBufferUtil.bytes("values"), 0L); DeletionInfo delInfo1 = rm.getColumnFamilies().iterator().next().deletionInfo(); rm.apply(); store.forceBlockingFlush(); // Delete row in second sstable with higher timestamp rm = new RowMutation(TABLE1, key.key); - rm.delete(new QueryPath(CF_NAME, null, null), 1); - rm.add(new QueryPath(CF_NAME, null, ByteBufferUtil.bytes("c")), ByteBufferUtil.bytes("values"), 1L); + rm.delete(CF_NAME, 1); + rm.add(CF_NAME, ByteBufferUtil.bytes("c"), ByteBufferUtil.bytes("values"), 1L); DeletionInfo delInfo2 = rm.getColumnFamilies().iterator().next().deletionInfo(); assert delInfo2.getTopLevelDeletion().markedForDeleteAt == 1L; rm.apply(); @@ -99,7 +99,7 @@ public class RowIterationTest extends SchemaLoader // Delete a row in first sstable RowMutation rm = new RowMutation(TABLE1, key.key); - rm.delete(new QueryPath(CF_NAME, null, null), 0); + rm.delete(CF_NAME, 0); rm.apply(); store.forceBlockingFlush(); diff --git a/test/unit/org/apache/cassandra/db/RowTest.java b/test/unit/org/apache/cassandra/db/RowTest.java index c176abf4ce..a36fb9e9fd 100644 --- a/test/unit/org/apache/cassandra/db/RowTest.java +++ b/test/unit/org/apache/cassandra/db/RowTest.java @@ -47,21 +47,6 @@ public class RowTest extends SchemaLoader assertEquals(cfDiff.deletionInfo(), delInfo); } - @Test - public void testDiffSuperColumn() - { - SuperColumn sc1 = new SuperColumn(ByteBufferUtil.bytes("one"), AsciiType.instance); - sc1.addColumn(column("subcolumn", "A", 0)); - - SuperColumn sc2 = new SuperColumn(ByteBufferUtil.bytes("one"), AsciiType.instance); - DeletionInfo delInfo = new DeletionInfo(0, 0); - sc2.delete(delInfo); - - SuperColumn scDiff = (SuperColumn)sc1.diff(sc2); - assertEquals(scDiff.getSubColumns().size(), 0); - assertEquals(scDiff.deletionInfo(), delInfo); - } - @Test public void testResolve() { diff --git a/test/unit/org/apache/cassandra/db/ScrubTest.java b/test/unit/org/apache/cassandra/db/ScrubTest.java index fbde9088d3..a652f7f7e3 100644 --- a/test/unit/org/apache/cassandra/db/ScrubTest.java +++ b/test/unit/org/apache/cassandra/db/ScrubTest.java @@ -33,6 +33,8 @@ import org.apache.cassandra.Util; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.db.columniterator.IdentityQueryFilter; import org.apache.cassandra.db.compaction.CompactionManager; +import org.apache.cassandra.db.filter.NamesQueryFilter; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.io.util.FileUtils; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.CLibrary; @@ -93,7 +95,7 @@ public class ScrubTest extends SchemaLoader boolean caught = false; try { - rows = cfs.getRangeSlice(ByteBufferUtil.bytes("1"), Util.range("", ""), 1000, new IdentityQueryFilter(), null); + rows = cfs.getRangeSlice(Util.range("", ""), 1000, new NamesQueryFilter(CompositeType.build(ByteBufferUtil.bytes("1"))), null); fail("This slice should fail"); } catch (NegativeArraySizeException e) @@ -103,7 +105,7 @@ public class ScrubTest extends SchemaLoader assert caught : "'corrupt' test file actually was not"; CompactionManager.instance.performScrub(cfs); - rows = cfs.getRangeSlice(ByteBufferUtil.bytes("1"), Util.range("", ""), 1000, new IdentityQueryFilter(), null); + rows = cfs.getRangeSlice(Util.range("", ""), 1000, new IdentityQueryFilter(), null); assertEquals(100, rows.size()); } @@ -118,13 +120,13 @@ public class ScrubTest extends SchemaLoader // insert data and verify we get it back w/ range query fillCF(cfs, 1); - rows = cfs.getRangeSlice(null, Util.range("", ""), 1000, new IdentityQueryFilter(), null); + rows = cfs.getRangeSlice(Util.range("", ""), 1000, new IdentityQueryFilter(), null); assertEquals(1, rows.size()); CompactionManager.instance.performScrub(cfs); // check data is still there - rows = cfs.getRangeSlice(null, Util.range("", ""), 1000, new IdentityQueryFilter(), null); + rows = cfs.getRangeSlice(Util.range("", ""), 1000, new IdentityQueryFilter(), null); assertEquals(1, rows.size()); } @@ -158,13 +160,13 @@ public class ScrubTest extends SchemaLoader // insert data and verify we get it back w/ range query fillCF(cfs, 10); - rows = cfs.getRangeSlice(null, Util.range("", ""), 1000, new IdentityQueryFilter(), null); + rows = cfs.getRangeSlice(Util.range("", ""), 1000, new IdentityQueryFilter(), null); assertEquals(10, rows.size()); CompactionManager.instance.performScrub(cfs); // check data is still there - rows = cfs.getRangeSlice(null, Util.range("", ""), 1000, new IdentityQueryFilter(), null); + rows = cfs.getRangeSlice(Util.range("", ""), 1000, new IdentityQueryFilter(), null); assertEquals(10, rows.size()); } @@ -198,11 +200,11 @@ public class ScrubTest extends SchemaLoader assert cfs.getSSTables().size() > 0; List rows; - rows = cfs.getRangeSlice(null, Util.range("", ""), 1000, new IdentityQueryFilter(), null); + rows = cfs.getRangeSlice(Util.range("", ""), 1000, new IdentityQueryFilter(), null); assert !isRowOrdered(rows) : "'corrupt' test file actually was not"; CompactionManager.instance.performScrub(cfs); - rows = cfs.getRangeSlice(null, Util.range("", ""), 1000, new IdentityQueryFilter(), null); + rows = cfs.getRangeSlice(Util.range("", ""), 1000, new IdentityQueryFilter(), null); assert isRowOrdered(rows) : "Scrub failed: " + rows; assert rows.size() == 6: "Got " + rows.size(); } diff --git a/test/unit/org/apache/cassandra/db/SecondaryIndexColumnSizeTest.java b/test/unit/org/apache/cassandra/db/SecondaryIndexColumnSizeTest.java index 8872d650a9..708c04f2f0 100644 --- a/test/unit/org/apache/cassandra/db/SecondaryIndexColumnSizeTest.java +++ b/test/unit/org/apache/cassandra/db/SecondaryIndexColumnSizeTest.java @@ -29,7 +29,6 @@ import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.db.index.PerColumnSecondaryIndex; import org.apache.cassandra.db.index.PerRowSecondaryIndex; import org.apache.cassandra.db.index.SecondaryIndexSearcher; -import org.apache.cassandra.thrift.Column; import org.apache.cassandra.utils.ByteBufferUtil; import static org.junit.Assert.assertFalse; @@ -40,9 +39,6 @@ public class SecondaryIndexColumnSizeTest @Test public void test64kColumn() { - Column column = new Column(); - column.name = ByteBufferUtil.bytes("test"); - // a byte buffer more than 64k ByteBuffer buffer = ByteBuffer.allocate(1024 * 65); buffer.clear(); @@ -53,7 +49,7 @@ public class SecondaryIndexColumnSizeTest // for read buffer.flip(); - column.value = buffer; + Column column = new Column(ByteBufferUtil.bytes("test"), buffer, 0); MockRowIndex mockRowIndex = new MockRowIndex(); MockColumnIndex mockColumnIndex = new MockColumnIndex(); @@ -203,17 +199,17 @@ public class SecondaryIndexColumnSizeTest } @Override - public void delete(ByteBuffer rowKey, IColumn col) + public void delete(ByteBuffer rowKey, Column col) { } @Override - public void insert(ByteBuffer rowKey, IColumn col) + public void insert(ByteBuffer rowKey, Column col) { } @Override - public void update(ByteBuffer rowKey, IColumn col) + public void update(ByteBuffer rowKey, Column col) { } diff --git a/test/unit/org/apache/cassandra/db/SerializationsTest.java b/test/unit/org/apache/cassandra/db/SerializationsTest.java index acfdf4b4e1..5be7096e5b 100644 --- a/test/unit/org/apache/cassandra/db/SerializationsTest.java +++ b/test/unit/org/apache/cassandra/db/SerializationsTest.java @@ -23,6 +23,7 @@ import org.apache.cassandra.Util; import org.apache.cassandra.config.Schema; import org.apache.cassandra.db.filter.*; import org.apache.cassandra.db.marshal.BytesType; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.dht.AbstractBounds; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.Range; @@ -45,34 +46,39 @@ import java.util.*; public class SerializationsTest extends AbstractSerializationsTester { + Statics statics = new Statics(); + @BeforeClass public static void loadSchema() throws IOException { loadSchema(true); } + private ByteBuffer startCol = ByteBufferUtil.bytes("Start"); + private ByteBuffer stopCol = ByteBufferUtil.bytes("Stop"); + private ByteBuffer emptyCol = ByteBufferUtil.bytes(""); + public NamesQueryFilter namesPred = new NamesQueryFilter(statics.NamedCols); + public NamesQueryFilter namesSCPred = new NamesQueryFilter(statics.NamedSCCols); + public SliceQueryFilter emptyRangePred = new SliceQueryFilter(emptyCol, emptyCol, false, 100); + public SliceQueryFilter nonEmptyRangePred = new SliceQueryFilter(startCol, stopCol, true, 100); + public SliceQueryFilter nonEmptyRangeSCPred = new SliceQueryFilter(CompositeType.build(statics.SC, startCol), CompositeType.build(statics.SC, stopCol), true, 100); + private void testRangeSliceCommandWrite() throws IOException { - ByteBuffer startCol = ByteBufferUtil.bytes("Start"); - ByteBuffer stopCol = ByteBufferUtil.bytes("Stop"); - ByteBuffer emptyCol = ByteBufferUtil.bytes(""); - NamesQueryFilter namesPred = new NamesQueryFilter(Statics.NamedCols); - SliceQueryFilter emptyRangePred = new SliceQueryFilter(emptyCol, emptyCol, false, 100); - SliceQueryFilter nonEmptyRangePred = new SliceQueryFilter(startCol, stopCol, true, 100); IPartitioner part = StorageService.getPartitioner(); AbstractBounds bounds = new Range(part.getRandomToken(), part.getRandomToken()).toRowBounds(); - RangeSliceCommand namesCmd = new RangeSliceCommand(Statics.KS, "Standard1", null, namesPred, bounds, 100); + RangeSliceCommand namesCmd = new RangeSliceCommand(statics.KS, "Standard1", namesPred, bounds, 100); MessageOut namesCmdMsg = namesCmd.createMessage(); - RangeSliceCommand emptyRangeCmd = new RangeSliceCommand(Statics.KS, "Standard1", null, emptyRangePred, bounds, 100); + RangeSliceCommand emptyRangeCmd = new RangeSliceCommand(statics.KS, "Standard1", emptyRangePred, bounds, 100); MessageOut emptyRangeCmdMsg = emptyRangeCmd.createMessage(); - RangeSliceCommand regRangeCmd = new RangeSliceCommand(Statics.KS, "Standard1", null, nonEmptyRangePred, bounds, 100); + RangeSliceCommand regRangeCmd = new RangeSliceCommand(statics.KS, "Standard1", nonEmptyRangePred, bounds, 100); MessageOut regRangeCmdMsg = regRangeCmd.createMessage(); - RangeSliceCommand namesCmdSup = new RangeSliceCommand(Statics.KS, "Super1", Statics.SC, namesPred, bounds, 100); + RangeSliceCommand namesCmdSup = new RangeSliceCommand(statics.KS, "Super1", namesSCPred, bounds, 100); MessageOut namesCmdSupMsg = namesCmdSup.createMessage(); - RangeSliceCommand emptyRangeCmdSup = new RangeSliceCommand(Statics.KS, "Super1", Statics.SC, emptyRangePred, bounds, 100); + RangeSliceCommand emptyRangeCmdSup = new RangeSliceCommand(statics.KS, "Super1", emptyRangePred, bounds, 100); MessageOut emptyRangeCmdSupMsg = emptyRangeCmdSup.createMessage(); - RangeSliceCommand regRangeCmdSup = new RangeSliceCommand(Statics.KS, "Super1", Statics.SC, nonEmptyRangePred, bounds, 100); + RangeSliceCommand regRangeCmdSup = new RangeSliceCommand(statics.KS, "Super1", nonEmptyRangeSCPred, bounds, 100); MessageOut regRangeCmdSupMsg = regRangeCmdSup.createMessage(); DataOutputStream out = getOutput("db.RangeSliceCommand.bin"); @@ -107,8 +113,8 @@ public class SerializationsTest extends AbstractSerializationsTester private void testSliceByNamesReadCommandWrite() throws IOException { - SliceByNamesReadCommand standardCmd = new SliceByNamesReadCommand(Statics.KS, Statics.Key, Statics.StandardPath, Statics.NamedCols); - SliceByNamesReadCommand superCmd = new SliceByNamesReadCommand(Statics.KS, Statics.Key, Statics.SuperPath, Statics.NamedCols); + SliceByNamesReadCommand standardCmd = new SliceByNamesReadCommand(statics.KS, statics.Key, statics.StandardCF, namesPred); + SliceByNamesReadCommand superCmd = new SliceByNamesReadCommand(statics.KS, statics.Key, statics.SuperCF, namesSCPred); DataOutputStream out = getOutput("db.SliceByNamesReadCommand.bin"); SliceByNamesReadCommand.serializer.serialize(standardCmd, out, getVersion()); @@ -142,8 +148,9 @@ public class SerializationsTest extends AbstractSerializationsTester private void testSliceFromReadCommandWrite() throws IOException { - SliceFromReadCommand standardCmd = new SliceFromReadCommand(Statics.KS, Statics.Key, Statics.StandardPath, Statics.Start, Statics.Stop, true, 100); - SliceFromReadCommand superCmd = new SliceFromReadCommand(Statics.KS, Statics.Key, Statics.SuperPath, Statics.Start, Statics.Stop, true, 100); + SliceFromReadCommand standardCmd = new SliceFromReadCommand(statics.KS, statics.Key, statics.StandardCF, nonEmptyRangePred); + SliceFromReadCommand superCmd = new SliceFromReadCommand(statics.KS, statics.Key, statics.SuperCF, nonEmptyRangeSCPred); + DataOutputStream out = getOutput("db.SliceFromReadCommand.bin"); SliceFromReadCommand.serializer.serialize(standardCmd, out, getVersion()); SliceFromReadCommand.serializer.serialize(superCmd, out, getVersion()); @@ -151,6 +158,7 @@ public class SerializationsTest extends AbstractSerializationsTester ReadCommand.serializer.serialize(superCmd, out, getVersion()); standardCmd.createMessage().serialize(out, getVersion()); superCmd.createMessage().serialize(out, getVersion()); + out.close(); // test serializedSize @@ -177,15 +185,15 @@ public class SerializationsTest extends AbstractSerializationsTester private void testRowWrite() throws IOException { DataOutputStream out = getOutput("db.Row.bin"); - Row.serializer.serialize(Statics.StandardRow, out, getVersion()); - Row.serializer.serialize(Statics.SuperRow, out, getVersion()); - Row.serializer.serialize(Statics.NullRow, out, getVersion()); + Row.serializer.serialize(statics.StandardRow, out, getVersion()); + Row.serializer.serialize(statics.SuperRow, out, getVersion()); + Row.serializer.serialize(statics.NullRow, out, getVersion()); out.close(); // test serializedSize - testSerializedSize(Statics.StandardRow, Row.serializer); - testSerializedSize(Statics.SuperRow, Row.serializer); - testSerializedSize(Statics.NullRow, Row.serializer); + testSerializedSize(statics.StandardRow, Row.serializer); + testSerializedSize(statics.SuperRow, Row.serializer); + testSerializedSize(statics.NullRow, Row.serializer); } @Test @@ -203,17 +211,17 @@ public class SerializationsTest extends AbstractSerializationsTester private void testRowMutationWrite() throws IOException { - RowMutation emptyRm = new RowMutation(Statics.KS, Statics.Key); - RowMutation standardRowRm = new RowMutation(Statics.KS, Statics.StandardRow); - RowMutation superRowRm = new RowMutation(Statics.KS, Statics.SuperRow); - RowMutation standardRm = new RowMutation(Statics.KS, Statics.Key); - standardRm.add(Statics.StandardCf); - RowMutation superRm = new RowMutation(Statics.KS, Statics.Key); - superRm.add(Statics.SuperCf); + RowMutation emptyRm = new RowMutation(statics.KS, statics.Key); + RowMutation standardRowRm = new RowMutation(statics.KS, statics.StandardRow); + RowMutation superRowRm = new RowMutation(statics.KS, statics.SuperRow); + RowMutation standardRm = new RowMutation(statics.KS, statics.Key); + standardRm.add(statics.StandardCf); + RowMutation superRm = new RowMutation(statics.KS, statics.Key); + superRm.add(statics.SuperCf); Map mods = new HashMap(); - mods.put(Statics.StandardCf.metadata().cfId, Statics.StandardCf); - mods.put(Statics.SuperCf.metadata().cfId, Statics.SuperCf); - RowMutation mixedRm = new RowMutation(Statics.KS, Statics.Key, mods); + mods.put(statics.StandardCf.metadata().cfId, statics.StandardCf); + mods.put(statics.SuperCf.metadata().cfId, statics.SuperCf); + RowMutation mixedRm = new RowMutation(statics.KS, statics.Key, mods); DataOutputStream out = getOutput("db.RowMutation.bin"); RowMutation.serializer.serialize(emptyRm, out, getVersion()); @@ -265,9 +273,9 @@ public class SerializationsTest extends AbstractSerializationsTester private void testTruncateWrite() throws IOException { - Truncation tr = new Truncation(Statics.KS, "Doesn't Really Matter"); - TruncateResponse aff = new TruncateResponse(Statics.KS, "Doesn't Matter Either", true); - TruncateResponse neg = new TruncateResponse(Statics.KS, "Still Doesn't Matter", false); + Truncation tr = new Truncation(statics.KS, "Doesn't Really Matter"); + TruncateResponse aff = new TruncateResponse(statics.KS, "Doesn't Matter Either", true); + TruncateResponse neg = new TruncateResponse(statics.KS, "Still Doesn't Matter", false); DataOutputStream out = getOutput("db.Truncation.bin"); Truncation.serializer.serialize(tr, out, getVersion()); TruncateResponse.serializer.serialize(aff, out, getVersion()); @@ -338,39 +346,35 @@ public class SerializationsTest extends AbstractSerializationsTester private static class Statics { - private static final String KS = "Keyspace1"; - private static final ByteBuffer Key = ByteBufferUtil.bytes("Key01"); - private static final SortedSet NamedCols = new TreeSet(BytesType.instance) + private final String KS = "Keyspace1"; + private final ByteBuffer Key = ByteBufferUtil.bytes("Key01"); + private final SortedSet NamedCols = new TreeSet(BytesType.instance) {{ add(ByteBufferUtil.bytes("AAA")); add(ByteBufferUtil.bytes("BBB")); add(ByteBufferUtil.bytes("CCC")); }}; - private static final ByteBuffer SC = ByteBufferUtil.bytes("SCName"); - private static final QueryPath StandardPath = new QueryPath("Standard1"); - private static final QueryPath SuperPath = new QueryPath("Super1", SC); - private static final ByteBuffer Start = ByteBufferUtil.bytes("Start"); - private static final ByteBuffer Stop = ByteBufferUtil.bytes("Stop"); - - private static final ColumnFamily StandardCf = ColumnFamily.create(Statics.KS, "Standard1"); - private static final ColumnFamily SuperCf = ColumnFamily.create(Statics.KS, "Super1"); - - private static final SuperColumn SuperCol = new SuperColumn(Statics.SC, Schema.instance.getComparator(Statics.KS, "Super1")) + private final ByteBuffer SC = ByteBufferUtil.bytes("SCName"); + private final SortedSet NamedSCCols = new TreeSet(BytesType.instance) {{ - addColumn(new Column(bb("aaaa"))); - addColumn(new Column(bb("bbbb"), bb("bbbbb-value"))); - addColumn(new Column(bb("cccc"), bb("ccccc-value"), 1000L)); - addColumn(new DeletedColumn(bb("dddd"), 500, 1000)); - addColumn(new DeletedColumn(bb("eeee"), bb("eeee-value"), 1001)); - addColumn(new ExpiringColumn(bb("ffff"), bb("ffff-value"), 2000, 1000)); - addColumn(new ExpiringColumn(bb("gggg"), bb("gggg-value"), 2001, 1000, 2002)); + add(CompositeType.build(SC, ByteBufferUtil.bytes("AAA"))); + add(CompositeType.build(SC, ByteBufferUtil.bytes("BBB"))); + add(CompositeType.build(SC, ByteBufferUtil.bytes("CCC"))); }}; + private final String StandardCF = "Standard1"; + private final String SuperCF = "Super1"; + private final ByteBuffer Start = ByteBufferUtil.bytes("Start"); + private final ByteBuffer Stop = ByteBufferUtil.bytes("Stop"); - private static final Row StandardRow = new Row(Util.dk("key0"), Statics.StandardCf); - private static final Row SuperRow = new Row(Util.dk("key1"), Statics.SuperCf); - private static final Row NullRow = new Row(Util.dk("key2"), null); + private final ColumnFamily StandardCf = ColumnFamily.create(KS, StandardCF); + private final ColumnFamily SuperCf = ColumnFamily.create(KS, SuperCF); - static { + private final Row StandardRow = new Row(Util.dk("key0"), StandardCf); + private final Row SuperRow = new Row(Util.dk("key1"), SuperCf); + private final Row NullRow = new Row(Util.dk("key2"), null); + + private Statics() + { StandardCf.addColumn(new Column(bb("aaaa"))); StandardCf.addColumn(new Column(bb("bbbb"), bb("bbbbb-value"))); StandardCf.addColumn(new Column(bb("cccc"), bb("ccccc-value"), 1000L)); @@ -379,7 +383,13 @@ public class SerializationsTest extends AbstractSerializationsTester StandardCf.addColumn(new ExpiringColumn(bb("ffff"), bb("ffff-value"), 2000, 1000)); StandardCf.addColumn(new ExpiringColumn(bb("gggg"), bb("gggg-value"), 2001, 1000, 2002)); - SuperCf.addColumn(Statics.SuperCol); + SuperCf.addColumn(new Column(CompositeType.build(SC, bb("aaaa")))); + SuperCf.addColumn(new Column(CompositeType.build(SC, bb("bbbb")), bb("bbbbb-value"))); + SuperCf.addColumn(new Column(CompositeType.build(SC, bb("cccc")), bb("ccccc-value"), 1000L)); + SuperCf.addColumn(new DeletedColumn(CompositeType.build(SC, bb("dddd")), 500, 1000)); + SuperCf.addColumn(new DeletedColumn(CompositeType.build(SC, bb("eeee")), bb("eeee-value"), 1001)); + SuperCf.addColumn(new ExpiringColumn(CompositeType.build(SC, bb("ffff")), bb("ffff-value"), 2000, 1000)); + SuperCf.addColumn(new ExpiringColumn(CompositeType.build(SC, bb("gggg")), bb("gggg-value"), 2001, 1000, 2002)); } } } diff --git a/test/unit/org/apache/cassandra/db/SuperColumnTest.java b/test/unit/org/apache/cassandra/db/SuperColumnTest.java deleted file mode 100644 index 6c07d2dfc1..0000000000 --- a/test/unit/org/apache/cassandra/db/SuperColumnTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* -* 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.db; - -import org.junit.Test; - -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; -import static org.apache.cassandra.Util.getBytes; -import org.apache.cassandra.db.context.CounterContext; -import static org.apache.cassandra.db.context.CounterContext.ContextState; -import org.apache.cassandra.db.marshal.LongType; -import org.apache.cassandra.utils.ByteBufferUtil; -import org.apache.cassandra.utils.CounterId; - -public class SuperColumnTest -{ - private static final CounterContext cc = new CounterContext(); - - @Test - public void testMissingSubcolumn() { - SuperColumn sc = new SuperColumn(ByteBufferUtil.bytes("sc1"), LongType.instance); - sc.addColumn(new Column(getBytes(1), ByteBufferUtil.bytes("value"), 1)); - assertNotNull(sc.getSubColumn(getBytes(1))); - assertNull(sc.getSubColumn(getBytes(2))); - } - - @Test - public void testAddColumnIncrementCounter() - { - ContextState state; - - SuperColumn sc = new SuperColumn(ByteBufferUtil.bytes("sc1"), LongType.instance); - - state = ContextState.allocate(4, 1); - state.writeElement(CounterId.fromInt(1), 7L, 0L); - state.writeElement(CounterId.fromInt(2), 5L, 7L); - state.writeElement(CounterId.fromInt(4), 2L, 9L); - state.writeElement(CounterId.getLocalId(), 3L, 3L, true); - sc.addColumn(new CounterColumn(getBytes(1), state.context, 3L, 0L)); - - state = ContextState.allocate(4, 1); - state.writeElement(CounterId.fromInt(2), 3L, 4L); - state.writeElement(CounterId.fromInt(4), 4L, 1L); - state.writeElement(CounterId.fromInt(8), 9L, 0L); - state.writeElement(CounterId.getLocalId(), 9L, 5L, true); - sc.addColumn(new CounterColumn(getBytes(1), state.context, 10L, 0L)); - - state = ContextState.allocate(3, 0); - state.writeElement(CounterId.fromInt(2), 1L, 0L); - state.writeElement(CounterId.fromInt(3), 6L, 0L); - state.writeElement(CounterId.fromInt(7), 3L, 0L); - sc.addColumn(new CounterColumn(getBytes(2), state.context, 9L, 0L)); - - assertNotNull(sc.getSubColumn(getBytes(1))); - assertNull(sc.getSubColumn(getBytes(3))); - - // column: 1 - ContextState c1 = ContextState.allocate(5, 1); - c1.writeElement(CounterId.fromInt(1), 7L, 0L); - c1.writeElement(CounterId.fromInt(2), 5L, 7L); - c1.writeElement(CounterId.fromInt(4), 4L, 1L); - c1.writeElement(CounterId.fromInt(8), 9L, 0L); - c1.writeElement(CounterId.getLocalId(), 12L, 8L, true); - assert 0 == ByteBufferUtil.compareSubArrays( - ((CounterColumn)sc.getSubColumn(getBytes(1))).value(), - 0, - c1.context, - 0, - c1.context.remaining()); - - // column: 2 - ContextState c2 = ContextState.allocate(3, 0); - c2.writeElement(CounterId.fromInt(2), 1L, 0L); - c2.writeElement(CounterId.fromInt(3), 6L, 0L); - c2.writeElement(CounterId.fromInt(7), 3L, 0L); - assert 0 == ByteBufferUtil.compareSubArrays( - ((CounterColumn)sc.getSubColumn(getBytes(2))).value(), - 0, - c2.context, - 0, - c2.context.remaining()); - - assertNotNull(sc.getSubColumn(getBytes(1))); - assertNotNull(sc.getSubColumn(getBytes(2))); - assertNull(sc.getSubColumn(getBytes(3))); - } -} diff --git a/test/unit/org/apache/cassandra/db/TableTest.java b/test/unit/org/apache/cassandra/db/TableTest.java index 20ab17356c..0b14ccb679 100644 --- a/test/unit/org/apache/cassandra/db/TableTest.java +++ b/test/unit/org/apache/cassandra/db/TableTest.java @@ -40,7 +40,6 @@ import static org.apache.cassandra.Util.column; import static org.apache.cassandra.Util.expiringColumn; import static org.apache.cassandra.Util.getBytes; import org.apache.cassandra.Util; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.Int32Type; import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.utils.ByteBufferUtil; @@ -76,13 +75,13 @@ public class TableTest extends SchemaLoader { ColumnFamily cf; - cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, new QueryPath("Standard3"), new TreeSet())); + cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, "Standard3", new TreeSet())); assertColumns(cf); - cf = cfStore.getColumnFamily(QueryFilter.getSliceFilter(TEST_KEY, new QueryPath("Standard3"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 0)); + cf = cfStore.getColumnFamily(QueryFilter.getSliceFilter(TEST_KEY, "Standard3", ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 0)); assertColumns(cf); - cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, new QueryPath("Standard3"), ByteBufferUtil.bytes("col99"))); + cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, "Standard3", ByteBufferUtil.bytes("col99"))); assertColumns(cf); } }; @@ -109,10 +108,10 @@ public class TableTest extends SchemaLoader { ColumnFamily cf; - cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, new QueryPath("Standard1"), ByteBufferUtil.bytes("col1"))); + cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, "Standard1", ByteBufferUtil.bytes("col1"))); assertColumns(cf, "col1"); - cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, new QueryPath("Standard1"), ByteBufferUtil.bytes("col3"))); + cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, "Standard1", ByteBufferUtil.bytes("col3"))); assertColumns(cf, "col3"); } }; @@ -134,13 +133,13 @@ public class TableTest extends SchemaLoader rm.add(cf); rm.apply(); - cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), ByteBufferUtil.bytes("b"), ByteBufferUtil.bytes("c"), false, 100); + cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("b"), ByteBufferUtil.bytes("c"), false, 100); assertEquals(2, cf.getColumnCount()); - cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), ByteBufferUtil.bytes("b"), ByteBufferUtil.bytes("b"), false, 100); + cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("b"), ByteBufferUtil.bytes("b"), false, 100); assertEquals(1, cf.getColumnCount()); - cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), ByteBufferUtil.bytes("b"), ByteBufferUtil.bytes("c"), false, 1); + cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("b"), ByteBufferUtil.bytes("c"), false, 1); assertEquals(1, cf.getColumnCount()); } @@ -192,30 +191,30 @@ public class TableTest extends SchemaLoader assert DatabaseDescriptor.getColumnIndexSize() == 4096 : "Unexpected column index size, block boundaries won't be where tests expect them."; // test forward, spanning a segment. - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col096"), ByteBufferUtil.bytes("col099"), false, 4); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col096"), ByteBufferUtil.bytes("col099"), false, 4); assertColumns(cf, "col096", "col097", "col098", "col099"); // test reversed, spanning a segment. - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col099"), ByteBufferUtil.bytes("col096"), true, 4); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col099"), ByteBufferUtil.bytes("col096"), true, 4); assertColumns(cf, "col096", "col097", "col098", "col099"); // test forward, within a segment. - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col100"), ByteBufferUtil.bytes("col103"), false, 4); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col100"), ByteBufferUtil.bytes("col103"), false, 4); assertColumns(cf, "col100", "col101", "col102", "col103"); // test reversed, within a segment. - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col103"), ByteBufferUtil.bytes("col100"), true, 4); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col103"), ByteBufferUtil.bytes("col100"), true, 4); assertColumns(cf, "col100", "col101", "col102", "col103"); // test forward from beginning, spanning a segment. String[] strCols = new String[100]; // col000-col099 for (int i = 0; i < 100; i++) strCols[i] = "col" + fmt.format(i); - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.bytes("col099"), false, 100); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.bytes("col099"), false, 100); assertColumns(cf, strCols); // test reversed, from end, spanning a segment. - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.bytes("col288"), true, 12); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.bytes("col288"), true, 12); assertColumns(cf, "col288", "col289", "col290", "col291", "col292", "col293", "col294", "col295", "col296", "col297", "col298", "col299"); } }; @@ -249,7 +248,7 @@ public class TableTest extends SchemaLoader rm.add(cf); rm.apply(); - cf = cfs.getColumnFamily(ROW, new QueryPath("StandardLong1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 1); + cf = cfs.getColumnFamily(ROW, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 1); assertEquals(1, cf.getColumnNames().size()); assertEquals(i, cf.getColumnNames().iterator().next().getLong()); } @@ -261,11 +260,11 @@ public class TableTest extends SchemaLoader ColumnFamily cf; // key before the rows that exists - cf = cfStore.getColumnFamily(Util.dk("a"), new QueryPath("Standard2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); + cf = cfStore.getColumnFamily(Util.dk("a"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); assertColumns(cf); // key after the rows that exist - cf = cfStore.getColumnFamily(Util.dk("z"), new QueryPath("Standard2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); + cf = cfStore.getColumnFamily(Util.dk("z"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); assertColumns(cf); } @@ -289,7 +288,7 @@ public class TableTest extends SchemaLoader rm.apply(); rm = new RowMutation("Keyspace1", ROW.key); - rm.delete(new QueryPath("Standard1", null, ByteBufferUtil.bytes("col4")), 2L); + rm.delete("Standard1", ByteBufferUtil.bytes("col4"), 2L); rm.apply(); Runnable verify = new WrappedRunnable() @@ -298,26 +297,26 @@ public class TableTest extends SchemaLoader { ColumnFamily cf; - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col5"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col5"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2); assertColumns(cf, "col5", "col7"); - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col4"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col4"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2); assertColumns(cf, "col4", "col5", "col7"); assertColumns(ColumnFamilyStore.removeDeleted(cf, Integer.MAX_VALUE), "col5", "col7"); - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col5"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col5"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2); assertColumns(cf, "col3", "col4", "col5"); - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col6"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col6"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2); assertColumns(cf, "col3", "col4", "col5"); - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2); assertColumns(cf, "col7", "col9"); - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col95"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col95"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2); assertColumns(cf); - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2); assertColumns(cf); } }; @@ -348,11 +347,11 @@ public class TableTest extends SchemaLoader { ColumnFamily cf; - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2); assertColumns(cf, "col1", "col2"); assertColumns(ColumnFamilyStore.removeDeleted(cf, Integer.MAX_VALUE), "col1"); - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1); assertColumns(cf, "col2"); assertColumns(ColumnFamilyStore.removeDeleted(cf, Integer.MAX_VALUE)); } @@ -395,7 +394,7 @@ public class TableTest extends SchemaLoader { ColumnFamily cf; - cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3); + cf = cfStore.getColumnFamily(ROW, ByteBufferUtil.bytes("col2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3); assertColumns(cf, "col2", "col3", "col4"); ByteBuffer col = cf.getColumn(ByteBufferUtil.bytes("col2")).value(); @@ -446,7 +445,7 @@ public class TableTest extends SchemaLoader { DecoratedKey key = Util.dk("row3"); ColumnFamily cf; - cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), ByteBufferUtil.bytes("col1000"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3); + cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col1000"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3); assertColumns(cf, "col1000", "col1001", "col1002"); ByteBuffer col; @@ -457,7 +456,7 @@ public class TableTest extends SchemaLoader col = cf.getColumn(ByteBufferUtil.bytes("col1002")).value(); assertEquals(ByteBufferUtil.string(col), "v1002"); - cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), ByteBufferUtil.bytes("col1195"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3); + cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col1195"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3); assertColumns(cf, "col1195", "col1196", "col1197"); col = cf.getColumn(ByteBufferUtil.bytes("col1195")).value(); @@ -468,17 +467,17 @@ public class TableTest extends SchemaLoader assertEquals(ByteBufferUtil.string(col), "v1197"); - cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), ByteBufferUtil.bytes("col1996"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 1000); - IColumn[] columns = cf.getSortedColumns().toArray(new IColumn[0]); + cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col1996"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 1000); + Column[] columns = cf.getSortedColumns().toArray(new Column[0]); for (int i = 1000; i < 1996; i++) { String expectedName = "col" + i; - IColumn column = columns[i - 1000]; + Column column = columns[i - 1000]; assertEquals(ByteBufferUtil.string(column.name()), expectedName); assertEquals(ByteBufferUtil.string(column.value()), ("v" + i)); } - cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), ByteBufferUtil.bytes("col1990"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3); + cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col1990"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3); assertColumns(cf, "col1990", "col1991", "col1992"); col = cf.getColumn(ByteBufferUtil.bytes("col1990")).value(); assertEquals(ByteBufferUtil.string(col), "v1990"); @@ -487,7 +486,7 @@ public class TableTest extends SchemaLoader col = cf.getColumn(ByteBufferUtil.bytes("col1992")).value(); assertEquals(ByteBufferUtil.string(col), "v1992"); - cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 3); + cf = cfStore.getColumnFamily(key, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 3); assertColumns(cf, "col1997", "col1998", "col1999"); col = cf.getColumn(ByteBufferUtil.bytes("col1997")).value(); assertEquals(ByteBufferUtil.string(col), "v1997"); @@ -496,61 +495,18 @@ public class TableTest extends SchemaLoader col = cf.getColumn(ByteBufferUtil.bytes("col1999")).value(); assertEquals(ByteBufferUtil.string(col), "v1999"); - cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), ByteBufferUtil.bytes("col9000"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 3); + cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col9000"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 3); assertColumns(cf, "col1997", "col1998", "col1999"); - cf = cfStore.getColumnFamily(key, new QueryPath("Standard1"), ByteBufferUtil.bytes("col9000"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3); + cf = cfStore.getColumnFamily(key, ByteBufferUtil.bytes("col9000"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 3); assertColumns(cf); } - @Test - public void testGetSliceFromSuperBasic() throws Throwable + public static void assertColumns(ColumnFamily container, String... columnNames) { - // tests slicing against data from one row spread across two sstables - final Table table = Table.open("Keyspace1"); - final ColumnFamilyStore cfStore = table.getColumnFamilyStore("Super1"); - final DecoratedKey ROW = Util.dk("row2"); - - RowMutation rm = new RowMutation("Keyspace1", ROW.key); - ColumnFamily cf = ColumnFamily.create("Keyspace1", "Super1"); - SuperColumn sc = new SuperColumn(ByteBufferUtil.bytes("sc1"), Int32Type.instance); - sc.addColumn(new Column(getBytes(1), ByteBufferUtil.bytes("val1"), 1L)); - cf.addColumn(sc); - rm.add(cf); - rm.apply(); - - Runnable verify = new WrappedRunnable() - { - public void runMayThrow() throws Exception - { - ColumnFamily cf = cfStore.getColumnFamily(ROW, new QueryPath("Super1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 10); - assertColumns(cf, "sc1"); - - ByteBuffer val = cf.getColumn(ByteBufferUtil.bytes("sc1")).getSubColumn(getBytes(1)).value(); - - assertEquals(ByteBufferUtil.string(val), "val1"); - } - }; - - reTest(table.getColumnFamilyStore("Standard1"), verify); - } - - public static void assertColumns(ColumnFamily cf, String... columnNames) - { - assertColumns((IColumnContainer)cf, columnNames); - } - - public static void assertSubColumns(ColumnFamily cf, String scName, String... columnNames) - { - IColumnContainer sc = cf == null ? null : ((IColumnContainer)cf.getColumn(ByteBufferUtil.bytes(scName))); - assertColumns(sc, columnNames); - } - - public static void assertColumns(IColumnContainer container, String... columnNames) - { - Collection columns = container == null ? new TreeSet() : container.getSortedColumns(); + Collection columns = container == null ? new TreeSet() : container.getSortedColumns(); List L = new ArrayList(); - for (IColumn column : columns) + for (Column column : columns) { try { @@ -580,13 +536,7 @@ public class TableTest extends SchemaLoader assertColumn(cf.getColumn(ByteBufferUtil.bytes(name)), value, timestamp); } - public static void assertSubColumn(ColumnFamily cf, String scName, String name, String value, long timestamp) - { - SuperColumn sc = (SuperColumn)cf.getColumn(ByteBufferUtil.bytes(scName)); - assertColumn(sc.getSubColumn(ByteBufferUtil.bytes(name)), value, timestamp); - } - - public static void assertColumn(IColumn column, String value, long timestamp) + public static void assertColumn(Column column, String value, long timestamp) { assertNotNull(column); assertEquals(0, ByteBufferUtil.compareUnsigned(column.value(), ByteBufferUtil.bytes(value))); diff --git a/test/unit/org/apache/cassandra/db/TimeSortTest.java b/test/unit/org/apache/cassandra/db/TimeSortTest.java index 7ea91a5145..87777caf4b 100644 --- a/test/unit/org/apache/cassandra/db/TimeSortTest.java +++ b/test/unit/org/apache/cassandra/db/TimeSortTest.java @@ -31,7 +31,6 @@ import static org.apache.cassandra.Util.getBytes; import org.apache.cassandra.Util; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.LongType; import org.apache.cassandra.utils.ByteBufferUtil; @@ -47,16 +46,16 @@ public class TimeSortTest extends SchemaLoader DecoratedKey key = Util.dk("key0"); rm = new RowMutation("Keyspace1", key.key); - rm.add(new QueryPath("StandardLong1", null, getBytes(100)), ByteBufferUtil.bytes("a"), 100); + rm.add("StandardLong1", getBytes(100), ByteBufferUtil.bytes("a"), 100); rm.apply(); cfStore.forceBlockingFlush(); rm = new RowMutation("Keyspace1", key.key); - rm.add(new QueryPath("StandardLong1", null, getBytes(0)), ByteBufferUtil.bytes("b"), 0); + rm.add("StandardLong1", getBytes(0), ByteBufferUtil.bytes("b"), 0); rm.apply(); - ColumnFamily cf = cfStore.getColumnFamily(key, new QueryPath("StandardLong1"), getBytes(10), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1000); - Collection columns = cf.getSortedColumns(); + ColumnFamily cf = cfStore.getColumnFamily(key, getBytes(10), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1000); + Collection columns = cf.getSortedColumns(); assert columns.size() == 1; } @@ -71,7 +70,7 @@ public class TimeSortTest extends SchemaLoader RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes(Integer.toString(i))); for (int j = 0; j < 8; ++j) { - rm.add(new QueryPath("StandardLong1", null, getBytes(j * 2)), ByteBufferUtil.bytes("a"), j * 2); + rm.add("StandardLong1", getBytes(j * 2), ByteBufferUtil.bytes("a"), j * 2); } rm.apply(); } @@ -86,21 +85,21 @@ public class TimeSortTest extends SchemaLoader RowMutation rm = new RowMutation("Keyspace1", key.key); for (int j = 0; j < 4; ++j) { - rm.add(new QueryPath("StandardLong1", null, getBytes(j * 2 + 1)), ByteBufferUtil.bytes("b"), j * 2 + 1); + rm.add("StandardLong1", getBytes(j * 2 + 1), ByteBufferUtil.bytes("b"), j * 2 + 1); } rm.apply(); // and some overwrites rm = new RowMutation("Keyspace1", key.key); - rm.add(new QueryPath("StandardLong1", null, getBytes(0)), ByteBufferUtil.bytes("c"), 100); - rm.add(new QueryPath("StandardLong1", null, getBytes(10)), ByteBufferUtil.bytes("c"), 100); + rm.add("StandardLong1", getBytes(0), ByteBufferUtil.bytes("c"), 100); + rm.add("StandardLong1", getBytes(10), ByteBufferUtil.bytes("c"), 100); rm.apply(); // verify - ColumnFamily cf = cfStore.getColumnFamily(key, new QueryPath("StandardLong1"), getBytes(0), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1000); - Collection columns = cf.getSortedColumns(); + ColumnFamily cf = cfStore.getColumnFamily(key, getBytes(0), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1000); + Collection columns = cf.getSortedColumns(); assertEquals(12, columns.size()); - Iterator iter = columns.iterator(); - IColumn column; + Iterator iter = columns.iterator(); + Column column; for (int j = 0; j < 8; j++) { column = iter.next(); @@ -109,7 +108,7 @@ public class TimeSortTest extends SchemaLoader TreeSet columnNames = new TreeSet(LongType.instance); columnNames.add(getBytes(10)); columnNames.add(getBytes(0)); - cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("900"), new QueryPath("StandardLong1"), columnNames)); + cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("900"), "StandardLong1", columnNames)); assert "c".equals(ByteBufferUtil.string(cf.getColumn(getBytes(0)).value())); assert "c".equals(ByteBufferUtil.string(cf.getColumn(getBytes(10)).value())); } @@ -121,11 +120,11 @@ public class TimeSortTest extends SchemaLoader DecoratedKey key = Util.dk(Integer.toString(i)); for (int j = 0; j < 8; j += 3) { - ColumnFamily cf = table.getColumnFamilyStore("StandardLong1").getColumnFamily(key, new QueryPath("StandardLong1"), getBytes(j * 2), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1000); - Collection columns = cf.getSortedColumns(); + ColumnFamily cf = table.getColumnFamilyStore("StandardLong1").getColumnFamily(key, getBytes(j * 2), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1000); + Collection columns = cf.getSortedColumns(); assert columns.size() == 8 - j; int k = j; - for (IColumn c : columns) + for (Column c : columns) { assertEquals((k++) * 2, c.timestamp()); diff --git a/test/unit/org/apache/cassandra/db/compaction/CompactionsPurgeTest.java b/test/unit/org/apache/cassandra/db/compaction/CompactionsPurgeTest.java index deac172c1a..7511002b30 100644 --- a/test/unit/org/apache/cassandra/db/compaction/CompactionsPurgeTest.java +++ b/test/unit/org/apache/cassandra/db/compaction/CompactionsPurgeTest.java @@ -28,15 +28,13 @@ import junit.framework.Assert; import org.junit.Test; import org.apache.cassandra.SchemaLoader; -import org.apache.cassandra.db.IColumn; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.Table; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.RowMutation; import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.ColumnFamilyStore; -import org.apache.cassandra.db.SuperColumn; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.Util; @@ -66,7 +64,7 @@ public class CompactionsPurgeTest extends SchemaLoader rm = new RowMutation(TABLE1, key.key); for (int i = 0; i < 10; i++) { - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(cfName, ByteBufferUtil.bytes(String.valueOf(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } rm.apply(); cfs.forceBlockingFlush(); @@ -75,21 +73,21 @@ public class CompactionsPurgeTest extends SchemaLoader for (int i = 0; i < 10; i++) { rm = new RowMutation(TABLE1, key.key); - rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1); + rm.delete(cfName, ByteBufferUtil.bytes(String.valueOf(i)), 1); rm.apply(); } cfs.forceBlockingFlush(); // resurrect one column rm = new RowMutation(TABLE1, key.key); - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(5))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2); + rm.add(cfName, ByteBufferUtil.bytes(String.valueOf(5)), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2); rm.apply(); cfs.forceBlockingFlush(); // major compact and test that all columns but the resurrected one is completely gone CompactionManager.instance.submitMaximal(cfs, Integer.MAX_VALUE).get(); cfs.invalidateCachedRow(key); - ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName))); + ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, cfName)); assertColumns(cf, "5"); assert cf.getColumn(ByteBufferUtil.bytes(String.valueOf(5))) != null; } @@ -111,7 +109,7 @@ public class CompactionsPurgeTest extends SchemaLoader rm = new RowMutation(TABLE2, key.key); for (int i = 0; i < 10; i++) { - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(cfName, ByteBufferUtil.bytes(String.valueOf(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } rm.apply(); cfs.forceBlockingFlush(); @@ -120,7 +118,7 @@ public class CompactionsPurgeTest extends SchemaLoader for (int i = 0; i < 10; i++) { rm = new RowMutation(TABLE2, key.key); - rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1); + rm.delete(cfName, ByteBufferUtil.bytes(String.valueOf(i)), 1); rm.apply(); } cfs.forceBlockingFlush(); @@ -134,19 +132,19 @@ public class CompactionsPurgeTest extends SchemaLoader cfs.forceBlockingFlush(); Collection sstablesIncomplete = cfs.getSSTables(); rm = new RowMutation(TABLE2, key1.key); - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(5))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2); + rm.add(cfName, ByteBufferUtil.bytes(String.valueOf(5)), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2); rm.apply(); cfs.forceBlockingFlush(); new CompactionTask(cfs, sstablesIncomplete, Integer.MAX_VALUE).execute(null); // verify that minor compaction does not GC when key is present // in a non-compacted sstable - ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key1, new QueryPath(cfName))); + ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key1, cfName)); Assert.assertEquals(10, cf.getColumnCount()); // verify that minor compaction does GC when key is provably not // present in a non-compacted sstable - cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key2, new QueryPath(cfName))); + cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key2, cfName)); assert cf == null; } @@ -162,25 +160,25 @@ public class CompactionsPurgeTest extends SchemaLoader DecoratedKey key3 = Util.dk("key3"); // inserts rm = new RowMutation(TABLE2, key3.key); - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes("c1")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 8); - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes("c2")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 8); + rm.add(cfName, ByteBufferUtil.bytes("c1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 8); + rm.add(cfName, ByteBufferUtil.bytes("c2"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 8); rm.apply(); cfs.forceBlockingFlush(); // deletes rm = new RowMutation(TABLE2, key3.key); - rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes("c1")), 10); + rm.delete(cfName, ByteBufferUtil.bytes("c1"), 10); rm.apply(); cfs.forceBlockingFlush(); Collection sstablesIncomplete = cfs.getSSTables(); // delete so we have new delete in a diffrent SST. rm = new RowMutation(TABLE2, key3.key); - rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes("c2")), 9); + rm.delete(cfName, ByteBufferUtil.bytes("c2"), 9); rm.apply(); cfs.forceBlockingFlush(); new CompactionTask(cfs, sstablesIncomplete, Integer.MAX_VALUE).execute(null); - ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key3, new QueryPath(cfName))); + ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key3, cfName)); Assert.assertTrue(!cf.getColumn(ByteBufferUtil.bytes("c2")).isLive()); Assert.assertEquals(1, cf.getColumnCount()); } @@ -201,7 +199,7 @@ public class CompactionsPurgeTest extends SchemaLoader rm = new RowMutation(TABLE1, key.key); for (int i = 0; i < 5; i++) { - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(cfName, ByteBufferUtil.bytes(String.valueOf(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } rm.apply(); @@ -209,7 +207,7 @@ public class CompactionsPurgeTest extends SchemaLoader for (int i = 0; i < 5; i++) { rm = new RowMutation(TABLE1, key.key); - rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1); + rm.delete(cfName, ByteBufferUtil.bytes(String.valueOf(i)), 1); rm.apply(); } cfs.forceBlockingFlush(); @@ -218,7 +216,7 @@ public class CompactionsPurgeTest extends SchemaLoader // compact and test that the row is completely gone Util.compactAll(cfs).get(); assert cfs.getSSTables().isEmpty(); - ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName))); + ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(QueryFilter.getIdentityFilter(key, cfName)); assert cf == null : cf; } @@ -239,16 +237,16 @@ public class CompactionsPurgeTest extends SchemaLoader rm = new RowMutation(tableName, key.key); for (int i = 0; i < 10; i++) { - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(cfName, ByteBufferUtil.bytes(String.valueOf(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } rm.apply(); // move the key up in row cache - cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName))); + cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, cfName)); // deletes row rm = new RowMutation(tableName, key.key); - rm.delete(new QueryPath(cfName, null, null), 1); + rm.delete(cfName, 1); rm.apply(); // flush and major compact @@ -259,14 +257,14 @@ public class CompactionsPurgeTest extends SchemaLoader rm = new RowMutation(tableName, key.key); for (int i = 0; i < 10; i++) { - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(cfName, ByteBufferUtil.bytes(String.valueOf(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } rm.apply(); // Check that the second insert did went in - ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName))); + ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, cfName)); assertEquals(10, cf.getColumnCount()); - for (IColumn c : cf) + for (Column c : cf) assert !c.isMarkedForDelete(); } @@ -287,13 +285,13 @@ public class CompactionsPurgeTest extends SchemaLoader rm = new RowMutation(tableName, key.key); for (int i = 0; i < 10; i++) { - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, i); + rm.add(cfName, ByteBufferUtil.bytes(String.valueOf(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, i); } rm.apply(); // deletes row with timestamp such that not all columns are deleted rm = new RowMutation(tableName, key.key); - rm.delete(new QueryPath(cfName, null, null), 4); + rm.delete(cfName, 4); rm.apply(); // flush and major compact (with tombstone purging) @@ -304,61 +302,14 @@ public class CompactionsPurgeTest extends SchemaLoader rm = new RowMutation(tableName, key.key); for (int i = 0; i < 5; i++) { - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, i); + rm.add(cfName, ByteBufferUtil.bytes(String.valueOf(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, i); } rm.apply(); // Check that the second insert did went in - ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName))); + ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, cfName)); assertEquals(10, cf.getColumnCount()); - for (IColumn c : cf) + for (Column c : cf) assert !c.isMarkedForDelete(); } - - @Test - public void testCompactionPurgeTombstonedSuperColumn() throws IOException, ExecutionException, InterruptedException - { - CompactionManager.instance.disableAutoCompaction(); - - String tableName = "Keyspace1"; - String cfName = "Super5"; - Table table = Table.open(tableName); - ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName); - - DecoratedKey key = Util.dk("key5"); - RowMutation rm; - - ByteBuffer scName = ByteBufferUtil.bytes("sc"); - - // inserts - rm = new RowMutation(tableName, key.key); - for (int i = 0; i < 10; i++) - { - rm.add(new QueryPath(cfName, scName, ByteBuffer.wrap(String.valueOf(i).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, i); - } - rm.apply(); - - // deletes supercolumn with timestamp such that not all columns go - rm = new RowMutation(tableName, key.key); - rm.delete(new QueryPath(cfName, scName, null), 4); - rm.apply(); - - // flush and major compact - cfs.forceBlockingFlush(); - Util.compactAll(cfs).get(); - - // re-inserts with timestamp lower than delete - rm = new RowMutation(tableName, key.key); - for (int i = 0; i < 5; i++) - { - rm.add(new QueryPath(cfName, scName, ByteBuffer.wrap(String.valueOf(i).getBytes())), ByteBufferUtil.EMPTY_BYTE_BUFFER, i); - } - rm.apply(); - - // Check that the second insert did went in - ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName))); - SuperColumn sc = (SuperColumn)cf.getColumn(scName); - assert sc != null; - assertEquals(10, sc.getColumnCount()); - } } diff --git a/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java b/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java index b013d6df69..efef7bdce1 100644 --- a/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java +++ b/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java @@ -36,7 +36,7 @@ import org.apache.cassandra.db.*; import org.apache.cassandra.db.columniterator.IdentityQueryFilter; import org.apache.cassandra.db.columniterator.OnDiskAtomIterator; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.io.sstable.SSTableScanner; import org.apache.cassandra.io.util.FileUtils; @@ -78,7 +78,7 @@ public class CompactionsTest extends SchemaLoader DecoratedKey key = Util.dk(Integer.toString(i)); RowMutation rm = new RowMutation(TABLE1, key.key); for (int j = 0; j < 10; j++) - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(Integer.toString(j))), + rm.add("Standard1", ByteBufferUtil.bytes(Integer.toString(j)), ByteBufferUtil.EMPTY_BYTE_BUFFER, timestamp, j > 0 ? 3 : 0); // let first column never expire, since deleting all columns does not produce sstable @@ -138,7 +138,7 @@ public class CompactionsTest extends SchemaLoader // a subcolumn RowMutation rm = new RowMutation(TABLE1, key.key); - rm.add(new QueryPath("Super1", scName, ByteBufferUtil.bytes(0)), + rm.add("Super1", CompositeType.build(scName, ByteBufferUtil.bytes(0)), ByteBufferUtil.EMPTY_BYTE_BUFFER, FBUtilities.timestampMicros()); rm.apply(); @@ -146,7 +146,7 @@ public class CompactionsTest extends SchemaLoader // shadow the subcolumn with a supercolumn tombstone rm = new RowMutation(TABLE1, key.key); - rm.delete(new QueryPath("Super1", scName), FBUtilities.timestampMicros()); + rm.deleteRange("Super1", SuperColumns.startOf(scName), SuperColumns.endOf(scName), FBUtilities.timestampMicros()); rm.apply(); cfs.forceBlockingFlush(); @@ -155,12 +155,12 @@ public class CompactionsTest extends SchemaLoader // check that the shadowed column is gone SSTableReader sstable = cfs.getSSTables().iterator().next(); - SSTableScanner scanner = sstable.getScanner(new QueryFilter(null, new QueryPath("Super1", scName), new IdentityQueryFilter())); + SSTableScanner scanner = sstable.getScanner(new QueryFilter(null, "Super1", new IdentityQueryFilter())); scanner.seekTo(key); OnDiskAtomIterator iter = scanner.next(); assertEquals(key, iter.getKey()); - SuperColumn sc = (SuperColumn) iter.next(); - assert sc.getSubColumns().isEmpty(); + assert iter.next() instanceof RangeTombstone; + assert !iter.hasNext(); } public static void assertMaxTimestamp(ColumnFamilyStore cfs, long maxTimestampExpected) @@ -188,7 +188,7 @@ public class CompactionsTest extends SchemaLoader { DecoratedKey key = Util.dk(String.valueOf(i)); RowMutation rm = new RowMutation(TABLE1, key.key); - rm.add(new QueryPath("Standard2", null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, i); + rm.add("Standard2", ByteBufferUtil.bytes(String.valueOf(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, i); rm.apply(); if (i % 2 == 0) @@ -203,7 +203,7 @@ public class CompactionsTest extends SchemaLoader { DecoratedKey key = Util.dk(String.valueOf(i)); RowMutation rm = new RowMutation(TABLE1, key.key); - rm.add(new QueryPath("Standard2", null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, i); + rm.add("Standard2", ByteBufferUtil.bytes(String.valueOf(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, i); rm.apply(); } cfs.forceBlockingFlush(); @@ -250,19 +250,19 @@ public class CompactionsTest extends SchemaLoader // Add test row DecoratedKey key = Util.dk(k); RowMutation rm = new RowMutation(TABLE1, key.key); - rm.add(new QueryPath(cfname, ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes("c")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(cfname, CompositeType.build(ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes("c")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); rm.apply(); cfs.forceBlockingFlush(); Collection sstablesBefore = cfs.getSSTables(); - QueryFilter filter = QueryFilter.getIdentityFilter(key, new QueryPath(cfname, null, null)); + QueryFilter filter = QueryFilter.getIdentityFilter(key, cfname); assert !cfs.getColumnFamily(filter).isEmpty(); // Remove key rm = new RowMutation(TABLE1, key.key); - rm.delete(new QueryPath(cfname, null, null), 2); + rm.delete(cfname, 2); rm.apply(); ColumnFamily cf = cfs.getColumnFamily(filter); @@ -306,7 +306,7 @@ public class CompactionsTest extends SchemaLoader DecoratedKey key = Util.dk(String.valueOf(i % 2)); RowMutation rm = new RowMutation(TABLE1, key.key); long timestamp = j * ROWS_PER_SSTABLE + i; - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(String.valueOf(i / 2))), + rm.add("Standard1", ByteBufferUtil.bytes(String.valueOf(i / 2)), ByteBufferUtil.EMPTY_BYTE_BUFFER, timestamp); maxTimestampExpected = Math.max(timestamp, maxTimestampExpected); diff --git a/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java b/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java index 6a329c3c3a..e9cf236ec6 100644 --- a/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java +++ b/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java @@ -28,7 +28,6 @@ import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.RowMutation; import org.apache.cassandra.db.Table; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.dht.Range; import org.apache.cassandra.dht.Token; import org.apache.cassandra.io.sstable.SSTable; @@ -63,7 +62,7 @@ public class LeveledCompactionStrategyTest extends SchemaLoader RowMutation rm = new RowMutation(ksname, key.key); for (int c = 0; c < columns; c++) { - rm.add(new QueryPath(cfname, null, ByteBufferUtil.bytes("column" + c)), value, 0); + rm.add(cfname, ByteBufferUtil.bytes("column" + c), value, 0); } rm.apply(); store.forceBlockingFlush(); @@ -105,7 +104,7 @@ public class LeveledCompactionStrategyTest extends SchemaLoader RowMutation rm = new RowMutation(ksname, key.key); for (int c = 0; c < columns; c++) { - rm.add(new QueryPath(cfname, null, ByteBufferUtil.bytes("column" + c)), value, 0); + rm.add(cfname, ByteBufferUtil.bytes("column" + c), value, 0); } rm.apply(); store.forceBlockingFlush(); diff --git a/test/unit/org/apache/cassandra/db/compaction/OneCompactionTest.java b/test/unit/org/apache/cassandra/db/compaction/OneCompactionTest.java index 67906c581b..fb5ee93563 100644 --- a/test/unit/org/apache/cassandra/db/compaction/OneCompactionTest.java +++ b/test/unit/org/apache/cassandra/db/compaction/OneCompactionTest.java @@ -33,7 +33,6 @@ import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.RowMutation; import org.apache.cassandra.db.ColumnFamilyStore; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.utils.ByteBufferUtil; @@ -51,7 +50,7 @@ public class OneCompactionTest extends SchemaLoader for (int j = 0; j < insertsPerTable; j++) { DecoratedKey key = Util.dk(String.valueOf(j)); RowMutation rm = new RowMutation("Keyspace1", key.key); - rm.add(new QueryPath(columnFamilyName, null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); + rm.add(columnFamilyName, ByteBufferUtil.bytes("0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); rm.apply(); inserted.add(key); store.forceBlockingFlush(); diff --git a/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java b/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java index 2ed715ef16..5fd98a9bb6 100644 --- a/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java +++ b/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java @@ -35,7 +35,6 @@ import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.SyntaxException; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.utils.*; public class CompositeTypeTest extends SchemaLoader @@ -182,9 +181,9 @@ public class CompositeTypeTest extends SchemaLoader addColumn(rm, cname3); rm.apply(); - ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("k"), new QueryPath(cfName, null, null))); + ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("k"), cfName)); - Iterator iter = cf.getSortedColumns().iterator(); + Iterator iter = cf.getSortedColumns().iterator(); assert iter.next().name().equals(cname1); assert iter.next().name().equals(cname2); @@ -258,7 +257,7 @@ public class CompositeTypeTest extends SchemaLoader private void addColumn(RowMutation rm, ByteBuffer cname) { - rm.add(new QueryPath(cfName, null , cname), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(cfName, cname, ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } private ByteBuffer createCompositeKey(String s, UUID uuid, int i, boolean lastIsOne) diff --git a/test/unit/org/apache/cassandra/db/marshal/DynamicCompositeTypeTest.java b/test/unit/org/apache/cassandra/db/marshal/DynamicCompositeTypeTest.java index af9e85a4d0..f681403da7 100644 --- a/test/unit/org/apache/cassandra/db/marshal/DynamicCompositeTypeTest.java +++ b/test/unit/org/apache/cassandra/db/marshal/DynamicCompositeTypeTest.java @@ -31,7 +31,6 @@ import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.utils.*; public class DynamicCompositeTypeTest extends SchemaLoader @@ -180,9 +179,9 @@ public class DynamicCompositeTypeTest extends SchemaLoader addColumn(rm, cname3); rm.apply(); - ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("k"), new QueryPath(cfName, null, null))); + ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("k"), cfName)); - Iterator iter = cf.getSortedColumns().iterator(); + Iterator iter = cf.getSortedColumns().iterator(); assert iter.next().name().equals(cname1); assert iter.next().name().equals(cname2); @@ -231,7 +230,7 @@ public class DynamicCompositeTypeTest extends SchemaLoader private void addColumn(RowMutation rm, ByteBuffer cname) { - rm.add(new QueryPath(cfName, null , cname), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add(cfName, cname, ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); } private ByteBuffer createDynamicCompositeKey(String s, UUID uuid, int i, boolean lastIsOne) diff --git a/test/unit/org/apache/cassandra/io/LazilyCompactedRowTest.java b/test/unit/org/apache/cassandra/io/LazilyCompactedRowTest.java index ccb5b2c72a..eff932cda2 100644 --- a/test/unit/org/apache/cassandra/io/LazilyCompactedRowTest.java +++ b/test/unit/org/apache/cassandra/io/LazilyCompactedRowTest.java @@ -35,7 +35,6 @@ import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.*; import org.apache.cassandra.db.compaction.*; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.sstable.SSTableIdentityIterator; import org.apache.cassandra.io.sstable.SSTableReader; @@ -128,8 +127,8 @@ public class LazilyCompactedRowTest extends SchemaLoader assert columns == in2.readInt(); for (int i = 0; i < columns; i++) { - IColumn c1 = (IColumn)cf1.getOnDiskSerializer().deserializeFromSSTable(in1, Descriptor.Version.CURRENT); - IColumn c2 = (IColumn)cf2.getOnDiskSerializer().deserializeFromSSTable(in2, Descriptor.Version.CURRENT); + Column c1 = (Column)Column.onDiskSerializer().deserializeFromSSTable(in1, Descriptor.Version.CURRENT); + Column c2 = (Column)Column.onDiskSerializer().deserializeFromSSTable(in2, Descriptor.Version.CURRENT); assert c1.equals(c2) : c1.getString(cfs.metadata.comparator) + " != " + c2.getString(cfs.metadata.comparator); } // that should be everything @@ -177,7 +176,7 @@ public class LazilyCompactedRowTest extends SchemaLoader ByteBuffer key = ByteBufferUtil.bytes("k"); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("c")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add("Standard1", ByteBufferUtil.bytes("c"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); rm.apply(); cfs.forceBlockingFlush(); @@ -195,8 +194,8 @@ public class LazilyCompactedRowTest extends SchemaLoader ByteBuffer key = ByteBufferUtil.bytes("k"); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("c")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("d")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add("Standard1", ByteBufferUtil.bytes("c"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add("Standard1", ByteBufferUtil.bytes("d"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); rm.apply(); cfs.forceBlockingFlush(); @@ -215,7 +214,7 @@ public class LazilyCompactedRowTest extends SchemaLoader ByteBuffer key = ByteBuffer.wrap("k".getBytes()); RowMutation rm = new RowMutation("Keyspace1", key); for (int i = 0; i < 1000; i++) - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add("Standard1", ByteBufferUtil.bytes(i), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); rm.apply(); DataOutputBuffer out = new DataOutputBuffer(); RowMutation.serializer.serialize(rm, out, MessagingService.current_version); @@ -236,7 +235,7 @@ public class LazilyCompactedRowTest extends SchemaLoader ByteBuffer key = ByteBufferUtil.bytes("k"); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("c")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add("Standard1", ByteBufferUtil.bytes("c"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); rm.apply(); cfs.forceBlockingFlush(); @@ -257,8 +256,8 @@ public class LazilyCompactedRowTest extends SchemaLoader ByteBuffer key = ByteBufferUtil.bytes("k"); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("c")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("d")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add("Standard1", ByteBufferUtil.bytes("c"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); + rm.add("Standard1", ByteBufferUtil.bytes("d"), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); rm.apply(); cfs.forceBlockingFlush(); @@ -284,7 +283,7 @@ public class LazilyCompactedRowTest extends SchemaLoader { ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(i % 2)); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(String.valueOf(i / 2))), ByteBufferUtil.EMPTY_BYTE_BUFFER, j * ROWS_PER_SSTABLE + i); + rm.add("Standard1", ByteBufferUtil.bytes(String.valueOf(i / 2)), ByteBufferUtil.EMPTY_BYTE_BUFFER, j * ROWS_PER_SSTABLE + i); rm.apply(); } cfs.forceBlockingFlush(); @@ -294,28 +293,6 @@ public class LazilyCompactedRowTest extends SchemaLoader assertDigest(cfs, Integer.MAX_VALUE); } - @Test - public void testTwoRowSuperColumn() throws IOException, ExecutionException, InterruptedException - { - CompactionManager.instance.disableAutoCompaction(); - - Table table = Table.open("Keyspace4"); - ColumnFamilyStore cfs = table.getColumnFamilyStore("Super5"); - - ByteBuffer key = ByteBufferUtil.bytes("k"); - RowMutation rm = new RowMutation("Keyspace4", key); - ByteBuffer scKey = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes()); - rm.add(new QueryPath("Super5", scKey , ByteBufferUtil.bytes("c")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0); - rm.apply(); - cfs.forceBlockingFlush(); - - rm.apply(); - cfs.forceBlockingFlush(); - - assertBytes(cfs, Integer.MAX_VALUE); - } - - private static class LazilyCompactingController extends CompactionController { public LazilyCompactingController(ColumnFamilyStore cfs, Collection sstables, int gcBefore, boolean forceDeserialize) diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java index 1026301e3d..6e1e5c2e49 100644 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java @@ -38,7 +38,6 @@ import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.*; import org.apache.cassandra.db.columniterator.IdentityQueryFilter; import org.apache.cassandra.db.compaction.CompactionManager; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.LocalPartitioner; import org.apache.cassandra.dht.LocalToken; @@ -75,7 +74,7 @@ public class SSTableReaderTest extends SchemaLoader { ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j)); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard2", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); + rm.add("Standard2", ByteBufferUtil.bytes("0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); rm.apply(); } store.forceBlockingFlush(); @@ -116,7 +115,7 @@ public class SSTableReaderTest extends SchemaLoader { ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j)); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); + rm.add("Standard1", ByteBufferUtil.bytes("0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); rm.apply(); } store.forceBlockingFlush(); @@ -153,7 +152,7 @@ public class SSTableReaderTest extends SchemaLoader { ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j)); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); + rm.add("Standard1", ByteBufferUtil.bytes("0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); rm.apply(); } store.forceBlockingFlush(); @@ -181,7 +180,7 @@ public class SSTableReaderTest extends SchemaLoader { ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j)); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Standard2", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); + rm.add("Standard2", ByteBufferUtil.bytes("0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, j); rm.apply(); } store.forceBlockingFlush(); @@ -210,7 +209,7 @@ public class SSTableReaderTest extends SchemaLoader ColumnFamilyStore store = table.getColumnFamilyStore("Indexed1"); ByteBuffer key = ByteBufferUtil.bytes(String.valueOf("k1")); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), System.currentTimeMillis()); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), System.currentTimeMillis()); rm.apply(); store.forceBlockingFlush(); @@ -270,7 +269,7 @@ public class SSTableReaderTest extends SchemaLoader if (store.metadata.getKeyValidator().compare(lastKey.key, key.key) < 0) lastKey = key; RowMutation rm = new RowMutation(ks, key.key); - rm.add(new QueryPath(cf, null, ByteBufferUtil.bytes("col")), + rm.add(cf, ByteBufferUtil.bytes("col"), ByteBufferUtil.EMPTY_BYTE_BUFFER, timestamp); rm.apply(); } @@ -294,7 +293,7 @@ public class SSTableReaderTest extends SchemaLoader ColumnFamilyStore store = table.getColumnFamilyStore("Indexed1"); ByteBuffer key = ByteBufferUtil.bytes(String.valueOf("k1")); RowMutation rm = new RowMutation("Keyspace1", key); - rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), System.currentTimeMillis()); + rm.add("Indexed1", ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(1L), System.currentTimeMillis()); rm.apply(); store.forceBlockingFlush(); diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableSimpleWriterTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableSimpleWriterTest.java index 6efdc9b97b..1b14613df2 100644 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableSimpleWriterTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableSimpleWriterTest.java @@ -92,7 +92,7 @@ public class SSTableSimpleWriterTest extends SchemaLoader ColumnFamily cf = Util.getColumnFamily(t, Util.dk("Key10"), cfname); assert cf.getColumnCount() == INC * NBCOL : "expecting " + (INC * NBCOL) + " columns, got " + cf.getColumnCount(); int i = 0; - for (IColumn c : cf) + for (Column c : cf) { assert toInt(c.name()) == i : "Column name should be " + i + ", got " + toInt(c.name()); assert c.value().equals(bytes("v")); diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java index 12f2747a42..40ec0be071 100644 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java @@ -41,7 +41,7 @@ public class SSTableTest extends SchemaLoader ByteBuffer cbytes = ByteBuffer.wrap(new byte[1024]); new Random().nextBytes(cbytes.array()); ColumnFamily cf = ColumnFamily.create("Keyspace1", "Standard1"); - cf.addColumn(null, new Column(cbytes, cbytes)); + cf.addColumn(new Column(cbytes, cbytes)); SortedMap map = new TreeMap(); map.put(Util.dk(key), cf); @@ -75,7 +75,7 @@ public class SSTableTest extends SchemaLoader { ColumnFamily cf = ColumnFamily.create("Keyspace1", "Standard2"); ByteBuffer bytes = ByteBufferUtil.bytes(("Avinash Lakshman is a good man: " + i)); - cf.addColumn(null, new Column(bytes, bytes)); + cf.addColumn(new Column(bytes, bytes)); map.put(Util.dk(Integer.toString(i)), cf); bytesMap.put(ByteBufferUtil.bytes(Integer.toString(i)), Util.serializeForSSTable(cf)); } diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java b/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java index 2b0a13ae15..03759afb6e 100644 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableUtils.java @@ -27,7 +27,6 @@ import org.apache.cassandra.db.Column; import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.DeletionInfo; -import org.apache.cassandra.db.IColumn; import org.apache.cassandra.db.columniterator.OnDiskAtomIterator; import org.apache.cassandra.utils.ByteBufferUtil; @@ -40,11 +39,11 @@ public class SSTableUtils public static String TABLENAME = "Keyspace1"; public static String CFNAME = "Standard1"; - public static ColumnFamily createCF(long mfda, int ldt, IColumn... cols) + public static ColumnFamily createCF(long mfda, int ldt, Column... cols) { ColumnFamily cf = ColumnFamily.create(TABLENAME, CFNAME); cf.delete(new DeletionInfo(mfda, ldt)); - for (IColumn col : cols) + for (Column col : cols) cf.addColumn(col); return cf; } @@ -102,9 +101,9 @@ public class SSTableUtils // iterate columns while (lhs.hasNext()) { - IColumn clhs = (IColumn)lhs.next(); + Column clhs = (Column)lhs.next(); assert rhs.hasNext() : "LHS contained more columns than RHS for " + lhs.getKey(); - IColumn crhs = (IColumn)rhs.next(); + Column crhs = (Column)rhs.next(); assertEquals("Mismatched columns for " + lhs.getKey(), clhs, crhs); } diff --git a/test/unit/org/apache/cassandra/service/AntiEntropyServiceCounterTest.java b/test/unit/org/apache/cassandra/service/AntiEntropyServiceCounterTest.java index ec0dffc8c3..86897038e5 100644 --- a/test/unit/org/apache/cassandra/service/AntiEntropyServiceCounterTest.java +++ b/test/unit/org/apache/cassandra/service/AntiEntropyServiceCounterTest.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.LinkedList; import org.apache.cassandra.db.*; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.db.ConsistencyLevel; @@ -40,7 +39,7 @@ public class AntiEntropyServiceCounterTest extends AntiEntropyServiceTestAbstrac { List rms = new LinkedList(); RowMutation rm = new RowMutation(tablename, ByteBufferUtil.bytes("key1")); - rm.addCounter(new QueryPath(cfname, null, ByteBufferUtil.bytes("Column1")), 42); + rm.addCounter(cfname, ByteBufferUtil.bytes("Column1"), 42); rms.add(new CounterMutation(rm, ConsistencyLevel.ONE)); return rms; } diff --git a/test/unit/org/apache/cassandra/service/AntiEntropyServiceStandardTest.java b/test/unit/org/apache/cassandra/service/AntiEntropyServiceStandardTest.java index f419c372b8..76b0af2122 100644 --- a/test/unit/org/apache/cassandra/service/AntiEntropyServiceStandardTest.java +++ b/test/unit/org/apache/cassandra/service/AntiEntropyServiceStandardTest.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.LinkedList; import org.apache.cassandra.db.*; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.utils.ByteBufferUtil; public class AntiEntropyServiceStandardTest extends AntiEntropyServiceTestAbstract @@ -40,7 +39,7 @@ public class AntiEntropyServiceStandardTest extends AntiEntropyServiceTestAbstra List rms = new LinkedList(); RowMutation rm; rm = new RowMutation(tablename, ByteBufferUtil.bytes("key1")); - rm.add(new QueryPath(cfname, null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdfasdf"), 0); + rm.add(cfname, ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("asdfasdf"), 0); rms.add(rm); return rms; } diff --git a/test/unit/org/apache/cassandra/service/CassandraServerTest.java b/test/unit/org/apache/cassandra/service/CassandraServerTest.java index af2d1c779b..7bd0b8bb6f 100644 --- a/test/unit/org/apache/cassandra/service/CassandraServerTest.java +++ b/test/unit/org/apache/cassandra/service/CassandraServerTest.java @@ -27,7 +27,6 @@ import org.apache.cassandra.Util; import org.apache.cassandra.config.Schema; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.RowMutation; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.thrift.*; import org.apache.cassandra.utils.ByteBufferUtil; @@ -48,9 +47,7 @@ public class CassandraServerTest extends SchemaLoader for (int i = 0; i < 3050; i++) { RowMutation rm = new RowMutation("Keyspace1", key.key); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(String.valueOf(i))), - ByteBufferUtil.EMPTY_BYTE_BUFFER, - System.currentTimeMillis()); + rm.add("Standard1", ByteBufferUtil.bytes(String.valueOf(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, System.currentTimeMillis()); rm.apply(); } diff --git a/test/unit/org/apache/cassandra/service/RowResolverTest.java b/test/unit/org/apache/cassandra/service/RowResolverTest.java index 3c530f1c56..3373fd0422 100644 --- a/test/unit/org/apache/cassandra/service/RowResolverTest.java +++ b/test/unit/org/apache/cassandra/service/RowResolverTest.java @@ -28,11 +28,9 @@ import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.DeletionInfo; -import org.apache.cassandra.db.SuperColumn; import static junit.framework.Assert.*; import static org.apache.cassandra.Util.column; -import static org.apache.cassandra.Util.superColumn; import static org.apache.cassandra.db.TableTest.*; public class RowResolverTest extends SchemaLoader @@ -112,37 +110,6 @@ public class RowResolverTest extends SchemaLoader assertColumns(resolved); assertTrue(resolved.isMarkedForDelete()); assertEquals(1, resolved.deletionInfo().getTopLevelDeletion().markedForDeleteAt); - - ColumnFamily scf1 = ColumnFamily.create("Keyspace1", "Super1"); - scf1.addColumn(superColumn(scf1, "super-foo", column("one", "A", 0))); - - ColumnFamily scf2 = ColumnFamily.create("Keyspace1", "Super1"); - scf2.delete(new DeletionInfo(1L, (int) (System.currentTimeMillis() / 1000))); - - ColumnFamily superResolved = RowRepairResolver.resolveSuperset(Arrays.asList(scf1, scf2)); - // no columns in the cf - assertColumns(superResolved); - assertTrue(superResolved.isMarkedForDelete()); - assertEquals(1, superResolved.deletionInfo().getTopLevelDeletion().markedForDeleteAt); - } - - @Test - public void testResolveDeletedSuper() - { - // subcolumn is newer than a tombstone on its parent, but not newer than the row deletion - ColumnFamily scf1 = ColumnFamily.create("Keyspace1", "Super1"); - SuperColumn sc = superColumn(scf1, "super-foo", column("one", "A", 1)); - sc.delete(new DeletionInfo(0L, (int) (System.currentTimeMillis() / 1000))); - scf1.addColumn(sc); - - ColumnFamily scf2 = ColumnFamily.create("Keyspace1", "Super1"); - scf2.delete(new DeletionInfo(2L, (int) (System.currentTimeMillis() / 1000))); - - ColumnFamily superResolved = RowRepairResolver.resolveSuperset(Arrays.asList(scf1, scf2)); - // no columns in the cf - assertColumns(superResolved); - assertTrue(superResolved.isMarkedForDelete()); - assertEquals(2, superResolved.deletionInfo().getTopLevelDeletion().markedForDeleteAt); } @Test @@ -171,35 +138,5 @@ public class RowResolverTest extends SchemaLoader assertColumn(resolved, "two", "B", 3); assertTrue(resolved.isMarkedForDelete()); assertEquals(2, resolved.deletionInfo().getTopLevelDeletion().markedForDeleteAt); - - - ColumnFamily scf1 = ColumnFamily.create("Keyspace1", "Super1"); - scf1.delete(new DeletionInfo(0L, (int) (System.currentTimeMillis() / 1000))); - - // these columns created after the previous deletion - ColumnFamily scf2 = ColumnFamily.create("Keyspace1", "Super1"); - scf2.addColumn(superColumn(scf2, "super1", column("one", "A", 1), column("two", "A", 1))); - - //these columns created after the next delete - ColumnFamily scf3 = ColumnFamily.create("Keyspace1", "Super1"); - scf3.addColumn(superColumn(scf3, "super1", column("two", "B", 3))); - scf3.addColumn(superColumn(scf3, "super2", column("three", "A", 3), column("four", "A", 3))); - - ColumnFamily scf4 = ColumnFamily.create("Keyspace1", "Super1"); - scf4.delete(new DeletionInfo(2L, (int) (System.currentTimeMillis() / 1000))); - - ColumnFamily superResolved = RowRepairResolver.resolveSuperset(Arrays.asList(scf1, scf2, scf3, scf4)); - // will have deleted marker and two super cols - assertColumns(superResolved, "super1", "super2"); - - assertSubColumns(superResolved, "super1", "two"); - assertSubColumn(superResolved, "super1", "two", "B", 3); - - assertSubColumns(superResolved, "super2", "four", "three"); - assertSubColumn(superResolved, "super2", "three", "A", 3); - assertSubColumn(superResolved, "super2", "four", "A", 3); - - assertTrue(superResolved.isMarkedForDelete()); - assertEquals(2, superResolved.deletionInfo().getTopLevelDeletion().markedForDeleteAt); } } diff --git a/test/unit/org/apache/cassandra/streaming/BootstrapTest.java b/test/unit/org/apache/cassandra/streaming/BootstrapTest.java index 1af3074977..ab7296aec4 100644 --- a/test/unit/org/apache/cassandra/streaming/BootstrapTest.java +++ b/test/unit/org/apache/cassandra/streaming/BootstrapTest.java @@ -36,7 +36,7 @@ public class BootstrapTest extends SchemaLoader @Test public void testGetNewNames() throws IOException { - Descriptor desc = Descriptor.fromFilename(new File("Keyspace1", "Keyspace1-Standard1-ib-500-Data.db").toString()); + Descriptor desc = Descriptor.fromFilename(new File("Keyspace1", "Keyspace1-Standard1-ic-500-Data.db").toString()); // assert !desc.isLatestVersion; // minimum compatible version -- for now it is the latest as well PendingFile inContext = new PendingFile(null, desc, "Data.db", Arrays.asList(Pair.create(0L, 1L)), OperationType.BOOTSTRAP); diff --git a/test/unit/org/apache/cassandra/streaming/SerializationsTest.java b/test/unit/org/apache/cassandra/streaming/SerializationsTest.java index 5ebbc138d5..a81febaf05 100644 --- a/test/unit/org/apache/cassandra/streaming/SerializationsTest.java +++ b/test/unit/org/apache/cassandra/streaming/SerializationsTest.java @@ -30,7 +30,6 @@ import org.apache.cassandra.AbstractSerializationsTester; import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.RowMutation; import org.apache.cassandra.db.Table; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.dht.BytesToken; import org.apache.cassandra.dht.Range; import org.apache.cassandra.dht.Token; @@ -205,7 +204,7 @@ public class SerializationsTest extends AbstractSerializationsTester for (int i = 0; i < 100; i++) { RowMutation rm = new RowMutation(t.getName(), ByteBufferUtil.bytes(Long.toString(System.nanoTime()))); - rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("cola")), ByteBufferUtil.bytes("value"), 0); + rm.add("Standard1", ByteBufferUtil.bytes("cola"), ByteBufferUtil.bytes("value"), 0); rm.apply(); } try diff --git a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java index 86469e149b..07b19ae49b 100644 --- a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java +++ b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java @@ -33,7 +33,6 @@ import org.apache.cassandra.db.columniterator.IdentityQueryFilter; import org.apache.cassandra.db.context.CounterContext; import org.apache.cassandra.db.filter.IDiskAtomFilter; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.Range; import org.apache.cassandra.dht.Token; @@ -96,7 +95,7 @@ public class StreamingTransferTest extends SchemaLoader { String key = "key" + offs[i]; String col = "col" + offs[i]; - assert cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk(key), new QueryPath(cfs.name))) != null; + assert cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk(key), cfs.name)) != null; assert rows.get(i).key.key.equals(ByteBufferUtil.bytes(key)); assert rows.get(i).cf.getColumn(ByteBufferUtil.bytes(col)) != null; } @@ -161,23 +160,6 @@ public class StreamingTransferTest extends SchemaLoader } } - @Test - public void testTransferTableSuper() throws Exception - { - final Table table = Table.open("Keyspace1"); - final ColumnFamilyStore cfs = table.getColumnFamilyStore("Super1"); - - createAndTransfer(table, cfs, new Mutator() - { - public void mutate(String key, String col, long timestamp) throws Exception - { - RowMutation rm = new RowMutation(table.getName(), ByteBufferUtil.bytes(key)); - addMutation(rm, cfs.name, col, 1, "val1", timestamp); - rm.apply(); - } - }); - } - @Test public void testTransferTableCounter() throws Exception { @@ -274,10 +256,10 @@ public class StreamingTransferTest extends SchemaLoader assert rows.get(1).cf.getColumnCount() == 1; // these keys fall outside of the ranges and should not be transferred - assert cfstore.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("transfer1"), new QueryPath("Standard1"))) == null; - assert cfstore.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("transfer2"), new QueryPath("Standard1"))) == null; - assert cfstore.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("test2"), new QueryPath("Standard1"))) == null; - assert cfstore.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("test3"), new QueryPath("Standard1"))) == null; + assert cfstore.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("transfer1"), "Standard1")) == null; + assert cfstore.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("transfer2"), "Standard1")) == null; + assert cfstore.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("test2"), "Standard1")) == null; + assert cfstore.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("test3"), "Standard1")) == null; } @Test diff --git a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java index aace9efb36..c3a2e20281 100644 --- a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java +++ b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java @@ -40,9 +40,7 @@ import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.CounterColumn; import org.apache.cassandra.db.DeletionInfo; import org.apache.cassandra.db.ExpiringColumn; -import org.apache.cassandra.db.SuperColumn; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; import org.apache.cassandra.db.marshal.UTF8Type; import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.sstable.SSTableReader; @@ -68,12 +66,12 @@ public class SSTableExportTest extends SchemaLoader SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2); // Add rowA - cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colA")), ByteBufferUtil.bytes("valA"), System.currentTimeMillis()); + cfamily.addColumn(ByteBufferUtil.bytes("colA"), ByteBufferUtil.bytes("valA"), System.currentTimeMillis()); writer.append(Util.dk("rowA"), cfamily); cfamily.clear(); // Add rowB - cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colB")), ByteBufferUtil.bytes("valB"), System.currentTimeMillis()); + cfamily.addColumn(ByteBufferUtil.bytes("colB"), ByteBufferUtil.bytes("valB"), System.currentTimeMillis()); writer.append(Util.dk("rowB"), cfamily); cfamily.clear(); @@ -102,18 +100,18 @@ public class SSTableExportTest extends SchemaLoader int nowInSec = (int)(System.currentTimeMillis() / 1000) + 42; //live for 42 seconds // Add rowA - cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colA")), ByteBufferUtil.bytes("valA"), System.currentTimeMillis()); - cfamily.addColumn(null, new ExpiringColumn(ByteBufferUtil.bytes("colExp"), ByteBufferUtil.bytes("valExp"), System.currentTimeMillis(), 42, nowInSec)); + cfamily.addColumn(ByteBufferUtil.bytes("colA"), ByteBufferUtil.bytes("valA"), System.currentTimeMillis()); + cfamily.addColumn(new ExpiringColumn(ByteBufferUtil.bytes("colExp"), ByteBufferUtil.bytes("valExp"), System.currentTimeMillis(), 42, nowInSec)); writer.append(Util.dk("rowA"), cfamily); cfamily.clear(); // Add rowB - cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colB")), ByteBufferUtil.bytes("valB"), System.currentTimeMillis()); + cfamily.addColumn(ByteBufferUtil.bytes("colB"), ByteBufferUtil.bytes("valB"), System.currentTimeMillis()); writer.append(Util.dk("rowB"), cfamily); cfamily.clear(); // Add rowExclude - cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colX")), ByteBufferUtil.bytes("valX"), System.currentTimeMillis()); + cfamily.addColumn(ByteBufferUtil.bytes("colX"), ByteBufferUtil.bytes("valX"), System.currentTimeMillis()); writer.append(Util.dk("rowExclude"), cfamily); cfamily.clear(); @@ -148,56 +146,6 @@ public class SSTableExportTest extends SchemaLoader } - @Test - public void testExportSuperCf() throws IOException, ParseException - { - File tempSS = tempSSTableFile("Keyspace1", "Super4"); - ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Super4"); - SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2); - - // Add rowA - cfamily.addColumn(new QueryPath("Super4", ByteBufferUtil.bytes("superA"), ByteBufferUtil.bytes("colA")), ByteBufferUtil.bytes("valA"), System.currentTimeMillis()); - // set deletion info on the super col - ((SuperColumn) cfamily.getColumn(ByteBufferUtil.bytes("superA"))).setDeletionInfo(new DeletionInfo(0, 0)); - writer.append(Util.dk("rowA"), cfamily); - cfamily.clear(); - - // Add rowB - cfamily.addColumn(new QueryPath("Super4", ByteBufferUtil.bytes("superB"), ByteBufferUtil.bytes("colB")), ByteBufferUtil.bytes("valB"), System.currentTimeMillis()); - writer.append(Util.dk("rowB"), cfamily); - cfamily.clear(); - - // Add rowExclude - cfamily.addColumn(new QueryPath("Super4", ByteBufferUtil.bytes("superX"), ByteBufferUtil.bytes("colX")), ByteBufferUtil.bytes("valX"), System.currentTimeMillis()); - writer.append(Util.dk("rowExclude"), cfamily); - cfamily.clear(); - - SSTableReader reader = writer.closeAndOpenReader(); - - // Export to JSON and verify - File tempJson = File.createTempFile("Super4", ".json"); - SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[] { asHex("rowExclude") }); - - JSONArray json = (JSONArray) JSONValue.parseWithException(new FileReader(tempJson)); - assertEquals("unexpected number of rows", 2, json.size()); - - // make sure only the two rows we expect are there - JSONObject rowA = (JSONObject) json.get(0); - assertEquals("unexpected number of keys", 2, rowA.keySet().size()); - assertEquals("unexpected row key", asHex("rowA"), rowA.get("key")); - JSONObject rowB = (JSONObject) json.get(0); - assertEquals("unexpected number of keys", 2, rowB.keySet().size()); - assertEquals("unexpected row key", asHex("rowA"), rowB.get("key")); - - JSONObject cols = (JSONObject) rowA.get("columns"); - - JSONObject superA = (JSONObject) cols.get(cfamily.getComparator().getString(ByteBufferUtil.bytes("superA"))); - JSONArray subColumns = (JSONArray) superA.get("subColumns"); - JSONArray colA = (JSONArray) subColumns.get(0); - assert hexToBytes((String) colA.get(1)).equals(ByteBufferUtil.bytes("valA")); - assert colA.size() == 3; - } - @Test public void testRoundTripStandardCf() throws IOException, ParseException { @@ -206,12 +154,12 @@ public class SSTableExportTest extends SchemaLoader SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2); // Add rowA - cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("name")), ByteBufferUtil.bytes("val"), System.currentTimeMillis()); + cfamily.addColumn(ByteBufferUtil.bytes("name"), ByteBufferUtil.bytes("val"), System.currentTimeMillis()); writer.append(Util.dk("rowA"), cfamily); cfamily.clear(); // Add rowExclude - cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("name")), ByteBufferUtil.bytes("val"), System.currentTimeMillis()); + cfamily.addColumn(ByteBufferUtil.bytes("name"), ByteBufferUtil.bytes("val"), System.currentTimeMillis()); writer.append(Util.dk("rowExclude"), cfamily); cfamily.clear(); @@ -226,13 +174,13 @@ public class SSTableExportTest extends SchemaLoader new SSTableImport().importJson(tempJson.getPath(), "Keyspace1", "Standard1", tempSS2.getPath()); reader = SSTableReader.open(Descriptor.fromFilename(tempSS2.getPath())); - QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Standard1", null, null), ByteBufferUtil.bytes("name")); + QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), "Standard1", ByteBufferUtil.bytes("name")); ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily(); qf.collateOnDiskAtom(cf, Collections.singletonList(qf.getSSTableColumnIterator(reader)), Integer.MIN_VALUE); assertTrue(cf != null); assertTrue(cf.getColumn(ByteBufferUtil.bytes("name")).value().equals(hexToBytes("76616c"))); - qf = QueryFilter.getNamesFilter(Util.dk("rowExclude"), new QueryPath("Standard1", null, null), ByteBufferUtil.bytes("name")); + qf = QueryFilter.getNamesFilter(Util.dk("rowExclude"), "Standard1", ByteBufferUtil.bytes("name")); cf = qf.getSSTableColumnIterator(reader).getColumnFamily(); assert cf == null; } @@ -245,7 +193,7 @@ public class SSTableExportTest extends SchemaLoader SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2); // Add rowA - cfamily.addColumn(null, new CounterColumn(ByteBufferUtil.bytes("colA"), 42, System.currentTimeMillis())); + cfamily.addColumn(new CounterColumn(ByteBufferUtil.bytes("colA"), 42, System.currentTimeMillis())); writer.append(Util.dk("rowA"), cfamily); cfamily.clear(); @@ -276,7 +224,7 @@ public class SSTableExportTest extends SchemaLoader SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2); // Add rowA - cfamily.addColumn(null, new Column(ByteBufferUtil.bytes("data"), UTF8Type.instance.fromString("{\"foo\":\"bar\"}"))); + cfamily.addColumn(new Column(ByteBufferUtil.bytes("data"), UTF8Type.instance.fromString("{\"foo\":\"bar\"}"))); writer.append(Util.dk("rowA"), cfamily); cfamily.clear(); @@ -308,10 +256,8 @@ public class SSTableExportTest extends SchemaLoader SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2); // Add rowA - cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colName")), - ByteBufferUtil.bytes("val"), System.currentTimeMillis()); - cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colName1")), - ByteBufferUtil.bytes("val1"), System.currentTimeMillis()); + cfamily.addColumn(ByteBufferUtil.bytes("colName"), ByteBufferUtil.bytes("val"), System.currentTimeMillis()); + cfamily.addColumn(ByteBufferUtil.bytes("colName1"), ByteBufferUtil.bytes("val1"), System.currentTimeMillis()); cfamily.delete(new DeletionInfo(0, 0)); writer.append(Util.dk("rowA"), cfamily); diff --git a/test/unit/org/apache/cassandra/tools/SSTableImportTest.java b/test/unit/org/apache/cassandra/tools/SSTableImportTest.java index 6bed245719..a9d770a2b3 100644 --- a/test/unit/org/apache/cassandra/tools/SSTableImportTest.java +++ b/test/unit/org/apache/cassandra/tools/SSTableImportTest.java @@ -32,16 +32,16 @@ import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; +import org.apache.cassandra.db.Column; import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.CounterColumn; import org.apache.cassandra.db.DeletedColumn; import org.apache.cassandra.db.DeletionInfo; +import org.apache.cassandra.db.DeletionTime; import org.apache.cassandra.db.ExpiringColumn; -import org.apache.cassandra.db.IColumn; -import org.apache.cassandra.db.SuperColumn; import org.apache.cassandra.db.columniterator.OnDiskAtomIterator; import org.apache.cassandra.db.filter.QueryFilter; -import org.apache.cassandra.db.filter.QueryPath; +import org.apache.cassandra.db.marshal.CompositeType; import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.utils.ByteBufferUtil; @@ -59,13 +59,13 @@ public class SSTableImportTest extends SchemaLoader // Verify results SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); - QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Standard1")); + QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), "Standard1"); OnDiskAtomIterator iter = qf.getSSTableColumnIterator(reader); ColumnFamily cf = iter.getColumnFamily(); while (iter.hasNext()) cf.addAtom(iter.next()); assert cf.getColumn(ByteBufferUtil.bytes("colAA")).value().equals(hexToBytes("76616c4141")); assert !(cf.getColumn(ByteBufferUtil.bytes("colAA")) instanceof DeletedColumn); - IColumn expCol = cf.getColumn(ByteBufferUtil.bytes("colAC")); + Column expCol = cf.getColumn(ByteBufferUtil.bytes("colAC")); assert expCol.value().equals(hexToBytes("76616c4143")); assert expCol instanceof ExpiringColumn; assert ((ExpiringColumn)expCol).getTimeToLive() == 42 && expCol.getLocalDeletionTime() == 2000000000; @@ -88,13 +88,13 @@ public class SSTableImportTest extends SchemaLoader // Verify results SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); - QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Standard1")); + QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), "Standard1"); OnDiskAtomIterator iter = qf.getSSTableColumnIterator(reader); ColumnFamily cf = iter.getColumnFamily(); while (iter.hasNext()) cf.addAtom(iter.next()); assert cf.getColumn(ByteBufferUtil.bytes("colAA")).value().equals(hexToBytes("76616c4141")); assert !(cf.getColumn(ByteBufferUtil.bytes("colAA")) instanceof DeletedColumn); - IColumn expCol = cf.getColumn(ByteBufferUtil.bytes("colAC")); + Column expCol = cf.getColumn(ByteBufferUtil.bytes("colAC")); assert expCol.value().equals(hexToBytes("76616c4143")); assert expCol instanceof ExpiringColumn; assert ((ExpiringColumn)expCol).getTimeToLive() == 42 && expCol.getLocalDeletionTime() == 2000000000; @@ -105,19 +105,17 @@ public class SSTableImportTest extends SchemaLoader { String jsonUrl = resourcePath("SuperCF.json"); File tempSS = tempSSTableFile("Keyspace1", "Super4"); - new SSTableImport(true).importJson(jsonUrl, "Keyspace1", "Super4", tempSS.getPath()); + new SSTableImport(true, true).importJson(jsonUrl, "Keyspace1", "Super4", tempSS.getPath()); // Verify results SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); - QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Super4", null, null), ByteBufferUtil.bytes("superA")); + QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), "Super4"); ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily(); qf.collateOnDiskAtom(cf, Collections.singletonList(qf.getSSTableColumnIterator(reader)), Integer.MIN_VALUE); - IColumn superCol = cf.getColumn(ByteBufferUtil.bytes("superA")); - assertEquals("supercolumn deletion time did not match the expected time", new DeletionInfo(0, 0), - ((SuperColumn) superCol).deletionInfo()); - assert superCol != null; - assert superCol.getSubColumns().size() > 0; - IColumn subColumn = superCol.getSubColumn(ByteBufferUtil.bytes("636f6c4141")); + + DeletionTime delTime = cf.deletionInfo().rangeCovering(CompositeType.build(ByteBufferUtil.bytes("superA"))).iterator().next(); + assertEquals("supercolumn deletion time did not match the expected time", new DeletionInfo(0, 0), new DeletionInfo(delTime)); + Column subColumn = cf.getColumn(CompositeType.build(ByteBufferUtil.bytes("superA"), ByteBufferUtil.bytes("636f6c4141"))); assert subColumn.value().equals(hexToBytes("76616c75654141")); } @@ -127,7 +125,7 @@ public class SSTableImportTest extends SchemaLoader String jsonUrl = resourcePath("UnsortedSuperCF.json"); File tempSS = tempSSTableFile("Keyspace1", "Super4"); - int result = new SSTableImport(3,true).importJson(jsonUrl, "Keyspace1","Super4", tempSS.getPath()); + int result = new SSTableImport(3,true, true).importJson(jsonUrl, "Keyspace1","Super4", tempSS.getPath()); assert result == -1; } @@ -140,14 +138,14 @@ public class SSTableImportTest extends SchemaLoader new SSTableImport().importJson(jsonUrl, "Keyspace1", "Standard1", tempSS.getPath()); SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); - QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Standard1")); + QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), "Standard1"); OnDiskAtomIterator iter = qf.getSSTableColumnIterator(reader); ColumnFamily cf = iter.getColumnFamily(); while (iter.hasNext()) cf.addAtom(iter.next()); assert cf.getColumn(ByteBufferUtil.bytes("colAA")).value().equals(hexToBytes("76616c4141")); assert !(cf.getColumn(ByteBufferUtil.bytes("colAA")) instanceof DeletedColumn); - IColumn expCol = cf.getColumn(ByteBufferUtil.bytes("colAC")); + Column expCol = cf.getColumn(ByteBufferUtil.bytes("colAC")); assert expCol.value().equals(hexToBytes("76616c4143")); assert expCol instanceof ExpiringColumn; assert ((ExpiringColumn) expCol).getTimeToLive() == 42 && expCol.getLocalDeletionTime() == 2000000000; @@ -163,7 +161,7 @@ public class SSTableImportTest extends SchemaLoader // Verify results SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); - QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Standard1")); + QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), "Standard1"); OnDiskAtomIterator iter = qf.getSSTableColumnIterator(reader); ColumnFamily cf = iter.getColumnFamily(); assertEquals(cf.deletionInfo(), new DeletionInfo(0, 0)); @@ -171,7 +169,7 @@ public class SSTableImportTest extends SchemaLoader cf.addAtom(iter.next()); assert cf.getColumn(ByteBufferUtil.bytes("colAA")).value().equals(hexToBytes("76616c4141")); assert !(cf.getColumn(ByteBufferUtil.bytes("colAA")) instanceof DeletedColumn); - IColumn expCol = cf.getColumn(ByteBufferUtil.bytes("colAC")); + Column expCol = cf.getColumn(ByteBufferUtil.bytes("colAC")); assert expCol.value().equals(hexToBytes("76616c4143")); assert expCol instanceof ExpiringColumn; assert ((ExpiringColumn) expCol).getTimeToLive() == 42 && expCol.getLocalDeletionTime() == 2000000000; @@ -187,11 +185,11 @@ public class SSTableImportTest extends SchemaLoader // Verify results SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); - QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Counter1")); + QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), "Counter1"); OnDiskAtomIterator iter = qf.getSSTableColumnIterator(reader); ColumnFamily cf = iter.getColumnFamily(); while (iter.hasNext()) cf.addAtom(iter.next()); - IColumn c = cf.getColumn(ByteBufferUtil.bytes("colAA")); + Column c = cf.getColumn(ByteBufferUtil.bytes("colAA")); assert c instanceof CounterColumn: c; assert ((CounterColumn) c).total() == 42; } diff --git a/test/unit/org/apache/cassandra/utils/EncodedStreamsTest.java b/test/unit/org/apache/cassandra/utils/EncodedStreamsTest.java index 7fa4395749..2258988de2 100644 --- a/test/unit/org/apache/cassandra/utils/EncodedStreamsTest.java +++ b/test/unit/org/apache/cassandra/utils/EncodedStreamsTest.java @@ -110,14 +110,6 @@ public class EncodedStreamsTest extends SchemaLoader return cf; } - private ColumnFamily createSuperCF() - { - ColumnFamily cf = ColumnFamily.create(tableName, superCFName); - cf.addColumn(superColumn(cf, "Avatar", column("$2,782,275,172", "2009", 1))); - cf.addColumn(superColumn(cf, "Titanic", column("$1,925,905,151", "1997", 1))); - return cf; - } - @Test public void testCFSerialization() throws IOException { @@ -145,19 +137,5 @@ public class EncodedStreamsTest extends SchemaLoader Assert.assertEquals(cf, createCounterCF()); Assert.assertEquals(byteArrayOStream1.size(), (int) ColumnFamily.serializer.serializedSize(cf, TypeSizes.VINT, version)); } - - @Test - public void testSuperCFSerialization() throws IOException - { - ByteArrayOutputStream byteArrayOStream1 = new ByteArrayOutputStream(); - EncodedDataOutputStream odos = new EncodedDataOutputStream(byteArrayOStream1); - ColumnFamily.serializer.serialize(createSuperCF(), odos, version); - - ByteArrayInputStream byteArrayIStream1 = new ByteArrayInputStream(byteArrayOStream1.toByteArray()); - EncodedDataInputStream odis = new EncodedDataInputStream(new DataInputStream(byteArrayIStream1)); - ColumnFamily cf = ColumnFamily.serializer.deserialize(odis, version); - Assert.assertEquals(cf, createSuperCF()); - Assert.assertEquals(byteArrayOStream1.size(), (int) ColumnFamily.serializer.serializedSize(cf, TypeSizes.VINT, version)); - } }