Code review comment: We should not rely on "the last one is running", better filter it by state. So that we can unify the logic just same as batch cancel.

Code under review:
public boolean cancelLoadJob(CancelLoadStmt stmt, boolean isAccurateMatch) throws DdlException {
        
        String dbName = stmt.getDbName();
        String label = stmt.getLabel();

        
        Database db = Catalog.getCurrentCatalog().getDb(dbName);
        if (db == null) {
            throw new DdlException("Db does not exist. name: " + dbName);
        }
        
        List<LoadJob> loadJobs = Lists.newArrayList();
        readLock();
        try {
            Map<String, List<LoadJob>> labelToLoadJobs = dbLabelToLoadJobs.get(db.getId());
            if (labelToLoadJobs == null) {
                throw new DdlException("Load job does not exist");
            }

            
            List<LoadJob> matchLoadJobs = Lists.newArrayList();
            if (isAccurateMatch) {
                if (labelToLoadJobs.containsKey(label)) {
                    matchLoadJobs.addAll(labelToLoadJobs.get(label));
                }
            } else {
                for (Map.Entry<String, List<LoadJob>> entry : labelToLoadJobs.entrySet()) {
                    if (entry.getKey().contains(label)) {
                        matchLoadJobs.addAll(entry.getValue());
                    }
                }
            }

            if (matchLoadJobs.isEmpty()) {
                throw new DdlException("Load job does not exist");
            }

            
            if (isAccurateMatch) {
                
                LoadJob job = matchLoadJobs.get(matchLoadJobs.size() - 1);
                JobState state = job.getState();
                if (state == JobState.CANCELLED) {
                    throw new DdlException("Load job has been cancelled");
                } else if (state == JobState.QUORUM_FINISHED || state == JobState.FINISHED) {
                    throw new DdlException("Load job has been finished");
                }
                loadJobs.add(job);
            } else {
                List<LoadJob> uncompletedLoadJob = matchLoadJobs.stream().filter(job -> {
                    JobState state = job.getState();
                    return state != JobState.CANCELLED && state != JobState.QUORUM_FINISHED && state != JobState.FINISHED;
                }).collect(Collectors.toList());
                if (uncompletedLoadJob.isEmpty()) {
                    throw new DdlException("Load jobs which label like " + stmt.getLabel() +
                            " have all been cancelled or finished");
                }
                loadJobs.addAll(uncompletedLoadJob);
            }
        } finally {
            readUnlock();
        }

        
        Set<String> tableNames = Sets.newHashSet();
        for (LoadJob loadJob : loadJobs) {
            tableNames.addAll(loadJob.getTableNames());
        }

        if (tableNames.isEmpty()) {
            if (Catalog.getCurrentCatalog().getAuth().checkDbPriv(ConnectContext.get(), dbName,
                    PrivPredicate.LOAD)) {
                ErrorReport.reportDdlException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "CANCEL LOAD");
            }
        } else {
            for (String tblName : tableNames) {
                if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ConnectContext.get(), dbName, tblName,
                        PrivPredicate.LOAD)) {
                    ErrorReport.reportDdlException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, "CANCEL LOAD",
                            ConnectContext.get().getQualifiedUser(),
                            ConnectContext.get().getRemoteIP(), tblName);
                }
            }
        }

        
        for (LoadJob loadJob : loadJobs) {
            List<String> failedMsg = Lists.newArrayList();
            boolean ok = cancelLoadJob(loadJob, CancelType.USER_CANCEL, "user cancel", failedMsg);
            if (!ok) {
                throw new DdlException("Cancel load job [" + loadJob.getId() + "] fail, " +
                        "label=[" + loadJob.getLabel() + "] failed msg=" +
                        (failedMsg.isEmpty() ? "Unknown reason" : failedMsg.get(0)));
            }
        }

        return true;
    }


Revised code:
public boolean cancelLoadJob(CancelLoadStmt stmt, boolean isAccurateMatch) throws DdlException {
        
        String dbName = stmt.getDbName();
        String label = stmt.getLabel();

        
        Database db = Catalog.getCurrentCatalog().getDb(dbName);
        if (db == null) {
            throw new DdlException("Db does not exist. name: " + dbName);
        }
        
        List<LoadJob> loadJobs = Lists.newArrayList();
        readLock();
        try {
            Map<String, List<LoadJob>> labelToLoadJobs = dbLabelToLoadJobs.get(db.getId());
            if (labelToLoadJobs == null) {
                throw new DdlException("Load job does not exist");
            }

            
            List<LoadJob> matchLoadJobs = Lists.newArrayList();
            if (isAccurateMatch) {
                if (labelToLoadJobs.containsKey(label)) {
                    matchLoadJobs.addAll(labelToLoadJobs.get(label));
                }
            } else {
                for (Map.Entry<String, List<LoadJob>> entry : labelToLoadJobs.entrySet()) {
                    if (entry.getKey().contains(label)) {
                        matchLoadJobs.addAll(entry.getValue());
                    }
                }
            }

            if (matchLoadJobs.isEmpty()) {
                throw new DdlException("Load job does not exist");
            }

            
            List<LoadJob> uncompletedLoadJob = matchLoadJobs.stream().filter(job -> {
                JobState state = job.getState();
                return state != JobState.CANCELLED && state != JobState.QUORUM_FINISHED && state != JobState.FINISHED;
            }).collect(Collectors.toList());
            if (uncompletedLoadJob.isEmpty()) {
                throw new DdlException("There is no uncompleted job which label " +
                        (isAccurateMatch ? "is " : "like ") + stmt.getLabel());
            }
            loadJobs.addAll(uncompletedLoadJob);
        } finally {
            readUnlock();
        }

        
        Set<String> tableNames = Sets.newHashSet();
        for (LoadJob loadJob : loadJobs) {
            tableNames.addAll(loadJob.getTableNames());
        }

        if (tableNames.isEmpty()) {
            if (Catalog.getCurrentCatalog().getAuth().checkDbPriv(ConnectContext.get(), dbName,
                    PrivPredicate.LOAD)) {
                ErrorReport.reportDdlException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "CANCEL LOAD");
            }
        } else {
            for (String tblName : tableNames) {
                if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ConnectContext.get(), dbName, tblName,
                        PrivPredicate.LOAD)) {
                    ErrorReport.reportDdlException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, "CANCEL LOAD",
                            ConnectContext.get().getQualifiedUser(),
                            ConnectContext.get().getRemoteIP(), tblName);
                }
            }
        }

        
        for (LoadJob loadJob : loadJobs) {
            List<String> failedMsg = Lists.newArrayList();
            boolean ok = cancelLoadJob(loadJob, CancelType.USER_CANCEL, "user cancel", failedMsg);
            if (!ok) {
                throw new DdlException("Cancel load job [" + loadJob.getId() + "] fail, " +
                        "label=[" + loadJob.getLabel() + "] failed msg=" +
                        (failedMsg.isEmpty() ? "Unknown reason" : failedMsg.get(0)));
            }
        }

        return true;
    }