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

codec-memcache: copy metadata in binary full request response #9160

Merged
merged 1 commit into from
May 22, 2019

Conversation

fabienrenaud
Copy link
Contributor

@fabienrenaud fabienrenaud commented May 19, 2019

Motivations

Calling copy(), duplicate() or replace() on FullBinaryMemcacheResponse
or FullBinaryMemcacheRequest instances should copy status, opCode, etc.
that are defined in AbstractBinaryMemcacheMessage.

Modifications

  • Modified duplicate, copy and replace methods in
    DefaultFullBinaryMemcacheRequest and DefaultFullBinaryMemcacheResponse
    to always copy metadata from parent classes.
  • Unit tests verifying duplicate, copy and replace methods for
    DefaultFullBinaryMemcacheRequest and DefaultFullBinaryMemcacheResponse
    copy buffers and metadata as expected.

Result

Calling copy(), duplicate() or replace() methods on
DefaultFullBinaryMemcacheRequest or DefaultFullBinaryMemcacheResponse
produces valid copies with all expected metadata.

Fixes #9159

Checklist:

  • Signed ICLA

@netty-bot
Copy link

Can one of the admins verify this patch?

@fabienrenaud
Copy link
Contributor Author

fabienrenaud commented May 19, 2019 via email

@@ -0,0 +1,82 @@
/*
* Copyright 2013 The Netty Project
Copy link
Member

Choose a reason for hiding this comment

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

2019

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

FullBinaryMemcacheRequest actual) {
assertNotSame(expected, actual);

assertTrue(ByteBufUtil.equals(expected.key(), actual.key()));
Copy link
Member

Choose a reason for hiding this comment

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

just use assertEquals(expected.key(), actual.key() .... same for the other lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

assertEquals(expected.dataType(), actual.dataType());
assertEquals(expected.totalBodyLength(), actual.totalBodyLength());
assertEquals(expected.opaque(), actual.opaque());
assertEquals(expected.cas(), actual.cas());
Copy link
Member

Choose a reason for hiding this comment

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

call expected.release() and actual.release() in a finally block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting a ref count exception when running mvn test when I do that. The buffers are unpooled.

Copy link
Member

Choose a reason for hiding this comment

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

hmm can I see the exception ?

Copy link
Member

Choose a reason for hiding this comment

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

ah I now see why... you sometimes pass the same buffer / request .

Just change it to when you pass in the same instance to use retainedDuplicate(). This will ensure you will also increment the reference count

Copy link
Contributor Author

@fabienrenaud fabienrenaud May 20, 2019

Choose a reason for hiding this comment

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

Addressed.
I've added some code to track what refs should be released and cleaned up in a junit @After method.

Copy link
Member

Choose a reason for hiding this comment

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

See above... I would prefer if you just do it directly in the tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -0,0 +1,82 @@
/*
* Copyright 2013 The Netty Project
Copy link
Member

Choose a reason for hiding this comment

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

2019

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed


assertTrue(ByteBufUtil.equals(expected.key(), actual.key()));
assertTrue(ByteBufUtil.equals(expected.extras(), actual.extras()));
assertTrue(ByteBufUtil.equals(expectedContent, actual.content()));
Copy link
Member

Choose a reason for hiding this comment

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

see above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

assertEquals(expected.totalBodyLength(), actual.totalBodyLength());
assertEquals(expected.opaque(), actual.opaque());
assertEquals(expected.cas(), actual.cas());
}
Copy link
Member

Choose a reason for hiding this comment

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

see above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

@@ -232,4 +232,15 @@ public BinaryMemcacheMessage touch(Object hint) {
}
return this;
}

protected void copyMeta(AbstractBinaryMemcacheMessage dst) {
Copy link
Member

Choose a reason for hiding this comment

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

package-private ?

please add javadocs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

@fabienrenaud fabienrenaud force-pushed the issue-9159 branch 3 times, most recently from ec87354 to ca2db19 Compare May 20, 2019 15:41
@normanmaurer
Copy link
Member

@netty-bot test this please

*
* @param dst The instance where to copy the metadata of this instance to
*/
void copyMeta(DefaultBinaryMemcacheRequest dst) {
Copy link
Member

Choose a reason for hiding this comment

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

missing @Override ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no the signature of the methods are different:

super: void copyMeta(AbstractBinaryMemcacheMessage dst)
this : void copyMeta(DefaultBinaryMemcacheRequest dst)

*
* @param dst The instance where to copy the metadata of this instance to
*/
void copyMeta(DefaultBinaryMemcacheResponse dst) {
Copy link
Member

Choose a reason for hiding this comment

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

missing @Override ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no the signature of the methods are different:

super: void copyMeta(AbstractBinaryMemcacheMessage dst)
this : void copyMeta(DefaultBinaryMemcacheResponse dst)


@Before
public void setUp() {
refToRelease = new LinkedList<ReferenceCounted>();
Copy link
Member

Choose a reason for hiding this comment

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

honestly I think it would be a lot cleaner if you just release stuff in the tests itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure...

assertEquals(expected.dataType(), actual.dataType());
assertEquals(expected.totalBodyLength(), actual.totalBodyLength());
assertEquals(expected.opaque(), actual.opaque());
assertEquals(expected.cas(), actual.cas());
Copy link
Member

Choose a reason for hiding this comment

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

See above... I would prefer if you just do it directly in the tests

Motivations
-----------
Calling `copy()`, `duplicate()` or `replace()` on `FullBinaryMemcacheResponse`
or `FullBinaryMemcacheRequest` instances should copy status, opCode, etc.
that are defined in `AbstractBinaryMemcacheMessage`.

Modifications
-------------
 - Modified duplicate, copy and replace methods in
DefaultFullBinaryMemcacheRequest and DefaultFullBinaryMemcacheResponse
to always copy metadata from parent classes.
 - Unit tests verifying duplicate, copy and replace methods for
DefaultFullBinaryMemcacheRequest and DefaultFullBinaryMemcacheResponse
copy buffers and metadata as expected.

Result
------
Calling copy(), duplicate() or replace() methods on
DefaultFullBinaryMemcacheRequest or DefaultFullBinaryMemcacheResponse
produces valid copies with all expected metadata.

Fixes netty#9159
@normanmaurer
Copy link
Member

@netty-bot test this please

1 similar comment
@normanmaurer
Copy link
Member

@netty-bot test this please

@normanmaurer normanmaurer added this to the 4.1.37.Final milestone May 22, 2019
@normanmaurer normanmaurer merged commit 52c5389 into netty:4.1 May 22, 2019
@normanmaurer
Copy link
Member

@fabienrenaud thanks a lot!

normanmaurer pushed a commit that referenced this pull request May 22, 2019
Motivations
-----------
Calling `copy()`, `duplicate()` or `replace()` on `FullBinaryMemcacheResponse`
or `FullBinaryMemcacheRequest` instances should copy status, opCode, etc.
that are defined in `AbstractBinaryMemcacheMessage`.

Modifications
-------------
 - Modified duplicate, copy and replace methods in
DefaultFullBinaryMemcacheRequest and DefaultFullBinaryMemcacheResponse
to always copy metadata from parent classes.
 - Unit tests verifying duplicate, copy and replace methods for
DefaultFullBinaryMemcacheRequest and DefaultFullBinaryMemcacheResponse
copy buffers and metadata as expected.

Result
------
Calling copy(), duplicate() or replace() methods on
DefaultFullBinaryMemcacheRequest or DefaultFullBinaryMemcacheResponse
produces valid copies with all expected metadata.

Fixes #9159
@fabienrenaud fabienrenaud deleted the issue-9159 branch May 23, 2019 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

codec-memcache: copy, duplicate, replace not copying full request/response metadata
3 participants