liyafan82 commented on a change in pull request #8511:
[FLINK-12319][Library/CEP]Change the logic of releasing node from recursive to
non-recursive
URL: https://github.com/apache/flink/pull/8511#discussion_r296088014
##########
File path:
flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/sharedbuffer/SharedBufferAccessor.java
##########
@@ -235,31 +235,32 @@ public void lockNode(final NodeId node) {
* @throws Exception Thrown if the system cannot access the state.
*/
public void releaseNode(final NodeId node) throws Exception {
- Lockable<SharedBufferNode> sharedBufferNode =
sharedBuffer.getEntry(node);
- if (sharedBufferNode != null) {
- if (sharedBufferNode.release()) {
- removeNode(node, sharedBufferNode.getElement());
- } else {
- sharedBuffer.upsertEntry(node,
sharedBufferNode);
+ // the stack used to detect all nodes that needs to be released.
+ Stack<NodeId> nodesToExamine = new Stack<>();
+ nodesToExamine.push(node);
+
+ while (!nodesToExamine.isEmpty()) {
+ NodeId curNode = nodesToExamine.pop();
+ Lockable<SharedBufferNode> curBufferNode =
sharedBuffer.getEntry(curNode);
+
+ if (curBufferNode == null) {
+ break;
Review comment:
@dawidwys Good question. Thanks.
There can be duplicated attempts to remove a node. So if we do not check
whether currBufferNode is null, an NPE will be thrown.
As an example, please take a look at
CEPITCase#testFlatSelectSerializationWithAnonymousClass. There are two attempts
to release the node from NFA#doProcess method.
When a node is released (and set to null), the decedent nodes have already
been released too, so there is no need to continue examining nodes in
nodesToExamine.
Please note that such logic is not designed by me. The original code worked
the same way. I just refactor the code so that the logic is identical to the
original code.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services