mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-07-19 22:42:20 +00:00
fix(filer): use DROP TABLE IF EXISTS in SQL stores (#10158)
Concurrent bucket deletion across multiple filer replicas races on the per-bucket DROP TABLE. The first replica drops the table; the rest hit an undefined-table error (postgres 42P01, mysql 1051) which propagates out of DeleteFolderChildren and panics the filer. On restart the same pending DROP re-runs and the filer crash-loops. Make the drop idempotent. Same defect class in all SQL backends, so fix postgres, postgres2, mysql, mysql2, and sqlite together.
This commit is contained in:
@@ -72,7 +72,7 @@ func (store *MysqlStore) initialize(dsn string, upsertQuery string, enableUpsert
|
||||
}
|
||||
gen := &SqlGenMysql{
|
||||
CreateTableSqlTemplate: "",
|
||||
DropTableSqlTemplate: "DROP TABLE `%s`",
|
||||
DropTableSqlTemplate: "DROP TABLE IF EXISTS `%s`",
|
||||
UpsertQueryTemplate: upsertQuery,
|
||||
}
|
||||
store.SqlGenerator = gen
|
||||
|
||||
@@ -65,7 +65,7 @@ func (store *MysqlStore2) initialize(createTable, upsertQuery string, enableUpse
|
||||
}
|
||||
gen := &mysql.SqlGenMysql{
|
||||
CreateTableSqlTemplate: createTable,
|
||||
DropTableSqlTemplate: "DROP TABLE `%s`",
|
||||
DropTableSqlTemplate: "DROP TABLE IF EXISTS `%s`",
|
||||
UpsertQueryTemplate: upsertQuery,
|
||||
}
|
||||
store.SqlGenerator = gen
|
||||
|
||||
@@ -64,7 +64,7 @@ func (store *PostgresStore) initialize(upsertQuery string, enableUpsert bool, us
|
||||
}
|
||||
gen := &SqlGenPostgres{
|
||||
CreateTableSqlTemplate: "",
|
||||
DropTableSqlTemplate: `drop table "%s"`,
|
||||
DropTableSqlTemplate: `drop table if exists "%s"`,
|
||||
UpsertQueryTemplate: upsertQuery,
|
||||
}
|
||||
store.SqlGenerator = gen
|
||||
|
||||
@@ -70,7 +70,7 @@ func (store *PostgresStore2) initialize(createTable, upsertQuery string, enableU
|
||||
}
|
||||
gen := &postgres.SqlGenPostgres{
|
||||
CreateTableSqlTemplate: createTable,
|
||||
DropTableSqlTemplate: `drop table "%s"`,
|
||||
DropTableSqlTemplate: `drop table if exists "%s"`,
|
||||
UpsertQueryTemplate: upsertQuery,
|
||||
}
|
||||
store.SqlGenerator = gen
|
||||
|
||||
@@ -54,7 +54,7 @@ func (store *SqliteStore) initialize(dbFile, createTable, upsertQuery string) (e
|
||||
store.SupportBucketTable = true
|
||||
store.SqlGenerator = &mysql.SqlGenMysql{
|
||||
CreateTableSqlTemplate: createTable,
|
||||
DropTableSqlTemplate: "drop table `%s`",
|
||||
DropTableSqlTemplate: "drop table if exists `%s`",
|
||||
UpsertQueryTemplate: upsertQuery,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user