Skip to content

Commit 082b0ad

Browse files
authored
Merge pull request #1610 from Altinity/kafka_keeper_path_1120
Back up and restore Kafka offsets stored in Keeper (kafka_keeper_path)
2 parents de41b40 + 26e03a0 commit 082b0ad

16 files changed

Lines changed: 2103 additions & 9 deletions

File tree

‎ReadMe.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ Create schema and restore data from backup: `curl -s localhost:7171/backup/resto
803803
- Optional string query argument `restore_schema_as_attach` or `restore-schema-as-attach` works the same as the `--restore-schema-as-attach` CLI argument.
804804
- Optional boolean query argument `resume` works the same as the `--resume` CLI argument (resume download for object disk data).
805805
- Optional boolean query argument `skip_empty_tables` or `skip-empty-tables` works the same as the `--skip-empty-tables` CLI argument (skip restoring tables that have no data).
806+
- Optional boolean query argument `skip_kafka_keeper_hold` or `skip-kafka-keeper-hold` works the same as the `--skip-kafka-keeper-hold` CLI argument (don't hold consumption of restored Kafka tables with `kafka_keeper_path` via partition locks until data restore completes, release already placed locks).
806807
- Optional boolean query argument `rebind_replica_path_if_exists` or `rebind-replica-path-if-exists` works the same as the `--rebind-replica-path-if-exists` CLI argument (overrides `clickhouse.rebind_replica_path_if_exists` for this request, rebind a restored ReplicatedMergeTree to `default_replica_path` when the original ZK path still has leftover state but our replica entry is absent). WARNING: never set during a concurrent HA multi-replica restore.
807808
- Optional boolean query argument `drop_replica_if_exists` or `drop-replica-if-exists` works the same as the `--drop-replica-if-exists` CLI argument (overrides `clickhouse.drop_replica_if_exists` for this request, execute `SYSTEM DROP REPLICA ... FROM ZKPATH ...` and keep the original replication path when our own replica entry still exists in ZooKeeper but no local table uses it). WARNING: never set during a concurrent HA multi-replica restore.
808809
- Optional string query argument `callback` allow pass callback URL which will call with POST with `application/json` with payload `{"status":"error|success|cancel","error":"not empty when error happens", "operation_id" : "<random_uuid>", "command":"<full command line>", "duration":"<elapsed>"}`. When omitted or empty, falls back to `general.callback_url` if configured.
@@ -837,6 +838,7 @@ A backup with ClickHouse Cloud / native `BACKUP ... TO S3/AzureBlobStorage` layo
837838
- Optional boolean query argument `allow_missing_files` or `allow-missing-files` works the same as the `--allow-missing-files` CLI argument (skip data parts missing on remote storage instead of failing, overrides `general.allow_missing_files_on_download` for this request).
838839
- Optional boolean query argument `streaming` works the same as the `--streaming` CLI argument (restore each table right after its download and delete its local copy, see [Streaming mode](#streaming-mode)).
839840
- Optional boolean query argument `skip_empty_tables` or `skip-empty-tables` works the same as the `--skip-empty-tables` CLI argument (skip restoring tables that have no data).
841+
- Optional boolean query argument `skip_kafka_keeper_hold` or `skip-kafka-keeper-hold` works the same as the `--skip-kafka-keeper-hold` CLI argument (don't hold consumption of restored Kafka tables with `kafka_keeper_path` via partition locks until data restore completes, release already placed locks).
840842
- Optional boolean query argument `rebind_replica_path_if_exists` or `rebind-replica-path-if-exists` works the same as the `--rebind-replica-path-if-exists` CLI argument (overrides `clickhouse.rebind_replica_path_if_exists` for this request, rebind a restored ReplicatedMergeTree to `default_replica_path` when the original ZK path still has leftover state but our replica entry is absent). WARNING: never set during a concurrent HA multi-replica restore.
841843
- Optional boolean query argument `drop_replica_if_exists` or `drop-replica-if-exists` works the same as the `--drop-replica-if-exists` CLI argument (overrides `clickhouse.drop_replica_if_exists` for this request, execute `SYSTEM DROP REPLICA ... FROM ZKPATH ...` and keep the original replication path when our own replica entry still exists in ZooKeeper but no local table uses it). WARNING: never set during a concurrent HA multi-replica restore.
842844
- Optional string query argument `callback` allow pass callback URL which will call with POST with `application/json` with payload `{"status":"error|success|cancel","error":"not empty when error happens", "operation_id" : "<random_uuid>", "command":"<full command line>", "duration":"<elapsed>"}`. When omitted or empty, falls back to `general.callback_url` if configured.
@@ -1135,7 +1137,7 @@ NAME:
11351137
clickhouse-backup restore - Create schema and restore data from backup
11361138
11371139
USAGE:
1138-
clickhouse-backup restore [-t, --tables=<db>.<table>] [-m, --restore-database-mapping=<originDB>:<targetDB>[,<...>]] [--tm, --restore-table-mapping=<originTable>:<targetTable>[,<...>]] [--partitions=<partitions_names>] [-s, --schema] [-d, --data] [--rm, --drop] [-i, --ignore-dependencies] [--rbac] [--configs] [--named-collections] [--resume] [--skip-empty-tables] <backup_name>
1140+
clickhouse-backup restore [-t, --tables=<db>.<table>] [-m, --restore-database-mapping=<originDB>:<targetDB>[,<...>]] [--tm, --restore-table-mapping=<originTable>:<targetTable>[,<...>]] [--partitions=<partitions_names>] [-s, --schema] [-d, --data] [--rm, --drop] [-i, --ignore-dependencies] [--rbac] [--configs] [--named-collections] [--resume] [--skip-empty-tables] [--skip-kafka-keeper-hold] <backup_name>
11391141
11401142
OPTIONS:
11411143
--table string, --tables string, -t string Restore only database and objects which matched with table name patterns, separated by comma, allow ? and * as wildcard
@@ -1151,6 +1153,7 @@ OPTIONS:
11511153
--schema, -s Restore schema only
11521154
--data, -d Restore data only
11531155
--rm, --drop Drop exists schema objects before restore
1156+
--skip-kafka-keeper-hold Don't hold consumption of restored Kafka tables with kafka_keeper_path via partition locks until data restore completes, release already placed locks
11541157
-i, --ignore-dependencies Ignore dependencies when drop exists schema objects
11551158
--rbac, --restore-rbac, --do-restore-rbac Restore RBAC related objects, enabled always when general->rbac_restore_always: true
11561159
--configs, --restore-configs, --do-restore-configs Restore 'clickhouse-server' CONFIG related files, enabled always when general->config_restore_always: true
@@ -1179,7 +1182,7 @@ NAME:
11791182
clickhouse-backup restore_remote - Download and restore
11801183
11811184
USAGE:
1182-
clickhouse-backup restore_remote [--schema] [--data] [-t, --tables=<db>.<table>] [-m, --restore-database-mapping=<originDB>:<targetDB>[,<...>]] [--tm, --restore-table-mapping=<originTable>:<targetTable>[,<...>]] [--partitions=<partitions_names>] [--rm, --drop] [-i, --ignore-dependencies] [--rbac] [--configs] [--named-collections] [--resumable] [--skip-empty-tables] <backup_name>
1185+
clickhouse-backup restore_remote [--schema] [--data] [-t, --tables=<db>.<table>] [-m, --restore-database-mapping=<originDB>:<targetDB>[,<...>]] [--tm, --restore-table-mapping=<originTable>:<targetTable>[,<...>]] [--partitions=<partitions_names>] [--rm, --drop] [-i, --ignore-dependencies] [--rbac] [--configs] [--named-collections] [--resumable] [--skip-empty-tables] [--skip-kafka-keeper-hold] <backup_name>
11831186
11841187
DESCRIPTION:
11851188
A remote backup with ClickHouse Cloud / native BACKUP layout (.backup without metadata.json, `cloud` in `list remote`) is restored via restore_cloud, only with remote_storage s3 or azblob and without mapping, --schema, --data, --rbac, --configs, --named-collections, --resume and --streaming options
@@ -1199,6 +1202,7 @@ OPTIONS:
11991202
--schema, -s Download and Restore schema only
12001203
--data, -d Download and Restore data only
12011204
--rm, --drop Drop schema objects before restore
1205+
--skip-kafka-keeper-hold Don't hold consumption of restored Kafka tables with kafka_keeper_path via partition locks until data restore completes, release already placed locks
12021206
-i, --ignore-dependencies Ignore dependencies when drop exists schema objects
12031207
--rbac, --restore-rbac, --do-restore-rbac Download and Restore RBAC related objects, enabled always when general->rbac_restore_always: true
12041208
--configs, --restore-configs, --do-restore-configs Download and Restore 'clickhouse-server' CONFIG related files, enabled always when general->config_restore_always: true

‎cmd/clickhouse-backup/main.go‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,12 @@ func newRootCommand() *cli.Command {
602602
{
603603
Name: "restore",
604604
Usage: "Create schema and restore data from backup",
605-
UsageText: "clickhouse-backup restore [-t, --tables=<db>.<table>] [-m, --restore-database-mapping=<originDB>:<targetDB>[,<...>]] [--tm, --restore-table-mapping=<originTable>:<targetTable>[,<...>]] [--partitions=<partitions_names>] [-s, --schema] [-d, --data] [--rm, --drop] [-i, --ignore-dependencies] [--rbac] [--configs] [--named-collections] [--resume] [--skip-empty-tables] <backup_name>",
605+
UsageText: "clickhouse-backup restore [-t, --tables=<db>.<table>] [-m, --restore-database-mapping=<originDB>:<targetDB>[,<...>]] [--tm, --restore-table-mapping=<originTable>:<targetTable>[,<...>]] [--partitions=<partitions_names>] [-s, --schema] [-d, --data] [--rm, --drop] [-i, --ignore-dependencies] [--rbac] [--configs] [--named-collections] [--resume] [--skip-empty-tables] [--skip-kafka-keeper-hold] <backup_name>",
606606
Action: func(ctx context.Context, c *cli.Command) error {
607607
b := backup.NewBackuper(config.GetConfigFromCli(c))
608608
b.DryRun = c.Bool("dry-run")
609609
b.EmbeddedOnClusterWorker = c.Bool("embedded-on-cluster-worker")
610+
b.SkipKafkaKeeperHold = c.Bool("skip-kafka-keeper-hold")
610611
return withDryRunResult(c, b, b.Restore(c.Args().First(), c.String("tables"), c.StringSlice("restore-database-mapping"), c.StringSlice("restore-table-mapping"), c.StringSlice("partitions"), c.StringSlice("skip-projections"), c.Bool("schema"), c.Bool("data"), c.Bool("drop"), c.Bool("ignore-dependencies"), c.Bool("rbac"), c.Bool("rbac-only"), c.Bool("configs"), c.Bool("configs-only"), c.Bool("named-collections"), c.Bool("named-collections-only"), c.Bool("resume"), c.Bool("restore-schema-as-attach"), c.Bool("replicated-copy-to-detached"), c.Bool("skip-empty-tables"), version, commandIdFromCli(c)))
611612
},
612613
Flags: []cli.Flag{
@@ -657,6 +658,11 @@ func newRootCommand() *cli.Command {
657658
Hidden: false,
658659
Usage: "Drop exists schema objects before restore",
659660
},
661+
&cli.BoolFlag{
662+
Name: "skip-kafka-keeper-hold",
663+
Hidden: false,
664+
Usage: "Don't hold consumption of restored Kafka tables with kafka_keeper_path via partition locks until data restore completes, release already placed locks",
665+
},
660666
&cli.BoolFlag{
661667
Name: "i",
662668
Aliases: []string{"ignore-dependencies"},
@@ -745,14 +751,15 @@ func newRootCommand() *cli.Command {
745751
{
746752
Name: "restore_remote",
747753
Usage: "Download and restore",
748-
UsageText: "clickhouse-backup restore_remote [--schema] [--data] [-t, --tables=<db>.<table>] [-m, --restore-database-mapping=<originDB>:<targetDB>[,<...>]] [--tm, --restore-table-mapping=<originTable>:<targetTable>[,<...>]] [--partitions=<partitions_names>] [--rm, --drop] [-i, --ignore-dependencies] [--rbac] [--configs] [--named-collections] [--resumable] [--skip-empty-tables] <backup_name>",
754+
UsageText: "clickhouse-backup restore_remote [--schema] [--data] [-t, --tables=<db>.<table>] [-m, --restore-database-mapping=<originDB>:<targetDB>[,<...>]] [--tm, --restore-table-mapping=<originTable>:<targetTable>[,<...>]] [--partitions=<partitions_names>] [--rm, --drop] [-i, --ignore-dependencies] [--rbac] [--configs] [--named-collections] [--resumable] [--skip-empty-tables] [--skip-kafka-keeper-hold] <backup_name>",
749755
Description: "A remote backup with ClickHouse Cloud / native BACKUP layout (.backup without metadata.json, `cloud` in `list remote`) is restored via restore_cloud, only with remote_storage s3 or azblob and without mapping, --schema, --data, --rbac, --configs, --named-collections, --resume and --streaming options\n" +
750756
" https://github.com/Altinity/clickhouse-backup/issues/1574",
751757
Action: func(ctx context.Context, c *cli.Command) error {
752758
b := backup.NewBackuper(config.GetConfigFromCli(c))
753759
b.DryRun = c.Bool("dry-run")
754760
b.EmbeddedOnClusterWorker = c.Bool("embedded-on-cluster-worker")
755761
b.DiskLimit = c.Int("disk-limit")
762+
b.SkipKafkaKeeperHold = c.Bool("skip-kafka-keeper-hold")
756763
return withDryRunResult(c, b, b.RestoreFromRemote(c.Args().First(), c.String("tables"), c.StringSlice("restore-database-mapping"), c.StringSlice("restore-table-mapping"), c.StringSlice("partitions"), c.StringSlice("skip-projections"), c.Bool("schema"), c.Bool("d"), c.Bool("rm"), c.Bool("i"), c.Bool("rbac"), c.Bool("rbac-only"), c.Bool("configs"), c.Bool("configs-only"), c.Bool("named-collections"), c.Bool("named-collections-only"), c.Bool("resume"), c.Bool("restore-schema-as-attach"), c.Bool("replicated-copy-to-detached"), c.Bool("skip-empty-tables"), c.Bool("hardlink-exists-files"), c.Bool("streaming"), version, commandIdFromCli(c)))
757764
},
758765
Flags: []cli.Flag{
@@ -803,6 +810,11 @@ func newRootCommand() *cli.Command {
803810
Hidden: false,
804811
Usage: "Drop schema objects before restore",
805812
},
813+
&cli.BoolFlag{
814+
Name: "skip-kafka-keeper-hold",
815+
Hidden: false,
816+
Usage: "Don't hold consumption of restored Kafka tables with kafka_keeper_path via partition locks until data restore completes, release already placed locks",
817+
},
806818
&cli.BoolFlag{
807819
Name: "i",
808820
Aliases: []string{"ignore-dependencies"},

‎pkg/backup/backuper.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ type Backuper struct {
6868
skipEmbeddedClusterFanOut bool
6969
// DiskLimit - max allowed local disk usage in percent after download, 0 disables the check, see issues/1458
7070
DiskLimit int
71+
// SkipKafkaKeeperHold - don't hold consumption of restored Kafka tables with kafka_keeper_path via partition locks between
72+
// schema and data restore and release the already placed locks, see issues/1120
73+
SkipKafkaKeeperHold bool
74+
// kafkaHeldLocks - keeper paths of partition locks placed by the current schema restore, see issues/1120
75+
kafkaHeldLocks []string
7176
// freezes - shadow uuids of the running `create`, persisted in <backup_name>/freezes.tmp, see issues/1563
7277
freezes *freezesState
7378
freezesMutex sync.Mutex

0 commit comments

Comments
 (0)