Skip to content

Commit 17d40cc

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent e003db3 commit 17d40cc

File tree

1 file changed

+14
-9
lines changed
  • operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer

1 file changed

+14
-9
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,28 +255,33 @@ public Set<R> getSecondaryResources(P primary) {
255255

256256
if (useSecondaryToPrimaryIndex()) {
257257
var primaryID = ResourceID.fromResource(primary);
258-
var complementaryIds = temporalPrimaryToSecondaryIndex.getSecondaryResources(primaryID);
258+
// Note that the order matter is these lines. This method is not synchronized
259+
// because of performance reasons. If it was in reverse order, it could happen
260+
// that we did not receive yet an event in the informer so the index would not
261+
// be updated. However, before reading it from temp IDs the event arrives and erases
262+
// the temp index. So in case of Add not id would be found.
263+
var temporalIds = temporalPrimaryToSecondaryIndex.getSecondaryResources(primaryID);
259264
var resources = byIndex(PRIMARY_TO_SECONDARY_INDEX_NAME, resourceIdToString(primaryID));
260-
log.debug("Resources in cache: {} kind: {}", resources, resourceType().getSimpleName());
265+
261266
log.debug(
262267
"Using informer primary to secondary index to find secondary resources for primary name:"
263-
+ " {} namespace: {}. Found {}",
268+
+ " {} namespace: {}. Found number {}",
264269
primary.getMetadata().getName(),
265270
primary.getMetadata().getNamespace(),
266271
resources.size());
267272

268-
log.debug("Complementary ids: {}", complementaryIds);
273+
log.debug("Complementary ids: {}", temporalIds);
269274
var res =
270275
resources.stream()
271276
.map(
272277
r -> {
273278
var resourceId = ResourceID.fromResource(r);
274279
Optional<R> resource = temporaryResourceCache.getResourceFromCache(resourceId);
275-
complementaryIds.remove(resourceId);
280+
temporalIds.remove(resourceId);
276281
return resource.orElse(r);
277282
})
278283
.collect(Collectors.toSet());
279-
complementaryIds.forEach(
284+
temporalIds.forEach(
280285
id -> {
281286
Optional<R> resource = get(id);
282287
resource.ifPresentOrElse(res::add, () -> log.warn("Resource not found: {}", id));
@@ -299,15 +304,15 @@ public Set<R> getSecondaryResources(P primary) {
299304
@Override
300305
public synchronized void handleRecentResourceUpdate(
301306
ResourceID resourceID, R resource, R previousVersionOfResource) {
302-
handleRecentCreateOrUpdate(Operation.UPDATE, resource, previousVersionOfResource);
307+
handleRecentCreateOrUpdate(resource, previousVersionOfResource);
303308
}
304309

305310
@Override
306311
public synchronized void handleRecentResourceCreate(ResourceID resourceID, R resource) {
307-
handleRecentCreateOrUpdate(Operation.ADD, resource, null);
312+
handleRecentCreateOrUpdate(resource, null);
308313
}
309314

310-
private void handleRecentCreateOrUpdate(Operation operation, R newResource, R oldResource) {
315+
private void handleRecentCreateOrUpdate(R newResource, R oldResource) {
311316
temporalPrimaryToSecondaryIndex.explicitAddOrUpdate(newResource);
312317
temporaryResourceCache.putResource(
313318
newResource,

0 commit comments

Comments
 (0)