Skip to content
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

[DROOLS-6892] Wrapper class unwrapped value is not indexed in exec-model #4318

Merged
merged 2 commits into from
Apr 21, 2022

Conversation

tkobayas
Copy link
Contributor

@tkobayas tkobayas commented Apr 20, 2022

Ports
This PR is for 7.x
for main -> https://github.com/kiegroup/drools/pull/4328

JIRA:
https://issues.redhat.com/browse/DROOLS-6892

How to replicate CI configuration locally?

Build Chain tool does "simple" maven build(s), the builds are just Maven commands, but because the repositories relates and depends on each other and any change in API or class method could affect several of those repositories there is a need to use build-chain tool to handle cross repository builds and be sure that we always use latest version of the code for each repository.

build-chain tool is a build tool which can be used on command line locally or in Github Actions workflow(s), in case you need to change multiple repositories and send multiple dependent pull requests related with a change you can easily reproduce the same build by executing it on Github hosted environment or locally in your development environment. See local execution details to get more information about it.

How to retest this PR or trigger a specific build:
  • a pull request please add comment: Jenkins retest this

  • for a full downstream build

    • for jenkins job: please add comment: Jenkins run fdb
    • for github actions job: add the label run_fdb
  • a compile downstream build please add comment: Jenkins run cdb

  • a full production downstream build please add comment: Jenkins execute product fdb

  • an upstream build please add comment: Jenkins run upstream

@tkobayas
Copy link
Contributor Author

Jenkins run fdb

@tkobayas tkobayas force-pushed the DROOLS-6892-non-getter-for-index branch from 92a0773 to 3bae31a Compare April 20, 2022 07:07
@tkobayas
Copy link
Contributor Author

Jenkins run fdb

@tkobayas
Copy link
Contributor Author

tkobayas commented Apr 20, 2022

non-exec-model

  • property reactivity
    • Mask: AlphaNode.declaredMask relies on ClassUtils.getAccessibleProperties()
    • React: AsmUtil.parseModifiedProperties() -> modificationMask relies on ClassUtils.getAccessibleProperties()
  • index
    • Props and index are stored by ClassFieldAccessorFactory.getClassFieldReader() -> ClassFieldInspectorImpl.processClassWithoutByteCode()

exec-model

  • property reactivity
    • Mask: AlphaNode.declaredMask relies on ClassUtils.getAccessibleProperties()
    • React: Writing D.reactOn("prop-name") relies on ClassUtils.getAccessibleProperties(). Also the prop react mask BitMaskUtil.calculatePatternMask() relies on DomainClassMetadata.getPropertyIndex()
  • index
    • D.alphaIndexedBy(..., ..., xxx_Metadata_INSTANCE.getPropertyIndex("prop-name"), ...) relies on DomainClassMetadata.getPropertyIndex()

As you see, in Non-exec-model, props for property reactivity and props for index are separately managed.

On the other hand, in exec-model, property reactivity relies on ClassUtils.getAccessibleProperties() and also index relies on DomainClassMetadata.getPropertyIndex() which is populated by ClassUtils.getAccessibleProperties().

One possible approach is to enhance ClassUtils.getAccessibleProperties() to include non-getter method (e.g. Person.calcAge(), Integer.intvalue()). However, it will have a wide impact to property reactivity behaviour on both non-exec-model and exec-model.

In this PR, I took a conservative approach only focusing on the index issue. I don't change ClassUtils.getAccessibleProperties() so property reactivity wouldn't change. For exec-model DomainClassMetadata.getPropertyIndex(), I call getAccessiblePropertiesIncludingNonGetterValueMethod which returns both accessibleProperties and nonGetterValueMethods. In exec-model, D.reactOn still refers to DomainClassMetadata.getPropertyIndex() but the index number is consistent with ClassUtils.getAccessibleProperties() because nonGetterValueMethods are added at last. So now Person.calcAge() and Integer.intvalue() can be indexed. But they are not subject to property reactivity. If we want to improve property reactivity to react to Person.calcAge(), I may raise a new JIRA (note: we don't want to react to Integer.intvalue() which is immutable).

@mariofusco Feel free to share your thought on this. Thanks!

private static void replaceTypeInIndex(String bindingId, Class accumulateFunctionResultType, Expression expression) {
expression.findAll(MethodCallExpr.class)
.stream()
.map(mce -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this was for debug (you can use peek instead of map in future) and now you can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for spotting! Fixed.

Copy link
Contributor

@mariofusco mariofusco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for me, I just left a minor comment. I just wonder if this could have any relevant impact on executable model generation time. I think we could merge it anyway, but maybe you could ask Daniel to run some of our benchmarks against it?

@tkobayas
Copy link
Contributor Author

FDB : flaky test

org.kie.server.router.repository.FileRepositoryTest.testWatchServiceOnLatelyCreatedConfigFile
java.lang.AssertionError: expected:<2> but was:<0>

@tkobayas
Copy link
Contributor Author

tkobayas commented Apr 21, 2022

I just wonder if this could have any relevant impact on executable model generation time. I think we could merge it anyway, but maybe you could ask Daniel to run some of our benchmarks against it?

Yes, it would potentially have a negative impact on executable model generation time. I'll check with Daniel. Thank you for the suggestion.

@hellowdan I sent an email to you. Thanks!

@tkobayas tkobayas requested a review from hellowdan April 21, 2022 02:38
@mariofusco mariofusco merged commit 68c4afa into apache:7.x Apr 21, 2022
tkobayas added a commit to tkobayas/drools that referenced this pull request Apr 21, 2022
…del (apache#4318)

* [DROOLS-6892] Wrapper class unwrapped value is not indexed in exec-model

* - remove syso
mariofusco added a commit to mariofusco/drools that referenced this pull request Apr 21, 2022
mariofusco added a commit that referenced this pull request Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants