From issues-return-183725-archive-asf-public=cust-asf.ponee.io@flink.apache.org Fri Aug 10 15:17:11 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1E8B8180676 for ; Fri, 10 Aug 2018 15:17:09 +0200 (CEST) Received: (qmail 37527 invoked by uid 500); 10 Aug 2018 13:17:09 -0000 Mailing-List: contact issues-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list issues@flink.apache.org Received: (qmail 37419 invoked by uid 99); 10 Aug 2018 13:17:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Aug 2018 13:17:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id B59A61A0861 for ; Fri, 10 Aug 2018 13:17:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.501 X-Spam-Level: X-Spam-Status: No, score=-109.501 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 0oaGk9r4HoAT for ; Fri, 10 Aug 2018 13:17:06 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 439CE5F57D for ; Fri, 10 Aug 2018 13:17:05 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 06ADBE2644 for ; Fri, 10 Aug 2018 13:17:04 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id BCA2B23FC8 for ; Fri, 10 Aug 2018 13:17:02 +0000 (UTC) Date: Fri, 10 Aug 2018 13:17:02 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@flink.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FLINK-9642) Reduce the count to deal with state during a CEP process MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/FLINK-9642?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1657= 6261#comment-16576261 ]=20 ASF GitHub Bot commented on FLINK-9642: --------------------------------------- dawidwys commented on a change in pull request #6205: [FLINK-9642]Reduce th= e count to deal with state during a CEP process URL: https://github.com/apache/flink/pull/6205#discussion_r209251047 =20 =20 ########## File path: flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nf= a/sharedbuffer/SharedBuffer.java ########## @@ -204,227 +133,78 @@ public NodeId put( =09 * @throws Exception Thrown if the system cannot access the state. =09 */ =09public boolean isEmpty() throws Exception { -=09=09return Iterables.isEmpty(eventsBuffer.keys()); +=09=09return Iterables.isEmpty(eventsBuffer.keys()) && Iterables.isEmpty(e= ventsBufferCache.keySet()); =09} =20 =09/** -=09 * Returns all elements from the previous relation starting at the give= n entry. -=09 * -=09 * @param nodeId id of the starting entry -=09 * @param version Version of the previous relation which shall be extra= cted -=09 * @return Collection of previous relations starting with the given val= ue -=09 * @throws Exception Thrown if the system cannot access the state. +=09 * Put an event to cache. +=09 * @param eventId id of the event +=09 * @param event event body =09 */ -=09public List>> extractPatterns( -=09=09=09final NodeId nodeId, -=09=09=09final DeweyNumber version) throws Exception { - -=09=09List>> result =3D new ArrayList<>(); - -=09=09// stack to remember the current extraction states -=09=09Stack extractionStates =3D new Stack<>(); - -=09=09// get the starting shared buffer entry for the previous relation -=09=09Lockable entryLock =3D entries.get(nodeId); - -=09=09if (entryLock !=3D null) { -=09=09=09SharedBufferNode entry =3D entryLock.getElement(); -=09=09=09extractionStates.add(new ExtractionState(Tuple2.of(nodeId, entry)= , version, new Stack<>())); - -=09=09=09// use a depth first search to reconstruct the previous relations -=09=09=09while (!extractionStates.isEmpty()) { -=09=09=09=09final ExtractionState extractionState =3D extractionStates.pop= (); -=09=09=09=09// current path of the depth first search -=09=09=09=09final Stack> currentPath =3D = extractionState.getPath(); -=09=09=09=09final Tuple2 currentEntry =3D extrac= tionState.getEntry(); - -=09=09=09=09// termination criterion -=09=09=09=09if (currentEntry =3D=3D null) { -=09=09=09=09=09final Map> completePath =3D new Linke= dHashMap<>(); - -=09=09=09=09=09while (!currentPath.isEmpty()) { -=09=09=09=09=09=09final NodeId currentPathEntry =3D currentPath.pop().f0; - -=09=09=09=09=09=09String page =3D currentPathEntry.getPageName(); -=09=09=09=09=09=09List values =3D completePath -=09=09=09=09=09=09=09.computeIfAbsent(page, k -> new ArrayList<>()); -=09=09=09=09=09=09values.add(currentPathEntry.getEventId()); -=09=09=09=09=09} -=09=09=09=09=09result.add(completePath); -=09=09=09=09} else { - -=09=09=09=09=09// append state to the path -=09=09=09=09=09currentPath.push(currentEntry); - -=09=09=09=09=09boolean firstMatch =3D true; -=09=09=09=09=09for (SharedBufferEdge edge : currentEntry.f1.getEdges()) { -=09=09=09=09=09=09// we can only proceed if the current version is compati= ble to the version -=09=09=09=09=09=09// of this previous relation -=09=09=09=09=09=09final DeweyNumber currentVersion =3D extractionState.get= Version(); -=09=09=09=09=09=09if (currentVersion.isCompatibleWith(edge.getDeweyNumber(= ))) { -=09=09=09=09=09=09=09final NodeId target =3D edge.getTarget(); -=09=09=09=09=09=09=09Stack> newPath; - -=09=09=09=09=09=09=09if (firstMatch) { -=09=09=09=09=09=09=09=09// for the first match we don't have to copy the c= urrent path -=09=09=09=09=09=09=09=09newPath =3D currentPath; -=09=09=09=09=09=09=09=09firstMatch =3D false; -=09=09=09=09=09=09=09} else { -=09=09=09=09=09=09=09=09newPath =3D new Stack<>(); -=09=09=09=09=09=09=09=09newPath.addAll(currentPath); -=09=09=09=09=09=09=09} - -=09=09=09=09=09=09=09extractionStates.push(new ExtractionState( -=09=09=09=09=09=09=09=09target !=3D null ? Tuple2.of(target, entries.get(t= arget).getElement()) : null, -=09=09=09=09=09=09=09=09edge.getDeweyNumber(), -=09=09=09=09=09=09=09=09newPath)); -=09=09=09=09=09=09} -=09=09=09=09=09} -=09=09=09=09} - -=09=09=09} -=09=09} -=09=09return result; +=09void cacheEvent(EventId eventId, Lockable event) { +=09=09this.eventsBufferCache.put(eventId, event); =09} =20 -=09public Map> materializeMatch(Map>= match) { -=09=09return materializeMatch(match, new HashMap<>()); +=09/** +=09 * Put a ShareBufferNode to cache. +=09 * @param nodeId id of the event +=09 * @param entry SharedBufferNode +=09 */ +=09void cacheEntry(NodeId nodeId, Lockable entry) { +=09=09this.entryCache.put(nodeId, entry); =09} =20 -=09public Map> materializeMatch(Map>= match, Map cache) { - -=09=09Map> materializedMatch =3D new LinkedHashMap<>(match= .size()); - -=09=09for (Map.Entry> pattern : match.entrySet()) { -=09=09=09List events =3D new ArrayList<>(pattern.getValue().size()); -=09=09=09for (EventId eventId : pattern.getValue()) { -=09=09=09=09V event =3D cache.computeIfAbsent(eventId, id -> { -=09=09=09=09=09try { -=09=09=09=09=09=09return eventsBuffer.get(id).getElement(); -=09=09=09=09=09} catch (Exception ex) { -=09=09=09=09=09=09throw new WrappingRuntimeException(ex); -=09=09=09=09=09} -=09=09=09=09}); -=09=09=09=09events.add(event); -=09=09=09} -=09=09=09materializedMatch.put(pattern.getKey(), events); -=09=09} - -=09=09return materializedMatch; +=09/** +=09 * Remove an event from cache and state. +=09 * @param eventId id of the event +=09 */ +=09void removeEvent(EventId eventId) throws Exception { +=09=09this.eventsBufferCache.remove(eventId); +=09=09this.eventsBuffer.remove(eventId); =09} =20 =09/** -=09 * Increases the reference counter for the given entry so that it is no= t -=09 * accidentally removed. -=09 * -=09 * @param node id of the entry -=09 * @throws Exception Thrown if the system cannot access the state. +=09 * remove a ShareBufferNode from cache and state. +=09 * @param nodeId id of the event =09 */ -=09public void lockNode(final NodeId node) throws Exception { -=09=09Lockable sharedBufferNode =3D entries.get(node); -=09=09if (sharedBufferNode !=3D null) { -=09=09=09sharedBufferNode.lock(); -=09=09=09entries.put(node, sharedBufferNode); -=09=09} +=09void removeEntry(NodeId nodeId) throws Exception { +=09=09this.entryCache.remove(nodeId); +=09=09this.entries.remove(nodeId); =09} =20 =09/** -=09 * Decreases the reference counter for the given entry so that it can b= e -=09 * removed once the reference counter reaches 0. -=09 * -=09 * @param node id of the entry +=09 * Try to get the sharedBufferNode from state iff the node has not been= quered during this turn process. +=09 * @param nodeId id of the event +=09 * @return SharedBufferNode =09 * @throws Exception Thrown if the system cannot access the state. =09 */ -=09public void releaseNode(final NodeId node) throws Exception { -=09=09Lockable sharedBufferNode =3D entries.get(node); -=09=09if (sharedBufferNode !=3D null) { -=09=09=09if (sharedBufferNode.release()) { -=09=09=09=09removeNode(node, sharedBufferNode.getElement()); -=09=09=09} else { -=09=09=09=09entries.put(node, sharedBufferNode); -=09=09=09} -=09=09} +=09Lockable getEntry(NodeId nodeId) throws Exception { +=09=09Lockable entry =3D entryCache.get(nodeId); +=09=09return entry !=3D null ? entry : entries.get(nodeId); =09} =20 -=09private void removeNode(NodeId node, SharedBufferNode sharedBufferNode)= throws Exception { -=09=09entries.remove(node); -=09=09EventId eventId =3D node.getEventId(); -=09=09releaseEvent(eventId); - -=09=09for (SharedBufferEdge sharedBufferEdge : sharedBufferNode.getEdges()= ) { -=09=09=09releaseNode(sharedBufferEdge.getTarget()); -=09=09} -=09} - -=09private void lockEvent(EventId eventId) throws Exception { -=09=09Lockable eventWrapper =3D eventsBuffer.get(eventId); -=09=09checkState( -=09=09=09eventWrapper !=3D null, -=09=09=09"Referring to non existent event with id %s", -=09=09=09eventId); -=09=09eventWrapper.lock(); -=09=09eventsBuffer.put(eventId, eventWrapper); +=09Lockable getEvent(EventId eventId) throws Exception { +=09=09Lockable event =3D eventsBufferCache.get(eventId); +=09=09return event !=3D null ? event : eventsBuffer.get(eventId); =09} =20 =09/** -=09 * Decreases the reference counter for the given event so that it can b= e -=09 * removed once the reference counter reaches 0. -=09 * -=09 * @param eventId id of the event +=09 * Flush the event and node from cache to state. =20 Review comment: Missing empty line ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. =20 For queries about this service, please contact Infrastructure at: users@infra.apache.org > Reduce the count to deal with state during a CEP process=20 > --------------------------------------------------------- > > Key: FLINK-9642 > URL: https://issues.apache.org/jira/browse/FLINK-9642 > Project: Flink > Issue Type: Improvement > Components: CEP > Affects Versions: 1.6.0 > Reporter: aitozi > Assignee: aitozi > Priority: Major > Labels: pull-request-available > > With the rework of sharedBuffer Flink-9418, the lock & release operation = is deal with rocksdb state which is different from the previous version whi= ch will read the state of sharedBuffer all to memory, i think we can add a = cache or variable in sharedbuffer to cache the LockAble Object to mark the = ref change in once process in NFA, this will reduce the count when the even= ts point to the same NodeId.. And flush the result to MapState at the end o= f process.=C2=A0 -- This message was sent by Atlassian JIRA (v7.6.3#76005)