Code review comment: ```suggestion             throw new AlterCancelException("Database " + dbId + " does not exist"); ```

Code under review:
protected void runWaitingTxnJob() throws AlterCancelException {
        Preconditions.checkState(jobState == JobState.WAITING_TXN, jobState);

        if (optimizeClause == null) {
            throw new AlterCancelException("optimize clause is null since FE restart, job: " + jobId);
        }

        List<String> tmpPartitionNames;
        List<String> partitionNames = Lists.newArrayList();
        List<String> tableColumnNames = Lists.newArrayList();

        
        
        
        Database db = GlobalStateMgr.getCurrentState().getDb(dbId);
        if (db == null) {
            throw new AlterCancelException("Databasee " + dbId + " does not exist");
        }

        Locker locker = new Locker();
        locker.lockDatabase(db, LockType.READ);
        try {
            dbName = db.getFullName();
            OlapTable tbl = checkAndGetTable(db, tableId);
            if (getTmpPartitionIds().stream().anyMatch(id -> tbl.getPartition(id) == null)) {
                throw new AlterCancelException("partitions changed during insert");
            }
            tmpPartitionNames = getTmpPartitionIds().stream()
                    .map(partitionId -> tbl.getPartition(partitionId).getName())
                    .collect(Collectors.toList());
            optimizeClause.getSourcePartitionIds().stream()
                    .map(partitionId -> tbl.getPartition(partitionId)).forEach(
                        partition -> {
                            partitionNames.add(partition.getName());
                        }
            );
            tableColumnNames = tbl.getBaseSchema().stream().filter(column -> !column.isGeneratedColumn())
                    .map(col -> ParseUtil.backquote(col.getName())).collect(Collectors.toList());
        } finally {
            locker.unLockDatabase(db, LockType.READ);
        }

        
        for (int i = 0; i < tmpPartitionNames.size(); ++i) {
            String tmpPartitionName = tmpPartitionNames.get(i);
            String partitionName = partitionNames.get(i);
            String rewriteSql = "insert into " + dbName + "." + tableName + " TEMPORARY PARTITION ("
                    + tmpPartitionName + ") select " + Joiner.on(", ").join(tableColumnNames)
                    + " from " + dbName + "." + tableName + " partition (" + partitionName + ")";
            String taskName = getName() + "_" + tmpPartitionName;
            OptimizeTask rewriteTask = TaskBuilder.buildOptimizeTask(taskName, properties, rewriteSql, dbName);
            rewriteTask.setPartitionName(partitionName);
            rewriteTask.setTempPartitionName(tmpPartitionName);
            rewriteTasks.add(rewriteTask);
        }

        this.jobState = JobState.RUNNING;
        span.addEvent("setRunning");

        
        LOG.info("transfer optimize job {} state to {}", jobId, this.jobState);
    }

Line commented on: throw new AlterCancelException("Databasee " + dbId + " does not exist");

Revised code:
protected void runWaitingTxnJob() throws AlterCancelException {
        Preconditions.checkState(jobState == JobState.WAITING_TXN, jobState);

        if (optimizeClause == null) {
            throw new AlterCancelException("optimize clause is null since FE restart, job: " + jobId);
        }

        List<String> tmpPartitionNames;
        List<String> partitionNames = Lists.newArrayList();
        List<String> tableColumnNames = Lists.newArrayList();

        
        
        
        Database db = GlobalStateMgr.getCurrentState().getDb(dbId);
        if (db == null) {
            throw new AlterCancelException("Database " + dbId + " does not exist");
        }

        Locker locker = new Locker();
        locker.lockDatabase(db, LockType.READ);
        try {
            dbName = db.getFullName();
            OlapTable tbl = checkAndGetTable(db, tableId);
            if (getTmpPartitionIds().stream().anyMatch(id -> tbl.getPartition(id) == null)) {
                throw new AlterCancelException("partitions changed during insert");
            }
            tmpPartitionNames = getTmpPartitionIds().stream()
                    .map(partitionId -> tbl.getPartition(partitionId).getName())
                    .collect(Collectors.toList());
            optimizeClause.getSourcePartitionIds().stream()
                    .map(partitionId -> tbl.getPartition(partitionId)).forEach(
                        partition -> {
                            partitionNames.add(partition.getName());
                        }
            );
            tableColumnNames = tbl.getBaseSchema().stream().filter(column -> !column.isGeneratedColumn())
                    .map(col -> ParseUtil.backquote(col.getName())).collect(Collectors.toList());
        } finally {
            locker.unLockDatabase(db, LockType.READ);
        }

        
        for (int i = 0; i < tmpPartitionNames.size(); ++i) {
            String tmpPartitionName = tmpPartitionNames.get(i);
            String partitionName = partitionNames.get(i);
            String rewriteSql = "insert into " + dbName + "." + tableName + " TEMPORARY PARTITION ("
                    + tmpPartitionName + ") select " + Joiner.on(", ").join(tableColumnNames)
                    + " from " + dbName + "." + tableName + " partition (" + partitionName + ")";
            String taskName = getName() + "_" + tmpPartitionName;
            OptimizeTask rewriteTask = TaskBuilder.buildOptimizeTask(taskName, properties, rewriteSql, dbName);
            rewriteTask.setPartitionName(partitionName);
            rewriteTask.setTempPartitionName(tmpPartitionName);
            rewriteTasks.add(rewriteTask);
        }

        this.jobState = JobState.RUNNING;
        span.addEvent("setRunning");

        
        LOG.info("transfer optimize job {} state to {}", jobId, this.jobState);
    }