Skip to content

Commit

Permalink
ddl: Do not physical drop table after tiflash replica is set to 0 (#9440
Browse files Browse the repository at this point in the history
)

close #9438

ddl: Do not physical drop table after tiflash replica is set to 0
To avoid a potential data loss issue when altering tiflash replica
  • Loading branch information
JaySon-Huang authored Sep 19, 2024
1 parent 9e3ba66 commit d347613
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 8 additions & 2 deletions dbms/src/TiDB/Schema/SchemaBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ void SchemaBuilder<Getter, NameMapper>::applySetTiFlashReplica(DatabaseID databa
auto & tmt_context = context.getTMTContext();
if (table_info->replica_info.count == 0)
{
// Replicat number is to 0, mark the table as tombstone in TiFlash
auto storage = tmt_context.getStorages().get(keyspace_id, table_info->id);
if (unlikely(storage == nullptr))
{
Expand All @@ -402,7 +401,14 @@ void SchemaBuilder<Getter, NameMapper>::applySetTiFlashReplica(DatabaseID databa
return;
}

applyDropTable(database_id, table_id, "SetTiFlashReplica-0");
// We can not mark the table is safe to be physically drop from the tiflash instances when
// the number of tiflash replica is set to be 0.
// There could be a concurrent issue that cause data loss. Check the following link for details:
// https://github.com/pingcap/tiflash/issues/9438#issuecomment-2360370761
// applyDropTable(database_id, table_id, "SetTiFlashReplica-0");

// Now only update the replica number to be 0 instead
updateTiFlashReplicaNumOnStorage(database_id, table_id, storage, table_info);
return;
}

Expand Down
4 changes: 1 addition & 3 deletions tests/fullstack-test2/ddl/alter_table_tiflash_replica.test
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ mysql> set session tidb_isolation_read_engines='tiflash';select * from test.t;
| x |
+----+
| 1 |
+----+
| 8 |
+----+
| 50 |
+----+

>> DBGInvoke get_partition_tables_tiflash_replica_count("test", "t")
┌─get_partition_tables_tiflash_replica_count(test, t)─┐
│ 1/1/1/ │
└─────────────────────────────────────────────────────┘
└─────────────────────────────────────────────────────┘

0 comments on commit d347613

Please sign in to comment.