Skip to content

feat: apply a thread safe lock over dataloaders (#1838) #1840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

samuelAndalon
Copy link
Contributor

cherry pick #1838

### 📝 Description
apply a synchronized lock over data loaders, the reactive stack could
cause multiple threads trying to access to the same memory.

### 🔗 Related Issues
ExpediaGroup#1837
ExpediaGroup#1819
@dariuszkuc
Copy link
Collaborator

do we need to synchronize any of those methods as well? (assuming no as registry "should be" thread safe?)

    override fun register(key: String, dataLoader: DataLoader<*, *>): DataLoaderRegistry = registry.register(key, dataLoader)
    override fun <K, V> computeIfAbsent(key: String, mappingFunction: Function<String, DataLoader<*, *>>): DataLoader<K, V> = registry.computeIfAbsent(key, mappingFunction)
    override fun combine(registry: DataLoaderRegistry): DataLoaderRegistry = this.registry.combine(registry)
    override fun getDataLoaders(): MutableList<DataLoader<*, *>> = registry.dataLoaders
    override fun getDataLoadersMap(): MutableMap<String, DataLoader<*, *>> = registry.dataLoadersMap
    override fun unregister(key: String): DataLoaderRegistry = registry.unregister(key)
    override fun <K, V> getDataLoader(key: String): DataLoader<K, V> = registry.getDataLoader(key)
    override fun getKeys(): MutableSet<String> = registry.keys
    override fun dispatchAllWithCount(): Int = registry.dispatchAllWithCount()
    override fun dispatchDepth(): Int = registry.dispatchDepth()
    override fun getStatistics(): Statistics = registry.statistics

@samuelAndalon
Copy link
Contributor Author

lets start with what we have, if we need a fully concurrent and thread safe registry we can just write our own implementation of the cache map instead of using
https://github.com/graphql-java/java-dataloader/blob/master/src/main/java/org/dataloader/impl/DefaultCacheMap.java

@samuelAndalon samuelAndalon merged commit 13c91fb into ExpediaGroup:6.x.x Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants