5959public class JobCoordinatorService {
6060
6161 private final int SPEC_PUBLISHING_TIMEOUT_SECONDS = 5 ;
62+ public static final String VERSION_LABEL = "feast_version" ;
6263
6364 private final JobRepository jobRepository ;
6465 private final SpecService specService ;
@@ -68,6 +69,8 @@ public class JobCoordinatorService {
6869 private final KafkaTemplate <String , FeatureSetSpec > specPublisher ;
6970 private final List <Store .Subscription > featureSetSubscriptions ;
7071 private final List <String > whitelistedStores ;
72+ private final Map <String , String > jobLabels ;
73+ private final String currentVersion ;
7174
7275 @ Autowired
7376 public JobCoordinatorService (
@@ -88,6 +91,9 @@ public JobCoordinatorService(
8891 .map (JobProperties .CoordinatorProperties .FeatureSetSelector ::toSubscription )
8992 .collect (Collectors .toList ());
9093 this .whitelistedStores = feastProperties .getJobs ().getCoordinator ().getWhitelistedStores ();
94+ this .currentVersion = feastProperties .getVersion ();
95+ this .jobLabels = new HashMap <>(feastProperties .getJobs ().getCoordinator ().getJobSelector ());
96+ this .jobLabels .put (VERSION_LABEL , this .currentVersion );
9197 }
9298
9399 /**
@@ -161,7 +167,7 @@ List<JobTask> makeJobUpdateTasks(Iterable<Pair<Source, Set<Store>>> sourceToStor
161167 Source source = mapping .getKey ();
162168 Set <Store > stores = mapping .getValue ();
163169
164- Job job = groupingStrategy .getOrCreateJob (source , stores );
170+ Job job = groupingStrategy .getOrCreateJob (source , stores , this . jobLabels );
165171
166172 if (job .isDeployed ()) {
167173 if (!job .isRunning ()) {
@@ -177,7 +183,7 @@ List<JobTask> makeJobUpdateTasks(Iterable<Pair<Source, Set<Store>>> sourceToStor
177183 // it would make sense to spawn clone of current job
178184 // and terminate old version on the next Poll.
179185 // Both jobs should be in the same consumer group and not conflict with each other
180- job = job .cloneWithId (groupingStrategy .createJobId (job ));
186+ job = job .cloneWithIdAndLabels (groupingStrategy .createJobId (job ), this . jobLabels );
181187 job .addAllStores (stores );
182188
183189 isSafeToStopJobs = false ;
@@ -214,8 +220,9 @@ List<JobTask> makeJobUpdateTasks(Iterable<Pair<Source, Set<Store>>> sourceToStor
214220 /**
215221 * Decides whether we need to upgrade (restart) given job. Since we send updated FeatureSets to
216222 * IngestionJob via Kafka, and there's only one source per job (if it change - new job would be
217- * created) the only things that can cause upgrade here are stores: new stores can be added, or
218- * existing stores will change subscriptions.
223+ * created) main trigger that can cause upgrade here are stores: new stores can be added, or
224+ * existing stores will change subscriptions. Another trigger is release of new version: current
225+ * version is being compared with job's version stored in labels.
219226 *
220227 * @param job {@link Job} to check
221228 * @param stores Set of {@link Store} new version of stores (vs current version job.getStores())
@@ -227,6 +234,10 @@ private boolean jobRequiresUpgrade(Job job, Set<Store> stores) {
227234 return true ;
228235 }
229236
237+ if (!this .currentVersion .equals (job .getLabels ().get (VERSION_LABEL ))) {
238+ return true ;
239+ }
240+
230241 return false ;
231242 }
232243
@@ -257,7 +268,9 @@ FeatureSet allocateFeatureSetToJobs(FeatureSet featureSet) {
257268
258269 // Add featureSet to allocated job if not allocated before
259270 for (Pair <Source , Set <Store >> jobArgs : groupingStrategy .collectSingleJobInput (jobArgsStream )) {
260- Job job = groupingStrategy .getOrCreateJob (jobArgs .getLeft (), jobArgs .getRight ());
271+ Job job =
272+ groupingStrategy .getOrCreateJob (
273+ jobArgs .getLeft (), jobArgs .getRight (), Collections .emptyMap ());
261274 if (!job .isRunning ()) {
262275 continue ;
263276 }
0 commit comments