Author: gdusbabek
Date: Fri Nov 19 15:28:18 2010
New Revision: 1036896
URL: http://svn.apache.org/viewvc?rev=1036896&view=rev
Log:
use avro structures inside UpdateColumnFamily. patch by gdusbabek, reviewe by
jbellis. CASSANDRA-1715
Modified:
cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java
cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java
Modified:
cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java?rev=1036896&r1=1036895&r2=1036896&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java Fri
Nov 19 15:28:18 2010
@@ -701,7 +701,7 @@ public class CassandraServer implements
try
{
oldCfm.apply(cf_def);
- UpdateColumnFamily update = new
UpdateColumnFamily(CFMetaData.convertToThrift(cf_def));
+ UpdateColumnFamily update = new UpdateColumnFamily(cf_def);
applyMigrationOnStage(update);
return DatabaseDescriptor.getDefsVersion().toString();
}
Modified: cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java?rev=1036896&r1=1036895&r2=1036896&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java Fri
Nov 19 15:28:18 2010
@@ -583,13 +583,27 @@ public final class CFMetaData
return validator;
}
- public void apply(org.apache.cassandra.avro.CfDef cf_def) throws
ConfigurationException
+ /** applies implicit defaults to cf definition. useful in updates */
+ public static void applyImplicitDefaults(org.apache.cassandra.thrift.CfDef
cf_def)
{
- apply(convertToThrift(cf_def));
+ if (!cf_def.isSetMin_compaction_threshold())
+
cf_def.setMin_compaction_threshold(CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD);
+ if (!cf_def.isSetMax_compaction_threshold())
+
cf_def.setMax_compaction_threshold(CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD);
+ if (!cf_def.isSetRow_cache_save_period_in_seconds())
+
cf_def.setRow_cache_save_period_in_seconds(CFMetaData.DEFAULT_ROW_CACHE_SAVE_PERIOD_IN_SECONDS);
+ if (!cf_def.isSetKey_cache_save_period_in_seconds())
+
cf_def.setKey_cache_save_period_in_seconds(CFMetaData.DEFAULT_KEY_CACHE_SAVE_PERIOD_IN_SECONDS);
+ if (!cf_def.isSetMemtable_flush_after_mins())
+
cf_def.setMemtable_flush_after_mins(CFMetaData.DEFAULT_MEMTABLE_LIFETIME_IN_MINS);
+ if (!cf_def.isSetMemtable_throughput_in_mb())
+
cf_def.setMemtable_throughput_in_mb(CFMetaData.DEFAULT_MEMTABLE_THROUGHPUT_IN_MB);
+ if (!cf_def.isSetMemtable_operations_in_millions())
+
cf_def.setMemtable_operations_in_millions(CFMetaData.DEFAULT_MEMTABLE_OPERATIONS_IN_MILLIONS);
}
// merges some final fields from this CFM with modifiable fields from
CfDef into a new CFMetaData.
- public void apply(org.apache.cassandra.thrift.CfDef cf_def) throws
ConfigurationException
+ public void apply(org.apache.cassandra.avro.CfDef cf_def) throws
ConfigurationException
{
// validate
if (cf_def.id != cfId)
@@ -614,7 +628,7 @@ public final class CFMetaData
validateMinMaxCompactionThresholds(cf_def);
validateMemtableSettings(cf_def);
- comment = cf_def.comment == null ? "" : cf_def.comment;
+ comment = cf_def.comment == null ? "" : cf_def.comment.toString();
rowCacheSize = cf_def.row_cache_size;
keyCacheSize = cf_def.key_cache_size;
readRepairChance = cf_def.read_repair_chance;
@@ -631,8 +645,8 @@ public final class CFMetaData
// adjust secondary indexes. figure out who is coming and going.
Set<ByteBuffer> toRemove = new HashSet<ByteBuffer>();
Set<ByteBuffer> newIndexNames = new HashSet<ByteBuffer>();
- Set<org.apache.cassandra.thrift.ColumnDef> toAdd = new
HashSet<org.apache.cassandra.thrift.ColumnDef>();
- for (org.apache.cassandra.thrift.ColumnDef def :
cf_def.column_metadata)
+ Set<org.apache.cassandra.avro.ColumnDef> toAdd = new
HashSet<org.apache.cassandra.avro.ColumnDef>();
+ for (org.apache.cassandra.avro.ColumnDef def : cf_def.column_metadata)
{
newIndexNames.add(def.name);
if (!column_metadata.containsKey(def.name))
@@ -646,15 +660,18 @@ public final class CFMetaData
for (ByteBuffer indexName : toRemove)
column_metadata.remove(indexName);
// update the ones staying
- for (org.apache.cassandra.thrift.ColumnDef def :
cf_def.column_metadata)
+ for (org.apache.cassandra.avro.ColumnDef def : cf_def.column_metadata)
{
- column_metadata.get(def.name).setIndexType(def.index_type);
- column_metadata.get(def.name).setIndexName(def.index_name);
+ column_metadata.get(def.name).setIndexType(def.index_type == null
? null : org.apache.cassandra.thrift.IndexType.valueOf(def.index_type.name()));
+ column_metadata.get(def.name).setIndexName(def.index_name == null
? null : def.index_name.toString());
}
// add the new ones coming in.
- for (org.apache.cassandra.thrift.ColumnDef def : toAdd)
+ for (org.apache.cassandra.avro.ColumnDef def : toAdd)
{
- ColumnDefinition cd = new ColumnDefinition(def.name,
def.validation_class, def.index_type, def.index_name);
+ ColumnDefinition cd = new ColumnDefinition(def.name,
+
def.validation_class.toString(),
+ def.index_type == null
? null :
org.apache.cassandra.thrift.IndexType.valueOf(def.index_type.toString()),
+ def.index_name == null
? null : def.index_name.toString());
column_metadata.put(cd.name, cd);
}
}
@@ -739,43 +756,40 @@ public final class CFMetaData
return def;
}
- private static String stringOrNull(CharSequence cs)
+ public static org.apache.cassandra.avro.CfDef
convertToAvro(org.apache.cassandra.thrift.CfDef def)
{
- return cs == null ? null : cs.toString();
- }
-
- public static org.apache.cassandra.thrift.CfDef
convertToThrift(org.apache.cassandra.avro.CfDef def)
- {
- org.apache.cassandra.thrift.CfDef newDef = new
org.apache.cassandra.thrift.CfDef(def.keyspace.toString(), def.name.toString());
- newDef.setColumn_type(def.column_type.toString());
- newDef.setComment(def.comment.toString());
- newDef.setComparator_type(stringOrNull(def.comparator_type));
-
newDef.setDefault_validation_class(stringOrNull(def.default_validation_class));
- newDef.setGc_grace_seconds(def.gc_grace_seconds);
- newDef.setId(def.id);
-
newDef.setKey_cache_save_period_in_seconds(def.key_cache_save_period_in_seconds);
- newDef.setKey_cache_size(def.key_cache_size);
- newDef.setKeyspace(def.keyspace.toString());
- newDef.setMax_compaction_threshold(def.max_compaction_threshold);
- newDef.setMemtable_flush_after_mins(def.memtable_flush_after_mins);
-
newDef.setMemtable_operations_in_millions(def.memtable_operations_in_millions);
- newDef.setMemtable_throughput_in_mb(def.memtable_throughput_in_mb);
- newDef.setMin_compaction_threshold(def.min_compaction_threshold);
- newDef.setName(def.name.toString());
- newDef.setRead_repair_chance(def.read_repair_chance);
-
newDef.setRow_cache_save_period_in_seconds(def.row_cache_save_period_in_seconds);
- newDef.setRow_cache_size(def.row_cache_size);
- newDef.setSubcomparator_type(stringOrNull(def.subcomparator_type));
- List<org.apache.cassandra.thrift.ColumnDef> columnMeta = new
ArrayList<org.apache.cassandra.thrift.ColumnDef>();
- for (org.apache.cassandra.avro.ColumnDef cdef : def.column_metadata)
- {
- org.apache.cassandra.thrift.ColumnDef tdef = new
org.apache.cassandra.thrift.ColumnDef(cdef.name,
stringOrNull(cdef.validation_class));
- tdef.setIndex_name(stringOrNull(cdef.index_name));
- if (cdef.index_type != null)
-
tdef.setIndex_type(org.apache.cassandra.thrift.IndexType.valueOf(cdef.index_type.name()));
+ org.apache.cassandra.avro.CfDef newDef = new
org.apache.cassandra.avro.CfDef();
+ newDef.keyspace = def.getKeyspace();
+ newDef.name = def.getName();
+ newDef.column_type = def.getColumn_type();
+ newDef.comment = def.getComment();
+ newDef.comparator_type = def.getComparator_type();
+ newDef.default_validation_class = def.getDefault_validation_class();
+ newDef.gc_grace_seconds = def.getGc_grace_seconds();
+ newDef.id = def.getId();
+ newDef.key_cache_save_period_in_seconds =
def.getKey_cache_save_period_in_seconds();
+ newDef.key_cache_size = def.getKey_cache_size();
+ newDef.max_compaction_threshold = def.getMax_compaction_threshold();
+ newDef.memtable_flush_after_mins = def.getMemtable_flush_after_mins();
+ newDef.memtable_operations_in_millions =
def.getMemtable_operations_in_millions();
+ newDef.memtable_throughput_in_mb = def.getMemtable_throughput_in_mb();
+ newDef.min_compaction_threshold = def.getMin_compaction_threshold();
+ newDef.read_repair_chance = def.getRead_repair_chance();
+ newDef.row_cache_save_period_in_seconds =
def.getRow_cache_save_period_in_seconds();
+ newDef.row_cache_size = def.getRow_cache_size();
+ newDef.subcomparator_type = def.getSubcomparator_type();
+
+ List<org.apache.cassandra.avro.ColumnDef> columnMeta = new
ArrayList<org.apache.cassandra.avro.ColumnDef>();
+ for (org.apache.cassandra.thrift.ColumnDef cdef :
def.getColumn_metadata())
+ {
+ org.apache.cassandra.avro.ColumnDef tdef = new
org.apache.cassandra.avro.ColumnDef();
+ tdef.name = cdef.BufferForName();
+ tdef.validation_class = cdef.getValidation_class();
+ tdef.index_name = cdef.getIndex_name();
+ tdef.index_type = cdef.getIndex_type() == null ? null :
org.apache.cassandra.avro.IndexType.valueOf(cdef.getIndex_type().name());
columnMeta.add(tdef);
}
- newDef.setColumn_metadata(columnMeta);
+ newDef.column_metadata = columnMeta;
return newDef;
}
Modified:
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java?rev=1036896&r1=1036895&r2=1036896&view=diff
==============================================================================
---
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
(original)
+++
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
Fri Nov 19 15:28:18 2010
@@ -645,12 +645,12 @@ public class DatabaseDescriptor
return conf.thrift_framed_transport_size_in_mb * 1024 * 1024;
}
- public static AbstractType getComparator(String compareWith) throws
ConfigurationException
+ public static AbstractType getComparator(CharSequence compareWith) throws
ConfigurationException
{
if (compareWith == null)
compareWith = "BytesType";
- return FBUtilities.getComparator(compareWith);
+ return FBUtilities.getComparator(compareWith.toString());
}
/**
Modified:
cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java?rev=1036896&r1=1036895&r2=1036896&view=diff
==============================================================================
---
cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java
(original)
+++
cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java
Fri Nov 19 15:28:18 2010
@@ -44,15 +44,15 @@ public class UpdateColumnFamily extends
protected UpdateColumnFamily() { }
/** assumes validation has already happened. That is, replacing oldCfm
with newCfm is neither illegal or totally whackass. */
- public UpdateColumnFamily(CfDef cf_def) throws ConfigurationException,
IOException
+ public UpdateColumnFamily(org.apache.cassandra.avro.CfDef cf_def) throws
ConfigurationException, IOException
{
super(UUIDGen.makeType1UUIDFromHost(FBUtilities.getLocalAddress()),
DatabaseDescriptor.getDefsVersion());
- KSMetaData ksm =
DatabaseDescriptor.getTableDefinition(cf_def.keyspace);
+ KSMetaData ksm =
DatabaseDescriptor.getTableDefinition(cf_def.keyspace.toString());
if (ksm == null)
throw new ConfigurationException("Keyspace does not already
exist.");
- CFMetaData oldCfm =
DatabaseDescriptor.getCFMetaData(CFMetaData.getId(cf_def.keyspace,
cf_def.name));
+ CFMetaData oldCfm =
DatabaseDescriptor.getCFMetaData(CFMetaData.getId(cf_def.keyspace.toString(),
cf_def.name.toString()));
oldCfm.apply(cf_def);
this.metadata = oldCfm;
Modified:
cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java?rev=1036896&r1=1036895&r2=1036896&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
Fri Nov 19 15:28:18 2010
@@ -42,6 +42,7 @@ import org.apache.cassandra.config.Confi
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.KSMetaData;
import org.apache.cassandra.db.ColumnFamily;
+import org.apache.cassandra.db.ColumnFamilyNotDefinedException;
import org.apache.cassandra.db.ColumnFamilyType;
import org.apache.cassandra.db.DecoratedKey;
import org.apache.cassandra.db.ExpiringColumn;
@@ -858,7 +859,8 @@ public class CassandraServer implements
try
{
// ideally, apply() would happen on the stage with the
- UpdateColumnFamily update = new UpdateColumnFamily(cf_def);
+ CFMetaData.applyImplicitDefaults(cf_def);
+ UpdateColumnFamily update = new
UpdateColumnFamily(CFMetaData.convertToAvro(cf_def));
applyMigrationOnStage(update);
return DatabaseDescriptor.getDefsVersion().toString();
}
@@ -876,6 +878,7 @@ public class CassandraServer implements
}
}
+ // @see CFMetaData.applyImplicitDefaults().
private CFMetaData convertToCFMetaData(CfDef cf_def) throws
InvalidRequestException, ConfigurationException
{
ColumnFamilyType cfType = ColumnFamilyType.create(cf_def.column_type);
@@ -884,6 +887,7 @@ public class CassandraServer implements
throw new InvalidRequestException("Invalid column type " +
cf_def.column_type);
}
+ CFMetaData.applyImplicitDefaults(cf_def);
CFMetaData.validateMinMaxCompactionThresholds(cf_def);
CFMetaData.validateMemtableSettings(cf_def);
Modified: cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java?rev=1036896&r1=1036895&r2=1036896&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java Fri Nov 19
15:28:18 2010
@@ -548,46 +548,36 @@ public class DefsTest extends CleanupHel
assert DatabaseDescriptor.getCFMetaData(cf.tableName, cf.cfName) !=
null;
// updating certain fields should fail.
- CfDef cf_def = new CfDef();
- cf_def.setId(cf.cfId);
- cf_def.setKeyspace(cf.tableName);
- cf_def.setName(cf.cfName);
- cf_def.setColumn_type(cf.cfType.name());
- cf_def.setComment(cf.getComment());
- cf_def.setComparator_type(cf.comparator.getClass().getName());
- cf_def.setSubcomparator_type(null);
- cf_def.setGc_grace_seconds(cf.getGcGraceSeconds());
- cf_def.setKey_cache_size(cf.getKeyCacheSize());
- cf_def.setRead_repair_chance(cf.getReadRepairChance());
- cf_def.setRow_cache_size(43.3);
- cf_def.setColumn_metadata(new ArrayList<ColumnDef>());
- cf_def.setDefault_validation_class("BytesType");
- cf_def.setMin_compaction_threshold(5);
- cf_def.setMax_compaction_threshold(31);
+ org.apache.cassandra.avro.CfDef cf_def = CFMetaData.convertToAvro(cf);
+ cf_def.row_cache_size = 43.3;
+ cf_def.column_metadata = new
ArrayList<org.apache.cassandra.avro.ColumnDef>();
+ cf_def.default_validation_class ="BytesType";
+ cf_def.min_compaction_threshold = 5;
+ cf_def.max_compaction_threshold = 31;
// test valid operations.
- cf_def.setComment("Modified comment");
+ cf_def.comment = "Modified comment";
new UpdateColumnFamily(cf_def).apply(); // doesn't get set back here.
- cf_def.setRow_cache_size(2d);
+ cf_def.row_cache_size = 2d;
new UpdateColumnFamily(cf_def).apply();
- cf_def.setKey_cache_size(3d);
+ cf_def.key_cache_size = 3d;
new UpdateColumnFamily(cf_def).apply();
- cf_def.setRead_repair_chance(0.23);
+ cf_def.read_repair_chance = 0.23;
new UpdateColumnFamily(cf_def).apply();
- cf_def.setGc_grace_seconds(12);
+ cf_def.gc_grace_seconds = 12;
new UpdateColumnFamily(cf_def).apply();
- cf_def.setDefault_validation_class("UTF8Type");
+ cf_def.default_validation_class = "UTF8Type";
new UpdateColumnFamily(cf_def).apply();
- cf_def.setMin_compaction_threshold(3);
+ cf_def.min_compaction_threshold = 3;
new UpdateColumnFamily(cf_def).apply();
- cf_def.setMax_compaction_threshold(33);
+ cf_def.max_compaction_threshold = 33;
new UpdateColumnFamily(cf_def).apply();
// can't test changing the reconciler because there is only one impl.
@@ -605,82 +595,82 @@ public class DefsTest extends CleanupHel
int oldId = cf_def.id;
try
{
- cf_def.setId(cf_def.getId() + 1);
+ cf_def.id++;
cf.apply(cf_def);
throw new AssertionError("Should have blown up when you used a
different id.");
}
catch (ConfigurationException expected)
{
- cf_def.setId(oldId);
+ cf_def.id = oldId;
}
- String oldStr = cf_def.getName();
+ CharSequence oldStr = cf_def.name;
try
{
- cf_def.setName(cf_def.getName() + "_renamed");
+ cf_def.name = cf_def.name + "_renamed";
cf.apply(cf_def);
throw new AssertionError("Should have blown up when you used a
different name.");
}
catch (ConfigurationException expected)
{
- cf_def.setName(oldStr);
+ cf_def.name = oldStr;
}
- oldStr = cf_def.getKeyspace();
+ oldStr = cf_def.keyspace;
try
{
- cf_def.setKeyspace(oldStr + "_renamed");
+ cf_def.keyspace = oldStr + "_renamed";
cf.apply(cf_def);
throw new AssertionError("Should have blown up when you used a
different keyspace.");
}
catch (ConfigurationException expected)
{
- cf_def.setKeyspace(oldStr);
+ cf_def.keyspace = oldStr;
}
try
{
- cf_def.setColumn_type(ColumnFamilyType.Super.name());
+ cf_def.column_type = ColumnFamilyType.Super.name();
cf.apply(cf_def);
throw new AssertionError("Should have blwon up when you used a
different cf type.");
}
catch (ConfigurationException expected)
{
- cf_def.setColumn_type(ColumnFamilyType.Standard.name());
+ cf_def.column_type = ColumnFamilyType.Standard.name();
}
- oldStr = cf_def.getComparator_type();
+ oldStr = cf_def.comparator_type;
try
{
- cf_def.setComparator_type(BytesType.class.getSimpleName());
+ cf_def.comparator_type = BytesType.class.getSimpleName();
cf.apply(cf_def);
throw new AssertionError("Should have blown up when you used a
different comparator.");
}
catch (ConfigurationException expected)
{
- cf_def.setComparator_type(UTF8Type.class.getSimpleName());
+ cf_def.comparator_type = UTF8Type.class.getSimpleName();
}
try
{
- cf_def.setMin_compaction_threshold(34);
+ cf_def.min_compaction_threshold = 34;
cf.apply(cf_def);
throw new AssertionError("Should have blown up when min > max.");
}
catch (ConfigurationException expected)
{
- cf_def.setMin_compaction_threshold(3);
+ cf_def.min_compaction_threshold = 3;
}
try
{
- cf_def.setMax_compaction_threshold(2);
+ cf_def.max_compaction_threshold = 2;
cf.apply(cf_def);
throw new AssertionError("Should have blown up when max > min.");
}
catch (ConfigurationException expected)
{
- cf_def.setMax_compaction_threshold(33);
+ cf_def.max_compaction_threshold = 33;
}
}
@@ -706,5 +696,4 @@ public class DefsTest extends CleanupHel
CFMetaData.DEFAULT_MEMTABLE_OPERATIONS_IN_MILLIONS,
Collections.<ByteBuffer,
ColumnDefinition>emptyMap());
}
-
}