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

Fix QueryContext.getAdditionalFailureInfo bug #13120

Merged

Conversation

kewang1024
Copy link
Collaborator

For queryAllocations(a map) that tracks all the Operator and
its consuming memory for per query, it consists of a special key
FORCE_FREE_OPERATION with a negative number as its value
for memory management purpose. When reading queryAllocations,
we should skip key FORCE_FREE_OPERATION.

@@ -68,6 +68,8 @@
private final long maxSpill;
private final SpillSpaceTracker spillSpaceTracker;
private final Map<TaskId, TaskContext> taskContexts = new ConcurrentHashMap();
// Corresponding to AbstractAggregatedMemoryContext.FORCE_FREE_TAG
Copy link
Contributor

Choose a reason for hiding this comment

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

Please directly use AbstractAggregatedMemoryContext.FORCE_FREE_TAG. It's more error proof that way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please directly use AbstractAggregatedMemoryContext.FORCE_FREE_TAG. It's more error proof that way.

They're in different project, so if we want to directly use, we need to add maven dependency. Should we add maven dependency or just use this this way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AbstractAggregatedMemoryContext.FORCE_FREE_TAG is in presto-memory-context

@@ -352,6 +354,7 @@ private String getAdditionalFailureInfo(long allocated, long delta)
}

String topConsumers = queryAllocations.entrySet().stream()
.filter(entry -> !entry.getKey().equals(FORCE_FREE_TAG))
Copy link
Contributor

Choose a reason for hiding this comment

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

Another way to do this (if it's not proper to import AbstractAggregatedMemoryContext.FORCE_FREE_TAG directly, is to make sure queryAllocations returned by memoryPool.getTaggedMemoryAllocations().get(queryId) do not include this entry.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Just chat with @nezihyigitbasi and we agreed that we should just filter this entry out in MemoryPool.getTaggedMemoryAllocations.

@rongrong rongrong requested a review from nezihyigitbasi July 31, 2019 00:23
@kewang1024 kewang1024 force-pushed the fix_getAdditionalFailureInfo_bug branch 3 times, most recently from 52a9ac7 to f723ecc Compare August 13, 2019 18:28
@@ -351,6 +353,16 @@ private synchronized void updateTaggedMemoryAllocations(QueryId queryId, String
@VisibleForTesting
synchronized Map<QueryId, Map<String, Long>> getTaggedMemoryAllocations()
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 getting quite expensive. Let's just change this to getTaggedMemoryAllocations(queryId) instead. If tests are not easy to fix, introduce a separate function instead so this one (with the old implementation) is only used in tests.

@kewang1024 kewang1024 force-pushed the fix_getAdditionalFailureInfo_bug branch 2 times, most recently from 370f3c2 to 6956e1f Compare August 19, 2019 23:13
@kewang1024 kewang1024 requested a review from rongrong August 20, 2019 03:32
Map<String, Long> memoryMap = taggedMemoryAllocations.get(targetQueryId)
.entrySet().stream()
.filter(entry -> !entry.getKey().equals(FORCE_FREE_TAG))
.collect(Collectors.toMap(map -> map.getKey(), map -> map.getValue()));
Copy link
Contributor

Choose a reason for hiding this comment

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

.collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue))

.entrySet().stream()
.filter(entry -> !entry.getKey().equals(FORCE_FREE_TAG))
.collect(Collectors.toMap(map -> map.getKey(), map -> map.getValue()));
return ImmutableMap.copyOf(memoryMap);
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to make another copy.

if (taggedMemoryAllocations.get(targetQueryId) == null) {
return null;
}
Map<String, Long> memoryMap = taggedMemoryAllocations.get(targetQueryId)
Copy link
Contributor

Choose a reason for hiding this comment

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

return taggedMemoryAllocations.get(...)

@kewang1024 kewang1024 force-pushed the fix_getAdditionalFailureInfo_bug branch 2 times, most recently from e212dac to 954e7f1 Compare August 20, 2019 21:27
Copy link
Contributor

@rongrong rongrong left a comment

Choose a reason for hiding this comment

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

Sorry that I missed this in last review. One final thing. Thanks!

}

@VisibleForTesting
synchronized Map<String, Long> getTaggedMemoryAllocationsByID(QueryId targetQueryId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, missed this. You can just name this function getTaggedMemoryAllocations. The signature is obviously suggesting it's "by ID" so it's not necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

getTaggedMemoryAllocations

but we have another getTaggedMemoryAllocations which is called in the test, so I decided to preserve that function and created this new function.
how about changing to getTaggedMemoryAllocation (without the s) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine. You can just overload the function name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's fine. You can just overload the function name.

I see your point, Done and Done.

@kewang1024 kewang1024 force-pushed the fix_getAdditionalFailureInfo_bug branch 3 times, most recently from 166f532 to 466a6d9 Compare August 21, 2019 20:19
@@ -351,6 +352,19 @@ private synchronized void updateTaggedMemoryAllocations(QueryId queryId, String
@VisibleForTesting
synchronized Map<QueryId, Map<String, Long>> getTaggedMemoryAllocations()
{
return ImmutableMap.copyOf(taggedMemoryAllocations);
return taggedMemoryAllocations.keySet().stream()
.collect(toImmutableMap(queryId -> queryId, queryId -> getTaggedMemoryAllocations(queryId)));
Copy link
Contributor

Choose a reason for hiding this comment

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

        return taggedMemoryAllocations.keySet().stream()
                .collect(toImmutableMap(identity(), this::getTaggedMemoryAllocations));

@kewang1024 kewang1024 force-pushed the fix_getAdditionalFailureInfo_bug branch from 466a6d9 to c560900 Compare August 21, 2019 20:28
@@ -351,6 +353,19 @@ private synchronized void updateTaggedMemoryAllocations(QueryId queryId, String
@VisibleForTesting
synchronized Map<QueryId, Map<String, Long>> getTaggedMemoryAllocations()
{
return ImmutableMap.copyOf(taggedMemoryAllocations);
return taggedMemoryAllocations.keySet().stream()
.collect(toImmutableMap(identity(), queryId -> getTaggedMemoryAllocations(queryId)));
Copy link
Contributor

Choose a reason for hiding this comment

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

this:: getTaggedMemoryAllocations

For queryAllocations(a map) that tracks all the Operator and
its consuming memory for per query, it consists of a special key
FORCE_FREE_OPERATION with a negative number as its value
for memory management purpose. When reading queryAllocations,
we should skip key FORCE_FREE_OPERATION.
@kewang1024 kewang1024 force-pushed the fix_getAdditionalFailureInfo_bug branch from c560900 to c8eb80b Compare August 21, 2019 21:26
@rongrong rongrong merged commit 1fc8e5b into prestodb:master Aug 22, 2019
@kewang1024 kewang1024 deleted the fix_getAdditionalFailureInfo_bug branch March 12, 2023 20:24
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