luoyuxia commented on code in PR #1984:
URL: https://github.com/apache/fluss/pull/1984#discussion_r2682239540


##########
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/lake/values/tiering/ValuesLakeWriter.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.lake.values.tiering;
+
+import org.apache.fluss.lake.serializer.SimpleVersionedSerializer;
+import org.apache.fluss.lake.values.ValuesLake;
+import org.apache.fluss.lake.writer.LakeWriter;
+import org.apache.fluss.record.LogRecord;
+import org.apache.fluss.utils.InstantiationUtils;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.UUID;
+
+/** Implementation of {@link LakeWriter} for values lake. */
+public class ValuesLakeWriter implements 
LakeWriter<ValuesLakeWriter.ValuesWriteResult> {
+    private final String tableId;
+    private final String stageId;

Review Comment:
   I'm wondering whether `stageId` rename to `writerId` is better?



##########
fluss-flink/fluss-flink-common/src/main/java/org/apache/fluss/flink/tiering/committer/TieringCommitOperator.java:
##########
@@ -108,29 +103,14 @@ public TieringCommitOperator(
         this.collectedTableBucketWriteResults = new HashMap<>();
         this.flussConfig = flussConf;
         this.lakeTieringConfig = lakeTieringConfig;
-        this.operatorEventGateway =
-                parameters
-                        .getOperatorEventDispatcher()
-                        
.getOperatorEventGateway(TieringSource.TIERING_SOURCE_OPERATOR_UID);
         this.setup(
                 parameters.getContainingTask(),
                 parameters.getStreamConfig(),
                 parameters.getOutput());
-    }
-
-    @Override
-    public void setup(
-            StreamTask<?, ?> containingTask,
-            StreamConfig config,
-            Output<StreamRecord<CommittableMessage<Committable>>> output) {
-        super.setup(containingTask, config, output);
-        int attemptNumber = 
RuntimeContextAdapter.getAttemptNumber(getRuntimeContext());
-        if (attemptNumber > 0) {
-            LOG.info("Send TieringFailoverEvent, current attempt number: {}", 
attemptNumber);
-            // attempt number is greater than zero, the job must failover
-            operatorEventGateway.sendEventToCoordinator(
-                    new SourceEventWrapper(new TieringFailOverEvent()));
-        }
+        this.operatorEventGateway =
+                parameters
+                        .getOperatorEventDispatcher()
+                        
.getOperatorEventGateway(TieringSource.TIERING_SOURCE_OPERATOR_UID);

Review Comment:
   Now, we can remove `RuntimeContextAdapter` now..



##########
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/lake/values/ValuesLake.java:
##########
@@ -0,0 +1,212 @@
+/*
+ * 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.lake.values;
+
+import org.apache.fluss.record.LogRecord;
+import org.apache.fluss.row.InternalRow;
+import org.apache.fluss.utils.MapUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import static org.apache.fluss.utils.Preconditions.checkNotNull;
+import static org.apache.fluss.utils.concurrent.LockUtils.inLock;
+
+/**
+ * An in-memory lake storage implementation for testing, supporting only log 
tables.
+ *
+ * <p>Provides utilities for managing tables, writing records, committing 
stages, and retrieving
+ * results in a test environment.
+ */
+public class ValuesLake {

Review Comment:
   The same to other Valuesxxxx



##########
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/tiering/FlinkValuesTieringTestBase.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.client.Connection;
+import org.apache.fluss.client.ConnectionFactory;
+import org.apache.fluss.client.admin.Admin;
+import org.apache.fluss.client.table.Table;
+import org.apache.fluss.client.table.writer.TableWriter;
+import org.apache.fluss.client.table.writer.UpsertWriter;
+import org.apache.fluss.config.ConfigOptions;
+import org.apache.fluss.config.Configuration;
+import org.apache.fluss.fs.FsPath;
+import org.apache.fluss.lake.values.ValuesLake;
+import org.apache.fluss.metadata.DataLakeFormat;
+import org.apache.fluss.metadata.Schema;
+import org.apache.fluss.metadata.TableBucket;
+import org.apache.fluss.metadata.TableDescriptor;
+import org.apache.fluss.metadata.TablePath;
+import org.apache.fluss.row.InternalRow;
+import org.apache.fluss.server.replica.Replica;
+import org.apache.fluss.server.testutils.FlussClusterExtension;
+import org.apache.fluss.server.zk.data.lake.LakeTable;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.fluss.lake.committer.LakeCommitter.FLUSS_LAKE_SNAP_BUCKET_OFFSET_PROPERTY;
+import static org.apache.fluss.testutils.common.CommonTestUtils.retry;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Test base for tiering to Values Lake by Flink. */
+class FlinkValuesTieringTestBase {

Review Comment:
   nit:
   rename to FlinkTieringTestBase?



##########
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/lake/values/ValuesLake.java:
##########
@@ -0,0 +1,312 @@
+/*
+ * 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.lake.values;
+
+import org.apache.fluss.metadata.Schema;
+import org.apache.fluss.record.LogRecord;
+import org.apache.fluss.row.InternalRow;
+import org.apache.fluss.utils.MapUtils;
+import org.apache.fluss.utils.types.Tuple2;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.apache.fluss.utils.Preconditions.checkArgument;
+import static org.apache.fluss.utils.Preconditions.checkNotNull;
+
+/**
+ * In-memory implementation of a lake storage for testing purposes.
+ *
+ * <p>Provides utilities for managing tables, writing records, committing 
stages, and retrieving
+ * results in a test environment.
+ */
+public class ValuesLake {
+    private static final Logger LOG = 
LoggerFactory.getLogger(ValuesLake.class);
+
+    private static final Map<String, ValuesTable> globalTables = 
MapUtils.newConcurrentHashMap();
+    private static final Map<String, TableFailureController> 
FAILURE_CONTROLLERS =
+            MapUtils.newConcurrentHashMap();
+
+    public static TableFailureController failWhen(String tableId) {
+        return FAILURE_CONTROLLERS.computeIfAbsent(tableId, k -> new 
TableFailureController());
+    }
+
+    public static void clearAllFailureControls() {
+        FAILURE_CONTROLLERS.clear();
+    }
+
+    public static Schema getTableSchema(String tableId) {
+        return globalTables.get(tableId).schema;
+    }
+
+    public static List<InternalRow> getResults(String tableId) {
+        ValuesTable table = globalTables.get(tableId);
+        checkNotNull(table, tableId + " does not exist");
+        return table.getResult();
+    }
+
+    public static void writeRecord(String tableId, String stageId, LogRecord 
record)
+            throws IOException {
+        ValuesTable table = globalTables.get(tableId);
+        checkNotNull(table, tableId + " does not exist");
+        TableFailureController controller = FAILURE_CONTROLLERS.get(tableId);
+        if (controller != null) {
+            controller.checkWriteShouldFail(tableId);
+        }
+        table.writeRecord(stageId, record);
+        LOG.info("Write record to stage {}: {}", stageId, record);
+    }
+
+    public static long commit(
+            String tableId, List<String> stageIds, Map<String, String> 
snapshotProperties)
+            throws IOException {
+        ValuesTable table = globalTables.get(tableId);
+        checkNotNull(table, "commit stage %s failed, table %s does not exist", 
stageIds, tableId);
+        table.commit(stageIds, snapshotProperties);
+        LOG.info("Commit table {} stage {}", tableId, stageIds);
+        return table.getSnapshotId();
+    }
+
+    public static void abort(String tableId, List<String> stageIds) {
+        ValuesTable table = globalTables.get(tableId);
+        checkNotNull(
+                table, "abort stage record %s failed, table %s does not 
exist", stageIds, tableId);
+        table.abort(stageIds);
+        LOG.info("Abort table {} stage {}", tableId, stageIds);
+    }
+
+    public static ValuesTable getTable(String tableId) {
+        return globalTables.get(tableId);
+    }
+
+    public static void createTable(String tableId, Schema schema) {
+        if (!globalTables.containsKey(tableId)) {
+            globalTables.put(tableId, new ValuesTable(schema));
+            ValuesTable table = globalTables.get(tableId);
+            checkNotNull(table, "create table %s failed", tableId);
+        }
+    }
+
+    public static void dropTable(String tableId) {
+        globalTables.remove(tableId);
+    }
+
+    public static void truncateTable(String tableId) {
+        ValuesTable table = globalTables.get(tableId);
+        checkNotNull(table, "truncate table %s failed", tableId);
+        table.truncateTable();
+    }
+
+    public static void clear() {
+        globalTables.clear();
+    }
+
+    /** maintain the columns, primaryKeys and records of a specific table in 
memory. */
+    public static class ValuesTable {
+
+        private final Object lock;
+
+        // [primaryKeys, rowValue]
+        private final Map<String, InternalRow> records;
+        private final List<InternalRow> logRecords;
+        private final Map<String, List<Tuple2<String, LogRecord>>> 
stageRecords;
+        private final Map<String, List<LogRecord>> stageLogRecords;
+        private final Schema schema;
+
+        private final List<Schema.Column> columns;
+
+        private final List<String> primaryKeys;
+
+        // indexes of primaryKeys in columns
+        private final List<Integer> primaryKeyIndexes;
+
+        private long snapshotId = 0L;
+
+        private final Map<Long, Map<String, String>> snapshotProperties = new 
HashMap<>();

Review Comment:
   Actaully, we don't need in testing..We don't need 
`checkFlussOffsetsInValues` in the test that is to test failover.



##########
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/lake/values/ValuesLake.java:
##########
@@ -0,0 +1,212 @@
+/*
+ * 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.lake.values;
+
+import org.apache.fluss.record.LogRecord;
+import org.apache.fluss.row.InternalRow;
+import org.apache.fluss.utils.MapUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import static org.apache.fluss.utils.Preconditions.checkNotNull;
+import static org.apache.fluss.utils.concurrent.LockUtils.inLock;
+
+/**
+ * An in-memory lake storage implementation for testing, supporting only log 
tables.
+ *
+ * <p>Provides utilities for managing tables, writing records, committing 
stages, and retrieving
+ * results in a test environment.
+ */
+public class ValuesLake {

Review Comment:
   nit: rename to `TestingValuesLake`



##########
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/tiering/source/enumerator/TieringSourceEnumeratorTest.java:
##########
@@ -629,8 +610,9 @@ void testHandleFailedTieringTableEvent() throws Throwable {
         }
     }
 
-    @Test
-    void testHandleFailOverEvent() throws Throwable {
+    @ParameterizedTest
+    @ValueSource(ints = {1, 2})

Review Comment:
   nit: maybe we can always test with numSubtasks = 3 instead run two tests(one 
use 1 as numSubtasks, one use 2) to reduce test?



##########
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/lake/values/tiering/ValuesLakeCommitter.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.lake.values.tiering;
+
+import org.apache.fluss.lake.committer.CommittedLakeSnapshot;
+import org.apache.fluss.lake.committer.LakeCommitter;
+import org.apache.fluss.lake.serializer.SimpleVersionedSerializer;
+import org.apache.fluss.lake.values.ValuesLake;
+import org.apache.fluss.utils.InstantiationUtils;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/** Implementation of {@link LakeCommitter} for values lake. */
+public class ValuesLakeCommitter
+        implements LakeCommitter<
+                ValuesLakeWriter.ValuesWriteResult, 
ValuesLakeCommitter.ValuesCommittable> {
+    private final String tableId;
+
+    public ValuesLakeCommitter(String tableId) {
+        this.tableId = tableId;
+    }
+
+    @Override
+    public ValuesCommittable toCommittable(
+            List<ValuesLakeWriter.ValuesWriteResult> valuesWriteResults) 
throws IOException {
+        return new ValuesCommittable(
+                valuesWriteResults.stream()
+                        .map(ValuesLakeWriter.ValuesWriteResult::getStageId)
+                        .collect(Collectors.toList()));
+    }
+
+    @Override
+    public long commit(ValuesCommittable committable, Map<String, String> 
snapshotProperties)
+            throws IOException {
+        return ValuesLake.commit(tableId, committable.getStageIds(), 
snapshotProperties);
+    }
+
+    @Override
+    public void abort(ValuesCommittable committable) throws IOException {
+        ValuesLake.abort(tableId, committable.getStageIds());
+    }
+
+    @Override
+    public CommittedLakeSnapshot getMissingLakeSnapshot(@Nullable Long 
latestLakeSnapshotIdOfFluss)
+            throws IOException {
+        ValuesLake.ValuesTable table = ValuesLake.getTable(tableId);

Review Comment:
   we can just return null for simpility



-- 
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]

Reply via email to