Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id ED417200D26 for ; Fri, 20 Oct 2017 11:46:04 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id EBA9F160BCB; Fri, 20 Oct 2017 09:46:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1649D1609E1 for ; Fri, 20 Oct 2017 11:46:03 +0200 (CEST) Received: (qmail 99933 invoked by uid 500); 20 Oct 2017 09:46:03 -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 99924 invoked by uid 99); 20 Oct 2017 09:46:03 -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; Fri, 20 Oct 2017 09:46:03 +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 7728AC3C98 for ; Fri, 20 Oct 2017 09:46:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 6VAjb4adxIBk for ; Fri, 20 Oct 2017 09:46:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 1B2F55FD38 for ; Fri, 20 Oct 2017 09:46:01 +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 8C547E0443 for ; Fri, 20 Oct 2017 09:46: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 4837721EE4 for ; Fri, 20 Oct 2017 09:46:00 +0000 (UTC) Date: Fri, 20 Oct 2017 09:46:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@flink.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FLINK-7623) Detecting whether an operator is restored doesn't work with chained state MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 20 Oct 2017 09:46:05 -0000 [ https://issues.apache.org/jira/browse/FLINK-7623?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16212429#comment-16212429 ] ASF GitHub Bot commented on FLINK-7623: --------------------------------------- Github user StefanRRichter commented on a diff in the pull request: https://github.com/apache/flink/pull/4851#discussion_r145920720 --- Diff: flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/RestoreStreamTaskTest.java --- @@ -0,0 +1,325 @@ +/* + * 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 implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.streaming.runtime.tasks; + +import org.apache.flink.api.common.state.ListState; +import org.apache.flink.api.common.state.ListStateDescriptor; +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeutils.base.LongSerializer; +import org.apache.flink.api.common.typeutils.base.StringSerializer; +import org.apache.flink.runtime.checkpoint.CheckpointMetaData; +import org.apache.flink.runtime.checkpoint.CheckpointOptions; +import org.apache.flink.runtime.checkpoint.OperatorSubtaskState; +import org.apache.flink.runtime.checkpoint.StateAssignmentOperation; +import org.apache.flink.runtime.checkpoint.TaskStateSnapshot; +import org.apache.flink.runtime.jobgraph.OperatorID; +import org.apache.flink.runtime.jobgraph.OperatorInstanceID; +import org.apache.flink.runtime.operators.testutils.MockInputSplitProvider; +import org.apache.flink.runtime.state.StateInitializationContext; +import org.apache.flink.runtime.state.StateSnapshotContext; +import org.apache.flink.streaming.api.operators.AbstractStreamOperator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.streaming.util.TestHarnessUtil; +import org.apache.flink.util.TestLogger; + +import org.junit.Test; + +import java.util.Collections; +import java.util.Optional; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.atomic.AtomicLong; + +import static org.junit.Assert.assertEquals; + +/** + * Tests ensuring correct behaviour of {@link org.apache.flink.runtime.state.ManagedInitializationContext#isRestored} + * method. + */ +public class RestoreStreamTaskTest extends TestLogger { + @Test + public void testRestore() throws Exception { + AcknowledgeStreamMockEnvironment environment1 = processRecords( + new OperatorID(42L, 42L), + new CounterOperator(), + new OperatorID(44L, 44L), + new CounterOperator(), + Optional.empty()); + + assertEquals(2, environment1.getCheckpointStateHandles().getSubtaskStateMappings().size()); + + TaskStateSnapshot stateHandles = environment1.getCheckpointStateHandles(); + + try { + AcknowledgeStreamMockEnvironment environment2 = processRecords( + new OperatorID(42L, 42L), + new RestoreCounterOperator(), + new OperatorID(44L, 44L), + new RestoreCounterOperator(), + Optional.of(stateHandles)); + + assertEquals(2, RestoreCounterOperator.RESTORE_COUNTER.get()); + } + finally { + RestoreCounterOperator.RESTORE_COUNTER.getAndSet(0); + } + } + + @Test + public void testRestoreWithNewId() throws Exception { + AcknowledgeStreamMockEnvironment environment1 = processRecords( + new OperatorID(42L, 42L), + new CounterOperator(), + new OperatorID(44L, 44L), + new CounterOperator(), + Optional.empty()); + + assertEquals(2, environment1.getCheckpointStateHandles().getSubtaskStateMappings().size()); + + TaskStateSnapshot stateHandles = environment1.getCheckpointStateHandles(); + + try { + AcknowledgeStreamMockEnvironment environment2 = processRecords( + new OperatorID(4242L, 4242L), + new RestoreCounterOperator(), + new OperatorID(44L, 44L), + new RestoreCounterOperator(), + Optional.of(stateHandles)); + + assertEquals(1, RestoreCounterOperator.RESTORE_COUNTER.get()); + } + finally { + RestoreCounterOperator.RESTORE_COUNTER.getAndSet(0); + } + } + + @Test + public void testRestoreAfterScaleUp() throws Exception { + OperatorID headOperatorID = new OperatorID(42L, 42L); + OperatorID tailOperatorID = new OperatorID(44L, 44L); + + AcknowledgeStreamMockEnvironment environment1 = processRecords( + headOperatorID, + new CounterOperator(), + tailOperatorID, + new CounterOperator(), + Optional.empty()); + + assertEquals(2, environment1.getCheckpointStateHandles().getSubtaskStateMappings().size()); + + // test empty state in case of scale up + OperatorSubtaskState emptyHeadOperatorState = StateAssignmentOperation.operatorSubtaskStateFrom( + new OperatorInstanceID(0, headOperatorID), + Collections.emptyMap(), + Collections.emptyMap(), + Collections.emptyMap(), + Collections.emptyMap()); + + TaskStateSnapshot stateHandles = environment1.getCheckpointStateHandles(); + stateHandles.putSubtaskStateByOperatorID(headOperatorID, emptyHeadOperatorState); --- End diff -- I would say it's great to have this unit test, eventually an IT case could also make sense. But this can be done in a different work / PR. > Detecting whether an operator is restored doesn't work with chained state > ------------------------------------------------------------------------- > > Key: FLINK-7623 > URL: https://issues.apache.org/jira/browse/FLINK-7623 > Project: Flink > Issue Type: Bug > Components: DataStream API, State Backends, Checkpointing > Affects Versions: 1.4.0, 1.3.2 > Reporter: Aljoscha Krettek > Assignee: Piotr Nowojski > Priority: Blocker > Fix For: 1.4.0, 1.3.3 > > Attachments: StreamingJob.java > > > Originally reported on the ML: https://lists.apache.org/thread.html/22a2cf83de3107aa81a03a921325a191c29df8aa8676798fcd497199@%3Cuser.flink.apache.org%3E > If we have a chain of operators where multiple of them have operator state, detection of the {{context.isRestored()}} flag (of {{CheckpointedFunction}}) does not work correctly. It's best exemplified using this minimal example where both the source and the flatMap have state: > {code} > final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); > env > .addSource(new MaSource()).uid("source-1") > .flatMap(new MaFlatMap()).uid("flatMap-1"); > env.execute("testing"); > {code} > If I do a savepoint with these UIDs, then change "source-1" to "source-2" and restore from the savepoint {{context.isRestored()}} still reports {{true}} for the source. -- This message was sent by Atlassian JIRA (v6.4.14#64029)