Skip to content

Commit d6335e4

Browse files
Try attach table if INCORRECT_DATA(error code 117) with "CREATE TABLE" (#1820)
When multiple disks are combined into a single volume and the default disk(not in the volume, just includes metadata) becomes lost, the ClickHouse operator attempts to recover the tables. However, because the actual table data still exists intact on other disks (not on the lost default disk), ClickHouse throws the following error during the CREATE TABLE operation, and the table fails to recover properly: ```sh <Error> executeQuery: Code: 117. DB::Exception: Data directory for table already contains data parts - probably it was unclean DROP table or manual intervention. You must either clear directory by hand or use ATTACH TABLE instead of CREATE TABLE if you need to use that parts. (INCORRECT_DATA) (version 25.6.3.116 (official build)) ``` In this situation, the issue can be resolved by using the ATTACH TABLE command instead. Since there is already existing logic that falls back to ATTACH TABLE for other error codes, we only need to add specific handling for error code 117. Signed-off-by: thomas.e <thomas.e@kakaocorp.com> Co-authored-by: thomas.e <thomas.e@kakaocorp.com>
1 parent e87bdf5 commit d6335e4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/model/clickhouse/cluster.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ func (c *Cluster) exec(ctx context.Context, host string, queries []string, _opts
167167
sqlAttach := strings.ReplaceAll(sql, "CREATE TABLE", "ATTACH TABLE")
168168
err = conn.Exec(ctx, sqlAttach, opts)
169169
}
170+
if err != nil && strings.Contains(err.Error(), "Code: 117") && strings.Contains(sql, "CREATE TABLE") {
171+
// WARNING: error message or code may change in newer ClickHouse versions
172+
c.l.V(1).M(host).F().Info("Directory for table already exists. Trying ATTACH TABLE instead")
173+
sqlAttach := strings.ReplaceAll(sql, "CREATE TABLE", "ATTACH TABLE")
174+
err = conn.Exec(ctx, sqlAttach, opts)
175+
}
170176
if err == nil || strings.Contains(err.Error(), "ALREADY_EXISTS") {
171177
queries[i] = "" // Query is executed or object already exists, removing from the list
172178
} else {

0 commit comments

Comments
 (0)