Merge branch 'cassandra-3.0' into cassandra-3.9

This commit is contained in:
Stefania Alborghetti 2016-07-25 08:42:41 +08:00
commit 7ca3e28cd5
8 changed files with 44 additions and 39 deletions

View File

@ -9,7 +9,8 @@ Merged from 3.0:
* Fix problem with undeleteable rows on upgrade to new sstable format (CASSANDRA-12144)
Merged from 2.2:
* Fixed cqlshlib.test.remove_test_db (CASSANDRA-12214)
Merged from 2.1:
* cannot use cql since upgrading python to 2.7.11+ (CASSANDRA-11850)
3.8
* Fix hdr logging for single operation workloads (CASSANDRA-12145)

View File

@ -722,10 +722,6 @@ class Shell(cmd.Cmd):
self.display_timezone = display_timezone
# If there is no schema metadata present (due to a schema mismatch), force schema refresh
if not self.conn.metadata.keyspaces:
self.refresh_schema_metadata_best_effort()
self.session.default_timeout = request_timeout
self.session.row_factory = ordered_dict_factory
self.session.default_consistency_level = cassandra.ConsistencyLevel.ONE
@ -778,15 +774,6 @@ class Shell(cmd.Cmd):
"If you experience encoding problems, change your console"
" codepage with 'chcp 65001' before starting cqlsh.\n".format(self.encoding))
def refresh_schema_metadata_best_effort(self):
try:
self.conn.refresh_schema_metadata(5) # will throw exception if there is a schema mismatch
except Exception:
self.printerr("Warning: schema version mismatch detected, which might be caused by DOWN nodes; if "
"this is not the case, check the schema versions of your nodes in system.local and "
"system.peers.")
self.conn.refresh_schema_metadata(0)
def set_expanded_cql_version(self, ver):
ver, vertuple = full_cql_version(ver)
self.cql_version = ver
@ -1116,7 +1103,7 @@ class Shell(cmd.Cmd):
except EOFError:
self.handle_eof()
except CQL_ERRORS, cqlerr:
self.printerr(unicode(cqlerr))
self.printerr(cqlerr.message.decode(encoding='utf-8'))
except KeyboardInterrupt:
self.reset_statement()
print
@ -1271,22 +1258,27 @@ class Shell(cmd.Cmd):
if not statement:
return False, None
while True:
future = self.session.execute_async(statement, trace=self.tracing_enabled)
result = None
try:
result = future.result()
except CQL_ERRORS, err:
self.printerr(unicode(err.__class__.__name__) + u": " + err.message.decode(encoding='utf-8'))
except Exception:
import traceback
self.printerr(traceback.format_exc())
# Even if statement failed we try to refresh schema if not agreed (see CASSANDRA-9689)
if not future.is_schema_agreed:
try:
future = self.session.execute_async(statement, trace=self.tracing_enabled)
result = future.result()
break
except cassandra.OperationTimedOut, err:
self.refresh_schema_metadata_best_effort()
self.printerr(unicode(err.__class__.__name__) + u": " + unicode(err))
return False, None
except CQL_ERRORS, err:
self.printerr(unicode(err.__class__.__name__) + u": " + unicode(err))
return False, None
except Exception, err:
import traceback
self.printerr(traceback.format_exc())
return False, None
self.conn.refresh_schema_metadata(5) # will throw exception if there is a schema mismatch
except Exception:
self.printerr("Warning: schema version mismatch detected; check the schema versions of your "
"nodes in system.local and system.peers.")
self.conn.refresh_schema_metadata(-1)
if result is None:
return False, None
if statement.query_string[:6].lower() == 'select':
self.print_result(result, self.parse_for_select_meta(statement.query_string))

View File

@ -677,11 +677,11 @@ class ExportTask(CopyTask):
hosts = []
if replicas:
for r in replicas:
if r.is_up and r.datacenter == local_dc:
if r.is_up is not False and r.datacenter == local_dc:
hosts.append(r.address)
if not hosts:
hosts.append(hostname) # fallback to default host if no replicas in current dc
return {'hosts': tuple(hosts), 'attempts': 0, 'rows': 0}
return {'hosts': tuple(hosts), 'attempts': 0, 'rows': 0, 'workerno': -1}
if begin_token and begin_token < min_token:
shell.printerr('Begin token %d must be bigger or equal to min token %d' % (begin_token, min_token))
@ -748,8 +748,11 @@ class ExportTask(CopyTask):
return None
def send_work(self, ranges, tokens_to_send):
i = 0
prev_worker_no = ranges[tokens_to_send[0]]['workerno']
i = prev_worker_no + 1 if -1 <= prev_worker_no < (self.num_processes - 1) else 0
for token_range in tokens_to_send:
ranges[token_range]['workerno'] = i
self.outmsg.channels[i].send((token_range, ranges[token_range]))
ranges[token_range]['attempts'] += 1
@ -1352,6 +1355,7 @@ class ChildProcess(mp.Process):
self.thousands_sep = options.copy['thousandssep']
self.boolean_styles = options.copy['boolstyle']
self.max_attempts = options.copy['maxattempts']
self.encoding = options.copy['encoding']
# Here we inject some failures for testing purposes, only if this environment variable is set
if os.environ.get('CQLSH_COPY_TEST_FAILURES', ''):
self.test_failures = json.loads(os.environ.get('CQLSH_COPY_TEST_FAILURES', ''))
@ -1466,7 +1470,6 @@ class ExportProcess(ChildProcess):
def __init__(self, params):
ChildProcess.__init__(self, params=params, target=self.run)
options = params['options']
self.encoding = options.copy['encoding']
self.float_precision = options.copy['floatprecision']
self.double_precision = options.copy['doubleprecision']
self.nullval = options.copy['nullval']
@ -1727,6 +1730,7 @@ class ImportConversion(object):
self.boolean_styles = parent.boolean_styles
self.date_time_format = parent.date_time_format.timestamp_format
self.debug = parent.debug
self.encoding = parent.encoding
self.table_meta = table_meta
self.primary_key_indexes = [self.columns.index(col.name) for col in self.table_meta.primary_key]
@ -1748,8 +1752,13 @@ class ImportConversion(object):
# only when using prepared statements
self.coltypes = [table_meta.columns[name].cql_type for name in parent.valid_columns]
# these functions are used for non-prepared statements to protect values with quotes if required
self.protectors = [protect_value if t in ('ascii', 'text', 'timestamp', 'date', 'time', 'inet') else lambda v: v
for t in self.coltypes]
self.protectors = [self._get_protector(t) for t in self.coltypes]
def _get_protector(self, t):
if t in ('ascii', 'text', 'timestamp', 'date', 'time', 'inet'):
return lambda v: unicode(protect_value(v), self.encoding)
else:
return lambda v: v
@staticmethod
def _get_primary_key_statement(parent, table_meta):
@ -2085,7 +2094,7 @@ class TokenMap(object):
def filter_replicas(self, hosts):
shuffled = tuple(sorted(hosts, key=lambda k: random.random()))
return filter(lambda r: r.is_up and r.datacenter == self.local_dc, shuffled) if hosts else ()
return filter(lambda r: r.is_up is not False and r.datacenter == self.local_dc, shuffled) if hosts else ()
class FastTokenAwarePolicy(DCAwareRoundRobinPolicy):

View File

@ -189,6 +189,8 @@ class ProcRunner:
flags=0, ptty_timeout=None):
if not isinstance(until, re._pattern_type):
until = re.compile(until, flags)
cqlshlog.debug("Searching for %r" % (until.pattern,))
got = self.readbuf
self.readbuf = ''
with timing_out(timeout):

View File

@ -554,7 +554,7 @@ class TestCqlshOutput(BaseTestCase):
self.assertTrue(outputlines[start_index+1].endswith('cqlsh:system> '))
midline = ColoredText(outputlines[start_index])
self.assertEqual(midline.plain(),
'InvalidRequest: code=2200 [Invalid query] message="Keyspace \'nonexistentkeyspace\' does not exist"')
'InvalidRequest: Error from server: code=2200 [Invalid query] message="Keyspace \'nonexistentkeyspace\' does not exist"')
self.assertColorFromTags(midline,
"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR")
@ -620,6 +620,7 @@ class TestCqlshOutput(BaseTestCase):
varintcol varint
) WITH bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND cdc = false
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}

View File

@ -83,7 +83,7 @@ def total_micro_seconds(td):
"""
Convert a timedelta into total microseconds
"""
return int((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6)) if td else "--"
return int((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6)) if td else "--"
def datetime_from_utc_to_local(utc_datetime):