From issues-return-172500-archive-asf-public=cust-asf.ponee.io@flink.apache.org Wed Jun 20 17:10:06 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 4AE2818076D for ; Wed, 20 Jun 2018 17:10:05 +0200 (CEST) Received: (qmail 89093 invoked by uid 500); 20 Jun 2018 15:10:04 -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 89082 invoked by uid 99); 20 Jun 2018 15:10:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jun 2018 15:10:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id EC24CC0064 for ; Wed, 20 Jun 2018 15:10:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -110.301 X-Spam-Level: X-Spam-Status: No, score=-110.301 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, 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 (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id OxagkmHGfVcd for ; Wed, 20 Jun 2018 15:10:02 +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 1A1355F27D for ; Wed, 20 Jun 2018 15:10:02 +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 BBFE5E0D0A for ; Wed, 20 Jun 2018 15:10:00 +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 3768F21840 for ; Wed, 20 Jun 2018 15:10:00 +0000 (UTC) Date: Wed, 20 Jun 2018 15:10:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@flink.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FLINK-9514) Create wrapper with TTL logic for value state 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-9514?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1651= 8243#comment-16518243 ]=20 ASF GitHub Bot commented on FLINK-9514: --------------------------------------- Github user sihuazhou commented on a diff in the pull request: https://github.com/apache/flink/pull/6186#discussion_r196809755 =20 --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/state/tt= l/AbstractTtlDecorator.java --- @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or imp= lied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.runtime.state.ttl; + +import org.apache.flink.util.Preconditions; +import org.apache.flink.util.function.SupplierWithException; +import org.apache.flink.util.function.ThrowingConsumer; +import org.apache.flink.util.function.ThrowingRunnable; + +/** + * Base class for TTL logic wrappers. + * + * @param Type of originally wrapped object + */ +abstract class AbstractTtlDecorator { +=09final T original; +=09final TtlConfig config; +=09final TtlTimeProvider timeProvider; +=09final boolean updateTsOnRead; +=09final boolean returnExpired; + +=09AbstractTtlDecorator( +=09=09T original, +=09=09TtlConfig config, +=09=09TtlTimeProvider timeProvider) { +=09=09Preconditions.checkNotNull(original); +=09=09Preconditions.checkNotNull(config); +=09=09Preconditions.checkNotNull(timeProvider); +=09=09Preconditions.checkArgument(config.getTtlUpdateType() !=3D TtlUp= dateType.Disabled, +=09=09=09"State does not need to be wrapped with TTL if it is configur= ed as disabled."); +=09=09this.original =3D original; +=09=09this.config =3D config; +=09=09this.timeProvider =3D timeProvider; +=09=09this.updateTsOnRead =3D config.getTtlUpdateType() =3D=3D TtlUpda= teType.OnReadAndWrite; +=09=09this.returnExpired =3D config.getStateVisibility() =3D=3D TtlSta= teVisibility.Relaxed; +=09} + +=09 V getUnexpried(TtlValue ttlValue) { +=09=09return ttlValue =3D=3D null || (expired(ttlValue) && !returnExpi= red) ? null : ttlValue.getUserValue(); +=09} + +=09 boolean expired(TtlValue ttlValue) { +=09=09return ttlValue !=3D null && ttlValue.getExpirationTimestamp() <= =3D timeProvider.currentTimestamp(); +=09} + +=09 TtlValue wrapWithTs(V value) { +=09=09return wrapWithTs(value, newExpirationTimestamp()); +=09} + +=09static TtlValue wrapWithTs(V value, long ts) { +=09=09return value =3D=3D null ? null : new TtlValue<>(value, ts); +=09} + +=09 TtlValue rewrapWithNewTs(TtlValue ttlValue) { +=09=09return wrapWithTs(ttlValue.getUserValue()); +=09} + +=09private long newExpirationTimestamp() { +=09=09return timeProvider.currentTimestamp() + config.getTtl().toMilli= seconds(); --- End diff -- =20 This will be called a lot often, so does it make sense to introduce a f= ield to remember the `config.getTtl().toMilliseconds()`? > Create wrapper with TTL logic for value state > --------------------------------------------- > > Key: FLINK-9514 > URL: https://issues.apache.org/jira/browse/FLINK-9514 > Project: Flink > Issue Type: Sub-task > Components: State Backends, Checkpointing > Affects Versions: 1.6.0 > Reporter: Andrey Zagrebin > Assignee: Andrey Zagrebin > Priority: Major > Fix For: 1.6.0 > > > TTL state decorator uses original state with packed TTL and add TTL logic= using time provider: > {code:java} > TtlValueState implements ValueState { > ValueState> underlyingState; > =C2=A0=C2=A0InternalTimeService timeProvider; > V value() { > TtlValue valueWithTtl =3D underlyingState.get(); > // ttl logic here (e.g. update timestamp) > return valueWithTtl.getValue(); > } > void update() { ... underlyingState.update(valueWithTtl) ... =C2=A0} > } > {code} > TTL decorators are apply to state produced by normal state binder in its = TTL wrapper from=C2=A0FLINK-9513 -- This message was sent by Atlassian JIRA (v7.6.3#76005)