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

SpringProxyJobClassNameProvider may cause job conflicts in non proxy mode #2012

Closed
BertOnline opened this issue Nov 19, 2021 · 2 comments · Fixed by #2459
Closed

SpringProxyJobClassNameProvider may cause job conflicts in non proxy mode #2012

BertOnline opened this issue Nov 19, 2021 · 2 comments · Fixed by #2459
Assignees
Labels

Comments

@BertOnline
Copy link

BertOnline commented Nov 19, 2021

Bug Report

Which version of ElasticJob did you use?

3.0.1

Which project did you use? ElasticJob-Lite or ElasticJob-Cloud?

ElasticJob-Lite

Expected behavior

Job registration succeeded

Actual behavior

Job conflict with register center. The job 'test' in register center's class is 'com.test.elasticjob.CustomJob$$Lambda$1124/0x0000000800a5d440', your job class is 'com.test.elasticjob.CustomJob$$Lambda$1111/0x0000000800a60440'

Reason analyze (If you can)

Code causing the problem:

@Component
public class CustomJob {

    private static final int SINGLE_SHARDING_TOTAL_COUNT = 1;

    @Autowired
    private ZookeeperRegistryCenter zookeeperRegistryCenter;

    public void customJob() {
        JobConfiguration jobConfig = JobConfiguration
                .newBuilder("test", SINGLE_SHARDING_TOTAL_COUNT)
                .jobParameter("")
                .cron("0 30 2 ? * *")
                .overwrite(true)
                .jobShardingStrategyType("ROUND_ROBIN")
                .monitorExecution(true)
                .failover(true)
                .build();
        new ScheduleJobBootstrap(zookeeperRegistryCenter, (SimpleJob) shardingContext -> System.out.println("test"), jobConfig).schedule();
    }

}

Wrong location in source code:

@Slf4j
public final class SpringProxyJobClassNameProvider implements JobClassNameProvider {

    public SpringProxyJobClassNameProvider() {
        log.info("create SpringProxyJobClassNameProvider");
    }

    @Override
    public String getJobClassName(final ElasticJob elasticJob) {
        return AopUtils.isAopProxy(elasticJob) ? AopTargetUtils.getTarget(elasticJob).getClass().getName() : elasticJob.getClass().getName();
    }
}

When I create a SimpleJob using an anonymous inner class or lambda expression, if AopUtils.isAopProxy(elasticJob) == true, and return elasticJob.getClass().getName(), it will cause a job conflict with ZK. For the solution,when AopUtils.isAopProxy(elasticJob) == true, please refer to org.apache.shardingsphere.elasticjob.lite.internal.setup.DefaultJobClassNameProvider#getJobClassName

    @Override
    public String getJobClassName(final ElasticJob elasticJob) {
        Class<? extends ElasticJob> elasticJobClass = elasticJob.getClass();
        String elasticJobClassName = elasticJobClass.getName();
        return isLambdaClass(elasticJobClass) ? trimLambdaClassSuffix(elasticJobClassName) : elasticJobClassName;
    }
@linghengqian
Copy link
Member

Are you going to submit a PR?

@linghengqian
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants