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

Using an empty string MongoDB 'replica-set-name' property will result in ClusterType=REPLICA_SET #42055

Closed
ooooym opened this issue Aug 29, 2024 · 5 comments
Labels
type: bug A general bug
Milestone

Comments

@ooooym
Copy link

ooooym commented Aug 29, 2024

如代码所示,不对代码做StringUtils.isBlank处理,会导致ClusterSettings的ClusterType=REPLICA_SET,这可能会产生负面影响。

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 29, 2024
@philwebb
Copy link
Member

Courtesy of Google Translate:

As shown in the code, not doing StringUtils.isBlank processing in the code will result in ClusterType=REPLICA_SET of ClusterSettings, which may have negative effects.

@philwebb philwebb changed the title 没有处理isBlank场景 Using an empty string MongoDB 'replica-set-name' property will result in ClusterType=REPLICA_SET Aug 29, 2024
@philwebb
Copy link
Member

philwebb commented Aug 29, 2024

@miaoGod I'm not sure we should make the change you're suggesting. We follow the same logic as the MongoDB driver (see https://github.com/mongodb/mongo-java-driver/blob/634fd094992f09cf39deec0ea2afeb12b4db61ef/driver-core/src/main/com/mongodb/connection/ClusterSettings.java#L621) which doesn't check for empty string.

What triggered you to raise this issue? Have you actually tried to use a blank string in your own application?

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label Aug 29, 2024
@ooooym
Copy link
Author

ooooym commented Aug 29, 2024

@philwebb 是的,我确实遇到了这种场景,详情如下:
由于预算有限,在测试环境的mongodb配置仅有一台实例,而生产的配置为两台实例(一主一从),而在使用主从复制配置时,我使用的方式如下代码:

spring:
  data:
    mongodb:
      replica-set-name: ${mongo.replicaSetName}

其中的mongo.replicaSetName引用的是application-{env}.properties中的配置

按照以上配置启动项目以后,我发现mongo.replicaSetName无论是否有值,ClusterSettings的ClusterType都会为REPLICA_SET,
但是如果我将replica-set-name配置项直接去掉而不是让他等于一个空字符串,ClusterSettings的ClusterType则为UNKNOWN

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 29, 2024
@philwebb
Copy link
Member

Translated:

Yes, I did encounter this scenario, the details are as follows:

Due to limited budget, the mongodb configuration in the test environment only has one instance, while the production configuration has two instances (one master and one slave). When using the master-slave replication configuration, I use the following code:

spring:
  data:
    mongodb:
      replica-set-name: ${mongo.replicaSetName}

The mongo.replicaSetName refers to the configuration in application-{env}.properties

After starting the project according to the above configuration, I found that regardless of whether mongo.replicaSetName has a value or not, the ClusterType of ClusterSettings will be REPLICA_SET.

But if I remove the replica-set-name configuration item directly instead of making it equal to an empty string, the ClusterType of ClusterSettings is UNKNOWN.

@philwebb
Copy link
Member

That seems like a valid use-case. We'll fix this.

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Aug 29, 2024
@philwebb philwebb added this to the 3.2.x milestone Aug 29, 2024
@philwebb philwebb modified the milestones: 3.2.x, 3.2.10 Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants