Optimize table on large table online DDL Feature
OPTIMIZE TABLE is almost useless for InnoDB.  Why are you running it?
Some people like to break up the disk into partitions.  But that leads to overflowing one partition when there is spare room in another.  You could move tmpdir to a bigger partition?
OPTIMIZE TABLE table must copy the table over.  Ditto for flavors of ALTER TABLE.  Hence, you must have enough spare disp space, preferrable in the same FS, as the table.
MySQL 8.0 has some &quot;inline&quot; or &quot;in place&quot; ALTERs; maybe it would help here.
Percona's pt-online-schema-change avoids blocking writes during schema changes.  Ditto for gh-ost.  These probably need the extas disk space, so may not be relevant.

Moral of this story...  Don't let the disk get so full that you can't make a full copy of the biggest table.