Source:
<code>public void resourceOffers(SchedulerDriver driver, List<Protos.Offer> offers) { if (!reconcileTasks.isEmpty()) { declineAllOffers(driver, offers); return; } CrateState state = stateStore.state(); int required = state.missingInstances(); if (required == 0) { declineAllOffers(driver, offers); } else if (required < 0) { killInstances(driver, required * -1); declineAllOffers(driver, offers); } else { int launched = 0; for (Protos.Offer offer : offers) { if (launched == required || !slaveWithRunningInstance(offer.getSlaveId().getValue())) { driver.declineOffer(offer.getId()); continue; } else { <START> stateStore.state().slavesWithInstances().remove(offer.getSlaveId().getValue()); <END> } CrateExecutableInfo crateInfo = obtainExecInfo(offer, offer.getAttributesList()); if (crateInfo == null) { driver.declineOffer(offer.getId()); } else { Protos.TaskID taskId = taskID(UUID.randomUUID().toString()); Protos.TaskInfo taskInfo = Protos.TaskInfo.newBuilder() .setName(configuration.clusterName) .setTaskId(taskId) .setData(ByteString.copyFrom(crateInfo.toStream())) .setExecutor(createExecutor()) .setSlaveId(offer.getSlaveId()) .addAllResources(configuration.getAllRequiredResources()) .build(); crateInstances.addInstance(new CrateInstance( offer.getHostname(), taskId.getValue(), configuration.version, configuration.transportPort, taskInfo.getExecutor().getExecutorId().getValue(), taskInfo.getSlaveId().getValue() )); state.instances(crateInstances); Protos.Filters filters = Protos.Filters.newBuilder().setRefuseSeconds(1).build(); driver.launchTasks(Arrays.asList(offer.getId()), Arrays.asList(taskInfo), filters); launched++; } } stateStore.save(); } }</code><technical_language>this is early remove slave id, offer get rejected a lines ;)</technical_language>

Target:
public void resourceOffers(SchedulerDriver driver, List<Protos.Offer> offers) { if (!reconcileTasks.isEmpty()) { declineAllOffers(driver, offers); return; } CrateState state = stateStore.state(); int required = state.missingInstances(); if (required == 0) { declineAllOffers(driver, offers); } else if (required < 0) { killInstances(driver, required * -1); declineAllOffers(driver, offers); } else { int launched = 0; for (Protos.Offer offer : offers) { if (launched == required || !slaveWithRunningInstance(offer.getSlaveId().getValue())) { driver.declineOffer(offer.getId()); continue; } CrateExecutableInfo crateInfo = obtainExecInfo(offer, offer.getAttributesList()); if (crateInfo == null) { driver.declineOffer(offer.getId()); } else { Protos.TaskID taskId = taskID(UUID.randomUUID().toString()); Protos.TaskInfo taskInfo = Protos.TaskInfo.newBuilder() .setName(configuration.clusterName) .setTaskId(taskId) .setData(ByteString.copyFrom(crateInfo.toStream())) .setExecutor(createExecutor()) .setSlaveId(offer.getSlaveId()) .addAllResources(configuration.getAllRequiredResources()) .build(); crateInstances.addInstance(new CrateInstance( offer.getHostname(), taskId.getValue(), configuration.version, configuration.transportPort, taskInfo.getExecutor().getExecutorId().getValue(), taskInfo.getSlaveId().getValue() )); state.instances(crateInstances); Protos.Filters filters = Protos.Filters.newBuilder().setRefuseSeconds(1).build(); driver.launchTasks(Arrays.asList(offer.getId()), Arrays.asList(taskInfo), filters); launched++; } stateStore.state().slavesWithInstances().remove(offer.getSlaveId().getValue()); } stateStore.save(); } }