-
Notifications
You must be signed in to change notification settings - Fork 28
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
Fix undefined behaviour in backing store #1558
Conversation
d0502d1
to
9414f6f
Compare
You might want to look at the follow PRs and see if any of the fixes/optimizations could be ported here. |
…ot changed, collection consistency would not be checked
Missing KiotaSerialization helper updates. To be tracked by #1561 next sprint |
components/abstractions/src/main/java/com/microsoft/kiota/store/InMemoryBackingStore.java
Outdated
Show resolved
Hide resolved
components/abstractions/src/main/java/com/microsoft/kiota/store/InMemoryBackingStore.java
Outdated
Show resolved
Hide resolved
components/abstractions/src/main/java/com/microsoft/kiota/store/InMemoryBackingStore.java
Outdated
Show resolved
Hide resolved
components/abstractions/src/main/java/com/microsoft/kiota/store/InMemoryBackingStore.java
Outdated
Show resolved
Hide resolved
components/abstractions/src/main/java/com/microsoft/kiota/store/InMemoryBackingStore.java
Outdated
Show resolved
Hide resolved
components/abstractions/src/main/java/com/microsoft/kiota/store/InMemoryBackingStore.java
Outdated
Show resolved
Hide resolved
components/abstractions/src/main/java/com/microsoft/kiota/store/InMemoryBackingStore.java
Show resolved
Hide resolved
…e/InMemoryBackingStore.java Co-authored-by: Vincent Biret <[email protected]>
components/abstractions/src/main/java/com/microsoft/kiota/store/InMemoryBackingStore.java
Outdated
Show resolved
Hide resolved
components/abstractions/src/main/java/com/microsoft/kiota/store/InMemoryBackingStore.java
Outdated
Show resolved
Hide resolved
components/abstractions/src/main/java/com/microsoft/kiota/store/InMemoryBackingStore.java
Outdated
Show resolved
Hide resolved
…e/InMemoryBackingStore.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like @andrueastman revie as well before we merge this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of comments from me. Otherwise this looks good to me.
Thanks for looking into this @Ndiritu
Object[] items = getObjectArrayFromCollectionWrapper(collectionTuple); | ||
|
||
for (final Object item : items) { | ||
if (!(item instanceof BackedModel)) break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for this we may need to handle the case for maps in separately as this may be an incorrect assumption for them.
Since getObjectArrayFromCollectionWrapper
will also unwrap the values of a map as an array, the key values pairs in the map are not guaranteed to have the same type. A map i.e. additionalData can have primitives and complex backed models too..
Object[] items = getObjectArrayFromCollectionWrapper(collectionTuple); | ||
for (final Object item : items) { | ||
if (!(item instanceof BackedModel)) break; | ||
nestedBackedModelsToEnumerate.add((BackedModel) item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar concern here, the cast will most likely fail if we called getObjectArrayFromCollectionWrapper
on a map that has mixed types and the first item happened to be a backed model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. Made these updates & added tests.
Tests also exposed a bug where we now need to propagate returnOnlyChangedValues
to nested BackedModels
to ensure nested models with collection properties are checked. We have limited the collection checks to happen during enumeration only when we want to return changed values.
…ngedValues to nested backed models
cb64a81
to
631f1cf
Compare
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
Fixes a bug encountered while marking all properties in an
InMemoryBackingStore
as dirty.Context
When iterating over a
Map
entrySet()
, any modification to the underlying map causes undefined behavior during the iteration.The
InMemoryBackingStore
iterates over the underlying store'sentrySet()
and currently callsensureCollectionPropertyIsConsistent()
which may update the underlying Map by callingset()
to update the collection size & flag the collection as dirty in case of additions/deletions.Undefined behaviour manifests as repeated iterations over the same set of items in the underlying store causing performance issues. The situation is amplified when we have a collection of
BackedModel
s where eachBackedModel
has a collection property that has been updated and we need to mark all properties of all theBackedModel
s as dirty.Changes
This PR:
BackedModel
elementsget()
to determine whether a value is dirty or not which matches its interface definition.getValueFromWrapper()
now only unwraps values from the underlying storeThe sample test case would previously fail after running for
~60s
vs with this fix, it passes in~3s
on the same hardware.closes microsoftgraph/msgraph-sdk-java#2106