push replication_factor into strategy_options

patch by jhermes and jbellis; reviewed by jhanna for CASSANDRA-1263

git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1090905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2011-04-10 22:59:57 +00:00
parent 6f4daeac59
commit 8c7bc2fe87
39 changed files with 961 additions and 1951 deletions

View File

@ -16,7 +16,8 @@
* Fix clustertool to not throw exception when calling get_endpoints (CASSANDRA-2437)
* upgrade to thrift 0.6 (CASSANDRA-2412)
* repair works on a token range instead of full ring (CASSANDRA-2324)
* purge tombstone from row cache (CASSANDRA-2305)
* purge tombstones from row cache (CASSANDRA-2305)
* push replication_factor into strategy_options (CASSANDRA-1263)
0.7.5

View File

@ -9,7 +9,7 @@ client and typing "help;"
*/
create keyspace Keyspace1
with replication_factor = 1
with strategy_options=[{replication_factor:1}]
and placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy';
use Keyspace1;

File diff suppressed because it is too large Load Diff

View File

@ -7,4 +7,4 @@
from thrift.Thrift import *
from ttypes import *
VERSION = "19.5.0"
VERSION = "20.0.0"

View File

@ -353,6 +353,165 @@ class SuperColumn:
def __ne__(self, other):
return not (self == other)
class CounterColumn:
"""
Attributes:
- name
- value
"""
thrift_spec = (
None, # 0
(1, TType.STRING, 'name', None, None, ), # 1
(2, TType.I64, 'value', None, None, ), # 2
)
def __init__(self, name=None, value=None,):
self.name = name
self.value = value
def read(self, iprot):
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
return
iprot.readStructBegin()
while True:
(fname, ftype, fid) = iprot.readFieldBegin()
if ftype == TType.STOP:
break
if fid == 1:
if ftype == TType.STRING:
self.name = iprot.readString();
else:
iprot.skip(ftype)
elif fid == 2:
if ftype == TType.I64:
self.value = iprot.readI64();
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
iprot.readStructEnd()
def write(self, oprot):
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
return
oprot.writeStructBegin('CounterColumn')
if self.name != None:
oprot.writeFieldBegin('name', TType.STRING, 1)
oprot.writeString(self.name)
oprot.writeFieldEnd()
if self.value != None:
oprot.writeFieldBegin('value', TType.I64, 2)
oprot.writeI64(self.value)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
def validate(self):
if self.name is None:
raise TProtocol.TProtocolException(message='Required field name is unset!')
if self.value is None:
raise TProtocol.TProtocolException(message='Required field value is unset!')
return
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.iteritems()]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
def __ne__(self, other):
return not (self == other)
class CounterSuperColumn:
"""
Attributes:
- name
- columns
"""
thrift_spec = (
None, # 0
(1, TType.STRING, 'name', None, None, ), # 1
(2, TType.LIST, 'columns', (TType.STRUCT,(CounterColumn, CounterColumn.thrift_spec)), None, ), # 2
)
def __init__(self, name=None, columns=None,):
self.name = name
self.columns = columns
def read(self, iprot):
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
return
iprot.readStructBegin()
while True:
(fname, ftype, fid) = iprot.readFieldBegin()
if ftype == TType.STOP:
break
if fid == 1:
if ftype == TType.STRING:
self.name = iprot.readString();
else:
iprot.skip(ftype)
elif fid == 2:
if ftype == TType.LIST:
self.columns = []
(_etype10, _size7) = iprot.readListBegin()
for _i11 in xrange(_size7):
_elem12 = CounterColumn()
_elem12.read(iprot)
self.columns.append(_elem12)
iprot.readListEnd()
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
iprot.readStructEnd()
def write(self, oprot):
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
return
oprot.writeStructBegin('CounterSuperColumn')
if self.name != None:
oprot.writeFieldBegin('name', TType.STRING, 1)
oprot.writeString(self.name)
oprot.writeFieldEnd()
if self.columns != None:
oprot.writeFieldBegin('columns', TType.LIST, 2)
oprot.writeListBegin(TType.STRUCT, len(self.columns))
for iter13 in self.columns:
iter13.write(oprot)
oprot.writeListEnd()
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
def validate(self):
if self.name is None:
raise TProtocol.TProtocolException(message='Required field name is unset!')
if self.columns is None:
raise TProtocol.TProtocolException(message='Required field columns is unset!')
return
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.iteritems()]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
def __ne__(self, other):
return not (self == other)
class ColumnOrSuperColumn:
"""
Methods for fetching rows/records from Cassandra will return either a single instance of ColumnOrSuperColumn or a list
@ -361,23 +520,34 @@ class ColumnOrSuperColumn:
in Columns, those values will be in the attribute column. This change was made between 0.3 and 0.4 to standardize on
single query methods that may return either a SuperColumn or Column.
If the query was on a counter column family, you will either get a counter_column (instead of a column) or a
counter_super_column (instead of a super_column)
@param column. The Column returned by get() or get_slice().
@param super_column. The SuperColumn returned by get() or get_slice().
@param counter_column. The Counterolumn returned by get() or get_slice().
@param counter_super_column. The CounterSuperColumn returned by get() or get_slice().
Attributes:
- column
- super_column
- counter_column
- counter_super_column
"""
thrift_spec = (
None, # 0
(1, TType.STRUCT, 'column', (Column, Column.thrift_spec), None, ), # 1
(2, TType.STRUCT, 'super_column', (SuperColumn, SuperColumn.thrift_spec), None, ), # 2
(3, TType.STRUCT, 'counter_column', (CounterColumn, CounterColumn.thrift_spec), None, ), # 3
(4, TType.STRUCT, 'counter_super_column', (CounterSuperColumn, CounterSuperColumn.thrift_spec), None, ), # 4
)
def __init__(self, column=None, super_column=None,):
def __init__(self, column=None, super_column=None, counter_column=None, counter_super_column=None,):
self.column = column
self.super_column = super_column
self.counter_column = counter_column
self.counter_super_column = counter_super_column
def read(self, iprot):
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
@ -400,6 +570,18 @@ class ColumnOrSuperColumn:
self.super_column.read(iprot)
else:
iprot.skip(ftype)
elif fid == 3:
if ftype == TType.STRUCT:
self.counter_column = CounterColumn()
self.counter_column.read(iprot)
else:
iprot.skip(ftype)
elif fid == 4:
if ftype == TType.STRUCT:
self.counter_super_column = CounterSuperColumn()
self.counter_super_column.read(iprot)
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
@ -418,6 +600,14 @@ class ColumnOrSuperColumn:
oprot.writeFieldBegin('super_column', TType.STRUCT, 2)
self.super_column.write(oprot)
oprot.writeFieldEnd()
if self.counter_column != None:
oprot.writeFieldBegin('counter_column', TType.STRUCT, 3)
self.counter_column.write(oprot)
oprot.writeFieldEnd()
if self.counter_super_column != None:
oprot.writeFieldBegin('counter_super_column', TType.STRUCT, 4)
self.counter_super_column.write(oprot)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
def validate(self):
@ -998,238 +1188,6 @@ class ColumnPath:
def __ne__(self, other):
return not (self == other)
class CounterColumn:
"""
Attributes:
- name
- value
"""
thrift_spec = (
None, # 0
(1, TType.STRING, 'name', None, None, ), # 1
(2, TType.I64, 'value', None, None, ), # 2
)
def __init__(self, name=None, value=None,):
self.name = name
self.value = value
def read(self, iprot):
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
return
iprot.readStructBegin()
while True:
(fname, ftype, fid) = iprot.readFieldBegin()
if ftype == TType.STOP:
break
if fid == 1:
if ftype == TType.STRING:
self.name = iprot.readString();
else:
iprot.skip(ftype)
elif fid == 2:
if ftype == TType.I64:
self.value = iprot.readI64();
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
iprot.readStructEnd()
def write(self, oprot):
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
return
oprot.writeStructBegin('CounterColumn')
if self.name != None:
oprot.writeFieldBegin('name', TType.STRING, 1)
oprot.writeString(self.name)
oprot.writeFieldEnd()
if self.value != None:
oprot.writeFieldBegin('value', TType.I64, 2)
oprot.writeI64(self.value)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
def validate(self):
if self.name is None:
raise TProtocol.TProtocolException(message='Required field name is unset!')
if self.value is None:
raise TProtocol.TProtocolException(message='Required field value is unset!')
return
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.iteritems()]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
def __ne__(self, other):
return not (self == other)
class CounterSuperColumn:
"""
Attributes:
- name
- columns
"""
thrift_spec = (
None, # 0
(1, TType.STRING, 'name', None, None, ), # 1
(2, TType.LIST, 'columns', (TType.STRUCT,(CounterColumn, CounterColumn.thrift_spec)), None, ), # 2
)
def __init__(self, name=None, columns=None,):
self.name = name
self.columns = columns
def read(self, iprot):
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
return
iprot.readStructBegin()
while True:
(fname, ftype, fid) = iprot.readFieldBegin()
if ftype == TType.STOP:
break
if fid == 1:
if ftype == TType.STRING:
self.name = iprot.readString();
else:
iprot.skip(ftype)
elif fid == 2:
if ftype == TType.LIST:
self.columns = []
(_etype10, _size7) = iprot.readListBegin()
for _i11 in xrange(_size7):
_elem12 = CounterColumn()
_elem12.read(iprot)
self.columns.append(_elem12)
iprot.readListEnd()
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
iprot.readStructEnd()
def write(self, oprot):
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
return
oprot.writeStructBegin('CounterSuperColumn')
if self.name != None:
oprot.writeFieldBegin('name', TType.STRING, 1)
oprot.writeString(self.name)
oprot.writeFieldEnd()
if self.columns != None:
oprot.writeFieldBegin('columns', TType.LIST, 2)
oprot.writeListBegin(TType.STRUCT, len(self.columns))
for iter13 in self.columns:
iter13.write(oprot)
oprot.writeListEnd()
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
def validate(self):
if self.name is None:
raise TProtocol.TProtocolException(message='Required field name is unset!')
if self.columns is None:
raise TProtocol.TProtocolException(message='Required field columns is unset!')
return
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.iteritems()]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
def __ne__(self, other):
return not (self == other)
class Counter:
"""
Attributes:
- column
- super_column
"""
thrift_spec = (
None, # 0
(1, TType.STRUCT, 'column', (CounterColumn, CounterColumn.thrift_spec), None, ), # 1
(2, TType.STRUCT, 'super_column', (CounterSuperColumn, CounterSuperColumn.thrift_spec), None, ), # 2
)
def __init__(self, column=None, super_column=None,):
self.column = column
self.super_column = super_column
def read(self, iprot):
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
return
iprot.readStructBegin()
while True:
(fname, ftype, fid) = iprot.readFieldBegin()
if ftype == TType.STOP:
break
if fid == 1:
if ftype == TType.STRUCT:
self.column = CounterColumn()
self.column.read(iprot)
else:
iprot.skip(ftype)
elif fid == 2:
if ftype == TType.STRUCT:
self.super_column = CounterSuperColumn()
self.super_column.read(iprot)
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
iprot.readStructEnd()
def write(self, oprot):
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
return
oprot.writeStructBegin('Counter')
if self.column != None:
oprot.writeFieldBegin('column', TType.STRUCT, 1)
self.column.write(oprot)
oprot.writeFieldEnd()
if self.super_column != None:
oprot.writeFieldBegin('super_column', TType.STRUCT, 2)
self.super_column.write(oprot)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
def validate(self):
return
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.iteritems()]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
def __ne__(self, other):
return not (self == other)
class SliceRange:
"""
A slice range is a structure that stores basic range, ordering and limit information for a query that will return
@ -1995,28 +1953,24 @@ class Deletion:
class Mutation:
"""
A Mutation is either an insert (represented by filling column_or_supercolumn), a deletion (represented by filling the deletion attribute),
a counter addition (represented by filling counter), or a counter deletion (represented by filling counter_deletion).
@param column_or_supercolumn. An insert to a column or supercolumn
A Mutation is either an insert (represented by filling column_or_supercolumn) or a deletion (represented by filling the deletion attribute).
@param column_or_supercolumn. An insert to a column or supercolumn (possibly counter column or supercolumn)
@param deletion. A deletion of a column or supercolumn
Attributes:
- column_or_supercolumn
- deletion
- counter
"""
thrift_spec = (
None, # 0
(1, TType.STRUCT, 'column_or_supercolumn', (ColumnOrSuperColumn, ColumnOrSuperColumn.thrift_spec), None, ), # 1
(2, TType.STRUCT, 'deletion', (Deletion, Deletion.thrift_spec), None, ), # 2
(3, TType.STRUCT, 'counter', (Counter, Counter.thrift_spec), None, ), # 3
)
def __init__(self, column_or_supercolumn=None, deletion=None, counter=None,):
def __init__(self, column_or_supercolumn=None, deletion=None,):
self.column_or_supercolumn = column_or_supercolumn
self.deletion = deletion
self.counter = counter
def read(self, iprot):
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
@ -2039,12 +1993,6 @@ class Mutation:
self.deletion.read(iprot)
else:
iprot.skip(ftype)
elif fid == 3:
if ftype == TType.STRUCT:
self.counter = Counter()
self.counter.read(iprot)
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
@ -2063,10 +2011,6 @@ class Mutation:
oprot.writeFieldBegin('deletion', TType.STRUCT, 2)
self.deletion.write(oprot)
oprot.writeFieldEnd()
if self.counter != None:
oprot.writeFieldBegin('counter', TType.STRUCT, 3)
self.counter.write(oprot)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
def validate(self):
@ -2407,13 +2351,13 @@ class CfDef:
(21, TType.I32, 'memtable_flush_after_mins', None, None, ), # 21
(22, TType.I32, 'memtable_throughput_in_mb', None, None, ), # 22
(23, TType.DOUBLE, 'memtable_operations_in_millions', None, None, ), # 23
(24, TType.BOOL, 'replicate_on_write', None, False, ), # 24
(24, TType.BOOL, 'replicate_on_write', None, None, ), # 24
(25, TType.DOUBLE, 'merge_shards_chance', None, None, ), # 25
(26, TType.STRING, 'key_validation_class', None, None, ), # 26
(27, TType.STRING, 'row_cache_provider', None, "org.apache.cassandra.cache.ConcurrentLinkedHashCacheProvider", ), # 27
)
def __init__(self, keyspace=None, name=None, column_type=thrift_spec[3][4], comparator_type=thrift_spec[5][4], subcomparator_type=None, comment=None, row_cache_size=thrift_spec[9][4], key_cache_size=thrift_spec[11][4], read_repair_chance=thrift_spec[12][4], column_metadata=None, gc_grace_seconds=None, default_validation_class=None, id=None, min_compaction_threshold=None, max_compaction_threshold=None, row_cache_save_period_in_seconds=None, key_cache_save_period_in_seconds=None, memtable_flush_after_mins=None, memtable_throughput_in_mb=None, memtable_operations_in_millions=None, replicate_on_write=thrift_spec[24][4], merge_shards_chance=None, key_validation_class=None, row_cache_provider=thrift_spec[27][4],):
def __init__(self, keyspace=None, name=None, column_type=thrift_spec[3][4], comparator_type=thrift_spec[5][4], subcomparator_type=None, comment=None, row_cache_size=thrift_spec[9][4], key_cache_size=thrift_spec[11][4], read_repair_chance=thrift_spec[12][4], column_metadata=None, gc_grace_seconds=None, default_validation_class=None, id=None, min_compaction_threshold=None, max_compaction_threshold=None, row_cache_save_period_in_seconds=None, key_cache_save_period_in_seconds=None, memtable_flush_after_mins=None, memtable_throughput_in_mb=None, memtable_operations_in_millions=None, replicate_on_write=None, merge_shards_chance=None, key_validation_class=None, row_cache_provider=thrift_spec[27][4],):
self.keyspace = keyspace
self.name = name
self.column_type = column_type
@ -2710,7 +2654,6 @@ class KsDef:
- name
- strategy_class
- strategy_options
- replication_factor
- cf_defs
"""
@ -2719,15 +2662,13 @@ class KsDef:
(1, TType.STRING, 'name', None, None, ), # 1
(2, TType.STRING, 'strategy_class', None, None, ), # 2
(3, TType.MAP, 'strategy_options', (TType.STRING,None,TType.STRING,None), None, ), # 3
(4, TType.I32, 'replication_factor', None, None, ), # 4
(5, TType.LIST, 'cf_defs', (TType.STRUCT,(CfDef, CfDef.thrift_spec)), None, ), # 5
(4, TType.LIST, 'cf_defs', (TType.STRUCT,(CfDef, CfDef.thrift_spec)), None, ), # 4
)
def __init__(self, name=None, strategy_class=None, strategy_options=None, replication_factor=None, cf_defs=None,):
def __init__(self, name=None, strategy_class=None, strategy_options=None, cf_defs=None,):
self.name = name
self.strategy_class = strategy_class
self.strategy_options = strategy_options
self.replication_factor = replication_factor
self.cf_defs = cf_defs
def read(self, iprot):
@ -2761,11 +2702,6 @@ class KsDef:
else:
iprot.skip(ftype)
elif fid == 4:
if ftype == TType.I32:
self.replication_factor = iprot.readI32();
else:
iprot.skip(ftype)
elif fid == 5:
if ftype == TType.LIST:
self.cf_defs = []
(_etype68, _size65) = iprot.readListBegin()
@ -2802,12 +2738,8 @@ class KsDef:
oprot.writeString(viter72)
oprot.writeMapEnd()
oprot.writeFieldEnd()
if self.replication_factor != None:
oprot.writeFieldBegin('replication_factor', TType.I32, 4)
oprot.writeI32(self.replication_factor)
oprot.writeFieldEnd()
if self.cf_defs != None:
oprot.writeFieldBegin('cf_defs', TType.LIST, 5)
oprot.writeFieldBegin('cf_defs', TType.LIST, 4)
oprot.writeListBegin(TType.STRUCT, len(self.cf_defs))
for iter73 in self.cf_defs:
iter73.write(oprot)
@ -2820,8 +2752,6 @@ class KsDef:
raise TProtocol.TProtocolException(message='Required field name is unset!')
if self.strategy_class is None:
raise TProtocol.TProtocolException(message='Required field strategy_class is unset!')
if self.replication_factor is None:
raise TProtocol.TProtocolException(message='Required field replication_factor is unset!')
if self.cf_defs is None:
raise TProtocol.TProtocolException(message='Required field cf_defs is unset!')
return

View File

@ -46,7 +46,7 @@ namespace rb CassandraThrift
# for every edit that doesn't result in a change to major/minor.
#
# See the Semantic Versioning Specification (SemVer) http://semver.org.
const string VERSION = "19.5.0"
const string VERSION = "20.0.0"
#
@ -401,8 +401,7 @@ struct KsDef {
1: required string name,
2: required string strategy_class,
3: optional map<string,string> strategy_options,
4: required i32 replication_factor,
5: required list<CfDef> cf_defs,
4: required list<CfDef> cf_defs,
}
/** CQL query compression */

View File

@ -44,6 +44,6 @@ import org.slf4j.LoggerFactory;
public class Constants {
public static final String VERSION = "19.5.0";
public static final String VERSION = "20.0.0";
}

View File

@ -48,13 +48,11 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("name", org.apache.thrift.protocol.TType.STRING, (short)1);
private static final org.apache.thrift.protocol.TField STRATEGY_CLASS_FIELD_DESC = new org.apache.thrift.protocol.TField("strategy_class", org.apache.thrift.protocol.TType.STRING, (short)2);
private static final org.apache.thrift.protocol.TField STRATEGY_OPTIONS_FIELD_DESC = new org.apache.thrift.protocol.TField("strategy_options", org.apache.thrift.protocol.TType.MAP, (short)3);
private static final org.apache.thrift.protocol.TField REPLICATION_FACTOR_FIELD_DESC = new org.apache.thrift.protocol.TField("replication_factor", org.apache.thrift.protocol.TType.I32, (short)4);
private static final org.apache.thrift.protocol.TField CF_DEFS_FIELD_DESC = new org.apache.thrift.protocol.TField("cf_defs", org.apache.thrift.protocol.TType.LIST, (short)5);
private static final org.apache.thrift.protocol.TField CF_DEFS_FIELD_DESC = new org.apache.thrift.protocol.TField("cf_defs", org.apache.thrift.protocol.TType.LIST, (short)4);
public String name;
public String strategy_class;
public Map<String,String> strategy_options;
public int replication_factor;
public List<CfDef> cf_defs;
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
@ -62,8 +60,7 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
NAME((short)1, "name"),
STRATEGY_CLASS((short)2, "strategy_class"),
STRATEGY_OPTIONS((short)3, "strategy_options"),
REPLICATION_FACTOR((short)4, "replication_factor"),
CF_DEFS((short)5, "cf_defs");
CF_DEFS((short)4, "cf_defs");
private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
@ -84,9 +81,7 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
return STRATEGY_CLASS;
case 3: // STRATEGY_OPTIONS
return STRATEGY_OPTIONS;
case 4: // REPLICATION_FACTOR
return REPLICATION_FACTOR;
case 5: // CF_DEFS
case 4: // CF_DEFS
return CF_DEFS;
default:
return null;
@ -128,8 +123,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
}
// isset id assignments
private static final int __REPLICATION_FACTOR_ISSET_ID = 0;
private BitSet __isset_bit_vector = new BitSet(1);
public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
static {
@ -142,8 +135,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING),
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))));
tmpMap.put(_Fields.REPLICATION_FACTOR, new org.apache.thrift.meta_data.FieldMetaData("replication_factor", org.apache.thrift.TFieldRequirementType.REQUIRED,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
tmpMap.put(_Fields.CF_DEFS, new org.apache.thrift.meta_data.FieldMetaData("cf_defs", org.apache.thrift.TFieldRequirementType.REQUIRED,
new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CfDef.class))));
@ -157,14 +148,11 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
public KsDef(
String name,
String strategy_class,
int replication_factor,
List<CfDef> cf_defs)
{
this();
this.name = name;
this.strategy_class = strategy_class;
this.replication_factor = replication_factor;
setReplication_factorIsSet(true);
this.cf_defs = cf_defs;
}
@ -172,8 +160,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
* Performs a deep copy on <i>other</i>.
*/
public KsDef(KsDef other) {
__isset_bit_vector.clear();
__isset_bit_vector.or(other.__isset_bit_vector);
if (other.isSetName()) {
this.name = other.name;
}
@ -195,7 +181,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
}
this.strategy_options = __this__strategy_options;
}
this.replication_factor = other.replication_factor;
if (other.isSetCf_defs()) {
List<CfDef> __this__cf_defs = new ArrayList<CfDef>();
for (CfDef other_element : other.cf_defs) {
@ -214,8 +199,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
this.name = null;
this.strategy_class = null;
this.strategy_options = null;
setReplication_factorIsSet(false);
this.replication_factor = 0;
this.cf_defs = null;
}
@ -302,29 +285,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
}
}
public int getReplication_factor() {
return this.replication_factor;
}
public KsDef setReplication_factor(int replication_factor) {
this.replication_factor = replication_factor;
setReplication_factorIsSet(true);
return this;
}
public void unsetReplication_factor() {
__isset_bit_vector.clear(__REPLICATION_FACTOR_ISSET_ID);
}
/** Returns true if field replication_factor is set (has been assigned a value) and false otherwise */
public boolean isSetReplication_factor() {
return __isset_bit_vector.get(__REPLICATION_FACTOR_ISSET_ID);
}
public void setReplication_factorIsSet(boolean value) {
__isset_bit_vector.set(__REPLICATION_FACTOR_ISSET_ID, value);
}
public int getCf_defsSize() {
return (this.cf_defs == null) ? 0 : this.cf_defs.size();
}
@ -390,14 +350,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
}
break;
case REPLICATION_FACTOR:
if (value == null) {
unsetReplication_factor();
} else {
setReplication_factor((Integer)value);
}
break;
case CF_DEFS:
if (value == null) {
unsetCf_defs();
@ -420,9 +372,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
case STRATEGY_OPTIONS:
return getStrategy_options();
case REPLICATION_FACTOR:
return new Integer(getReplication_factor());
case CF_DEFS:
return getCf_defs();
@ -443,8 +392,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
return isSetStrategy_class();
case STRATEGY_OPTIONS:
return isSetStrategy_options();
case REPLICATION_FACTOR:
return isSetReplication_factor();
case CF_DEFS:
return isSetCf_defs();
}
@ -491,15 +438,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
return false;
}
boolean this_present_replication_factor = true;
boolean that_present_replication_factor = true;
if (this_present_replication_factor || that_present_replication_factor) {
if (!(this_present_replication_factor && that_present_replication_factor))
return false;
if (this.replication_factor != that.replication_factor)
return false;
}
boolean this_present_cf_defs = true && this.isSetCf_defs();
boolean that_present_cf_defs = true && that.isSetCf_defs();
if (this_present_cf_defs || that_present_cf_defs) {
@ -531,11 +469,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
if (present_strategy_options)
builder.append(strategy_options);
boolean present_replication_factor = true;
builder.append(present_replication_factor);
if (present_replication_factor)
builder.append(replication_factor);
boolean present_cf_defs = true && (isSetCf_defs());
builder.append(present_cf_defs);
if (present_cf_defs)
@ -582,16 +515,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetReplication_factor()).compareTo(typedOther.isSetReplication_factor());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetReplication_factor()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.replication_factor, typedOther.replication_factor);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetCf_defs()).compareTo(typedOther.isSetCf_defs());
if (lastComparison != 0) {
return lastComparison;
@ -652,15 +575,7 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
case 4: // REPLICATION_FACTOR
if (field.type == org.apache.thrift.protocol.TType.I32) {
this.replication_factor = iprot.readI32();
setReplication_factorIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
case 5: // CF_DEFS
case 4: // CF_DEFS
if (field.type == org.apache.thrift.protocol.TType.LIST) {
{
org.apache.thrift.protocol.TList _list37 = iprot.readListBegin();
@ -686,9 +601,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
iprot.readStructEnd();
// check for required fields of primitive type, which can't be checked in the validate method
if (!isSetReplication_factor()) {
throw new org.apache.thrift.protocol.TProtocolException("Required field 'replication_factor' was not found in serialized data! Struct: " + toString());
}
validate();
}
@ -721,9 +633,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
oprot.writeFieldEnd();
}
}
oprot.writeFieldBegin(REPLICATION_FACTOR_FIELD_DESC);
oprot.writeI32(this.replication_factor);
oprot.writeFieldEnd();
if (this.cf_defs != null) {
oprot.writeFieldBegin(CF_DEFS_FIELD_DESC);
{
@ -771,10 +680,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
first = false;
}
if (!first) sb.append(", ");
sb.append("replication_factor:");
sb.append(this.replication_factor);
first = false;
if (!first) sb.append(", ");
sb.append("cf_defs:");
if (this.cf_defs == null) {
sb.append("null");
@ -794,7 +699,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
if (strategy_class == null) {
throw new org.apache.thrift.protocol.TProtocolException("Required field 'strategy_class' was not present! Struct: " + toString());
}
// alas, we cannot check 'replication_factor' because it's a primitive and you chose the non-beans generator.
if (cf_defs == null) {
throw new org.apache.thrift.protocol.TProtocolException("Required field 'cf_defs' was not present! Struct: " + toString());
}
@ -810,8 +714,6 @@ public class KsDef implements org.apache.thrift.TBase<KsDef, KsDef._Fields>, jav
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
try {
// it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
__isset_bit_vector = new BitSet(1);
read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
} catch (org.apache.thrift.TException te) {
throw new java.io.IOException(te);

View File

@ -72,7 +72,6 @@ protocol InterNode {
string name;
string strategy_class;
union{ map<string>, null } strategy_options;
int replication_factor;
array<CfDef> cf_defs;
}

View File

@ -442,10 +442,6 @@ replica_placement_strategy
: StringLiteral
;
replication_factor
: IntegerPositiveLiteral
;
keyspaceNewName
: Identifier
;

View File

@ -93,7 +93,6 @@ public class CliClient extends CliUserHelp
* this enum defines which arguments are valid
*/
private enum AddKeyspaceArgument {
REPLICATION_FACTOR,
PLACEMENT_STRATEGY,
STRATEGY_OPTIONS
}
@ -831,7 +830,7 @@ public class CliClient extends CliUserHelp
// first value is the keyspace name, after that it is all key=value
String keyspaceName = statement.getChild(0).getText();
KsDef ksDef = new KsDef(keyspaceName, DEFAULT_PLACEMENT_STRATEGY, 1, new LinkedList<CfDef>());
KsDef ksDef = new KsDef(keyspaceName, DEFAULT_PLACEMENT_STRATEGY, new LinkedList<CfDef>());
try
{
@ -966,9 +965,6 @@ public class CliClient extends CliUserHelp
case PLACEMENT_STRATEGY:
ksDef.setStrategy_class(CliUtils.unescapeSQLString(mValue));
break;
case REPLICATION_FACTOR:
ksDef.setReplication_factor(Integer.parseInt(mValue));
break;
case STRATEGY_OPTIONS:
ksDef.setStrategy_options(getStrategyOptionsFromTree(statement.getChild(i + 1)));
break;
@ -1468,15 +1464,8 @@ public class CliClient extends CliUserHelp
ks_def = metadata == null ? thriftClient.describe_keyspace(keySpaceName) : metadata;
sessionState.out.println(" Replication Strategy: " + ks_def.strategy_class);
if (ks_def.strategy_class.endsWith(".NetworkTopologyStrategy"))
{
Map<String, String> options = ks_def.strategy_options;
sessionState.out.println(" Options: [" + ((options == null) ? "" : FBUtilities.toString(options)) + "]");
}
else
{
sessionState.out.println(" Replication Factor: " + ks_def.replication_factor);
}
Map<String, String> options = ks_def.strategy_options;
sessionState.out.println(" Options: [" + ((options == null) ? "" : FBUtilities.toString(options)) + "]");
sessionState.out.println(" Column Families:");

View File

@ -143,20 +143,19 @@ public class CliUserHelp {
state.out.println("create keyspace <keyspace> with <att1>=<value1> and <att2>=<value2> ...;\n");
state.out.println("Create a new keyspace with the specified values for the given set of attributes.\n");
state.out.println("valid attributes are:");
state.out.println(" replication_factor: to how many nodes should entries to this keyspace be");
state.out.println(" replicated. Valid entries are integers greater than 0.");
state.out.println(" Applies to Simple and OldNT strategies but NOT NTS.");
state.out.println(" placement_strategy: the fully qualified class used to place replicas in");
state.out.println(" this keyspace. Valid values are");
state.out.println(" org.apache.cassandra.locator.SimpleStrategy,");
state.out.println(" org.apache.cassandra.locator.NetworkTopologyStrategy,");
state.out.println(" and org.apache.cassandra.locator.OldNetworkTopologyStrategy");
state.out.println(" strategy_options: additional options for placement_strategy.");
state.out.println(" Applies only to NetworkTopologyStrategy.");
state.out.println(" Simple and OldNetworkTopology strategies require");
state.out.println(" 'replication_factor':N, and NetworkTopologyStrategy");
state.out.println(" requires a map of 'DCName':N per-DC.");
state.out.println("\nexamples:");
state.out.println("create keyspace foo with");
state.out.println(" placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy';");
state.out.println(" and replication_factor = 3;");
state.out.println(" placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'");
state.out.println(" and strategy_options=[{replication_factor:3}];");
state.out.println("create keyspace foo with");
state.out.println(" placement_strategy = 'org.apache.cassandra.locator.NetworkTopologyStrategy';");
state.out.println(" and strategy_options=[{DC1:2, DC2:2}];");
@ -168,23 +167,22 @@ public class CliUserHelp {
state.out.println("update keyspace <keyspace> with <att1>=<value1> and <att2>=<value2> ...;\n");
state.out.println("Update a keyspace with the specified values for the given set of attributes.\n");
state.out.println("valid attributes are:");
state.out.println(" replication_factor: to how many nodes should entries to this keyspace be");
state.out.println(" replicated. Valid entries are integers greater than 0.");
state.out.println(" Applies to Simple and OldNT strategies but NOT NTS.");
state.out.println(" placement_strategy: the fully qualified class used to place replicas in");
state.out.println(" this keyspace. Valid values are");
state.out.println(" org.apache.cassandra.locator.SimpleStrategy,");
state.out.println(" org.apache.cassandra.locator.NetworkTopologyStrategy,");
state.out.println(" and org.apache.cassandra.locator.OldNetworkTopologyStrategy");
state.out.println(" strategy_options: additional options for placement_strategy.");
state.out.println(" Applies only to NetworkTopologyStrategy.");
state.out.println(" Simple and OldNetworkTopology strategies require");
state.out.println(" 'replication_factor':N, and NetworkTopologyStrategy");
state.out.println(" requires a map of 'DCName':N per-DC.");
state.out.println("\nexamples:");
state.out.println("update keyspace foo with");
state.out.println(" placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy';");
state.out.println(" and replication_factor = 3;");
state.out.println(" placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'");
state.out.println(" and strategy_options=[{replication_factor:4}];");
state.out.println("update keyspace foo with");
state.out.println(" placement_strategy = 'org.apache.cassandra.locator.NetworkTopologyStrategy';");
state.out.println(" and strategy_options=[{DC1:2, DC2:2}];");
state.out.println(" and strategy_options=[{DC1:3, DC2:2}];");
break;
case CliParser.NODE_ADD_COLUMN_FAMILY:

View File

@ -368,8 +368,7 @@ public class DatabaseDescriptor
// Hardcoded system tables
KSMetaData systemMeta = new KSMetaData(Table.SYSTEM_TABLE,
LocalStrategy.class,
null,
1,
KSMetaData.optsWithRF(1),
CFMetaData.StatusCf,
CFMetaData.HintsCf,
CFMetaData.MigrationsCf,

View File

@ -36,15 +36,13 @@ public final class KSMetaData
public final String name;
public final Class<? extends AbstractReplicationStrategy> strategyClass;
public final Map<String, String> strategyOptions;
public final int replicationFactor;
private final Map<String, CFMetaData> cfMetaData;
public KSMetaData(String name, Class<? extends AbstractReplicationStrategy> strategyClass, Map<String, String> strategyOptions, int replicationFactor, CFMetaData... cfDefs)
public KSMetaData(String name, Class<? extends AbstractReplicationStrategy> strategyClass, Map<String, String> strategyOptions, CFMetaData... cfDefs)
{
this.name = name;
this.strategyClass = strategyClass == null ? NetworkTopologyStrategy.class : strategyClass;
this.strategyOptions = strategyOptions;
this.replicationFactor = replicationFactor;
Map<String, CFMetaData> cfmap = new HashMap<String, CFMetaData>();
for (CFMetaData cfm : cfDefs)
cfmap.put(cfm.cfName, cfm);
@ -64,7 +62,6 @@ public final class KSMetaData
return other.name.equals(name)
&& ObjectUtils.equals(other.strategyClass, strategyClass)
&& ObjectUtils.equals(other.strategyOptions, strategyOptions)
&& other.replicationFactor == replicationFactor
&& other.cfMetaData.size() == cfMetaData.size()
&& other.cfMetaData.equals(cfMetaData);
}
@ -87,7 +84,6 @@ public final class KSMetaData
ks.strategy_options.put(new Utf8(e.getKey()), new Utf8(e.getValue()));
}
}
ks.replication_factor = replicationFactor;
ks.cf_defs = SerDeUtils.createArray(cfMetaData.size(), org.apache.cassandra.db.migration.avro.CfDef.SCHEMA$);
for (CFMetaData cfm : cfMetaData.values())
ks.cf_defs.add(cfm.deflate());
@ -99,8 +95,6 @@ public final class KSMetaData
{
StringBuilder sb = new StringBuilder();
sb.append(name)
.append("rep factor:")
.append(replicationFactor)
.append("rep strategy:")
.append(strategyClass.getSimpleName())
.append("{")
@ -136,7 +130,7 @@ public final class KSMetaData
for (int i = 0; i < cfsz; i++)
cfMetaData[i] = CFMetaData.inflate(cfiter.next());
return new KSMetaData(ks.name.toString(), repStratClass, strategyOptions, ks.replication_factor, cfMetaData);
return new KSMetaData(ks.name.toString(), repStratClass, strategyOptions, cfMetaData);
}
public static String convertOldStrategyName(String name)
@ -144,4 +138,11 @@ public final class KSMetaData
return name.replace("RackUnawareStrategy", "SimpleStrategy")
.replace("RackAwareStrategy", "OldNetworkTopologyStrategy");
}
public static Map<String,String> optsWithRF(final Integer rf)
{
Map<String, String> ret = new HashMap<String,String>();
ret.put("replication_factor", rf.toString());
return ret;
}
}

View File

@ -31,7 +31,6 @@ public class CreateKeyspaceStatement
private final String name;
private final Map<String, String> attrs;
private String strategyClass;
private int replicationFactor;
private Map<String, String> strategyOptions = new HashMap<String, String>();
/**
@ -65,20 +64,6 @@ public class CreateKeyspaceStatement
throw new InvalidRequestException("missing required argument \"strategy_class\"");
strategyClass = attrs.get("strategy_class");
// required
if (!attrs.containsKey("replication_factor"))
throw new InvalidRequestException("missing required argument \"replication_factor\"");
try
{
replicationFactor = Integer.parseInt(attrs.get("replication_factor"));
}
catch (NumberFormatException e)
{
throw new InvalidRequestException(String.format("\"%s\" is not valid for replication_factor",
attrs.get("replication_factor")));
}
// optional
for (String key : attrs.keySet())
if ((key.contains(":")) && (key.startsWith("strategy_options")))
@ -94,12 +79,7 @@ public class CreateKeyspaceStatement
{
return strategyClass;
}
public int getReplicationFactor()
{
return replicationFactor;
}
public Map<String, String> getStrategyOptions()
{
return strategyOptions;

View File

@ -640,8 +640,7 @@ public class QueryProcessor
{
KSMetaData ksm = new KSMetaData(create.getName(),
AbstractReplicationStrategy.getClass(create.getStrategyClass()),
create.getStrategyOptions(),
create.getReplicationFactor());
create.getStrategyOptions());
applyMigrationOnStage(new AddKeyspace(ksm));
}
catch (ConfigurationException e)

View File

@ -68,7 +68,7 @@ public class AddColumnFamily extends Migration
{
List<CFMetaData> newCfs = new ArrayList<CFMetaData>(ksm.cfMetaData().values());
newCfs.add(cfm);
return new KSMetaData(ksm.name, ksm.strategyClass, ksm.strategyOptions, ksm.replicationFactor, newCfs.toArray(new CFMetaData[newCfs.size()]));
return new KSMetaData(ksm.name, ksm.strategyClass, ksm.strategyOptions, newCfs.toArray(new CFMetaData[newCfs.size()]));
}
public void applyModels() throws IOException

View File

@ -64,7 +64,7 @@ public class DropColumnFamily extends Migration
List<CFMetaData> newCfs = new ArrayList<CFMetaData>(ksm.cfMetaData().values());
newCfs.remove(cfm);
assert newCfs.size() == ksm.cfMetaData().size() - 1;
return new KSMetaData(ksm.name, ksm.strategyClass, ksm.strategyOptions, ksm.replicationFactor, newCfs.toArray(new CFMetaData[newCfs.size()]));
return new KSMetaData(ksm.name, ksm.strategyClass, ksm.strategyOptions, newCfs.toArray(new CFMetaData[newCfs.size()]));
}
public void applyModels() throws IOException

View File

@ -76,7 +76,7 @@ public class RenameColumnFamily extends Migration
assert newCfs.size() == ksm.cfMetaData().size() - 1;
CFMetaData newCfm = CFMetaData.rename(oldCfm, newName);
newCfs.add(newCfm);
return new KSMetaData(ksm.name, ksm.strategyClass, ksm.strategyOptions, ksm.replicationFactor, newCfs.toArray(new CFMetaData[newCfs.size()]));
return new KSMetaData(ksm.name, ksm.strategyClass, ksm.strategyOptions, newCfs.toArray(new CFMetaData[newCfs.size()]));
}
public void applyModels() throws IOException

View File

@ -75,7 +75,7 @@ public class RenameKeyspace extends Migration
CFMetaData.purge(oldCf);
newCfs.add(CFMetaData.renameTable(oldCf, newName));
}
return new KSMetaData(newName, ksm.strategyClass, ksm.strategyOptions, ksm.replicationFactor, newCfs.toArray(new CFMetaData[newCfs.size()]));
return new KSMetaData(newName, ksm.strategyClass, ksm.strategyOptions, newCfs.toArray(new CFMetaData[newCfs.size()]));
}
public void applyModels() throws IOException

View File

@ -51,7 +51,7 @@ public class UpdateKeyspace extends Migration
oldKsm = DatabaseDescriptor.getKSMetaData(ksm.name);
if (oldKsm == null)
throw new ConfigurationException(ksm.name + " cannot be updated because it doesn't exist.");
this.newKsm = new KSMetaData(ksm.name, ksm.strategyClass, ksm.strategyOptions, ksm.replicationFactor, oldKsm.cfMetaData().values().toArray(new CFMetaData[]{}));
this.newKsm = new KSMetaData(ksm.name, ksm.strategyClass, ksm.strategyOptions, oldKsm.cfMetaData().values().toArray(new CFMetaData[]{}));
rm = makeDefinitionMutation(newKsm, oldKsm, newVersion);
}

View File

@ -30,7 +30,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.dht.Range;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.gms.FailureDetector;
@ -127,10 +126,13 @@ public abstract class AbstractReplicationStrategy
return WriteResponseHandler.create(writeEndpoints, hintedEndpoints, consistencyLevel, table);
}
public int getReplicationFactor()
{
return DatabaseDescriptor.getTableDefinition(table).replicationFactor;
}
/**
* calculate the RF based on strategy_options. When overwriting, ensure that this get()
* is FAST, as this is called often.
*
* @return the replication factor
*/
public abstract int getReplicationFactor();
/**
* returns <tt>Multimap</tt> of {live destination: ultimate targets}, where if target is not the same
@ -235,6 +237,8 @@ public abstract class AbstractReplicationStrategy
clearEndpointCache();
}
public abstract void validateOptions() throws ConfigurationException;
public static AbstractReplicationStrategy createReplicationStrategy(String table,
Class<? extends AbstractReplicationStrategy> strategyClass,
TokenMetadata tokenMetadata,
@ -254,6 +258,9 @@ public abstract class AbstractReplicationStrategy
throw new RuntimeException(e);
}
// Throws Config Exception if strat_opts don't contain required info
strategy.validateOptions();
return strategy;
}

View File

@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.utils.FBUtilities;
@ -38,4 +39,14 @@ public class LocalStrategy extends AbstractReplicationStrategy
{
return Arrays.asList(FBUtilities.getLocalAddress());
}
public int getReplicationFactor()
{
return 1;
}
public void validateOptions() throws ConfigurationException
{
// LocalStrategy doesn't expect any options.
}
}

View File

@ -164,4 +164,17 @@ public class NetworkTopologyStrategy extends AbstractReplicationStrategy
}
return super.getWriteResponseHandler(writeEndpoints, hintedEndpoints, consistency_level);
}
public void validateOptions() throws ConfigurationException
{
for (Entry<String,String> e : this.configOptions.entrySet())
{
int rf = Integer.parseInt(e.getValue());
if (rf < 0)
{
throw new ConfigurationException("Replication factor for NTS must be non-negative. dc: " +e.getKey()+", rf: "+rf);
}
}
}
}

View File

@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.dht.Token;
/**
@ -102,4 +103,26 @@ public class OldNetworkTopologyStrategy extends AbstractReplicationStrategy
return endpoints;
}
public int getReplicationFactor()
{
return Integer.parseInt(this.configOptions.get("replication_factor"));
}
public void validateOptions() throws ConfigurationException
{
if (this.configOptions == null)
{
throw new ConfigurationException("OldNetworkTopologyStrategy requires a replication_factor strategy option.");
}
if (this.configOptions.get("replication_factor") == null)
{
throw new ConfigurationException("OldNetworkTopologyStrategy requires a replication_factor strategy option.");
}
int rf = Integer.parseInt(this.configOptions.get("replication_factor"));
if (rf < 0)
{
throw new ConfigurationException("Replication factor for OldNetworkTopologyStrategy must be non-negative, "+rf+" given.");
}
}
}

View File

@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.dht.Token;
/**
@ -62,4 +63,25 @@ public class SimpleStrategy extends AbstractReplicationStrategy
return endpoints;
}
public int getReplicationFactor()
{
return Integer.parseInt(this.configOptions.get("replication_factor"));
}
public void validateOptions() throws ConfigurationException
{
if (this.configOptions == null)
{
throw new ConfigurationException("SimpleStrategy requires a replication_factor strategy option.");
}
if (this.configOptions.get("replication_factor") == null)
{
throw new ConfigurationException("SimpleStrategy requires a replication_factor strategy option.");
}
int rf = Integer.parseInt(this.configOptions.get("replication_factor"));
if (rf < 0)
{
throw new ConfigurationException("Replication factor for SimpleStrategy must be non-negative, "+rf+" given.");
}
}
}

View File

@ -49,8 +49,7 @@ import org.apache.cassandra.db.marshal.MarshalException;
import org.apache.cassandra.db.migration.*;
import org.apache.cassandra.db.context.CounterContext;
import org.apache.cassandra.dht.*;
import org.apache.cassandra.locator.AbstractReplicationStrategy;
import org.apache.cassandra.locator.DynamicEndpointSnitch;
import org.apache.cassandra.locator.*;
import org.apache.cassandra.scheduler.IRequestScheduler;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.StorageProxy;
@ -563,7 +562,7 @@ public class CassandraServer implements Cassandra.Iface
List<CfDef> cfDefs = new ArrayList<CfDef>();
for (CFMetaData cfm : ksm.cfMetaData().values())
cfDefs.add(CFMetaData.convertToThrift(cfm));
KsDef ksdef = new KsDef(ksm.name, ksm.strategyClass.getName(), ksm.replicationFactor, cfDefs);
KsDef ksdef = new KsDef(ksm.name, ksm.strategyClass.getName(), cfDefs);
ksdef.setStrategy_options(ksm.strategyOptions);
return ksdef;
}
@ -859,11 +858,23 @@ public class CassandraServer implements Cassandra.Iface
cfDefs.add(convertToCFMetaData(cfDef));
}
// Attempt to instantiate the ARS, which will throw a ConfigException if
// the strategy_options aren't fully formed or if the ARS Classname is invalid.
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
IEndpointSnitch eps = DatabaseDescriptor.getEndpointSnitch();
Class<? extends AbstractReplicationStrategy> cls = AbstractReplicationStrategy.getClass(ks_def.strategy_class);
AbstractReplicationStrategy strat = AbstractReplicationStrategy
.createReplicationStrategy(ks_def.name,
cls,
tmd,
eps,
ks_def.strategy_options);
KSMetaData ksm = new KSMetaData(ks_def.name,
AbstractReplicationStrategy.getClass(ks_def.strategy_class),
ks_def.strategy_options,
ks_def.replication_factor,
cfDefs.toArray(new CFMetaData[cfDefs.size()]));
applyMigrationOnStage(new AddKeyspace(ksm));
return DatabaseDescriptor.getDefsVersion().toString();
}
@ -921,11 +932,9 @@ public class CassandraServer implements Cassandra.Iface
try
{
KSMetaData ksm = new KSMetaData(
ks_def.name,
AbstractReplicationStrategy.getClass(ks_def.strategy_class),
ks_def.strategy_options,
ks_def.replication_factor);
KSMetaData ksm = new KSMetaData(ks_def.name,
AbstractReplicationStrategy.getClass(ks_def.strategy_class),
ks_def.strategy_options);
applyMigrationOnStage(new UpdateKeyspace(ksm));
return DatabaseDescriptor.getDefsVersion().toString();
}

View File

@ -148,7 +148,7 @@ class ThriftTester(BaseTester):
self.client.transport.close()
def define_schema(self):
keyspace1 = Cassandra.KsDef('Keyspace1', 'org.apache.cassandra.locator.SimpleStrategy', None, 1,
keyspace1 = Cassandra.KsDef('Keyspace1', 'org.apache.cassandra.locator.SimpleStrategy', {'replication_factor':'1'},
[
Cassandra.CfDef('Keyspace1', 'Standard1'),
Cassandra.CfDef('Keyspace1', 'Standard2'),
@ -167,7 +167,7 @@ class ThriftTester(BaseTester):
])
keyspace2 = Cassandra.KsDef('Keyspace2', 'org.apache.cassandra.locator.SimpleStrategy', None, 1,
keyspace2 = Cassandra.KsDef('Keyspace2', 'org.apache.cassandra.locator.SimpleStrategy', {'replication_factor':'1'},
[
Cassandra.CfDef('Keyspace2', 'Standard1'),
Cassandra.CfDef('Keyspace2', 'Standard3'),

View File

@ -324,14 +324,13 @@ class TestCql(ThriftTester):
"create a new keyspace"
init().execute("""
CREATE KEYSPACE TestKeyspace42 WITH strategy_options:DC1 = '1'
AND strategy_class = 'SimpleStrategy' AND replication_factor = 3
AND strategy_class = 'NetworkTopologyStrategy'
""")
# TODO: temporary (until this can be done with CQL).
ksdef = thrift_client.describe_keyspace("TestKeyspace42")
assert ksdef.replication_factor == 3
strategy_class = "org.apache.cassandra.locator.SimpleStrategy"
strategy_class = "org.apache.cassandra.locator.NetworkTopologyStrategy"
assert ksdef.strategy_class == strategy_class
assert ksdef.strategy_options['DC1'] == "1"
@ -340,7 +339,7 @@ class TestCql(ThriftTester):
conn = init()
conn.execute("""
CREATE KEYSPACE Keyspace4Drop
WITH strategy_class = SimpleStrategy AND replication_factor = 1
WITH strategy_class = SimpleStrategy AND strategy_options:replication_factor = 1
""")
# TODO: temporary (until this can be done with CQL).
@ -358,7 +357,7 @@ class TestCql(ThriftTester):
"create a new column family"
conn = init()
conn.execute("""
CREATE KEYSPACE CreateCFKeyspace WITH replication_factor = 1
CREATE KEYSPACE CreateCFKeyspace WITH strategy_options:replication_factor = 1
AND strategy_class = 'SimpleStrategy';
""")
conn.execute("USE CreateCFKeyspace;")
@ -422,7 +421,7 @@ class TestCql(ThriftTester):
"removing a column family"
conn = init()
conn.execute("""
CREATE KEYSPACE Keyspace4CFDrop WITH replication_factor = 1
CREATE KEYSPACE Keyspace4CFDrop WITH strategy_options:replication_factor = 1
AND strategy_class = 'SimpleStrategy';
""")
conn.execute('USE Keyspace4CFDrop;')

View File

@ -1121,7 +1121,7 @@ class TestMutations(ThriftTester):
assert sysks == kspaces[2]
ks1 = client.describe_keyspace("Keyspace1")
assert ks1.replication_factor == 1
assert ks1.strategy_options['replication_factor'] == '1', ks1.strategy_options
for cf in ks1.cf_defs:
if cf.name == "Standard1":
cf0 = cf
@ -1145,20 +1145,20 @@ class TestMutations(ThriftTester):
def test_invalid_ks_names(self):
def invalid_keyspace():
client.system_add_keyspace(KsDef('in-valid', 'org.apache.cassandra.locator.SimpleStrategy', {}, 1, []))
client.system_add_keyspace(KsDef('in-valid', 'org.apache.cassandra.locator.SimpleStrategy', {'replication_factor':'1'}, []))
_expect_exception(invalid_keyspace, InvalidRequestException)
def test_invalid_strategy_class(self):
def add_invalid_keyspace():
client.system_add_keyspace(KsDef('ValidKs', 'InvalidStrategyClass', {}, 1, []))
client.system_add_keyspace(KsDef('ValidKs', 'InvalidStrategyClass', {}, []))
exc = _expect_exception(add_invalid_keyspace, InvalidRequestException)
s = str(exc)
assert s.find("InvalidStrategyClass") > -1, s
assert s.find("Unable to find replication strategy") > -1, s
def update_invalid_keyspace():
client.system_add_keyspace(KsDef('ValidKsForUpdate', 'org.apache.cassandra.locator.SimpleStrategy', {}, 1, []))
client.system_update_keyspace(KsDef('ValidKsForUpdate', 'InvalidStrategyClass', {}, 1, []))
client.system_add_keyspace(KsDef('ValidKsForUpdate', 'org.apache.cassandra.locator.SimpleStrategy', {'replication_factor':'1'}, []))
client.system_update_keyspace(KsDef('ValidKsForUpdate', 'InvalidStrategyClass', {}, []))
exc = _expect_exception(update_invalid_keyspace, InvalidRequestException)
s = str(exc)
@ -1175,7 +1175,7 @@ class TestMutations(ThriftTester):
def invalid_cf_inside_new_ks():
cf = CfDef('ValidKsName_invalid_cf', 'in-valid')
_set_keyspace('system')
client.system_add_keyspace(KsDef('ValidKsName_invalid_cf', 'org.apache.cassandra.locator.SimpleStrategy', {}, 1, [cf]))
client.system_add_keyspace(KsDef('ValidKsName_invalid_cf', 'org.apache.cassandra.locator.SimpleStrategy', {'replication_factor': '1'}, [cf]))
_expect_exception(invalid_cf_inside_new_ks, InvalidRequestException)
def test_system_cf_recreate(self):
@ -1187,7 +1187,7 @@ class TestMutations(ThriftTester):
# create
newcf = CfDef(keyspace, cf_name)
newks = KsDef(keyspace, 'org.apache.cassandra.locator.SimpleStrategy', {}, 1, [newcf])
newks = KsDef(keyspace, 'org.apache.cassandra.locator.SimpleStrategy', {'replication_factor':'1'}, [newcf])
client.system_add_keyspace(newks)
_set_keyspace(keyspace)
@ -1211,7 +1211,9 @@ class TestMutations(ThriftTester):
def test_system_keyspace_operations(self):
# create. note large RF, this is OK
keyspace = KsDef('CreateKeyspace', 'org.apache.cassandra.locator.SimpleStrategy', {}, 10,
keyspace = KsDef('CreateKeyspace',
'org.apache.cassandra.locator.SimpleStrategy',
{'replication_factor': '10'},
[CfDef('CreateKeyspace', 'CreateKsCf')])
client.system_add_keyspace(keyspace)
newks = client.describe_keyspace('CreateKeyspace')
@ -1220,11 +1222,14 @@ class TestMutations(ThriftTester):
_set_keyspace('CreateKeyspace')
# modify valid
modified_keyspace = KsDef('CreateKeyspace', 'org.apache.cassandra.locator.OldNetworkTopologyStrategy', {}, 1, [])
modified_keyspace = KsDef('CreateKeyspace',
'org.apache.cassandra.locator.OldNetworkTopologyStrategy',
{'replication_factor': '1'},
[])
client.system_update_keyspace(modified_keyspace)
modks = client.describe_keyspace('CreateKeyspace')
assert modks.replication_factor == modified_keyspace.replication_factor
assert modks.strategy_class == modified_keyspace.strategy_class
assert modks.strategy_options == modified_keyspace.strategy_options
# drop
client.system_drop_keyspace('CreateKeyspace')
@ -1235,7 +1240,7 @@ class TestMutations(ThriftTester):
def test_create_then_drop_ks(self):
keyspace = KsDef('AddThenDrop',
strategy_class='org.apache.cassandra.locator.SimpleStrategy',
replication_factor=1,
strategy_options={'replication_factor':'1'},
cf_defs=[])
def test_existence():
client.describe_keyspace(keyspace.name)

View File

@ -68,11 +68,11 @@ public class SchemaLoader
String ks_rcs = "RowCacheSpace";
Class<? extends AbstractReplicationStrategy> simple = SimpleStrategy.class;
Map<String, String> no_opts = Collections.<String, String>emptyMap();
int rep_factor1 = 1;
int rep_factor2 = 2;
int rep_factor3 = 3;
int rep_factor5 = 5;
Map<String, String> opts_rf1 = KSMetaData.optsWithRF(1);
Map<String, String> opts_rf2 = KSMetaData.optsWithRF(2);
Map<String, String> opts_rf3 = KSMetaData.optsWithRF(3);
Map<String, String> opts_rf5 = KSMetaData.optsWithRF(5);
ColumnFamilyType st = ColumnFamilyType.Standard;
ColumnFamilyType su = ColumnFamilyType.Super;
@ -81,8 +81,7 @@ public class SchemaLoader
// Keyspace 1
schema.add(new KSMetaData(ks1,
simple,
no_opts,
rep_factor1,
opts_rf1,
// Column Families
standardCFMD(ks1, "Standard1"),
@ -125,8 +124,7 @@ public class SchemaLoader
// Keyspace 2
schema.add(new KSMetaData(ks2,
simple,
no_opts,
rep_factor1,
opts_rf1,
// Column Families
standardCFMD(ks2, "Standard1"),
@ -138,8 +136,7 @@ public class SchemaLoader
// Keyspace 3
schema.add(new KSMetaData(ks3,
simple,
no_opts,
rep_factor5,
opts_rf5,
// Column Families
standardCFMD(ks3, "Standard1"),
@ -148,8 +145,7 @@ public class SchemaLoader
// Keyspace 4
schema.add(new KSMetaData(ks4,
simple,
no_opts,
rep_factor3,
opts_rf3,
// Column Families
standardCFMD(ks4, "Standard1"),
@ -166,10 +162,7 @@ public class SchemaLoader
// Keyspace 5
schema.add(new KSMetaData(ks5,
simple,
no_opts,
rep_factor2,
// Column Families
opts_rf2,
standardCFMD(ks5, "Standard1"),
standardCFMD(ks5, "Counter1")
.defaultValidator(CounterColumnType.instance)));
@ -177,8 +170,7 @@ public class SchemaLoader
// KeyCacheSpace
schema.add(new KSMetaData(ks_kcs,
simple,
no_opts,
rep_factor1,
opts_rf1,
standardCFMD(ks_kcs, "Standard1")
.keyCacheSize(0.5),
standardCFMD(ks_kcs, "Standard2")
@ -187,8 +179,7 @@ public class SchemaLoader
// RowCacheSpace
schema.add(new KSMetaData(ks_rcs,
simple,
no_opts,
rep_factor1,
opts_rf1,
standardCFMD(ks_rcs, "CFWithoutCache"),
standardCFMD(ks_rcs, "CachedCF")
.rowCacheSize(100)));
@ -217,6 +208,6 @@ public class SchemaLoader
}
private static CFMetaData jdbcCFMD(String ksName, String cfName, AbstractType comp)
{
return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, comp, null).defaultValidator(comp);
return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, comp, comp).defaultValidator(comp);
}
}

View File

@ -106,7 +106,7 @@ public class CliTest extends CleanupHelper
"get Counter1['hello'];",
"truncate CF1;",
"update keyspace TestKeySpace with placement_strategy='org.apache.cassandra.locator.LocalStrategy';",
"update keyspace TestKeySpace with replication_factor=1 and strategy_options=[{DC1:3, DC2:4, DC5:1}];",
"update keyspace TestKeySpace with strategy_options=[{DC1:3, DC2:4, DC5:1}];",
"assume CF1 comparator as utf8;",
"assume CF1 sub_comparator as integer;",
"assume CF1 validator as lexicaluuid;",

View File

@ -63,7 +63,9 @@ public class DatabaseDescriptorTest
{
for (KSMetaData ksm : DatabaseDescriptor.tables.values())
{
KSMetaData ksmDupe = KSMetaData.inflate(serDe(ksm.deflate(), new org.apache.cassandra.db.migration.avro.KsDef()));
// Not testing round-trip on the KsDef via serDe() because maps
// cannot be compared in avro.
KSMetaData ksmDupe = KSMetaData.inflate(ksm.deflate());
assert ksmDupe != null;
assert ksmDupe.equals(ksm);
}
@ -78,9 +80,9 @@ public class DatabaseDescriptorTest
assert DatabaseDescriptor.getNonSystemTables().size() == 0;
// add a few.
AddKeyspace ks0 = new AddKeyspace(new KSMetaData("ks0", SimpleStrategy.class, null, 3));
AddKeyspace ks0 = new AddKeyspace(new KSMetaData("ks0", SimpleStrategy.class, KSMetaData.optsWithRF(3)));
ks0.apply();
AddKeyspace ks1 = new AddKeyspace(new KSMetaData("ks1", SimpleStrategy.class, null, 3));
AddKeyspace ks1 = new AddKeyspace(new KSMetaData("ks1", SimpleStrategy.class, KSMetaData.optsWithRF(3)));
ks1.apply();
assert DatabaseDescriptor.getTableDefinition("ks0") != null;

View File

@ -400,7 +400,7 @@ public class DefsTest extends CleanupHelper
DecoratedKey dk = Util.dk("key0");
CFMetaData newCf = addTestCF("NewKeyspace1", "AddedStandard1", "A new cf for a new ks");
KSMetaData newKs = new KSMetaData(newCf.ksName, SimpleStrategy.class, null, 5, newCf);
KSMetaData newKs = new KSMetaData(newCf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(5), newCf);
new AddKeyspace(newKs).apply();
@ -579,7 +579,7 @@ public class DefsTest extends CleanupHelper
{
assert DatabaseDescriptor.getTableDefinition("EmptyKeyspace") == null;
KSMetaData newKs = new KSMetaData("EmptyKeyspace", SimpleStrategy.class, null, 5);
KSMetaData newKs = new KSMetaData("EmptyKeyspace", SimpleStrategy.class, KSMetaData.optsWithRF(5));
new AddKeyspace(newKs).apply();
assert DatabaseDescriptor.getTableDefinition("EmptyKeyspace") != null;
@ -615,7 +615,7 @@ public class DefsTest extends CleanupHelper
{
// create a keyspace to serve as existing.
CFMetaData cf = addTestCF("UpdatedKeyspace", "AddedStandard1", "A new cf for a new ks");
KSMetaData oldKs = new KSMetaData(cf.ksName, SimpleStrategy.class, null, 5, cf);
KSMetaData oldKs = new KSMetaData(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(5), cf);
new AddKeyspace(oldKs).apply();
@ -624,7 +624,7 @@ public class DefsTest extends CleanupHelper
// anything with cf defs should fail.
CFMetaData cf2 = addTestCF(cf.ksName, "AddedStandard2", "A new cf for a new ks");
KSMetaData newBadKs = new KSMetaData(cf.ksName, SimpleStrategy.class, null, 4, cf2);
KSMetaData newBadKs = new KSMetaData(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(4), cf2);
try
{
new UpdateKeyspace(newBadKs).apply();
@ -636,7 +636,7 @@ public class DefsTest extends CleanupHelper
}
// names should match.
KSMetaData newBadKs2 = new KSMetaData(cf.ksName + "trash", SimpleStrategy.class, null, 4);
KSMetaData newBadKs2 = new KSMetaData(cf.ksName + "trash", SimpleStrategy.class, KSMetaData.optsWithRF(4));
try
{
new UpdateKeyspace(newBadKs2).apply();
@ -647,12 +647,10 @@ public class DefsTest extends CleanupHelper
// expected.
}
KSMetaData newKs = new KSMetaData(cf.ksName, OldNetworkTopologyStrategy.class, null, 1);
KSMetaData newKs = new KSMetaData(cf.ksName, OldNetworkTopologyStrategy.class, KSMetaData.optsWithRF(1));
new UpdateKeyspace(newKs).apply();
KSMetaData newFetchedKs = DatabaseDescriptor.getKSMetaData(newKs.name);
assert newFetchedKs.replicationFactor == newKs.replicationFactor;
assert newFetchedKs.replicationFactor != oldKs.replicationFactor;
assert newFetchedKs.strategyClass.equals(newKs.strategyClass);
assert !newFetchedKs.strategyClass.equals(oldKs.strategyClass);
}
@ -662,7 +660,7 @@ public class DefsTest extends CleanupHelper
{
// create a keyspace with a cf to update.
CFMetaData cf = addTestCF("UpdatedCfKs", "Standard1added", "A new cf that will be updated");
KSMetaData ksm = new KSMetaData(cf.ksName, SimpleStrategy.class, null, 1, cf);
KSMetaData ksm = new KSMetaData(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(1), cf);
new AddKeyspace(ksm).apply();
assert DatabaseDescriptor.getTableDefinition(cf.ksName) != null;

View File

@ -32,6 +32,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.config.KSMetaData;
import org.apache.cassandra.dht.BigIntegerToken;
import org.apache.cassandra.dht.Token;
@ -61,7 +62,7 @@ public class OldNetworkTopologyStrategyTest extends SchemaLoader
{
RackInferringSnitch endpointSnitch = new RackInferringSnitch();
AbstractReplicationStrategy strategy = new OldNetworkTopologyStrategy("Keyspace1", tmd, endpointSnitch, null);
AbstractReplicationStrategy strategy = new OldNetworkTopologyStrategy("Keyspace1", tmd, endpointSnitch, KSMetaData.optsWithRF(1));
addEndpoint("0", "5", "254.0.0.1");
addEndpoint("10", "15", "254.0.0.2");
addEndpoint("20", "25", "254.0.0.3");
@ -86,7 +87,7 @@ public class OldNetworkTopologyStrategyTest extends SchemaLoader
{
RackInferringSnitch endpointSnitch = new RackInferringSnitch();
AbstractReplicationStrategy strategy = new OldNetworkTopologyStrategy("Keyspace1", tmd, endpointSnitch, null);
AbstractReplicationStrategy strategy = new OldNetworkTopologyStrategy("Keyspace1", tmd, endpointSnitch, KSMetaData.optsWithRF(1));
addEndpoint("0", "5", "254.0.0.1");
addEndpoint("10", "15", "254.0.0.2");
addEndpoint("20", "25", "254.1.0.3");
@ -112,7 +113,7 @@ public class OldNetworkTopologyStrategyTest extends SchemaLoader
{
RackInferringSnitch endpointSnitch = new RackInferringSnitch();
AbstractReplicationStrategy strategy = new OldNetworkTopologyStrategy("Keyspace1", tmd, endpointSnitch, null);
AbstractReplicationStrategy strategy = new OldNetworkTopologyStrategy("Keyspace1", tmd, endpointSnitch, KSMetaData.optsWithRF(1));
addEndpoint("0", "5", "254.0.0.1");
addEndpoint("10", "15", "254.0.0.2");
addEndpoint("20", "25", "254.0.1.3");

View File

@ -32,6 +32,7 @@ import org.junit.Test;
import org.apache.cassandra.CleanupHelper;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.KSMetaData;
import org.apache.cassandra.db.Table;
import org.apache.cassandra.dht.*;
import org.apache.cassandra.service.StorageService;
@ -177,11 +178,12 @@ public class SimpleStrategyTest extends CleanupHelper
private AbstractReplicationStrategy getStrategy(String table, TokenMetadata tmd) throws ConfigurationException
{
KSMetaData ksmd = DatabaseDescriptor.getKSMetaData(table);
return AbstractReplicationStrategy.createReplicationStrategy(
table,
"org.apache.cassandra.locator.SimpleStrategy",
ksmd.strategyClass,
tmd,
new SimpleSnitch(),
null);
ksmd.strategyOptions);
}
}

View File

@ -32,6 +32,7 @@ import org.apache.cassandra.CleanupHelper;
import org.apache.cassandra.Util;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.KSMetaData;
import org.apache.cassandra.db.Row;
import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.dht.RandomPartitioner;
@ -177,11 +178,13 @@ public class ConsistencyLevelTest extends CleanupHelper
private AbstractReplicationStrategy getStrategy(String table, TokenMetadata tmd) throws ConfigurationException
{
return AbstractReplicationStrategy.createReplicationStrategy(table,
"org.apache.cassandra.locator.SimpleStrategy",
tmd,
new SimpleSnitch(),
null);
KSMetaData ksmd = DatabaseDescriptor.getKSMetaData(table);
return AbstractReplicationStrategy.createReplicationStrategy(
table,
ksmd.strategyClass,
tmd,
new SimpleSnitch(),
ksmd.strategyOptions);
}
}

View File

@ -32,6 +32,7 @@ import com.google.common.collect.Multimap;
import org.apache.cassandra.CleanupHelper;
import org.apache.cassandra.Util;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.KSMetaData;
import org.apache.cassandra.dht.*;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.VersionedValue;
@ -613,12 +614,13 @@ public class LeaveAndBootstrapTest extends CleanupHelper
private AbstractReplicationStrategy getStrategy(String table, TokenMetadata tmd) throws ConfigurationException
{
KSMetaData ksmd = DatabaseDescriptor.getKSMetaData(table);
return AbstractReplicationStrategy.createReplicationStrategy(
table,
"org.apache.cassandra.locator.SimpleStrategy",
ksmd.strategyClass,
tmd,
new SimpleSnitch(),
null);
ksmd.strategyOptions);
}
}

View File

@ -33,6 +33,7 @@ import com.google.common.collect.Multimap;
import org.apache.cassandra.CleanupHelper;
import org.apache.cassandra.Util;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.KSMetaData;
import org.apache.cassandra.dht.*;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.VersionedValue;
@ -504,12 +505,13 @@ public class MoveTest extends CleanupHelper
private AbstractReplicationStrategy getStrategy(String table, TokenMetadata tmd) throws ConfigurationException
{
KSMetaData ksmd = DatabaseDescriptor.getKSMetaData(table);
return AbstractReplicationStrategy.createReplicationStrategy(
table,
"org.apache.cassandra.locator.SimpleStrategy",
ksmd.strategyClass,
tmd,
new SimpleSnitch(),
null);
ksmd.strategyOptions);
}
private Token positionToken(int position)