/** * lock the path * @param path the path */ public Lock newLock(String path) { return new Lock(client, path); }
private void doFailOver(String server) { // TODO maybe think that one job fired just now, but the server crashed // lock the server's failover Lock lock = createServerFailoverLock(server); if(!lock.lock(1000)){ // has one server is doing failover return; } try { if (tryWaitServerStart(server)){ return; } Logs.warn("The server({}) left, will do failover.", server); // load the server's jobs Response<List<Long>> jobIdsResp = jobService.findJobIdsByServer(server); if (!jobIdsResp.isSuccess()){ Logs.warn("failed to find the server({})'s job ids, cause: {}", server, jobIdsResp.getErr()); return; } List<Long> jobIds = jobIdsResp.getData(); if (CollectionUtil.isNullOrEmpty(jobIds)){ // don't need to dispatch return; } // dispatch the jobs to other servers serverService.scheduleJobs(jobIds, serverCluster.alives()); } finally { lock.unlock(); } }