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

[flaky-tests] AdminApiSchemaTest#testSchemaInfoApi #14508

Merged

Conversation

nicoloboschi
Copy link
Contributor

@nicoloboschi nicoloboschi commented Mar 1, 2022

Motivation

This is the same fix applied here #12461. The problem with the other pull is that the AbstractSchema#clone() method does return the same instance, so the fix is not useful at all.

I see this test also failing in 2.8 and 2.9 branch, I recommend to cherry-pick it.

Modifications

  • Create a new INT schema for the test purpose
  • no-need-doc

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Mar 1, 2022
@lhotari
Copy link
Member

lhotari commented Mar 1, 2022

The problem with the other pull is that the AbstractSchema#clone() method does return the same instance, so the fix is not useful at all.

I wonder why

doesn't implement clone? It seems really misleading to have such a method on the API if it's not doing what it's supposed to do. #6356 added the clone method. Perhaps @congbobo184 could explain the reasoning?

@nicoloboschi
Copy link
Contributor Author

/pulsarbot rerun-failure-checks

@@ -708,7 +709,7 @@ public void testNullKeyValueProperty() throws PulsarAdminException, PulsarClient
map.put(null, "value"); // null key is not allowed for JSON, it's only for test here

// leave INT32 instance unchanged
final Schema<Integer> integerSchema = Schema.INT32.clone();
final Schema<Integer> integerSchema = DefaultImplementation.getDefaultImplementation().newIntSchema();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not good.
it means that users that use the public API Schema.INT32 and use clone() see surprises.

I believe that the problem is that clone() is not working properly

Schema are stateful objects in Pulsar and clone() is very important

Copy link
Contributor

Choose a reason for hiding this comment

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

if you don't want to open the Pandora box of clone() then please use Schema.JSON() that is guaranteed to always return a new instance

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 believe this solution works. SCHEMA_INFO is static, so any modification of it in one test will affect other tests. This is a design flaw.

A larger question for me is why we're letting users modify the SCHEMA_INFO object. It is static, so cloning isn't going to do anything.

Copy link
Contributor Author

@nicoloboschi nicoloboschi Mar 1, 2022

Choose a reason for hiding this comment

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

@michaeljmarshall good catch! you're right
I think the test issue can be just fixed as @eolivelli suggested, using a JSON schema. The type of the schema is not relevant for test itself.

I agree that the clone() method returnsthis because, probably, the initial intention was to keep it immutable.
Moving the getter to return an immutable map may be the right solution, even if it can be considered a breaking change because can cause runtime error while upgrading the client

Copy link
Member

Choose a reason for hiding this comment

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

Great point. In order to get this test passing, we can avoid the mutability issues for Schema.INT32.

Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

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

@lhotari - it's likely that clone returns this because it is supposed to be immutable. Unfortunately, the SCHEMA_INFO is static and mutable, so this bug would exist even if clone worked properly.

@nicoloboschi - great work identifying this issue. I think we'll need to discuss a large solution. In my mind, the SCHEMA_INFO shouldn't be modifiable in this case.

private static final IntSchema INSTANCE;
private static final SchemaInfo SCHEMA_INFO;
static {
SCHEMA_INFO = new SchemaInfoImpl()
.setName("INT32")
.setType(SchemaType.INT32)
.setSchema(new byte[0]);
INSTANCE = new IntSchema();
}

@@ -708,7 +709,7 @@ public void testNullKeyValueProperty() throws PulsarAdminException, PulsarClient
map.put(null, "value"); // null key is not allowed for JSON, it's only for test here

// leave INT32 instance unchanged
final Schema<Integer> integerSchema = Schema.INT32.clone();
final Schema<Integer> integerSchema = DefaultImplementation.getDefaultImplementation().newIntSchema();
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 believe this solution works. SCHEMA_INFO is static, so any modification of it in one test will affect other tests. This is a design flaw.

A larger question for me is why we're letting users modify the SCHEMA_INFO object. It is static, so cloning isn't going to do anything.

@michaeljmarshall
Copy link
Member

michaeljmarshall commented Mar 1, 2022

Note also that the properties map (the original issue from #12461) is a mutable map that is likely passed among threads:

/**
* Additional properties of the schema definition (implementation defined).
*/
@Builder.Default
private Map<String, String> properties = Collections.emptyMap();

Depending on how we access this map, that could be its own issue.

That SchemaInfoImpl class doesn't appear to be using safe publication of state either, which makes the mutability a larger problem.

@nicoloboschi
Copy link
Contributor Author

@michaeljmarshall @eolivelli I created this issue #14522 for continuing the discussion

@nicoloboschi
Copy link
Contributor Author

/pulsarbot rerun-failure-checks

@congbobo184
Copy link
Contributor

i think primitive schema also can implement clone

@congbobo184
Copy link
Contributor

The problem with the other pull is that the AbstractSchema#clone() method does return the same instance, so the fix is not useful at all.

I wonder why

doesn't implement clone? It seems really misleading to have such a method on the API if it's not doing what it's supposed to do. #6356 added the clone method. Perhaps @congbobo184 could explain the reasoning?

There will be some components inside and will change. When the user wants to use the component at that time, we need the clone method to get the current schema, and it will not affect the original schema. Doesn't seem to be of much use in primitive schema as they are all the same

Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

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

LGTM

@michaeljmarshall michaeljmarshall merged commit 32c3cd1 into apache:master Mar 7, 2022
michaeljmarshall pushed a commit that referenced this pull request Mar 7, 2022
* [flaky-tests] AdminApiSchemaTest#testSchemaInfoApi

* use custom json schema

* remove old comment

### Motivation
This is the same fix applied here #12461. The problem with the other pull is that the `AbstractSchema#clone()` method does return the same instance, so the fix is not useful at all.

I see this test also failing in 2.8 and 2.9 branch, I recommend to cherry-pick it.

### Modifications
* Create a new INT schema for the test purpose

- [x] `no-need-doc`

(cherry picked from commit 32c3cd1)
michaeljmarshall pushed a commit that referenced this pull request Mar 7, 2022
* [flaky-tests] AdminApiSchemaTest#testSchemaInfoApi

* use custom json schema

* remove old comment

### Motivation
This is the same fix applied here #12461. The problem with the other pull is that the `AbstractSchema#clone()` method does return the same instance, so the fix is not useful at all.

I see this test also failing in 2.8 and 2.9 branch, I recommend to cherry-pick it.

### Modifications
* Create a new INT schema for the test purpose

- [x] `no-need-doc`

(cherry picked from commit 32c3cd1)
michaeljmarshall pushed a commit that referenced this pull request Mar 7, 2022
* [flaky-tests] AdminApiSchemaTest#testSchemaInfoApi

* use custom json schema

* remove old comment

### Motivation
This is the same fix applied here #12461. The problem with the other pull is that the `AbstractSchema#clone()` method does return the same instance, so the fix is not useful at all.

I see this test also failing in 2.8 and 2.9 branch, I recommend to cherry-pick it.

### Modifications
* Create a new INT schema for the test purpose

- [x] `no-need-doc`

(cherry picked from commit 32c3cd1)
@michaeljmarshall michaeljmarshall added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Mar 7, 2022
nicoloboschi added a commit to datastax/pulsar that referenced this pull request Mar 7, 2022
* [flaky-tests] AdminApiSchemaTest#testSchemaInfoApi

* use custom json schema

* remove old comment

### Motivation
This is the same fix applied here apache#12461. The problem with the other pull is that the `AbstractSchema#clone()` method does return the same instance, so the fix is not useful at all.

I see this test also failing in 2.8 and 2.9 branch, I recommend to cherry-pick it.

### Modifications
* Create a new INT schema for the test purpose

- [x] `no-need-doc`

(cherry picked from commit 32c3cd1)
(cherry picked from commit 0f72a4f)
nicoloboschi added a commit to datastax/pulsar that referenced this pull request Mar 7, 2022
* [flaky-tests] AdminApiSchemaTest#testSchemaInfoApi

* use custom json schema

* remove old comment

### Motivation
This is the same fix applied here apache#12461. The problem with the other pull is that the `AbstractSchema#clone()` method does return the same instance, so the fix is not useful at all.

I see this test also failing in 2.8 and 2.9 branch, I recommend to cherry-pick it.

### Modifications
* Create a new INT schema for the test purpose

- [x] `no-need-doc`

(cherry picked from commit 32c3cd1)
(cherry picked from commit 0f72a4f)
gaozhangmin pushed a commit to gaozhangmin/pulsar that referenced this pull request Mar 8, 2022
* [flaky-tests] AdminApiSchemaTest#testSchemaInfoApi

* use custom json schema

* remove old comment

### Motivation
This is the same fix applied here apache#12461. The problem with the other pull is that the `AbstractSchema#clone()` method does return the same instance, so the fix is not useful at all.

I see this test also failing in 2.8 and 2.9 branch, I recommend to cherry-pick it.

### Modifications
* Create a new INT schema for the test purpose


- [x] `no-need-doc`
@codelipenghui codelipenghui modified the milestones: 2.11.0, 2.10.0 Mar 12, 2022
Nicklee007 pushed a commit to Nicklee007/pulsar that referenced this pull request Apr 20, 2022
* [flaky-tests] AdminApiSchemaTest#testSchemaInfoApi

* use custom json schema

* remove old comment

### Motivation
This is the same fix applied here apache#12461. The problem with the other pull is that the `AbstractSchema#clone()` method does return the same instance, so the fix is not useful at all.

I see this test also failing in 2.8 and 2.9 branch, I recommend to cherry-pick it.

### Modifications
* Create a new INT schema for the test purpose


- [x] `no-need-doc`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.4 release/2.9.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants