Skip to content

Commit 312088a

Browse files
Jiale Zhangjialez0
authored andcommitted
gateway: use 191-char prefix index on aa_instance_heartbeats.instance_id
The unique index on `instance_id` (VARCHAR(255), utf8mb4) overflowed MySQL InnoDB's 767-byte key length limit (255 * 4 = 1020 bytes), causing `CREATE UNIQUE INDEX ... ON aa_instance_heartbeats(instance_id)` to fail with "Specified key was too long" during gateway startup and aborting the migration. Switch the MySQL DDL to a 191-char prefix index, which keeps the index key under 767 bytes (191 * 4 = 764) while remaining longer than any realistic instance_id value. SQLite path is unaffected. Signed-off-by: Jiale Zhang <xinjian.zjl@alibaba-inc.com>
1 parent ce92d9d commit 312088a

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

  • trustee-gateway/internal/persistence/storage

trustee-gateway/internal/persistence/storage/database.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ func (d *Database) migrateAAInstanceHeartbeatIndexMySQL() error {
238238
logrus.Info("Cleaned up duplicate instance_id records in aa_instance_heartbeats")
239239
}
240240

241-
if err := d.DB.Exec("CREATE UNIQUE INDEX idx_aa_heartbeat_instance_id ON aa_instance_heartbeats(instance_id)").Error; err != nil {
241+
// Use a 191-char prefix to stay under MySQL InnoDB's 767-byte index key
242+
// limit when instance_id is VARCHAR(255) utf8mb4 (4 bytes/char → 1020 bytes).
243+
if err := d.DB.Exec("CREATE UNIQUE INDEX idx_aa_heartbeat_instance_id ON aa_instance_heartbeats(instance_id(191))").Error; err != nil {
242244
return fmt.Errorf("failed to create unique index on instance_id: %w", err)
243245
}
244246

0 commit comments

Comments
 (0)