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

there is a bug in file ServiceInfo #4136

Closed
shizhengxing opened this issue Nov 4, 2020 · 5 comments
Closed

there is a bug in file ServiceInfo #4136

shizhengxing opened this issue Nov 4, 2020 · 5 comments
Assignees
Labels
kind/bug Category issues or prs related to bug.
Milestone

Comments

@shizhengxing
Copy link
Contributor

shizhengxing commented Nov 4, 2020

java class name:com.alibaba.nacos.api.naming.pojo.ServiceInfo
method:

public ServiceInfo(String key) {  
    int maxIndex = 2;  
    int clusterIndex = 1;
    int serviceNameIndex = 0;

    String[] keys = key.split(Constants.SERVICE_INFO_SPLITER);
    if (keys.length >= maxIndex) {
        this.name = keys[serviceNameIndex];
        this.clusters = keys[clusterIndex];
    }

    this.name = keys[0];
}`

When read cache file from disk throuth method DiskCache.read(String cacheDir), the method use constructor public ServiceInfo(String key) to instantiate ServiceInfo,you can check the code in file DiskCache of line 111.
I give a example of the input param for method public ServiceInfo(String key) like group@@service_name@@clusters.

You can see when spilt with @@ ,the clusterIndex should be 2 not 1, and the serviceNameIndex should be 1 not 0,and the groupName can be fill with data of index=0.

@shizhengxing
Copy link
Contributor Author

shizhengxing commented Nov 4, 2020

if it confirmed ,i will fix it so quickly!

@KomachiSion KomachiSion added this to the 1.4.1 milestone Nov 5, 2020
@KomachiSion
Copy link
Collaborator

KomachiSion commented Nov 5, 2020

OK.

When you try to fix it. Please do some test for compatibility test with old version nacos server from 1.1.3 to 1.3.2

@KomachiSion KomachiSion added the kind/bug Category issues or prs related to bug. label Nov 5, 2020
@zrlw
Copy link
Contributor

zrlw commented Nov 5, 2020

java class name:com.alibaba.nacos.api.naming.pojo.ServiceInfo
method:

public ServiceInfo(String key) {  
    int maxIndex = 2;  
    int clusterIndex = 1;
    int serviceNameIndex = 0;

    String[] keys = key.split(Constants.SERVICE_INFO_SPLITER);
    if (keys.length >= maxIndex) {
        this.name = keys[serviceNameIndex];
        this.clusters = keys[clusterIndex];
    }

    this.name = keys[0];
}`

When read cache file from disk throuth method DiskCache.read(String cacheDir), the method use constructor public ServiceInfo(String key) to instantiate ServiceInfo,you can check the code in file DiskCache of line 111.
I give a example of the input param for method public ServiceInfo(String key) like group@@service_name@@clusters.

You can see when spilt with @@ ,the clusterIndex should be 2 not 1, and the serviceNameIndex should be 1 not 0,and the groupName can be fill with data of index=0.

you should consider 'key' in different situations:

1. name
2. group@@name
3. group@@name@@cluster

@shizhengxing
Copy link
Contributor Author

shizhengxing commented Nov 5, 2020

java class name:com.alibaba.nacos.api.naming.pojo.ServiceInfo
method:

public ServiceInfo(String key) {  
    int maxIndex = 2;  
    int clusterIndex = 1;
    int serviceNameIndex = 0;

    String[] keys = key.split(Constants.SERVICE_INFO_SPLITER);
    if (keys.length >= maxIndex) {
        this.name = keys[serviceNameIndex];
        this.clusters = keys[clusterIndex];
    }

    this.name = keys[0];
}`

When read cache file from disk throuth method DiskCache.read(String cacheDir), the method use constructor public ServiceInfo(String key) to instantiate ServiceInfo,you can check the code in file DiskCache of line 111.
I give a example of the input param for method public ServiceInfo(String key) like group@@service_name@@clusters.
You can see when spilt with @@ ,the clusterIndex should be 2 not 1, and the serviceNameIndex should be 1 not 0,and the groupName can be fill with data of index=0.

you should consider 'key' in different situations:

1. name
2. group@@name
3. group@@name@@cluster

got it ,thanks for your reminding

@shizhengxing
Copy link
Contributor Author

shizhengxing commented Nov 5, 2020

OK.

When you try to fix it. Please do some test for compatibility test with old version nacos server from 1.1.3 to 1.3.2

ok, i will do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Category issues or prs related to bug.
Projects
None yet
Development

No branches or pull requests

3 participants