Commit Graph

549 Commits

Author SHA1 Message Date
Kefu Chai
113fb32019 compaction: disambiguate format_to()
we should always qualify `format_to` with its namespace. otherwise
we'd have following failure when compiling with libstdc++ from GCC-13:

```
/home/kefu/dev/scylladb/compaction/table_state.hh:65:16: error: call to 'format_to' is ambiguous
        return format_to(ctx.out(), "{}.{} compaction_group={}", s->ks_name(), s->cf_name(), t.get_group_id());
               ^~~~~~~~~
```

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes #13760
2023-05-03 20:33:18 +03:00
Botond Dénes
022465d673 Merge 'Tone down offstrategy log message' from Benny Halevy
In many cases we trigger offstrategy compaction opportunistically
also when there's nothing to do.  In this case we still print
to the log lots of info-level message and call
`run_offstrategy_compaction` that wastes more cpu cycles
on learning that it has nothing to do.

This change bails out early if the maintenance set is empty
and prints a "Skipping off-strategy compaction" message in debug
level instead.

Fixes #13466

Also, add an group_id class and return it from compaction_group and table_state.
Use that to identify the compaction_group / table_state by "ks_name.cf_name compaction_group=idx/total" in log messages.

Fixes #13467

Closes #13520

* github.com:scylladb/scylladb:
  compaction_manager: print compaction_group id
  compaction_group, table_state: add group_id member
  compaction_manager: offstrategy compaction: skip compaction if no candidates are found
2023-05-02 08:05:18 +03:00
Avi Kivity
7b7d9bcb14 Merge 'Do not access owned_ranges_ptr across shards in update_sstable_cleanup_state' from Benny Halevy
This series fixes a few issues caused by f1bbf705f9
(f1bbf705f9):

- table, compaction_manager: prevent cross shard access to owned_ranges_ptr
  - Fixes #13631
- distributed_loader: distribute_reshard_jobs: pick one of the sstable shard owners
- compaction: make_partition_filter: do not assert shard ownership
  - allow the filtering reader now used during resharding to process tokens owned by other shards

Closes #13635

* github.com:scylladb/scylladb:
  compaction: make_partition_filter: do not assert shard ownership
  distributed_loader: distribute_reshard_jobs: pick one of the sstable shard owners
  table, compaction_manager: prevent cross shard access to owned_ranges_ptr
2023-05-01 22:51:00 +03:00
Kefu Chai
0232115eaa compaction: disambiguate type name
otherwise GCC-13 complains:

```
/home/kefu/dev/scylladb/compaction/compaction_state.hh:38:22: error: declaration of ‘compaction::owned_ranges_ptr compaction::compaction_state::owned_ranges_ptr’ changes meaning of ‘owned_ranges_ptr’ [-Wchanges-meaning]
   38 |     owned_ranges_ptr owned_ranges_ptr;
      |                      ^~~~~~~~~~~~~~~~
```

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2023-04-29 17:02:25 +08:00
Benny Halevy
9768046d7c compaction_manager: print compaction_group id
Add a formatter to compaction::table_state that
prints the table ks_name.cf_name and compaction group id.

Fixes #13467

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-24 10:07:03 +03:00
Benny Halevy
dabf46c37f compaction_group, table_state: add group_id member
To help identify the compaction group / table_state.

Ref #13467

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-24 10:06:04 +03:00
Benny Halevy
1134ca2767 compaction_manager: offstrategy compaction: skip compaction if no candidates are found
In many cases we trigger offstrategy compaction opportunistically
also when there's nothing to do.  In this case we still print
to the log lots of info-level message and call
`run_offstrategy_compaction` that wastes more cpu cycles
on learning that it has nothing to do.

This change bails out early if the maintenance set is empty
and prints a "Skipping off-strategy compaction" message in debug
level instead.

Fixes #13466

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-24 09:23:32 +03:00
Pavel Emelyanov
5e201b9120 database: Remove compaction_manager.hh inclusion into database.hh
The only reason why it's there (right next to compaction_fwd.hh) is
because the database::table_truncate_state subclass needs the definition
of compaction_manager::compaction_reenabler subclass.

However, the former sub is not used outside of database.cc and can be
defined in .cc. Keeping it outside of the header allows dropping the
compaction_manager.hh from database.hh thus greatly reducing its fanout
over the code (from ~180 indirect inclusions down to ~20).

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>

Closes #13622
2023-04-23 16:27:11 +03:00
Benny Halevy
2e24b05122 compaction: make_partition_filter: do not assert shard ownership
Now, with f1bbf705f9
(Cleanup sstables in resharding and other compaction types),
we may filter sstables as part of resharding compaction
and the assertion that all tokens are owned by the current
shard when filtering is no longer true.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-23 15:24:20 +03:00
Benny Halevy
2f61de8f7b table, compaction_manager: prevent cross shard access to owned_ranges_ptr
Seen after f1bbf705f9 in debug mode

distributed_loader collect_all_shared_sstables copies
compaction::owned_ranges_ptr (lw_shared_ptr<const
dht::token_range_vector>)
across shards.

Since update_sstable_cleanup_state is synchronous, it can
be passed a const refrence to the token_range_vector instead.
It is ok to access the memory read-only across shards
and since this happens on start-up, there are no special
performance requirements.

Fixes #13631

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-23 15:12:13 +03:00
Raphael S. Carvalho
a47bac931c Move TWCS option from table into TWCS itself
enable_optimized_twcs_queries is specific to TWCS, therefore it
belongs to TWCS, not replica::table.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>

Closes #13489
2023-04-14 08:28:16 +03:00
Raphael S. Carvalho
9760149e8d compaction: Don't bump compaction shares during major execution
Commit 49892a0, back in 2018, bumps the compaction shares by 200 to
guarantee a minimum base line.

However, after commit e3f561d, major compaction runs in maintenance
group meaning that bumping shares became completely irrelevant and
only causes regular compaction to be unnecessarily more aggressive.

Fixes #13487.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>

Closes #13488
2023-04-13 08:20:25 +03:00
Botond Dénes
525b21042f Merge 'Rewrite sstables keyspace compaction task' from Aleksandra Martyniuk
Task manager task implementations of classes that cover
rewrite sstables keyspace compaction which can be start
through /storage_service/keyspace_compaction/ api.

Top level task covers the whole compaction and creates child
tasks on each shard.

Closes #12714

* github.com:scylladb/scylladb:
  test: extend test_compaction_task.py to test rewrite sstables compaction
  compaction: create task manager's task for rewrite sstables keyspace compaction on one shard
  compaction: create task manager's task for rewrite sstables keyspace compaction
  compaction: create rewrite_sstables_compaction_task_impl
2023-04-12 08:38:59 +03:00
Aleksandra Martyniuk
25cfffc3ae compaction: rename local_offstrategy_keyspace_compaction_task_impl to shard_offstrategy_keyspace_compaction_task_impl
Closes #13475
2023-04-12 08:38:25 +03:00
Aleksandra Martyniuk
a93f044efa compaction: create task manager's task for rewrite sstables keyspace compaction on one shard
Implementation of task_manager's task that covers rewrite sstables keyspace
compaction on one shard.
2023-04-11 13:07:17 +02:00
Aleksandra Martyniuk
c4098df4ec compaction: create task manager's task for rewrite sstables keyspace compaction
Implementation of task_manager's task covering rewrite sstables keyspace
compaction that can be started through storage_service api.
2023-04-11 11:04:21 +02:00
Aleksandra Martyniuk
814254adfd compaction: create rewrite_sstables_compaction_task_impl
rewrite_sstables_compaction_task_impl serves as a base class of all
concrete rewrite sstables compaction task classes.
2023-04-11 11:03:09 +02:00
Benny Halevy
4db961ecac compaction_manager: compact_sstables: retrieve owned ranges if required
If any of the sstables to-be-compacted requires cleanup,
retrive the owned_ranges_ptr from the table_state.

With that, staging sstables will eventually be cleaned up
via regular compaction.

Refs #9559

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:36:10 +03:00
Benny Halevy
9105f9800c sstables: add a printer for shared_sstable
Refactor the printing logic in compaction::formatted_sstables_list
out to sstables::to_string(const shared_sstable&, bool include_origin)
and operator<<(const shared_sstable) on top of it.

So that we can easily print std::vector<shared_sstable>
from compaction_manager in the next patch.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:31:35 +03:00
Benny Halevy
d87925d9fc compaction_manager: keep owned_ranges_ptr in compaction_state
When perform_cleanup adds sstables to sstables_requiring_cleanup,
also save the owned_ranges_ptr in the compaction_state so
it could be used by other compaction types like
regular, reshape, or major compaction.

When the exhausted sstables are released, check
if sstables_requiring_cleanup is empty, and if it is,
clear also the owned_ranges_ptr.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:30:53 +03:00
Benny Halevy
c2bf0e0b72 compaction_manager: perform_cleanup: keep sstables in compaction_state::sstables_requiring_cleanup
As a first step towards parallel cleanup by
(regular) compaction and cleanup compaction,
filter all sstables in perform_cleanup
and keep the set of sstables in the compaction_state.

Erase from that set when the sstables are unregistered
from compaction.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:30:39 +03:00
Benny Halevy
b3192b9f16 compaction: refactor compaction_state out of compaction_manager
To use it both from compaction_manager and compaction_descriptor
in a following patch.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:28:16 +03:00
Benny Halevy
73280c0a15 compaction: refactor compaction_fwd.hh out of compaction_descriptor.hh
So it can be used in the next patch that will refactor
compaction_state out of class compaction_manager.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:19:04 +03:00
Benny Halevy
690697961c compaction_manager: compacting_sstable_registration: keep a ref to the compaction_state
To be used for managing sstables requiring cleanup.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:18:02 +03:00
Benny Halevy
cac60a09ac compaction_manager: refactor get_candidates
Allow getting candidates for compaction
from an arbitrary range of sstable, not only
the in_strategy_sstables.

To be used by perform_cleanup to mark all sstables
that require cleanup, even if they can't be
compacted at this time.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:16:57 +03:00
Benny Halevy
bbfe839a73 compaction_manager: get_candidates: mark as const
Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:16:12 +03:00
Benny Halevy
6ebafe74b9 table, compaction_manager: add requires_cleanup
Returns true iff any of the sstables in the set
requries cleanup.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:14:36 +03:00
Benny Halevy
d0690b64c1 table, compaction_manager: add update_sstable_cleanup_state
update_sstable_cleanup_state calls needs_cleanup and
inserts (or erases) the sstable into the respective
compaction_state.sstables_requiring_cleanup set.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:10:55 +03:00
Benny Halevy
1baca96de1 compaction_manager: needs_cleanup: delete unused schema param
It isn't needed.  The sstable already has a schema.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:03:53 +03:00
Benny Halevy
ac9f8486ba compaction_manager: perform_cleanup: disallow empty sorted_owened_ranges
I'm not sure why this was originally supported,
maybe for upgrade sstables where we may want to
rewrite the sstables without filtering any tokens,
but perform_sstable_upgrade is now following a
different code path and uses `rewrite_sstables`
directly, without pigybacking on cleanup.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 23:03:03 +03:00
Benny Halevy
0c6ce5af74 compaction: move owned ranges filtering to base class
Move the token filtering logic down from cleanup_compaction
to regular_compaction and class compaction so it can be
reused by other compaction types.

Create a _owned_ranges_checker in class compaction
when _owned_ranges is engaged, and use it in
compaction::setup to filter partitions based on the owned ranges.

Ref scylladb/scylladb#12998

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 22:55:09 +03:00
Benny Halevy
09df04c919 compaction: move owned_ranges into descriptor
Move the owned_ranges_ptr, currently used only by
cleanup and upgrade compactions, to the generic
compaction descriptor so we apply cleanup in other
compaction types.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2023-04-10 22:52:12 +03:00
Botond Dénes
9a02315c6b Merge 'Compaction reevaluation bug fixes' from Raphael "Raph" Carvalho
A problem in compaction reevaluation can cause the SSTable set to be left uncompacted for indefinite amount of time, potentially causing space and read amplification to be suboptimal.

Two revaluation problems are being fixed, one after off-strategy compaction ended, and another in compaction manager which intends to periodically reevaluate a need for compaction.

Fixes https://github.com/scylladb/scylladb/issues/13429.
Fixes https://github.com/scylladb/scylladb/issues/13430.

Closes #13431

* github.com:scylladb/scylladb:
  compaction: Make compaction reevaluation actually periodic
  replica: Reevaluate regular compaction on off-strategy completion
2023-04-05 13:51:21 +03:00
Raphael S. Carvalho
457c772c9c replica: Make compaction_group responsible for deleting off-strategy compaction input
Compaction group is responsible for deleting SSTables of "in-strategy"
compactions, i.e. regular, major, cleanup, etc.

Both in-strategy and off-strategy compaction have their completion
handled using the same compaction group interface, which is
compaction_group::table_state::on_compaction_completion(...,
				sstables::offstrategy offstrategy)

So it's important to bring symmetry there, by moving the responsibility
of deleting off-strategy input, from manager to group.

Another important advantage is that off-strategy deletion is now throttled
and gated, allowing for better control, e.g. table waiting for deletion
on shutdown.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>

Closes #13432
2023-04-05 08:37:48 +03:00
Raphael S. Carvalho
156ac0a67a compaction: Make compaction reevaluation actually periodic
The manager intended to periodically reevaluate compaction need for
each registered table. But it's not working as intended.
The reevaluation is one-off.

This means that compaction was not kicking in later for a table, with
low to none write activity, that had expired data 1 hour from now.

Also make sure that reevaluation happens within the compaction
scheduling group.

Fixes #13430.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
2023-04-04 09:16:19 -03:00
Botond Dénes
8167f11a23 Merge 'Move compaction manager tasks out of compaction manager' from Aleksandra Martyniuk
Task manager compaction tasks that cover compaction group
compaction need access to compaction_manager::tasks.

To avoid circular dependency and be able to rely on forward
declaration, task needs to be moved out of compaction manager.

To avoid naming confusion compaction_manager::task is renamed.

Closes #13226

* github.com:scylladb/scylladb:
  compaction: use compaction namespace in compaction_manager.cc
  compaction: rename compaction::task
  compaction: move compaction_manager::task out of compaction manager
  compaction: move sstable_task definition to source file
2023-04-03 15:40:42 +03:00
Aleksandra Martyniuk
8afa54d4f6 compaction: create task manager's task for offstrategy keyspace compaction on one shard
Implementation of task_manager's task that covers local offstrategy keyspace compaction.
2023-03-30 10:49:09 +02:00
Aleksandra Martyniuk
73860b7c9d compaction: create task manager's task for offstrategy keyspace compaction
Implementation of task_manager's task covering offstrategy keyspace compaction
that can be started through storage_service api.
2023-03-30 10:44:56 +02:00
Aleksandra Martyniuk
e8ef8a51d5 compaction: create offstrategy_compaction_task_impl
offstrategy_compaction_task_impl serves as a base class of all
concrete offstrategy compaction task classes.
2023-03-30 10:28:17 +02:00
Avi Kivity
472b155d76 Merge 'Allow each compaction group to have its own compaction strategy state' from Raphael "Raph" Carvalho
This is important for multiple compaction groups, as they cannot share state that must span a single SSTable set.

The solution is about:

1) Decoupling compaction strategy from its state; making compaction_strategy a pure stateless entity
2) Each compaction group storing its own compaction strategy state
3) Compaction group feeds its state into compaction strategy whenever needed

Closes #13351

* github.com:scylladb/scylladb:
  compaction: TWCS: wire up compaction_strategy_state
  compaction: LCS: wire up compaction_strategy_state
  compaction: Expose compaction_strategy_state through table_state
  replica: Add compaction_strategy_state to compaction group
  compaction: Introduce compaction_strategy_state
  compaction: add table_state param to compaction_strategy::notify_completion()
  compaction: LCS: extract state into a separate struct
  compaction: TWCS: prepare for stateless strategy
  compaction: TWCS: extract state into a separate struct
  compaction: add const-qualifier to a few compaction_strategy methods
2023-03-29 18:57:11 +03:00
Aleksandra Martyniuk
0ceee3e4b3 compaction: use compaction namespace in compaction_manager.cc 2023-03-29 15:28:14 +02:00
Aleksandra Martyniuk
d7d570e39d compaction: rename compaction::task
To avoid confusion with task manager tasks compaction::task is renamed
to compaction::compaction_task_exector. All inheriting classes are
modified similarly.
2023-03-29 15:23:18 +02:00
Aleksandra Martyniuk
f24391fbe4 compaction: move compaction_manager::task out of compaction manager
compaction_manager::task needs to be accessed from task manager compaction
tasks. Thus, compaction_manager::task and all inheriting classes are moved
from compaction manager to compaction namespace.
2023-03-29 15:21:24 +02:00
Aleksandra Martyniuk
37cafec9d5 compaction: move sstable_task definition to source file 2023-03-29 14:53:43 +02:00
Raphael S. Carvalho
989afbf83b compaction: TWCS: wire up compaction_strategy_state
TWCS no longer keeps internal state, and will now rely on state
managed by each compaction group through compaction::table_state.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
2023-03-28 08:48:15 -03:00
Raphael S. Carvalho
233fe6d3dc compaction: LCS: wire up compaction_strategy_state
LCS no longer keeps internal state, and will now rely on state
managed by each compaction group through compaction::table_state.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
2023-03-28 08:48:15 -03:00
Raphael S. Carvalho
2186a75e9b compaction: Expose compaction_strategy_state through table_state
That will allow compaction_strategy to access the compaction group state
through compaction::table_state, which is the interface at which replica
talks to the compaction layer.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
2023-03-28 08:48:10 -03:00
Raphael S. Carvalho
25f73a4181 compaction: Introduce compaction_strategy_state
Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
2023-03-27 15:46:11 -03:00
Raphael S. Carvalho
1ffe2f04ef compaction: add table_state param to compaction_strategy::notify_completion()
once compaction_strategy is made staless, the state must be retrieved
in notify_completion() through table_state.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
2023-03-27 13:40:02 -03:00
Raphael S. Carvalho
2ffaae97a4 compaction: LCS: extract state into a separate struct
Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
2023-03-27 13:40:02 -03:00