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

feat: add oceanbase-ce module #7502

Merged
merged 13 commits into from Feb 28, 2024
Merged

Conversation

whhe
Copy link
Contributor

@whhe whhe commented Sep 6, 2023

OceanBase is a distributed relational database developed by Ant Group, and its community edition is open sourced at https://github.com/oceanbase/oceanbase.

There is a docker image maintained by the official team, and in this pull request I add OceanBaseContainer and OceanBaseContainerProvider for a new oceanbase-ce module based on the docker image. https://github.com/oceanbase/oceanbase/tree/master/tools/docker/standalone.

Copy link
Member

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! I have left some suggestions. Please, also take a look at at the build which just failed.

@whhe
Copy link
Contributor Author

whhe commented Sep 7, 2023

Thanks for your contribution! I have left some suggestions. Please, also take a look at at the build which just failed.

Thank you for your review, I have addressed the comments in the latest commit.

For the CI failure, it seems the container start failed, and I guess the reason may be the memory is not enought. To start the docker container of OceanBase, at least 2 cpu and 8g memory are required.

@eddumelendez
Copy link
Member

To start the docker container of OceanBase, at least 2 cpu and 8g memory are required.

I think this is a concern due to IIRC Docker Desktop provides a default of 4g or 8g so it will be at limit all the time not even allowing running other test in parallel. Is there any way to consume less resources. So far, I've seen DB2 consuming ~1.75g

Copy link
Member

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the initial comments. Is there a web console provided with the image? Also it would be great if the image provides a directory where scripts can be copied and be part of the database initialization such as mysql does it due to the withInitScript limitation

@whhe
Copy link
Contributor Author

whhe commented Sep 7, 2023

To start the docker container of OceanBase, at least 2 cpu and 8g memory are required.

I think this is a concern due to IIRC Docker Desktop provides a default of 4g or 8g so it will be at limit all the time not even allowing running other test in parallel. Is there any way to consume less resources. So far, I've seen DB2 consuming ~1.75g

We have a plan to achieve lightweight deployment, but it may be difficult to achieve it in the near future.

Now we can't deploy the container on a free GitHub agent. For reference, we use the docker image through testcontainers on a self-hosted CI service in flink cdc.

@eddumelendez
Copy link
Member

eddumelendez commented Sep 7, 2023

Now we can't deploy the container on a free GitHub agent.

TBH, I think for now it will keep on hold if that the case 😕

Another option is to self-host the module as others do.

@whhe
Copy link
Contributor Author

whhe commented Sep 7, 2023

Now we can't deploy the container on a free GitHub agent.

TBH, I think for now it will keep on hold if that the case 😕

Another option is to self-host the module as others do.

OK, I understand. I would convert this pull request to a draft, and we can continue the process after oceanbase/oceanbase#1557 is basically completed.

@whhe whhe marked this pull request as draft September 7, 2023 06:00
@eddumelendez
Copy link
Member

great! Thanks for your understanding! I'll be following the issue in order to get updates

@whhe whhe marked this pull request as ready for review September 20, 2023 08:27
@whhe
Copy link
Contributor Author

whhe commented Sep 20, 2023

I updated the container class with the new image oceanbase/oceanbase-ce:4.2.0.0 which can be deployed on GitHub Action now https://hub.docker.com/r/oceanbase/oceanbase-ce.

Currently the startup time is still more than 1 minute, I think we can use 3 min in this version and update it when oceanbase/oceanbase#1573 is released. WDYT? @eddumelendez

@eddumelendez
Copy link
Member

Hi @whhe, great to see the improvements. Currently, 1 min is the maximum value we are setting. I would say reaching that limit would produce a not good experience when running tests, of course, it depends how those are set too. IMO, we can wait a little bit more and provide the best experience possible when the other issue is fixed.

@whhe
Copy link
Contributor Author

whhe commented Sep 26, 2023

Hi @whhe, great to see the improvements. Currently, 1 min is the maximum value we are setting. I would say reaching that limit would produce a not good experience when running tests, of course, it depends how those are set too. IMO, we can wait a little bit more and provide the best experience possible when the other issue is fixed.

Thanks for the suggestion, I think it makes perfect sense, will update this PR with the new image later.

@whhe whhe force-pushed the oceanbase-ce branch 2 times, most recently from fed062f to 0210dcf Compare January 5, 2024 09:20
@whhe
Copy link
Contributor Author

whhe commented Jan 5, 2024

Hi @eddumelendez, I updated this PR with our latest docker image, which can start in less than 30s with FASTBOOT enabled. I think we can go back to the review process now.

@whhe whhe force-pushed the oceanbase-ce branch 2 times, most recently from 7011359 to d2a6a21 Compare January 16, 2024 07:23
@whhe
Copy link
Contributor Author

whhe commented Jan 24, 2024

@eddumelendez PTAL if you are available.

@whhe
Copy link
Contributor Author

whhe commented Feb 1, 2024

Hi @eddumelendez, is there any plan for this pr?

Copy link
Member

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, @whhe ! and sorry for the late reply. I have left some comments and some more general:

  1. Rename the module to oceanbase. Is it ok for you?
  2. Package should be org.testcontainers.oceanbase
  3. Run ./gradlew spotlessApply

Comment on lines 119 to 124
if (StringUtils.isEmpty(tenantName)) {
throw new IllegalArgumentException("Tenant name cannot be null or empty");
}
if (SYSTEM_TENANT_NAME.equals(tenantName)) {
throw new IllegalArgumentException("Tenant name cannot be " + SYSTEM_TENANT_NAME);
}
Copy link
Member

Choose a reason for hiding this comment

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

wonder if those validations should be at the image level and avoid duplicating the validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The response from the image may not be as direct as the error message here. It refers to the 'DEFAULT_DATABASE_NAME' in OracleContainer.


public String getJdbcUrl(String databaseName) {
String additionalUrlParams = constructUrlParameters("?", "&");
String prefix = driverClassName.contains("mysql") ? "jdbc:mysql://" : "jdbc:oceanbase://";
Copy link
Member

Choose a reason for hiding this comment

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

I think we should restrict more here because at first glance if any driverClassName different than mysql will choose oceanbase prefix, and not sure but that would be unexpected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 'driverClassName' is verified in withDriverClassName method, so its value is limited to these two options.

@whhe
Copy link
Contributor Author

whhe commented Feb 18, 2024

Thanks for your contribution, @whhe ! and sorry for the late reply. I have left some comments and some more general:

  1. Rename the module to oceanbase. Is it ok for you?
  2. Package should be org.testcontainers.oceanbase
  3. Run ./gradlew spotlessApply

Thanks for your review and sorry for the late reply, I just came back from the Chinese new year holiday.

I will address the comments soon, but for the module name, I used 'oceanbase-ce' because the community will most likely release a 'oceanbase-xe' docker image in the future for the OceanBase Enterprise Edition. So I think we'd better keep it here.

@eddumelendez
Copy link
Member

I think in that case the module can still be oceanbase and contain two implementations OceanbaseCEContainer and OceanbaseXEContainer, it depends in how much difference there is between both of them.

@whhe
Copy link
Contributor Author

whhe commented Feb 22, 2024

@eddumelendez PR updated, PTAL.

@whhe
Copy link
Contributor Author

whhe commented Feb 26, 2024

@eddumelendez Look forward to your feedback.

Copy link
Member

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

Thanks for the quick update! Left a couple of messages.

Comment on lines 125 to 130
@Override
protected void configure() {
if (!DEFAULT_TEST_TENANT_NAME.equals(tenantName)) {
withEnv("OB_TENANT_NAME", tenantName);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

according to the docs, the default value for OB_TENAN_NAME is test. So we can just have

Suggested change
@Override
protected void configure() {
if (!DEFAULT_TEST_TENANT_NAME.equals(tenantName)) {
withEnv("OB_TENANT_NAME", tenantName);
}
}
@Override
protected void configure() {
withEnv("OB_TENANT_NAME", tenantName);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

User can also use 'withEnv' method to set it manually, in this case if we do not check the value, there may be a mistake.

Copy link
Member

Choose a reason for hiding this comment

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

I don't fully understand because the default is test and the tenantName = DEFAULT_TEST_TENANT_NAME; where DEFAULT_TEST_TENANT_NAME = "test". Unless, the right one should use SYSTEM_TENANT_NAME instead

if (!SYSTEM_TENANT_NAME.equals(tenantName)) {
    withEnv("OB_TENANT_NAME", tenantName);
}

Once we resolve this comment I can proceed and merge 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.

I'm considering this situation: someone use the container class but not set the tenant name with given method withTenant, like new OceanBaseCEContainer("xxx").withEnv("OB_TENANT_NAME", "tc");. In this case, as the tenantName field is still 'test', a 'test' tenant will be created, not user defined value 'tc'.

I'm not sure if we should deal with it. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I think that given there is a default value in the image itself. The withTenant method and the withEnv in configure method can be omitted. If for some reason there is a need to modify it then new OceanBaseCEContainer(...).withEnv("OB_TENANT_NAME", "something"); that would a similar experience like running docker run command. Otherwise, it would be a little bit confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tenantName field here is required to construct the username used in jdbc connection, so I did not remove the withTenant method in previous cleanup. I reconsidered about it and maybe use the default value with necessary description is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Member

Choose a reason for hiding this comment

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

I just noticed we were missing a test for this use case and also think a little bit more about it. In the configure method we can add getEnvMap().computeIfAbsent("OB_TENAN_NAME", k -> tenantName != null ? tenantName : DEFAULT_TENANT_NAME) or just getEnvMap().computeIfAbsent("OB_TENAN_NAME", k -> tenantName) and we can keep withTenantName. LMK if this can help to the use case described.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you are right, we can resolve it by using the envMap, but I think it's not necessary for now.

At present no other withXXX method is provided in this container class and all env options are set by withEnv, I think it's good and clean. Lets keep it like this.

@eddumelendez
Copy link
Member

One last change, can we add an entry for oceanbase here, please?

@eddumelendez eddumelendez added this to the next milestone Feb 28, 2024
@eddumelendez eddumelendez merged commit f23c1ec into testcontainers:main Feb 28, 2024
96 checks passed
@eddumelendez
Copy link
Member

Thanks for your contribution, @whhe !

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

Successfully merging this pull request may close these issues.

None yet

2 participants