private boolean checkDriverState(MigrationDriverState expectedState, MigrationEvent migrationEvent) {
        if (migrationEvent instanceof MigrationWriteEvent) {
            LeaderAndEpoch curLeaderAndEpoch = KRaftMigrationDriver.this.curLeaderAndEpoch;
            LeaderAndEpoch eventLeaderAndEpoch = ((MigrationWriteEvent) migrationEvent).eventLeaderAndEpoch();
            if (!eventLeaderAndEpoch.equals(curLeaderAndEpoch)) {
                log.info("Current leader epoch is {}, but event was created with epoch {}. Not running this event {}.",
                        curLeaderAndEpoch, eventLeaderAndEpoch, migrationEvent);
                return false;
            }
        }

        if (!migrationState.equals(expectedState)) {
            log.info("Expected driver state {} but found {}. Not running this event {}.",
                expectedState, migrationState, migrationEvent);
            return false;
        }

        return true;
    }
Check that the migration driver is in the correct state for a given event. If the event causes
updates (i.e., to ZK or broker RPCs), also check that the event is for the current KRaft controller epoch.
metadata/src/main/java/org/apache/kafka/metadata/migration/KRaftMigrationDriver.java