Merge branch 'cassandra-1.2' into trunk
Conflicts:
src/java/org/apache/cassandra/config/CFMetaData.java
src/java/org/apache/cassandra/config/ColumnDefinition.java
src/java/org/apache/cassandra/config/KSMetaData.java
src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
src/java/org/apache/cassandra/db/RowMutation.java
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/79fe644a
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/79fe644a
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/79fe644a
Branch: refs/heads/trunk
Commit: 79fe644aa11fc16733dcb9762ac081daace2c677
Parents: 41ef86b 86a077a
Author: Sylvain Lebresne <[email protected]>
Authored: Mon Jul 22 11:11:56 2013 +0200
Committer: Sylvain Lebresne <[email protected]>
Committed: Mon Jul 22 11:11:56 2013 +0200
----------------------------------------------------------------------
src/java/org/apache/cassandra/config/CFMetaData.java | 6 +++---
src/java/org/apache/cassandra/config/ColumnDefinition.java | 4 ++--
src/java/org/apache/cassandra/config/KSMetaData.java | 2 +-
src/java/org/apache/cassandra/config/TriggerOptions.java | 4 ++--
src/java/org/apache/cassandra/db/RowMutation.java | 6 +++++-
5 files changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/79fe644a/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/config/CFMetaData.java
index 573819a,f3b235d..9ab24fb
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@@ -1482,21 -1291,37 +1482,21 @@@ public final class CFMetaDat
*/
public RowMutation dropFromSchema(long timestamp)
{
- RowMutation rm = new RowMutation(Table.SYSTEM_KS,
SystemTable.getSchemaKSKey(ksName));
+ RowMutation rm = new RowMutation(Keyspace.SYSTEM_KS,
SystemKeyspace.getSchemaKSKey(ksName));
- ColumnFamily cf =
rm.addOrGet(SystemKeyspace.SCHEMA_COLUMNFAMILIES_CF);
+ ColumnFamily cf = rm.addOrGet(SchemaColumnFamiliesCf);
int ldt = (int) (System.currentTimeMillis() / 1000);
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName, ""));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName, "id"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName, "type"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"comparator"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"subcomparator"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName, "comment"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"read_repair_chance"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"local_read_repair_chance"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"replicate_on_write"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"populate_io_cache_on_flush"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"gc_grace_seconds"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"default_validator"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"key_validator"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"min_compaction_threshold"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"max_compaction_threshold"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"key_alias"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"key_aliases"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"bloom_filter_fp_chance"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName, "caching"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"compaction_strategy_class"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"compression_parameters"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"value_alias"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"column_aliases"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
"compaction_strategy_options"));
+ ColumnNameBuilder builder =
SchemaColumnFamiliesCf.getCfDef().getColumnNameBuilder();
+ builder.add(ByteBufferUtil.bytes(cfName));
+ cf.addAtom(new RangeTombstone(builder.build(),
builder.buildAsEndOfRange(), timestamp, ldt));
+
- ColumnFamily tcf = rm.addOrGet(SystemKeyspace.SCHEMA_TRIGGERS_CF);
++ ColumnFamily tcf = rm.addOrGet(SchemaTriggersCf);
+ ColumnNameBuilder tbuilder =
SchemaTriggersCf.getCfDef().getColumnNameBuilder();
+ tbuilder.add(ByteBufferUtil.bytes(cfName));
+ tcf.addAtom(new RangeTombstone(tbuilder.build(),
tbuilder.buildAsEndOfRange(), timestamp, ldt));
for (ColumnDefinition cd : column_metadata.values())
- cd.deleteFromSchema(rm, cfName,
getColumnDefinitionComparator(cd), timestamp);
+ cd.deleteFromSchema(rm, cfName, timestamp);
return rm;
}
@@@ -1513,26 -1338,18 +1513,26 @@@
{
// For property that can be null (and can be changed), we insert
tombstones, to make sure
// we don't keep a property the user has removed
- ColumnFamily cf =
rm.addOrGet(SystemKeyspace.SCHEMA_COLUMNFAMILIES_CF);
+ ColumnFamily cf = rm.addOrGet(SchemaColumnFamiliesCf);
int ldt = (int) (System.currentTimeMillis() / 1000);
- Integer oldId = Schema.instance.convertNewCfId(cfId);
- if (oldId != null) // keep old ids (see CASSANDRA-3794 for details)
- cf.addColumn(Column.create(oldId, timestamp, cfName, "id"));
-
cf.addColumn(Column.create("", timestamp, cfName, ""));
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"));
http://git-wip-us.apache.org/repos/asf/cassandra/blob/79fe644a/src/java/org/apache/cassandra/config/ColumnDefinition.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/config/ColumnDefinition.java
index 6b979b7,db5f7ed..2959f18
--- a/src/java/org/apache/cassandra/config/ColumnDefinition.java
+++ b/src/java/org/apache/cassandra/config/ColumnDefinition.java
@@@ -195,14 -145,17 +195,14 @@@ public class ColumnDefinitio
* @param cfName The name of the parent ColumnFamily
* @param timestamp The timestamp to use for column modification
*/
- public void deleteFromSchema(RowMutation rm, String cfName,
AbstractType<?> comparator, long timestamp)
+ public void deleteFromSchema(RowMutation rm, String cfName, long
timestamp)
{
- ColumnFamily cf = rm.addOrGet(SystemKeyspace.SCHEMA_COLUMNS_CF);
+ ColumnFamily cf = rm.addOrGet(CFMetaData.SchemaColumnsCf);
int ldt = (int) (System.currentTimeMillis() / 1000);
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
comparator.getString(name), ""));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
comparator.getString(name), "validator"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
comparator.getString(name), "index_type"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
comparator.getString(name), "index_options"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
comparator.getString(name), "index_name"));
- cf.addColumn(DeletedColumn.create(ldt, timestamp, cfName,
comparator.getString(name), "component_index"));
+ ColumnNameBuilder builder =
CFMetaData.SchemaColumnsCf.getCfDef().getColumnNameBuilder();
+ builder.add(ByteBufferUtil.bytes(cfName)).add(name);
+ cf.addAtom(new RangeTombstone(builder.build(),
builder.buildAsEndOfRange(), timestamp, ldt));
}
public void toSchema(RowMutation rm, String cfName, AbstractType<?>
comparator, long timestamp)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/79fe644a/src/java/org/apache/cassandra/config/KSMetaData.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/config/KSMetaData.java
index edeb20e,b92f9a5..cf14e58
--- a/src/java/org/apache/cassandra/config/KSMetaData.java
+++ b/src/java/org/apache/cassandra/config/KSMetaData.java
@@@ -236,8 -237,8 +236,8 @@@ public final class KSMetaDat
public RowMutation toSchema(long timestamp)
{
- RowMutation rm = new RowMutation(Table.SYSTEM_KS,
SystemTable.getSchemaKSKey(name));
+ RowMutation rm = new RowMutation(Keyspace.SYSTEM_KS,
SystemKeyspace.getSchemaKSKey(name));
- ColumnFamily cf = rm.addOrGet(SystemKeyspace.SCHEMA_KEYSPACES_CF);
+ ColumnFamily cf = rm.addOrGet(CFMetaData.SchemaKeyspacesCf);
cf.addColumn(Column.create(durableWrites, timestamp,
"durable_writes"));
cf.addColumn(Column.create(strategyClass.getName(), timestamp,
"strategy_class"));
http://git-wip-us.apache.org/repos/asf/cassandra/blob/79fe644a/src/java/org/apache/cassandra/config/TriggerOptions.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/config/TriggerOptions.java
index 7411756,0000000..339ee24
mode 100644,000000..100644
--- a/src/java/org/apache/cassandra/config/TriggerOptions.java
+++ b/src/java/org/apache/cassandra/config/TriggerOptions.java
@@@ -1,110 -1,0 +1,110 @@@
+/*
+ * 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.config;
+
+import static org.apache.cassandra.cql3.QueryProcessor.processInternal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.cassandra.cql3.ColumnNameBuilder;
+import org.apache.cassandra.cql3.UntypedResultSet;
+import org.apache.cassandra.cql3.UntypedResultSet.Row;
+import org.apache.cassandra.db.ColumnFamily;
+import org.apache.cassandra.db.RangeTombstone;
+import org.apache.cassandra.db.RowMutation;
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+public class TriggerOptions
+{
+ private static final String CLASS_KEY = "class";
+ private static final String OPTIONS_KEY = "trigger_options";
+
+ public static Map<String, Map<String, String>> getAllTriggers(String
ksName, String cfName)
+ {
+ String req = "SELECT * FROM system.%s WHERE keyspace_name='%s' AND
columnfamily_name='%s'";
+ UntypedResultSet result = processInternal(String.format(req,
SystemKeyspace.SCHEMA_TRIGGERS_CF, ksName, cfName));
+ Map<String, Map<String, String>> triggers = new HashMap<>();
+ if (result.isEmpty())
+ return triggers;
+ for (Row row : result)
+ triggers.put(row.getString("trigger_name"),
row.getMap(OPTIONS_KEY, UTF8Type.instance, UTF8Type.instance));
+ return triggers;
+ }
+
+ public static void addColumns(RowMutation rm, String cfName,
Entry<String, Map<String, String>> tentry, long modificationTimestamp)
+ {
- ColumnFamily cf = rm.addOrGet(SystemKeyspace.SCHEMA_TRIGGERS_CF);
++ ColumnFamily cf = rm.addOrGet(CFMetaData.SchemaTriggersCf);
+ assert tentry.getValue().get(CLASS_KEY) != null;
+ ColumnNameBuilder builder =
CFMetaData.SchemaTriggersCf.getCfDef().getColumnNameBuilder();
+
builder.add(ByteBufferUtil.bytes(cfName)).add(ByteBufferUtil.bytes(tentry.getKey())).add(ByteBufferUtil.bytes(OPTIONS_KEY));
+ for (Entry<String, String> entry : tentry.getValue().entrySet())
+ {
+ ColumnNameBuilder builderCopy = builder.copy();
+ builderCopy.add(ByteBufferUtil.bytes(entry.getKey()));
+ cf.addColumn(builderCopy.build(),
ByteBufferUtil.bytes(entry.getValue()), modificationTimestamp);
+ }
+ }
+
+ public static void deleteColumns(RowMutation rm, String cfName,
Entry<String, Map<String, String>> tentry, long modificationTimestamp)
+ {
- ColumnFamily cf = rm.addOrGet(SystemKeyspace.SCHEMA_TRIGGERS_CF);
++ ColumnFamily cf = rm.addOrGet(CFMetaData.SchemaTriggersCf);
+ int ldt = (int) (System.currentTimeMillis() / 1000);
+ ColumnNameBuilder builder =
CFMetaData.SchemaTriggersCf.getCfDef().getColumnNameBuilder();
+
builder.add(ByteBufferUtil.bytes(cfName)).add(ByteBufferUtil.bytes(tentry.getKey()));
+ cf.addAtom(new RangeTombstone(builder.build(),
builder.buildAsEndOfRange(), modificationTimestamp, ldt));
+ }
+
+ public static void update(CFMetaData cfm, String triggerName, String
clazz)
+ {
+ Map<String, Map<String, String>> existingTriggers = cfm.getTriggers();
+ assert existingTriggers.get(triggerName) == null;
+ Map<String, String> triggerUnit = new HashMap<>();
+ triggerUnit.put(CLASS_KEY, clazz);
+ existingTriggers.put(triggerName, triggerUnit);
+ cfm.triggers(existingTriggers);
+ }
+
+ public static void remove(CFMetaData cfm, String triggerName)
+ {
+ Map<String, Map<String, String>> existingTriggers =
cfm.getTriggers(); // have a copy of the triggers
+ existingTriggers.remove(triggerName);
+ cfm.triggers(existingTriggers);
+ }
+
+ public static boolean hasTrigger(CFMetaData cfm, String triggerName)
+ {
+ return cfm.getTriggers().get(triggerName) != null;
+ }
+
+ public static Collection<String> extractClasses(Map<String, Map<String,
String>> triggers)
+ {
+ List<String> classes = new ArrayList<>();
+ if (triggers.isEmpty())
+ return null;
+ for (Map<String, String> options : triggers.values())
+ classes.add(options.get(CLASS_KEY));
+ return classes;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/79fe644a/src/java/org/apache/cassandra/db/RowMutation.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/db/RowMutation.java
index 2d4188e,69f4a5f..fd9e723
--- a/src/java/org/apache/cassandra/db/RowMutation.java
+++ b/src/java/org/apache/cassandra/db/RowMutation.java
@@@ -120,7 -149,11 +120,11 @@@ public class RowMutation implements IMu
*/
public ColumnFamily addOrGet(String cfName)
{
- CFMetaData cfm = Schema.instance.getCFMetaData(keyspaceName, cfName);
- return addOrGet(Schema.instance.getCFMetaData(table, cfName));
++ return addOrGet(Schema.instance.getCFMetaData(keyspaceName, cfName));
+ }
+
+ public ColumnFamily addOrGet(CFMetaData cfm)
+ {
ColumnFamily cf = modifications.get(cfm.cfId);
if (cf == null)
{