beryllw commented on code in PR #1984: URL: https://github.com/apache/fluss/pull/1984#discussion_r2675205628
########## fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/tiering/TieringFailoverITCase.java: ########## @@ -0,0 +1,346 @@ +/* + * 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.fluss.flink.tiering; + +import org.apache.fluss.config.Configuration; +import org.apache.fluss.flink.tiering.committer.CommittableMessageTypeInfo; +import org.apache.fluss.flink.tiering.committer.TieringCommitOperatorFactory; +import org.apache.fluss.flink.tiering.source.TableBucketWriteResultTypeInfo; +import org.apache.fluss.flink.tiering.source.TieringSource; +import org.apache.fluss.lake.values.ValuesLake; +import org.apache.fluss.lake.values.tiering.ValuesLakeTieringFactory; +import org.apache.fluss.lake.writer.LakeTieringFactory; +import org.apache.fluss.metadata.Schema; +import org.apache.fluss.metadata.TableBucket; +import org.apache.fluss.metadata.TablePath; +import org.apache.fluss.row.BinaryString; +import org.apache.fluss.row.Decimal; +import org.apache.fluss.row.InternalRow; +import org.apache.fluss.row.TimestampLtz; +import org.apache.fluss.row.TimestampNtz; +import org.apache.fluss.types.DataTypes; +import org.apache.fluss.utils.TypeUtils; + +import org.apache.flink.api.common.eventtime.WatermarkStrategy; +import org.apache.flink.configuration.PipelineOptions; +import org.apache.flink.core.execution.JobClient; +import org.apache.flink.streaming.api.datastream.DataStreamSource; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.sink.v2.DiscardingSink; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import static org.apache.fluss.flink.tiering.source.TieringSource.TIERING_SOURCE_TRANSFORMATION_UID; +import static org.apache.fluss.flink.tiering.source.TieringSourceOptions.POLL_TIERING_TABLE_INTERVAL; +import static org.apache.fluss.lake.committer.BucketOffset.FLUSS_LAKE_SNAP_BUCKET_OFFSET_PROPERTY; +import static org.apache.fluss.testutils.DataTestUtils.row; +import static org.assertj.core.api.Assertions.assertThat; + +/** Test tiering failover. */ +class TieringFailoverITCase extends FlinkValuesTieringTestBase { + protected static final String DEFAULT_DB = "fluss"; + + private static StreamExecutionEnvironment execEnv; + + private static final Schema pkSchema = + Schema.newBuilder() + .column("f_boolean", DataTypes.BOOLEAN()) + .column("f_byte", DataTypes.TINYINT()) + .column("f_short", DataTypes.SMALLINT()) + .column("f_int", DataTypes.INT()) + .column("f_long", DataTypes.BIGINT()) + .column("f_float", DataTypes.FLOAT()) + .column("f_double", DataTypes.DOUBLE()) + .column("f_string", DataTypes.STRING()) + .column("f_decimal1", DataTypes.DECIMAL(5, 2)) + .column("f_decimal2", DataTypes.DECIMAL(20, 0)) + .column("f_timestamp_ltz1", DataTypes.TIMESTAMP_LTZ(3)) + .column("f_timestamp_ltz2", DataTypes.TIMESTAMP_LTZ(6)) + .column("f_timestamp_ntz1", DataTypes.TIMESTAMP(3)) + .column("f_timestamp_ntz2", DataTypes.TIMESTAMP(6)) + .column("f_binary", DataTypes.BINARY(4)) + .column("f_date", DataTypes.DATE()) + .column("f_time", DataTypes.TIME()) + .column("f_char", DataTypes.CHAR(3)) + .column("f_bytes", DataTypes.BYTES()) + .primaryKey("f_string") + .build(); + + @BeforeAll + protected static void beforeAll() { + FlinkValuesTieringTestBase.beforeAll(); + execEnv = StreamExecutionEnvironment.getExecutionEnvironment(); + execEnv.setParallelism(2); + execEnv.enableCheckpointing(1000); + } + + @Test + void testTiering() throws Exception { + // create a pk table, write some records and wait until snapshot finished + TablePath t1 = TablePath.of(DEFAULT_DB, "pkTable"); + long t1Id = createPkTable(t1, 1, false, pkSchema); + TableBucket t1Bucket = new TableBucket(t1Id, 0); + // write records + List<InternalRow> rows = + Arrays.asList( + row( + true, + (byte) 100, + (short) 200, + 1, + 1 + 400L, + 500.1f, + 600.0d, + "v1", + Decimal.fromUnscaledLong(900, 5, 2), + Decimal.fromBigDecimal(new java.math.BigDecimal(1000), 20, 0), + TimestampLtz.fromEpochMillis(1698235273400L), + TimestampLtz.fromEpochMillis(1698235273400L, 7000), + TimestampNtz.fromMillis(1698235273501L), + TimestampNtz.fromMillis(1698235273501L, 8000), + new byte[] {5, 6, 7, 8}, + TypeUtils.castFromString("2023-10-25", DataTypes.DATE()), + TypeUtils.castFromString("09:30:00.0", DataTypes.TIME()), + BinaryString.fromString("abc"), + new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}), + row( + true, + (byte) 100, + (short) 200, + 2, + 2 + 400L, + 500.1f, + 600.0d, + "v2", + Decimal.fromUnscaledLong(900, 5, 2), + Decimal.fromBigDecimal(new java.math.BigDecimal(1000), 20, 0), + TimestampLtz.fromEpochMillis(1698235273400L), + TimestampLtz.fromEpochMillis(1698235273400L, 7000), + TimestampNtz.fromMillis(1698235273501L), + TimestampNtz.fromMillis(1698235273501L, 8000), + new byte[] {5, 6, 7, 8}, + TypeUtils.castFromString("2023-10-25", DataTypes.DATE()), + TypeUtils.castFromString("09:30:00.0", DataTypes.TIME()), + BinaryString.fromString("abc"), + new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}), + row( + true, + (byte) 100, + (short) 200, + 3, + 3 + 400L, + 500.1f, + 600.0d, + "v3", + Decimal.fromUnscaledLong(900, 5, 2), + Decimal.fromBigDecimal(new java.math.BigDecimal(1000), 20, 0), + TimestampLtz.fromEpochMillis(1698235273400L), + TimestampLtz.fromEpochMillis(1698235273400L, 7000), + TimestampNtz.fromMillis(1698235273501L), + TimestampNtz.fromMillis(1698235273501L, 8000), + new byte[] {5, 6, 7, 8}, + TypeUtils.castFromString("2023-10-25", DataTypes.DATE()), + TypeUtils.castFromString("09:30:00.0", DataTypes.TIME()), + BinaryString.fromString("abc"), + new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})); + List<InternalRow> expectedRows = new ArrayList<>(rows); + writeRows(t1, rows); + waitUntilSnapshot(t1Id, 1, 0); + + // fail the first write to the pk table + ValuesLake.failWhen(t1.toString()).failWriteOnce(); + + // then start tiering job + JobClient jobClient = buildTieringJob(execEnv); + try { + // check the status of replica after synced + assertReplicaStatus(t1Bucket, 3); + + checkDataInValuesPrimaryKeyTable(t1, rows); + // check snapshot property in values lake Review Comment: We’d better check to make sure no data is missing. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
