introduce RawColumnDefinition for yaml import and fix CFMetaData deserialize bug. patch by jbellis

git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@960972 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2010-07-06 18:21:22 +00:00
parent 16ff779db9
commit 8250594efd
5 changed files with 53 additions and 7 deletions

View File

@ -255,14 +255,13 @@ public final class CFMetaData
double keyCacheSize = din.readDouble();
double readRepairChance = din.readDouble();
int cfId = din.readInt();
int columnMetadataSize = din.readInt();
int columnMetadataEntries = din.readInt();
Map<byte[], ColumnDefinition> column_metadata = new TreeMap<byte[], ColumnDefinition>(FBUtilities.byteArrayComparator);
while (columnMetadataSize > 0)
for (int i = 0; i < columnMetadataEntries; i++)
{
int cdSize = din.readInt();
byte[] cdBytes = new byte[cdSize];
if (in.read(cdBytes) != cdSize)
throw new IOException("short read of ColumnDefinition");
din.readFully(cdBytes);
ColumnDefinition cd = ColumnDefinition.deserialize(cdBytes);
column_metadata.put(cd.name, cd);
}

View File

@ -18,5 +18,5 @@ public class ColumnFamily {
public double keys_cached = CFMetaData.DEFAULT_KEY_CACHE_SIZE;
public double read_repair_chance = CFMetaData.DEFAULT_READ_REPAIR_CHANCE;
public boolean preload_row_cache = CFMetaData.DEFAULT_PRELOAD_ROW_CACHE;
public Map<byte[], ColumnDefinition> column_metata = Collections.emptyMap();
public RawColumnDefinition[] column_metadata = new RawColumnDefinition[0];
}

View File

@ -115,11 +115,14 @@ public class DatabaseDescriptor
InputStream input = new FileInputStream(new File(configFileName));
org.yaml.snakeyaml.constructor.Constructor constructor = new org.yaml.snakeyaml.constructor.Constructor(Config.class);
TypeDescription desc = new TypeDescription(Config.class);
desc.putListPropertyType("keyspaces", Keyspace.class);
TypeDescription ksDesc = new TypeDescription(Keyspace.class);
ksDesc.putListPropertyType("column_families", ColumnFamily.class);
desc.putListPropertyType("keyspaces", Keyspace.class);
TypeDescription cfDesc = new TypeDescription(ColumnFamily.class);
cfDesc.putListPropertyType("column_metadata", RawColumnDefinition.class);
constructor.addTypeDescription(desc);
constructor.addTypeDescription(ksDesc);
constructor.addTypeDescription(cfDesc);
Yaml yaml = new Yaml(new Loader(constructor));
conf = (Config)yaml.load(input);
@ -536,7 +539,34 @@ public class DatabaseDescriptor
{
throw new ConfigurationException("read_repair_chance must be between 0.0 and 1.0");
}
cfDefs[j++] = new CFMetaData(keyspace.name, cf.name, cfType, cf.clock_type, comparator, subcolumnComparator, reconciler, cf.comment, cf.rows_cached, cf.preload_row_cache, cf.keys_cached, cf.read_repair_chance, cf.column_metata);
Map<byte[], ColumnDefinition> metadata = new TreeMap<byte[], ColumnDefinition>(FBUtilities.byteArrayComparator);
for (RawColumnDefinition rcd : cf.column_metadata)
{
try
{
byte[] columnName = rcd.name.getBytes("UTF-8");
metadata.put(columnName, new ColumnDefinition(columnName, rcd.validator_class, rcd.index_type, rcd.index_name));
}
catch (UnsupportedEncodingException e)
{
throw new AssertionError(e);
}
}
cfDefs[j++] = new CFMetaData(keyspace.name,
cf.name,
cfType,
cf.clock_type,
comparator,
subcolumnComparator,
reconciler,
cf.comment,
cf.rows_cached,
cf.preload_row_cache,
cf.keys_cached,
cf.read_repair_chance,
metadata);
}
defs.add(new KSMetaData(keyspace.name, strategyClass, keyspace.replication_factor, cfDefs));

View File

@ -0,0 +1,11 @@
package org.apache.cassandra.config;
import org.apache.cassandra.thrift.IndexType;
public class RawColumnDefinition
{
public String name;
public String validator_class;
public IndexType index_type;
public String index_name;
}

View File

@ -62,6 +62,12 @@ keyspaces:
column_type: Super
compare_subcolumns_with: UTF8Type
- name: Indexed1
column_metadata:
- name: birthdate
validator_class: LongType
index_type: KEYS
- name: Keyspace2
replica_placement_strategy: org.apache.cassandra.locator.RackUnawareStrategy
replication_factor: 1