Skip to content

Commit 6802533

Browse files
author
Oleksii Moskalenko
authored
Fix: JobCoordinator tries to create duplicate FeatureSetJobStatuses (#847)
* fix repositories inconsistency * more stable featureSetJobStatus creation * populate Id manually * lint * lint * fix TestUtil
1 parent 3945180 commit 6802533

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

core/src/main/java/feast/core/model/FeatureSetJobStatus.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.Serializable;
2222
import javax.persistence.*;
2323
import javax.persistence.Entity;
24+
import lombok.AllArgsConstructor;
2425
import lombok.EqualsAndHashCode;
2526
import lombok.Getter;
2627
import lombok.Setter;
@@ -37,6 +38,7 @@
3738
public class FeatureSetJobStatus {
3839
@Embeddable
3940
@EqualsAndHashCode
41+
@AllArgsConstructor
4042
public static class FeatureSetJobStatusKey implements Serializable {
4143
public FeatureSetJobStatusKey() {}
4244

core/src/main/java/feast/core/service/JobCoordinatorService.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ private boolean jobRequiresUpgrade(Job job, Set<Store> stores) {
245245
* @param featureSet featureSet {@link FeatureSet} to find jobs and allocate
246246
*/
247247
FeatureSet allocateFeatureSetToJobs(FeatureSet featureSet) {
248-
Set<FeatureSetJobStatus> toAdd = new HashSet<>();
249-
Set<FeatureSetJobStatus> existing = featureSet.getJobStatuses();
248+
Map<FeatureSetJobStatus.FeatureSetJobStatusKey, FeatureSetJobStatus> current = new HashMap<>();
249+
Map<FeatureSetJobStatus.FeatureSetJobStatusKey, FeatureSetJobStatus> existing =
250+
featureSet.getJobStatuses().stream()
251+
.collect(Collectors.toMap(FeatureSetJobStatus::getId, s -> s));
250252

251253
Stream<Pair<Source, Store>> jobArgsStream =
252254
getAllStores().stream()
@@ -269,14 +271,17 @@ FeatureSet allocateFeatureSetToJobs(FeatureSet featureSet) {
269271
status.setJob(job);
270272
status.setDeliveryStatus(FeatureSetProto.FeatureSetJobDeliveryStatus.STATUS_IN_PROGRESS);
271273

272-
toAdd.add(status);
274+
current.put(
275+
new FeatureSetJobStatus.FeatureSetJobStatusKey(job.getId(), featureSet.getId()), status);
273276
}
274277

275-
Set<FeatureSetJobStatus> toDelete = Sets.difference(existing, toAdd);
276-
toAdd = Sets.difference(toAdd, existing);
278+
Set<FeatureSetJobStatus.FeatureSetJobStatusKey> toDelete =
279+
Sets.difference(existing.keySet(), current.keySet());
280+
Set<FeatureSetJobStatus.FeatureSetJobStatusKey> toAdd =
281+
Sets.difference(current.keySet(), existing.keySet());
277282

278-
jobStatusRepository.deleteAll(toDelete);
279-
jobStatusRepository.saveAll(toAdd);
283+
jobStatusRepository.deleteAll(toDelete.stream().map(existing::get).collect(Collectors.toSet()));
284+
jobStatusRepository.saveAll(toAdd.stream().map(current::get).collect(Collectors.toSet()));
280285
jobStatusRepository.flush();
281286
return featureSet;
282287
}
@@ -382,15 +387,17 @@ public void notifyJobsWhenFeatureSetUpdated() {
382387
// FeatureSet).
383388
// We now set status to IN_PROGRESS, so listenAckFromJobs would be able to
384389
// monitor delivery progress for each new version.
385-
fs.getJobStatuses().stream()
390+
Set<FeatureSetJobStatus> jobStatuses = fs.getJobStatuses();
391+
jobStatuses.stream()
386392
.filter(s -> s.getJob().isRunning())
387393
.forEach(
388394
jobStatus -> {
389395
jobStatus.setDeliveryStatus(
390396
FeatureSetProto.FeatureSetJobDeliveryStatus.STATUS_IN_PROGRESS);
391397
jobStatus.setVersion(fs.getVersion());
392398
});
393-
featureSetRepository.saveAndFlush(fs);
399+
jobStatusRepository.saveAll(jobStatuses);
400+
jobStatusRepository.flush();
394401
});
395402
}
396403

core/src/test/java/feast/core/util/TestUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public static FeatureSetJobStatus CreateFeatureSetJobStatusWithJob(
141141

142142
featureSetJobStatus.setDeliveryStatus(deliveryStatus);
143143
featureSetJobStatus.setVersion(version);
144+
featureSetJobStatus.setId(new FeatureSetJobStatus.FeatureSetJobStatusKey(job.getId(), 0));
144145

145146
return featureSetJobStatus;
146147
}

0 commit comments

Comments
 (0)