Merge branch 'cassandra-3.0' into cassandra-3.11

This commit is contained in:
Jason Brown 2018-01-15 06:03:50 -08:00
commit 02bbdd6342
8 changed files with 53 additions and 6 deletions

View File

@ -42,6 +42,8 @@ Merged from 2.2:
* Fix race that prevents submitting compaction for a table when executor is full (CASSANDRA-13801)
* Rely on the JVM to handle OutOfMemoryErrors (CASSANDRA-13006)
* Grab refs during scrub/index redistribution/cleanup (CASSANDRA-13873)
Merged from 2.1:
* More PEP8 compiance for cqlsh (CASSANDRA-14021)
3.11.1

View File

@ -127,6 +127,7 @@ def find_zip(libprefix):
if zips:
return max(zips) # probably the highest version, if multiple
cql_zip = find_zip(CQL_LIB_PREFIX)
if cql_zip:
ver = os.path.splitext(os.path.basename(cql_zip))[0][len(CQL_LIB_PREFIX):]
@ -374,6 +375,8 @@ def show_warning_without_quoting_line(message, category, filename, lineno, file=
file.write(warnings.formatwarning(message, category, filename, lineno, line=''))
except IOError:
pass
warnings.showwarning = show_warning_without_quoting_line
warnings.filterwarnings('always', category=cql3handling.UnexpectedTableStructure)
@ -2368,12 +2371,12 @@ def main(options, hostname, port):
if options.timezone:
try:
timezone = pytz.timezone(options.timezone)
except:
except Exception:
sys.stderr.write("Warning: could not recognize timezone '%s' specified in cqlshrc\n\n" % (options.timezone))
if 'TZ' in os.environ:
try:
timezone = pytz.timezone(os.environ['TZ'])
except:
except Exception:
sys.stderr.write("Warning: could not recognize timezone '%s' from environment value TZ\n\n" % (os.environ['TZ']))
except ImportError:
sys.stderr.write("Warning: Timezone defined and 'pytz' module for timezone conversion not installed. Timestamps will be displayed in UTC timezone.\n\n")
@ -2431,6 +2434,7 @@ def main(options, hostname, port):
if batch_mode and shell.statement_error:
sys.exit(2)
# always call this regardless of module name: when a sub-process is spawned
# on Windows then the module name is not __main__, see CASSANDRA-9304
insert_driver_hooks()

View File

@ -168,7 +168,7 @@ class SendingChannels(object):
for ch in self.channels:
try:
ch.close()
except:
except Exception:
pass
@ -222,7 +222,7 @@ class ReceivingChannels(object):
for ch in self.channels:
try:
ch.close()
except:
except Exception:
pass
@ -2147,8 +2147,8 @@ class ImportConversion(object):
pk_values = []
for i in partition_key_indexes:
val = serialize(i, row[i])
l = len(val)
pk_values.append(struct.pack(">H%dsB" % l, l, val, 0))
length = len(val)
pk_values.append(struct.pack(">H%dsB" % length, length, val, 0))
return b"".join(pk_values)
if len(partition_key_indexes) == 1:

View File

@ -34,6 +34,7 @@ class UnexpectedTableStructure(UserWarning):
def __str__(self):
return 'Unexpected table structure; may not translate correctly to CQL. ' + self.msg
SYSTEM_KEYSPACES = ('system', 'system_schema', 'system_traces', 'system_auth', 'system_distributed')
NONALTERBALE_KEYSPACES = ('system', 'system_schema')
@ -116,6 +117,7 @@ class Cql3ParsingRuleSet(CqlParsingRuleSet):
cqlword = cqlword[1:-1].replace("''", "'")
return cqlword
CqlRuleSet = Cql3ParsingRuleSet()
# convenience for remainder of module
@ -349,6 +351,7 @@ def prop_equals_completer(ctxt, cass):
return ()
return ['=']
completer_for('property', 'propeq')(prop_equals_completer)
@ -583,6 +586,7 @@ def alterable_ks_name_completer(ctxt, cass):
def cf_ks_name_completer(ctxt, cass):
return [maybe_escape_name(ks) + '.' for ks in cass.get_keyspace_names()]
completer_for('columnFamilyName', 'ksname')(cf_ks_name_completer)
completer_for('materializedViewName', 'ksname')(cf_ks_name_completer)
@ -593,6 +597,7 @@ def cf_ks_dot_completer(ctxt, cass):
return ['.']
return []
completer_for('columnFamilyName', 'dot')(cf_ks_dot_completer)
completer_for('materializedViewName', 'dot')(cf_ks_dot_completer)
@ -624,6 +629,7 @@ def mv_name_completer(ctxt, cass):
raise
return map(maybe_escape_name, mvnames)
completer_for('userTypeName', 'ksname')(cf_ks_name_completer)
completer_for('userTypeName', 'dot')(cf_ks_dot_completer)
@ -676,6 +682,7 @@ def working_on_keyspace(ctxt):
return True
return False
syntax_rules += r'''
<useStatement> ::= "USE" <keyspaceName>
;
@ -836,6 +843,7 @@ def select_relation_lhs_completer(ctxt, cass):
filterable.add(idx.index_options["target"])
return map(maybe_escape_name, filterable)
explain_completion('selector', 'colname')
syntax_rules += r'''
@ -910,6 +918,7 @@ def insert_option_completer(ctxt, cass):
opts.discard(opt.split()[0])
return opts
syntax_rules += r'''
<updateStatement> ::= "UPDATE" cf=<columnFamilyName>
( "USING" [updateopt]=<usingOption>
@ -1116,6 +1125,7 @@ def batch_opt_completer(ctxt, cass):
opts.discard(opt.split()[0])
return opts
syntax_rules += r'''
<truncateStatement> ::= "TRUNCATE" ("COLUMNFAMILY" | "TABLE")? cf=<columnFamilyName>
;
@ -1135,6 +1145,7 @@ def create_ks_wat_completer(ctxt, cass):
return ['KEYSPACE']
return ['KEYSPACE', 'SCHEMA']
syntax_rules += r'''
<createColumnFamilyStatement> ::= "CREATE" wat=( "COLUMNFAMILY" | "TABLE" ) ("IF" "NOT" "EXISTS")?
( ks=<nonSystemKeyspaceName> dot="." )? cf=<cfOrKsName>
@ -1183,6 +1194,7 @@ def create_cf_wat_completer(ctxt, cass):
return ['TABLE']
return ['TABLE', 'COLUMNFAMILY']
explain_completion('createColumnFamilyStatement', 'cf', '<new_table_name>')
explain_completion('compositeKeyCfSpec', 'newcolname', '<new_column_name>')
@ -1237,6 +1249,7 @@ def create_cf_composite_primary_key_comma_completer(ctxt, cass):
return ()
return [',']
syntax_rules += r'''
<idxName> ::= <identifier>
@ -1300,6 +1313,7 @@ def create_index_col_completer(ctxt, cass):
colnames = [cd.name for cd in layout.columns.values() if cd.name not in idx_targets]
return map(maybe_escape_name, colnames)
syntax_rules += r'''
<dropKeyspaceStatement> ::= "DROP" "KEYSPACE" ("IF" "EXISTS")? ksname=<nonSystemKeyspaceName>
;
@ -1357,6 +1371,7 @@ def idx_ks_idx_name_completer(ctxt, cass):
raise
return map(maybe_escape_name, idxnames)
syntax_rules += r'''
<alterTableStatement> ::= "ALTER" wat=( "COLUMNFAMILY" | "TABLE" ) cf=<columnFamilyName>
<alterInstructions>
@ -1391,6 +1406,7 @@ def alter_type_field_completer(ctxt, cass):
fields = [tuple[0] for tuple in layout]
return map(maybe_escape_name, fields)
explain_completion('alterInstructions', 'newcol', '<new_column_name>')
explain_completion('alterTypeInstructions', 'newcol', '<new_field_name>')
@ -1540,6 +1556,7 @@ def rolename_completer(ctxt, cass):
session = cass.session
return [maybe_quote(row[0].replace("'", "''")) for row in session.execute("LIST ROLES")]
syntax_rules += r'''
<createTriggerStatement> ::= "CREATE" "TRIGGER" ( "IF" "NOT" "EXISTS" )? <cident>
"ON" cf=<columnFamilyName> "USING" class=<stringLiteral>
@ -1563,6 +1580,7 @@ def drop_trigger_completer(ctxt, cass):
names = get_trigger_names(ctxt, cass)
return map(maybe_escape_name, names)
# END SYNTAX/COMPLETION RULE DEFINITIONS
CqlRuleSet.append_rules(syntax_rules)

View File

@ -99,6 +99,7 @@ class FormattedValue:
"""
return self.coloredval + self._pad(width, fill)
DEFAULT_VALUE_COLORS = dict(
default=YELLOW,
text=YELLOW,

View File

@ -45,6 +45,7 @@ def _show_control_chars(match):
txt = txt[1:-1]
return txt
bits_to_turn_red_re = re.compile(r'\\([^uUx]|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|U[0-9a-fA-F]{8})')
@ -56,6 +57,7 @@ def _make_turn_bits_red_f(color1, color2):
return color1 + txt + color2
return _turn_bits_red
default_null_placeholder = 'null'
default_float_precision = 3
default_colormap = DEFAULT_VALUE_COLORS
@ -100,6 +102,7 @@ def color_text(bval, colormap, displaywidth=None):
displaywidth -= bval.count(r'\\')
return FormattedValue(bval, coloredval, displaywidth)
DEFAULT_NANOTIME_FORMAT = '%H:%M:%S.%N'
DEFAULT_DATE_FORMAT = '%Y-%m-%d'
@ -206,6 +209,7 @@ def format_value_default(val, colormap, **_):
bval = controlchars_re.sub(_show_control_chars, escapedval)
return bval if colormap is NO_COLOR_MAP else color_text(bval, colormap)
# Mapping cql type base names ("int", "map", etc) to formatter functions,
# making format_value a generic function
_formatters = {}
@ -237,6 +241,8 @@ def formatter_for(typname):
def format_value_blob(val, colormap, **_):
bval = '0x' + binascii.hexlify(val)
return colorme(bval, colormap, 'blob')
formatter_for('buffer')(format_value_blob)
formatter_for('blob')(format_value_blob)
@ -259,6 +265,7 @@ def format_value_decimal(val, float_precision, colormap, decimal_sep=None, thous
def format_value_uuid(val, colormap, **_):
return format_python_formatted_type(val, colormap, 'uuid')
formatter_for('timeuuid')(format_value_uuid)
@ -273,6 +280,7 @@ def format_value_boolean(val, colormap, boolean_styles=None, **_):
val = boolean_styles[0] if val else boolean_styles[1]
return format_python_formatted_type(val, colormap, 'boolean')
formatter_for('boolean')(format_value_boolean)
@ -302,6 +310,7 @@ def format_floating_point_type(val, colormap, float_precision, decimal_sep=None,
return colorme(bval, colormap, 'float')
formatter_for('float')(format_floating_point_type)
formatter_for('double')(format_floating_point_type)
@ -311,6 +320,7 @@ def format_integer_type(val, colormap, thousands_sep=None, **_):
bval = format_integer_with_thousands_sep(val, thousands_sep) if thousands_sep else str(val)
return colorme(bval, colormap, 'int')
# We can get rid of this in cassandra-2.2
if sys.version_info >= (2, 7):
def format_integer_with_thousands_sep(val, thousands_sep=','):
@ -348,6 +358,7 @@ def format_value_timestamp(val, colormap, date_time_format, quote=False, **_):
bval = "'%s'" % bval
return colorme(bval, colormap, 'timestamp')
formatter_for('timestamp')(format_value_timestamp)
@ -366,6 +377,7 @@ def strftime(time_format, seconds, microseconds=0, timezone=None):
# able to correctly import timestamps exported as milliseconds since the epoch.
return '%d' % (seconds * 1000.0)
microseconds_regex = re.compile("(.*)(?:\.(\d{1,6}))(.*)")
@ -475,6 +487,7 @@ def format_value_text(val, encoding, colormap, quote=False, **_):
return bval if colormap is NO_COLOR_MAP else color_text(bval, colormap, wcwidth.wcswidth(bval.decode(encoding)))
# name alias
formatter_for('unicode')(format_value_text)
formatter_for('text')(format_value_text)
@ -522,6 +535,8 @@ def format_value_set(val, cqltype, encoding, colormap, date_time_format, float_p
return format_simple_collection(sorted(val), cqltype, '{', '}', encoding, colormap,
date_time_format, float_precision, nullval,
decimal_sep, thousands_sep, boolean_styles)
formatter_for('frozenset')(format_value_set)
formatter_for('sortedset')(format_value_set)
formatter_for('SortedSet')(format_value_set)
@ -548,6 +563,8 @@ def format_value_map(val, cqltype, encoding, colormap, date_time_format, float_p
+ rb
displaywidth = 4 * len(subs) + sum(k.displaywidth + v.displaywidth for (k, v) in subs)
return FormattedValue(bval, coloredval, displaywidth)
formatter_for('OrderedDict')(format_value_map)
formatter_for('OrderedMap')(format_value_map)
formatter_for('OrderedMapSerializedKey')(format_value_map)
@ -581,6 +598,7 @@ def format_value_utype(val, cqltype, encoding, colormap, date_time_format, float
displaywidth = 4 * len(subs) + sum(k.displaywidth + v.displaywidth for (k, v) in subs)
return FormattedValue(bval, coloredval, displaywidth)
NANOS_PER_MICRO = 1000
NANOS_PER_MILLI = 1000 * NANOS_PER_MICRO
NANOS_PER_SECOND = 1000 * NANOS_PER_MILLI

View File

@ -518,6 +518,7 @@ class ParsingRuleSet:
pattern.match(ctxt, completions)
return completions
import sys

View File

@ -94,6 +94,7 @@ def bisearch(ucs, table):
return 1
return 0
# The following two functions define the column width of an ISO 10646
# character as follows:
#
@ -178,6 +179,7 @@ combining = (
(0xE0100, 0xE01EF)
)
# sorted list of non-overlapping intervals of East Asian Ambiguous
# characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c"
ambiguous = (
@ -321,6 +323,7 @@ def wcwidth_cjk(c):
def wcswidth_cjk(s):
return mk_wcswidth_cjk(map(ord, s))
if __name__ == "__main__":
samples = (
('MUSIC SHARP SIGN', 1),