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

Ds java issue358 #136

Merged
merged 2 commits into from
Aug 10, 2021
Merged

Ds java issue358 #136

merged 2 commits into from
Aug 10, 2021

Conversation

leerho
Copy link
Contributor

@leerho leerho commented Aug 10, 2021

This PR fixes the datasketches-java issue #358, which was actually an issue in Memory, and the Druid issue #11544.

This is a rather complex set of changes that involved about 30 classes. Along the way I found some other other discrepancies and missing capabilities in the API and fixed those as well. The tests have been extensively rewritten to cover (I hope) all cases. I do want to add one more test that closely reproduces the bug discovered by the Druid folks.

I don't expect anyone to understand all the subtleties in these changes, at least not by only scanning. Nonetheless, I would appreciate another pair of eyes, just to see if anything looks weird.

There will be a few more PRs coming, but with different focus.

Copy link
Member

@davecromberge davecromberge left a comment

Choose a reason for hiding this comment

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

I have scanned through this PR and did not notice any unusual changes, but did not immediately understand some of the more subtle changes as you mentioned in the description.

Concerning the original issue raised on ds-java, I would like to understand how these changes address the problem. It looks as if a memory request server is now enforced via the default, (or provided from the user) for dynamic backed memory objects, such as byte buffers as is the case with Druid. Does this allow the memory to expand without the null-pointer exception - assuming the null pointer was related to not having a memory request server available?

* Gets the MemoryRequestServer object used by dynamic Memory-backed objects
* to request additional memory. To customize the actions of the MemoryRequestServer,
* extend the MemoryRequestServer interfact and
* set using {@link WritableMemory#allocateDirect(long, ByteOrder, MemoryRequestServer)}.
Copy link
Member

Choose a reason for hiding this comment

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

Minor: typo in interfact.

Copy link
Contributor Author

@leerho leerho Aug 10, 2021

Choose a reason for hiding this comment

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

The original design provided the MemoryRequestServer callback only for Memory segments allocated via WritableMemory.allocateDirect(...) calls. Memory segments allocated via WritableMemory.wrap(ByteBuffer) did not have this capability. This was a major oversight since all off-heap memory in Druid is allocated using ByteBuffers! It is unusual that no one has uncovered this until now. Nonetheless, the fix involves instrumenting all the paths involved in providing this callback mechanism for wrapped ByteBuffers.

*/
public static final long getCurrentDirectMemoryMapAllocated() {
return BaseStateImpl.currentDirectMemoryMapAllocated_.get();
}
Copy link
Member

Choose a reason for hiding this comment

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

What is the difference between allocated vs allocations? Is the latter some kind of rate measurement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allocated: the amount of total off-heap memory allocated via the WritableMemory.allocateDirect(..) mechanism.
Allocations: The number of allocation requests.

memNNO.putShort(0, (short) 1);
assertNull(ReflectUtil.getUnsafeObject(memNNO));
assertTrue(memNNO.isDirect());
checkCombinations(memNNO, off, cap, memNNO.isDirect(), NNO, false, true);
Copy link
Member

Choose a reason for hiding this comment

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

Is the result of ReflectUtil.getUnsafeObject null in both cases because the memory is off-heap?

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.

@leerho leerho merged commit e97d072 into master Aug 10, 2021
@leerho leerho deleted the DS-javaIssue358 branch August 10, 2021 17:10
@leerho
Copy link
Contributor Author

leerho commented Aug 11, 2021 via email

@AlexanderSaydakov
Copy link
Contributor

Oh, why so? In that case I would think we need a custom request server in our Druid extension.

@leerho
Copy link
Contributor Author

leerho commented Aug 12, 2021 via email

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.

3 participants