Skip to content

Commit

Permalink
fix #1058
Browse files Browse the repository at this point in the history
Signed-off-by: Slach <[email protected]>
  • Loading branch information
Slach committed Dec 9, 2024
1 parent 0148039 commit 5dac10f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/backup/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ func (b *Backuper) dropExistsRBAC(ctx context.Context, kind string, name string,
if !isKeeperRBACTypePrefixExists {
return fmt.Errorf("unsupported RBAC kind: %s", kind)
}
// rbacType contains name of keeper user directory
prefix, err := k.GetReplicatedAccessPath(rbacType)
if err != nil {
return fmt.Errorf("b.dropExistsRBAC -> k.GetReplicatedAccessPath error: %v", err)
Expand Down
11 changes: 8 additions & 3 deletions pkg/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (k *Keeper) GetReplicatedAccessPath(userDirectory string) (string, error) {
if zookeeperPath != "/" {
zookeeperPath = strings.TrimSuffix(zookeeperPathNode.InnerText(), "/")
}
log.Debug().Str("userDirectory", userDirectory).Str("zookeeper_path", zookeeperPath).Msg("k->GetReplicatedAccessPath")
return zookeeperPath, nil
}

Expand All @@ -125,7 +126,7 @@ func (k *Keeper) Dump(prefix, dumpFile string) (int, error) {
log.Warn().Msgf("can't close %s: %v", dumpFile, err)
}
}()
if !strings.HasPrefix(prefix, "/") && k.root != "" {
if k.root != "" && !strings.HasPrefix(prefix, k.root) {
prefix = path.Join(k.root, prefix)
}
bytes, err := k.dumpNodeRecursive(prefix, "", f)
Expand All @@ -136,6 +137,10 @@ func (k *Keeper) Dump(prefix, dumpFile string) (int, error) {
}

func (k *Keeper) ChildCount(prefix, nodePath string) (int, error) {
if k.root != "" && !strings.HasPrefix(prefix, k.root) {
prefix = path.Join(k.root, prefix)
}
log.Debug().Str("prefix", prefix).Str("nodePath", nodePath).Msg("k->ChildCount")
childrenNodes, _, err := k.conn.Children(path.Join(prefix, nodePath))
return len(childrenNodes), err
}
Expand All @@ -145,7 +150,7 @@ func (k *Keeper) dumpNodeRecursive(prefix, nodePath string, f *os.File) (int, er
if err != nil {
return 0, err
}
bytes, err := k.writeJsonString(f, DumpNode{Path: nodePath, Value: string(value)})
bytes, err := k.writeJsonString(f, DumpNode{Path: strings.TrimPrefix(nodePath, k.root), Value: string(value)})
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -186,7 +191,7 @@ func (k *Keeper) Restore(dumpFile, prefix string) error {
log.Warn().Msgf("can't close %s: %v", dumpFile, err)
}
}()
if !strings.HasPrefix(prefix, "/") && k.root != "" {
if k.root != "" && !strings.HasPrefix(prefix, k.root) {
prefix = path.Join(k.root, prefix)
}
scanner := bufio.NewScanner(f)
Expand Down
3 changes: 1 addition & 2 deletions test/integration/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ export QA_GCS_OVER_S3_BUCKET=XXX
# QA_GCS_CRED_JSON='{ "type": "service_account", "project_id": "XXXX", "private_key_id": "XXXXX", "private_key": "SSH KEY XXXX", "client_email": "XXXX", "client_id": "XXXX", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/<client_email_url_encoded>" }'
export QA_GCS_CRED_JSON=""
export QA_GCS_CRED_JSON_ENCODED=$(echo '{ "type": "service_account", "project_id": "XXXX", "private_key_id": "XXXXX", "private_key": "SSH KEY XXXX", "client_email": "XXXX", "client_id": "XXXX", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/<client_email_url_encoded>" }' | base64 -w 0 )
export CLICKHOUSE_TESTS_DIR=${PWD}/test/testflows/clickhouse_backup
export GOCOVERDIR=${PWD}/test/testflows/_coverage_
export GOCOVERDIR=${PWD}/test/integration/_coverage_
15 changes: 15 additions & 0 deletions test/integration/dynamic_settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,21 @@ EOT

fi

# https://github.com/Altinity/clickhouse-backup/issues/1058, clickhouse-keeper-client available from 23.9
if [[ "${CLICKHOUSE_VERSION}" == "head" || "${CLICKHOUSE_VERSION}" =~ ^23\.9 || "${CLICKHOUSE_VERSION}" =~ ^23\.1[0-9] || "${CLICKHOUSE_VERSION}" =~ ^2[4-9]\.[1-9] ]]; then

clickhouse-keeper-client -p 2181 -h zookeeper -q "touch '/custom_zookeeper_root'"

cat <<EOT > /etc/clickhouse-server/config.d/custom_zookeeper_root.xml
<yandex>
<zookeeper>
<root>/custom_zookeeper_root</root>
</zookeeper>
</yandex>
EOT

fi

# zookeeper RBAC available from 21.9
if [[ "${CLICKHOUSE_VERSION}" == "head" || "${CLICKHOUSE_VERSION}" =~ ^21\.9 || "${CLICKHOUSE_VERSION}" =~ ^21\.1[0-9] || "${CLICKHOUSE_VERSION}" =~ ^2[2-9]\.[1-9] ]]; then

Expand Down

0 comments on commit 5dac10f

Please sign in to comment.