Commit Graph

28115 Commits

Author SHA1 Message Date
Botond Dénes
2c600e34aa tools: introduce scylla-sstable
A tool which can be used to examine the content of sstable(s) and
execute various operations on them. The currently supported operations
are:
* dump - dumps the content of the sstable(s), similar to sstabledump;
* index-dump - dumps the content of the sstable index(es), similar to
  scylla-sstable-index;
* writetime-histogram - generates a histogram of all the timestamps in
  the sstable(s);
* custom - a hackable operation for the expert user (until scripting
  support is implemented);
* validate - validate the content of the sstable(s) with the mutation
  fragment stream validator, same as scrub in validate mode;
2021-09-07 17:10:44 +03:00
Botond Dénes
e86073c703 tools: extract finding selected operation (handler) into function
We want to use the pattern of having a command line flag for each
operation in more tools, so extract the logic which finds the selected
operation from the command line arguments into a function.
2021-09-07 15:47:22 +03:00
Botond Dénes
23a56beccc tools: add schema_loader
A utility which can load a schema from a schema.cql file. The file has
to contain all the "dependencies" of the table: keyspace, UDTs, etc.
This will be used by the scylla-sstable-crawler in the next patch.
2021-09-07 15:47:22 +03:00
Botond Dénes
64dce2a59e cql3: query_processor: add parse_statements() 2021-09-07 11:13:30 +03:00
Botond Dénes
68f5277e52 cql3: statements/create_type: expose create_type() 2021-09-07 10:37:25 +03:00
Botond Dénes
6b224b76b9 cql3: statements/create_keyspace: add get_keyspace_metadata() 2021-09-07 10:37:25 +03:00
Avi Kivity
dfc135dbd1 Merge "Keep range_tombstone apart from list linkage" from Pavel E
"
There's a landmine buried in range_rombstone's move constructor.
Whoever tries to use it risks grabbing the tombstone from the
containing list thus leaking the guy optionally invalidating an
iterator pointing at it. There's a safety without_link moving
constructor out there, but still.

To keep this place safe it's better to separate range_tombstone
from its linkage into anywhere. In particular to keep the range
tombstones in a range_tombstone_list here's the entry that keeps
the tombstone _and_ the list hook (which's a boost set hook).

The approach resembles the rows_entry::deletable_row pair.

tests: unit(dev, debug, patch from #9207)
fixes: #9243
"

* 'br-range-tombstone-vs-entry' of https://github.com/xemul/scylla:
  range_tombstone: Drop without-link constructor
  range_tombstone: Drop move_assign()
  range_tombstone: Move linkage into range_tombstone_entry
  range_tombstone_list: Prepare to use range_tombstone_entry
  range_tombstone, code: Add range_tombstone& getters
  range_tombstone_list: Factor out tombstone construction
  range_tombstone_list: Simplify (maybe) pop_front_and_lock()
  range_tombstone_list: De-templatize pop_as<>
  range_tombstone_list: Conceptualize erase_where()
  range_tombstone(_list): Mark some bits noexcept
  mutation: Use range_tombstone_list's iterators
  mutation_partition: Shorten memory usage calculation
  mutation_partition: Remove unused local variable
2021-09-05 17:26:13 +03:00
Raphael S. Carvalho
6849ec46b8 compaction: Don't purge tombstones in scrub
Scrub is supposed to not remove anything from input, write it as is
while fixing any corruption it might have. It shouldn't have any
assumption on the input. Additionally, a data shadowed by a tombstone
might be in another corrupted sstable, so expired tombstones should
not be purged in order to prevent data ressurection from occurring.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
Message-Id: <20210904165908.135044-1-raphaelsc@scylladb.com>
2021-09-05 17:10:34 +03:00
Dejan Mircevski
1fdaeca7d0 cql3: Reject updates with NULL key values
We were silently ignoring INSERTs with NULL values for primary-key
columns, which Cassandra rejects.  Fix it by rejecting any
modification_statement that would operate on empty partition or
clustering range.

This is the most direct fix, because range and slice are calculated in
one place for all modification statements.  It covers not only NULL
cases, but also impossible restrictions like c>0 AND c<0.
Unfortunately, Cassandra doesn't treat all modification statements
consistently, so this fix cannot fully match its behavior.  We err on
the side of tolerance, accepting some DELETE statements that Cassandra
rejects.  We add a TODO for rejecting such DELETEs later.

Fixes #7852.

Tests: unit (dev), cql-pytest against Cassandra 4.0

Signed-off-by: Dejan Mircevski <dejan@scylladb.com>

Closes #9286
2021-09-05 10:23:28 +03:00
Pavel Emelyanov
7a0e56d7c1 range_tombstone: Drop without-link constructor
The thing was used to move a range tombstone without detaching it
from the containing list (well, intrusive set). Now when the linkage
is gone this facility is no longer needed (and actually no longer
used).

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 19:34:50 +03:00
Pavel Emelyanov
f82b5f30f6 range_tombstone: Drop move_assign()
The helper was in use by move-assignment operator and by the .swap()
method. Since now the operator equals the helper, the code can be
merged and the .swap() can be prettified.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 19:34:50 +03:00
Pavel Emelyanov
d6af441eaa range_tombstone: Move linkage into range_tombstone_entry
Now it's time to remove the boost set's hook from the range_tombstone
and keep it wrapped into another class if the r._tombstone's location
is the range_tombstone_list.

Also the added previously .tombstone() getters and the _entry alias
can be removed -- all the code can work with the new class.

Two places in the code that made use of without_link{} move-constructor
are patched to get the range_tombstone part from the respective _entry
with the same result.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 19:34:45 +03:00
Pavel Emelyanov
b8c585c54d range_tombstone_list: Prepare to use range_tombstone_entry
A continuation of the previous patch. The range_tombstone_list works
with the range_tombstone very actively, kicking every single line
doing this to call .tombstone() seems excessive. Instead, declare
the range_tombstone_entry alias. When the entry will appear for real,
the alias would go away and the range_tombstone_list will be switched
into new entity right at once.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 19:34:45 +03:00
Pavel Emelyanov
5515f7187d range_tombstone, code: Add range_tombstone& getters
Currently all the code operates on the range_tombstone class.
and many of those places get the range tombstone in question
from the range_tombstone_list. Next patches will make that list
carry (and return) some new object called range_tombstone_entry,
so all the code that expects to see the former one there will
need to patched to get the range_tombstone from the _entry one.

This patch prepares the ground for that by introdusing the

    range_tombstone& tombstone() { return *this; }

getter on the range_tombstone itself and patching all future
users of the _entry to call .tombstone() right now.

Next patch will remove those getters together with adding the new
range_tombstone_entry object thus automatically converting all
the patched places into using the entry in a proper way.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 19:34:45 +03:00
Pavel Emelyanov
ae8a5bd046 range_tombstone_list: Factor out tombstone construction
Just add a helper for constructing the managed range
tombstone object. This will also help further patch
have less duplicating hunks in it.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 19:34:45 +03:00
Pavel Emelyanov
8f061b9b1c range_tombstone_list: Simplify (maybe) pop_front_and_lock()
The method returns a pointer on the left-most range tombstone
and expects the caller to "dispose" it. This is not very nice
because the callers thus needs to mess with the relevant deleter.

A nicer approach is the pop-like one (former pop_as<>-like)
which is in returning the range tombstone by value. This value
is move-constructed from the original object which is disposed
by the container itself.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 19:34:45 +03:00
Pavel Emelyanov
2e1b21d72b range_tombstone_list: De-templatize pop_as<>
The method pops the range tombstone from the containing list
and transparently "converts" it into some other type. Nowadays
all callers of it need range tombstone as-is, so the template
can be relaxed down to a plan call.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 19:34:45 +03:00
Pavel Emelyanov
e4965b1662 range_tombstone_list: Conceptualize erase_where()
Just while at this code

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 19:34:45 +03:00
Pavel Emelyanov
fcc02c6bed range_tombstone(_list): Mark some bits noexcept
The range_tombstone's .empty() and .operator bool are trivially such.

The swap()'s noexceptness comes from what it calls -- the without-link
move constructor (noexcept) and .move_assign(). The latter is noexcept
because it's already called from noexcept move-assign operator and
because it calls noexcept move operators of tombstones' fields. The
update_node() is noexcept for the same reason.

The range_tombstone_list's clear() is noexcept because both -- set
clear and disposer lambda are both such.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 19:31:43 +03:00
Pavel Emelyanov
87ce46d1c6 mutation: Use range_tombstone_list's iterators
The consume_clustering_fragments declares several auxiliary symbols
to work with rows' and range-tombstones' iterators. For the range
tombstones it relies on what container is declared inside the
range tombstone itself. Soon the container declaration will move
from range_tombstone class into a new entity and this place should
be prepared for that. The better place to get iterator types from
is the range-tombstones container itself.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 12:56:13 +03:00
Pavel Emelyanov
ac473a9e67 mutation_partition: Shorten memory usage calculation
The range_tombstone_list's replacer runs exactly the same loop

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 12:56:13 +03:00
Pavel Emelyanov
f173be29d9 mutation_partition: Remove unused local variable
Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-09-03 12:56:13 +03:00
Nadav Har'El
b3f4a37a75 test/alternator: verify that nulls are valid inside string and bytes
The tests in this patch verify that null characters are valid characters
inside string and bytes (blob) attributes in Alternator. The tests
verify this for both key attributes and non-key attributes (since those
are serialized differently, it's important to check both cases).

The tests pass on both DynamoDB and Alternator - confirming that we
don't have a bug in this area.

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
Message-Id: <20210824163442.186881-1-nyh@scylladb.com>
2021-09-03 08:49:06 +02:00
Avi Kivity
a81057b2e1 Merge "sstables: introduce crawling reader" from Botond
"
A special-purpose reader which doesn't use the index at all, designed to
be used in circumstances where the index is not reliable. The use-case
is scrub and validate which often have to work with corrupt indexes and
it is especially important that they don't further any existing
corruption.

Tests: unit(dev)
"

* 'crawling-sstable-reader/v2' of https://github.com/denesb/scylla:
  compaction: scrub/validate: use the crawling sstable reader
  sstables: wire in crawling reader
  sstables: mx/reader: add crawling reader
  sstables: kl/reader: add crawling reader
2021-09-02 16:26:35 +03:00
Nadav Har'El
068c4283b7 test/cql-pytest: add tests for some undocumented cases of string types
This patch adds tests for two undocumented (as far as I can tell) corner
cases of CQL's string types:

1. The types "text" and "varchar" are not just similar - they are in
   fact exactly the same type.

2. All CQL string and blob types ("ascii", "text" or "varchar", "blob")
   allow the null character as a valid character inside them. They are
   *not* C strings that get terminated by the first null.

These tests pass on both Cassandra and Scylla, so did not expose any
bug, but having such tests is useful to understand these (so-far)
undocumented behaviors - so we can later document them.

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
Message-Id: <20210824225641.194146-1-nyh@scylladb.com>
2021-09-02 15:45:47 +03:00
Pavel Solodovnikov
ebee744590 idl-compiler: make the script work with python 3.8
Python 3.8 doesn't allow to use built-in collection types
in type annotations (such as `list` or `dict`).
This feature is implemented starting from 3.9.

Replace `list[str]` type annotation with an old-style
`List[str]`, which uses `List` from the `typing` module.

Signed-off-by: Pavel Solodovnikov <pa.solodovnikov@scylladb.com>
Message-Id: <20210901131436.35231-1-pa.solodovnikov@scylladb.com>
2021-09-02 15:38:44 +03:00
Raphael S. Carvalho
3263c1d5f1 Make shutdown clean when stopping sstable reshard
After aa7cdc0392, run_custom_job() propagates stop exception.
The problem is that we fail to handle stop exception in the procedure
which stops ongoing compactions, so the exception will be propagated
all the way to init, which causes scylla to abort.

to fix this, let's swallow stop_exception in stop_ongoing_compactions(),
which is correct because compactions are stopped by triggering that
exception if signalled to stop.

when reshard is stopped, scylla init will fail as follow instead:
ERROR 2021-08-16 20:13:13,770 [shard 0] init - Startup failed: std::runtime_error
(Exception while populating keyspace 'keyspace5' with column family 'standard1'
from file ...

Fixes #9158.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
Message-Id: <20210816232434.78375-1-raphaelsc@scylladb.com>
2021-09-02 13:50:24 +03:00
Benny Halevy
33f579f783 distributed_loader: distributed_loader::get_sstables_from_upload_dir: do not copy vector containing foreign shared sstables
lw_shared_ptr must not be copied on a foreign shard.
Copying the vector on shard 0 tries increases the reference count of
lw_shared_ptr<sstable> elements that were created on other shards,
as seen in https://github.com/scylladb/scylla/issues/9278.

Fixes #9278

DTest: migration_test.py:TestLoadAndStream_with_3_0_md.load_and_stream_increase_cluster_test(debug)

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
Message-Id: <20210902084313.2003328-1-bhalevy@scylladb.com>
2021-09-02 13:49:06 +03:00
Avi Kivity
9c17f75f52 cql3: reduce noise in grammar when using cql3::expr types
The CQL grammar is obviously about cql3 and mostly about cql3
expressions, so add using namespace statements so we don't
have to specify it over and over again.

These statements are present in the headers, but only in the
cql_parser namespace, so it doesn't pollute other translation
units.

Closes #9255
2021-09-02 13:39:42 +03:00
Michał Radwański
9a1e82bb92 .gitignore: add compile_commands.json
compile_commands.json is a format of compilation database info for use
with several editors, such as VSCode (with official C++ extension) and
Vim (with youcompleteme). It can be generated with ninja:
```
ninja -t compdb > compile_commands.json
```

I propose this addition, so that this file won't be commited by
accident.

Closes #9279
2021-09-02 13:37:35 +03:00
Pavel Solodovnikov
f8fe043b94 build: allow to run SCYLLA-VERSION-GEN utility out of source
This change allows to invoke the script in out-of-source
builds: `git log` now uses `-C` option with the directory
containing the script.

Also, the destination path can now be overriden by providing
`-o|--output-dir PATH` option. By default it's set to the
`build` directory relative to the script location.

Usage message is now shown, when '-h|--help' option is
specified.

Signed-off-by: Pavel Solodovnikov <pa.solodovnikov@scylladb.com>
Message-Id: <20210831120257.46920-1-pa.solodovnikov@scylladb.com>
2021-09-02 13:04:34 +03:00
Takuya ASADA
729d0feef0 install-dependencies.sh: add scylla-driver to relocatable python3
Pass --pip-packages option to tools/python3/reloc/build_reloc.sh,
add scylla-driver to relocatable python3 which required for
fix_system_distributed_tables.py.

[avi: regenrate toolchain]

Ref #9040
2021-09-02 11:52:47 +03:00
Pavel Emelyanov
cfcea8fc33 storage_service: Replace is_local_dc() with vs db::is_local()
Both functions do the same -- get datacenters from given
endpoint and local broadcast address and compare them to
match (or not).

tests: unit(dev)

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
Message-Id: <20210902080858.16364-1-xemul@scylladb.com>
2021-09-02 11:25:48 +03:00
Avi Kivity
403645f58c Merge "raft: miscellaneous fixes" from Gleb
* 'raft-misc-v3' of github.com:scylladb/scylla-dev:
  raft: rename snapshot into snapshot_descriptor
  raft: drop snapshot if is application failed
  raft: fix local snapshot detection
  raft: replication_test: store multiple snapshots in a state machine
  raft: do not wait for entry to become stable before replicate it
2021-09-02 11:25:06 +03:00
Avi Kivity
8a1d99a039 Update seastar submodule
* seastar 07758294ef...c04a12edbd (4):
  > core: add alien() getter to reactor
  > io_priority_class: add missing headers
  > Merge "require deferred action to be noexcept" from Benny
  > net: silence compiler warning in tls_connected_socket_impl.
2021-09-02 11:11:49 +03:00
Michael Livshin
fbb5802229 mf-stream-validator: add previous partition key to error messages
Only seems to make sense in mutation fragment validation where
validation level is >= `partition_key`.

Fixes #9269

Signed-off-by: Michael Livshin <michael.livshin@scylladb.com>
Message-Id: <20210901165641.340185-1-michael.livshin@scylladb.com>
2021-09-02 11:05:33 +03:00
Botond Dénes
7a78601b5d compaction: scrub/validate: use the crawling sstable reader
Sstables that are scrubbed or validated are typically problematic ones
that potentially have corrupt indexes. To avoid using the index
altogether use the recently added crawling reader. Scrub and validate
never skips in the sstable anyway.
2021-09-01 16:21:49 +03:00
Botond Dénes
1abf665d1d sstables: wire in crawling reader 2021-09-01 16:21:49 +03:00
Avi Kivity
705f957425 Merge "Generalize TLS creds builder configuration" from Pavel E
"
There are 4 places out there that do the same steps parsing
"client_|server_encryption_options" and configuring the
seastar::tls::creds_builder with the values (messaging, redis,
alternator and transport).

Also to make redis and transport look slimmer main() cleans
the client_encryption_options by ... parsing it too.

This set introduces a (coroutinized) helper to configure the
creds_builder with map<string, string> and removes the options
beautification from main.

tests: unit(dev), dtest.internode_ssl_test(dev)
"

* 'br-generalize-tls-creds-builder-configuration' of https://github.com/xemul/scylla:
  code: Generalize tls::credentials_builder configuration
  transport, redis: Do not assume fixed encryption options
  messaging: Move encryption options parsing to ms
  main: Open-code internode encryption misconfig warning
  main, config: Move options parsing helpers
2021-09-01 14:19:19 +03:00
Nadav Har'El
72bc37ddc1 README.md: update link to docker build instructions
The link to the docker build instructions was outdated - from the time
our docker build was based on a Redhat distribution. It no longer is,
it's now based on Ubuntu, and the link changed accordingly.

Fixes #9276.

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
Message-Id: <20210901083055.445438-1-nyh@scylladb.com>
2021-09-01 11:50:11 +03:00
Liu Lan
a5c54867f8 alternator: Exclusive start key must lie within the segment
...when using Segment/TotalSegment option.

The requirement is not specified in DynamoDB documents, but found
in DynamoDB Local:

{"__type":"com.amazon.coral.validate#ValidationException",
"message":"Exclusive start key must lie within the segment"}

Fixes #9272

Signed-off-by: Liu Lan <liulan_yewu@cmss.chinamobile.com>

Closes #9270
2021-09-01 11:05:45 +03:00
Botond Dénes
9548200e85 sstables: mx/reader: add crawling reader
A special-purpose reader which doesn't use the index at all and hence
doesn't support skipping at all. It is designed to be used in conditions
in which the index is not reliable (scrub compaction).
2021-09-01 08:44:13 +03:00
Botond Dénes
4421929b25 sstables: kl/reader: add crawling reader
A special-purpose reader which doesn't use the index at all and hence
doesn't support skipping at all. It is designed to be used in conditions
in which the index is not reliable (scrub compaction).
2021-09-01 08:42:10 +03:00
Avi Kivity
8b59e3a0b1 Merge ' cql3: Demand ALLOW FILTERING for unlimited, sliced partitions ' from Dejan Mircevski
Return the pre- 6773563d3 behavior of demanding ALLOW FILTERING when partition slice is requested but on potentially unlimited number of partitions.  Put it on a flag defaulting to "off" for now.

Fixes #7608; see comments there for justification.

Tests: unit (debug, dev), dtest (cql_additional_test, paging_test)

Signed-off-by: Dejan Mircevski <dejan@scylladb.com>

Closes #9126

* github.com:scylladb/scylla:
  cql3: Demand ALLOW FILTERING for unlimited, sliced partitions
  cql3: Track warnings in prepared_statement
  test: Use ALLOW FILTERING more strictly
  cql3: Add statement_restrictions::to_string
2021-08-31 18:05:26 +03:00
Dejan Mircevski
2f28f68e84 cql3: Demand ALLOW FILTERING for unlimited, sliced partitions
When a query requests a partition slice but doesn't limit the number
of partitions, require that it also says ALLOW FILTERING.  Although
do_filter() isn't invoked for such queries, the performance can still
be unexpectedly slow, and we want to signal that to the user by
demanding they explicitly say ALLOW FILTERING.

Because we now reject queries that worked fine before, existing
applications can break.  Therefore, the behavior is controlled by a
flag currently defaulting to off.  We will default to "on" in the next
Scylla version.

Fixes #7608; see comments there for justification.

Signed-off-by: Dejan Mircevski <dejan@scylladb.com>
2021-08-31 10:45:41 -04:00
Nadav Har'El
9666921dbc Merge 'cql3: expr: introduce search_and_replace()' from Avi Kivity
Introduce a general-purpose search and replace function to manipulate
expressions, and use it to simplify replace_column_def() and
replace_token().

Closes #9259

* github.com:scylladb/scylla:
  cql3: expr: rewrite replace_token in terms of search_and_replace()
  cql3: expr: rewrite replace_column_def in terms of search_and_replace()
  cql3: expr: add general-purpose search-and-replace
2021-08-31 15:56:41 +03:00
Avi Kivity
6a0a5a17d7 Merge "Fix exception safety of btree::clone_from()" from Pavel E
"
When cloning throws in the middle it may leak some child
nodes triggering the respective assertion in node destructor.

Also there's a chance to mis-assert the linear node roll-back.

tests: unit(dev)
"

Fixes #9248
Backport: 4.5

* 'br-btree-clone-exceptions-2' of https://github.com/xemul/scylla:
  btree: Add commens in .clone() and .clear()
  btree, test: Test exception safety and non-leakness of btree::clone_from
  btree, test: Test key copy constructor may throw
  btree: Dont leak kids on clone roll-back
  btree: Destroy, not drop, node on clone roll-back
2021-08-31 14:34:14 +03:00
Pavel Emelyanov
e6d568b38e btree: Add commens in .clone() and .clear()
There are two tricky places about corner leaves pointers
managements. Add comments describing the magic.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
2021-08-31 12:36:54 +03:00
Avi Kivity
542a8bc0f3 cql3: expr: rewrite replace_token in terms of search_and_replace()
Use search_and_replace() to simplify replace_token(). Note the conversion
does not have 100% fidelity - the previous implementation throws on
some impossible subexpression types, and the new one passes them
through. It should be the caller's responsibility anyway, not a
side effect of replacing tokens, and since these subexpressions are
impossible there is no real effect on execution.

Note that this affects only TOKEN() calls on the partition key
columns in the right order. Other uses of the token function
(say with constants) won't be translated to the token subexpression
type. So something like

    WHERE token(pk) = token(?)

would only see the left-hand side replaced, not the right-hand
side, even if it were an expression rather than a term.
2021-08-31 12:29:47 +03:00
Avi Kivity
10ca63128a cql3: expr: rewrite replace_column_def in terms of search_and_replace()
We're won't introduce new expression types that are equivalent
to column_value, and search_and_replace() takes care of all
expressions that need to recurse, so we don't need std::visit()
for the search/replace lambda.
2021-08-31 12:29:47 +03:00