You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/03/24 18:20:44 UTC
[GitHub] [iceberg] stevenzwu opened a new pull request #4329: Flink: FLIP-27 source enumerator help classes
stevenzwu opened a new pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329
It mainly contains classes for streaming read (continuous split discovery) along with config and enumeration position classes.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828645753
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
i still have a litter concern, let's take an example:
1. Table T initially has some snapshots S1, S2 with data files F1-3;
2. Then table T appends F4-5 with S3, and F6 with S4;
3. Now S1, S2 are removed based on retention policy, and table T has snapshots S3, S4 with data files F1-6.
Now S3 is the earliest snapshot, right?
IIUC, the current implementation will scan only F6 and the following append files.
I think we should scan F4-6 for `EARLIEST_SNAPSHOT` strategy to correspond to `LATEST_SNAPSHOT` strategy.
WDYT, @stevenzwu
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828131536
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/IcebergEnumeratorConfig.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.io.Serializable;
+import java.time.Duration;
+import org.apache.flink.util.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+
+/**
+ * Settings for continuous split enumeration
+ */
+public class IcebergEnumeratorConfig implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public enum StartingStrategy {
+ /**
+ * First do a regular table scan.
+ * then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from the earliest snapshot
+ */
+ EARLIEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from a specific startSnapshotId
+ */
+ SPECIFIC_START_SNAPSHOT_ID,
+
+ /**
+ * Start incremental mode from a specific startTimestamp.
+ * Starting snapshot has a timestamp lower than or equal to the specified timestamp.
+ */
+ SPECIFIC_START_SNAPSHOT_TIMESTAMP
+ }
+
+ // for continuous enumerator
+ private final Duration splitDiscoveryInterval;
+ private final StartingStrategy startingStrategy;
+ private final Long startSnapshotId;
+ private final Long startSnapshotTimeMs;
+
+ private IcebergEnumeratorConfig(Builder builder) {
+ this.splitDiscoveryInterval = builder.splitDiscoveryInterval;
+ this.startingStrategy = builder.startingStrategy;
+ this.startSnapshotId = builder.startSnapshotId;
+ this.startSnapshotTimeMs = builder.startSnapshotTimeMs;
+ }
+
+ public Duration splitDiscoveryInterval() {
+ return splitDiscoveryInterval;
+ }
+
+ public StartingStrategy startingStrategy() {
+ return startingStrategy;
+ }
+
+ public Long startSnapshotId() {
+ return startSnapshotId;
+ }
+
+ public Long startSnapshotTimeMs() {
+ return startSnapshotTimeMs;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("splitDiscoveryInterval", splitDiscoveryInterval)
+ .add("startingStrategy", startingStrategy)
+ .add("startSnapshotId", startSnapshotId)
+ .add("startSnapshotTimeMs", startSnapshotTimeMs)
+ .toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private Duration splitDiscoveryInterval;
+ private StartingStrategy startingStrategy = StartingStrategy.LATEST_SNAPSHOT;
+ private Long startSnapshotId;
+ private Long startSnapshotTimeMs;
+
+ private Builder() {
+ }
+
+ /**
+ * This is required for continuous enumerator in streaming read
+ */
+ public Builder splitDiscoveryInterval(Duration interval) {
+ this.splitDiscoveryInterval = interval;
+ return this;
+ }
+
+ public Builder startingStrategy(StartingStrategy strategy) {
+ this.startingStrategy = strategy;
+ return this;
+ }
Review comment:
agree, I like your suggestion.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r833882073
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-enumerator-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Snapshot startSnapshot = getStartSnapshot(table, scanContext);
+ LOG.info("Get starting snapshot id {} based on strategy {}",
+ startSnapshot.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshot Id {}",
+ splits.size(), startSnapshot.snapshotId());
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshot.snapshotId())
+ .endSnapshotTimestampMs(startSnapshot.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static Snapshot getStartSnapshot(Table table, ScanContext scanContext) {
Review comment:
How would you deal with an empty table, i.e. no snapshots are produced?
Guess this method should return an `Optional<Snapshot>` ?
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-enumerator-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
Review comment:
nit: this else is not necessary.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r835777538
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-plan-worker-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Optional<Snapshot> startSnapshotOptional = getStartSnapshot(table, scanContext);
+ if (!startSnapshotOptional.isPresent()) {
+ // set IcebergEnumeratorPosition to null in this case
+ return new ContinuousEnumerationResult(Collections.emptyList(), null);
+ }
Review comment:
agree it is not just the first snapshot. I was using it just to simplify the discussion. it doesn't really matter how many snapshots are committed before the first discovery. semantics are the same.
I was saying `earliest` or `latest` snapshot can be interpreted as the earliest or latest valid snapshot of the table. Let's say when the Flink job started, it is an empty table. initial scan return null.
* case 1: there are 3 snapshots (S1, S2, S3) committed. Now Flink source ran initial scan again. For earliest strategy, S1 will be used as starting snapshot. For latest strategy, S3 will be used as starting snapshot.
* case 2: there is 1 snapshot committed. Now both earliest and latest strategy will discover S1 as starting snapshot
regarding -1 snapshot id, is it a reserved special id? I wouldn't find the usage for snapshot id. Also, `IncrementalDataTableScan` seems to validate the start snapshot id. This may not work.
```
Preconditions.checkArgument(
snapshotIdsRange.contains(newFromSnapshotId),
"from snapshot id %s not in existing snapshot ids range (%s, %s]",
newFromSnapshotId, context().fromSnapshotId(), newToSnapshotId);
```
@yittg I definitely see your perspective, which is a valid interpretation of earliest and latest for empty table. In your interpretation, earliest and latest will behave the same (with some imaginary snapshot as starting point). all future snapshot should be discovered. To implement this model, we need to change `appendsBetween` implementation to support a special starting snapshot id, which is invalid and yet indicates a special starting point.
To me, both interpretations are reasonable. I also think for the practical purpose, how to interpret earliest and latest strategy for an empty table is not that important for streaming job. Most of the streaming job's bootstrap point is not really important, as it is arbitrary anyway.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r836001364
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-plan-worker-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Optional<Snapshot> startSnapshotOptional = getStartSnapshot(table, scanContext);
+ if (!startSnapshotOptional.isPresent()) {
+ // set IcebergEnumeratorPosition to null in this case
+ return new ContinuousEnumerationResult(Collections.emptyList(), null);
+ }
Review comment:
sounds reasonable to me, thanks.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828645753
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
i still have a litter concern, let's take an example:
1. Table T initially has some snapshots S1, S2 with data files F1-3;
2. Then table T append F4, F5 with S3, and F6 with S4;
3. Now S1, S2 are removed based on retention policy, and table T has snapshots S3, S4 with data files F1-6.
Now S3 is the earliest snapshot, right?
IIUC, the current implementation will scan only F6 and the following append files.
I think we should scan F4-6 for `EARLIEST_SNAPSHOT` strategy to correspond to `LATEST_SNAPSHOT` strategy.
WDYT, @stevenzwu
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830173164
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -114,77 +128,100 @@ private ScanContext(boolean caseSensitive, Long snapshotId, Long startSnapshotId
this.includeColumnStats = includeColumnStats;
this.exposeLocality = exposeLocality;
this.planParallelism = planParallelism;
+
+ validate();
+ }
+
+ private void validate() {
+ if (isStreaming) {
+ if (startingStrategy == StreamingStartingStrategy.SPECIFIC_START_SNAPSHOT_ID) {
+ Preconditions.checkArgument(startSnapshotId != null,
+ "startSnapshotId cannot be null for SPECIFIC_START_SNAPSHOT_ID starting strategy");
Review comment:
We probably want to remove the specific variable names from the error messages. And we also phrase error messages more directly: `(Problem): (context)`
This should probably be: `Invalid starting snapshot for SPECIFIC_START_SNAPSHOT_ID strategy: null`
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830182614
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
Review comment:
Isn't it possible to process the table twice in the same JVM? I agree operator ID would be better.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831295868
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
Review comment:
make the thread pool name a constructor argument.
Because FLIP-27 source interface doesn't expose the operator ID, for now `tableName-UUID` is used to guarantee uniqueness. comments will be updated.
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -114,77 +128,100 @@ private ScanContext(boolean caseSensitive, Long snapshotId, Long startSnapshotId
this.includeColumnStats = includeColumnStats;
this.exposeLocality = exposeLocality;
this.planParallelism = planParallelism;
+
+ validate();
+ }
+
+ private void validate() {
+ if (isStreaming) {
+ if (startingStrategy == StreamingStartingStrategy.SPECIFIC_START_SNAPSHOT_ID) {
+ Preconditions.checkArgument(startSnapshotId != null,
+ "startSnapshotId cannot be null for SPECIFIC_START_SNAPSHOT_ID starting strategy");
Review comment:
will update
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831381400
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, ScanContext scanContext) {
+ List<HistoryEntry> historyEntries = table.history();
+ HistoryEntry startEntry;
+ switch (scanContext.startingStrategy()) {
+ case TABLE_SCAN_THEN_INCREMENTAL:
+ case LATEST_SNAPSHOT:
+ startEntry = historyEntries.get(historyEntries.size() - 1);
+ break;
+ case EARLIEST_SNAPSHOT:
+ startEntry = historyEntries.get(0);
+ break;
+ case SPECIFIC_START_SNAPSHOT_ID:
+ Optional<HistoryEntry> matchedEntry = historyEntries.stream()
+ .filter(entry -> entry.snapshotId() == scanContext.startSnapshotId())
+ .findFirst();
+ if (matchedEntry.isPresent()) {
+ startEntry = matchedEntry.get();
+ } else {
+ throw new IllegalArgumentException(
+ "Snapshot id not found in history: {}" + scanContext.startSnapshotId());
+ }
+ break;
+ case SPECIFIC_START_SNAPSHOT_TIMESTAMP:
Review comment:
will switch
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, ScanContext scanContext) {
+ List<HistoryEntry> historyEntries = table.history();
+ HistoryEntry startEntry;
+ switch (scanContext.startingStrategy()) {
+ case TABLE_SCAN_THEN_INCREMENTAL:
+ case LATEST_SNAPSHOT:
+ startEntry = historyEntries.get(historyEntries.size() - 1);
+ break;
+ case EARLIEST_SNAPSHOT:
Review comment:
will switch
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828497404
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
Review comment:
merged the `IcebergEnumeratorConfig` into `ScanContext`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828682805
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
yes, that is the current behavior for exclusive starting snapshot. Because EARLIEST_SNAPSHOT is S3, the incremental scan of (S3, S4], we will only scan F6 only (committed by S4).
if it is LATEST_SNAPSHOT (S4), there won't be any files from F1-F6. Only the files are committed by the next snapshot (S5) will be discovered.
@yittg you like to make the starting snapshot inclusive (vs exclusive that is currently implemented), right? It is doable, although a little more complexity. If that is what other people favor, we can make the change.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828605197
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, IcebergEnumeratorConfig enumeratorConfig) {
Review comment:
IIUC, these strategies mean semantic with AFTER?
EARLIEST_SNAPSHOT actually means START_AFTER_ EARLIEST_SNAPSHOT;
SPECIFIC_START_SNAPSHOT_ID actually means START_AFTER_SNAPSHOT_ID;
SPECIFIC_START_SNAPSHOT_TIMESTAMP actually means START_AFTER_SNAPSHOT_TIMESTAMP;
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828605197
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, IcebergEnumeratorConfig enumeratorConfig) {
Review comment:
IIUC, these strategies mean semantic with AFTER?
EARLIEST_SNAPSHOT actually means AFTER_ EARLIEST_SNAPSHOT;
SPECIFIC_START_SNAPSHOT_ID actually means START_AFTER_SNAPSHOT_ID;
SPECIFIC_START_SNAPSHOT_TIMESTAMP actually means START_AFTER_SNAPSHOT_TIMESTAMP;
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r834877847
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-plan-worker-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Optional<Snapshot> startSnapshotOptional = getStartSnapshot(table, scanContext);
+ if (!startSnapshotOptional.isPresent()) {
+ // set IcebergEnumeratorPosition to null in this case
+ return new ContinuousEnumerationResult(Collections.emptyList(), null);
+ }
Review comment:
guess we can not return null position here, then the next plan will still invoke `#discoverInitialSplits`. If some snapshots produced during this period, they will be seen as start snapshots and excluded.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830191916
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, ScanContext scanContext) {
+ List<HistoryEntry> historyEntries = table.history();
+ HistoryEntry startEntry;
+ switch (scanContext.startingStrategy()) {
+ case TABLE_SCAN_THEN_INCREMENTAL:
+ case LATEST_SNAPSHOT:
+ startEntry = historyEntries.get(historyEntries.size() - 1);
+ break;
+ case EARLIEST_SNAPSHOT:
+ startEntry = historyEntries.get(0);
+ break;
+ case SPECIFIC_START_SNAPSHOT_ID:
+ Optional<HistoryEntry> matchedEntry = historyEntries.stream()
Review comment:
`table.snapshot(snapshotId)`
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r833882072
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-enumerator-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Snapshot startSnapshot = getStartSnapshot(table, scanContext);
+ LOG.info("Get starting snapshot id {} based on strategy {}",
+ startSnapshot.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshot Id {}",
+ splits.size(), startSnapshot.snapshotId());
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshot.snapshotId())
+ .endSnapshotTimestampMs(startSnapshot.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static Snapshot getStartSnapshot(Table table, ScanContext scanContext) {
Review comment:
How would you deal with an empty table, i.e. no snapshots are produced?
Guess this method should return an `Optional<Snapshot>` ?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] openinx commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
openinx commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r840999463
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -114,77 +128,104 @@ private ScanContext(boolean caseSensitive, Long snapshotId, Long startSnapshotId
this.includeColumnStats = includeColumnStats;
this.exposeLocality = exposeLocality;
this.planParallelism = planParallelism;
+
+ validate();
+ }
+
+ private void validate() {
+ if (isStreaming) {
Review comment:
Will it be allowed to set any `startingStrategy` value if it's in batch mode ?
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -114,77 +128,104 @@ private ScanContext(boolean caseSensitive, Long snapshotId, Long startSnapshotId
this.includeColumnStats = includeColumnStats;
this.exposeLocality = exposeLocality;
this.planParallelism = planParallelism;
+
+ validate();
+ }
+
+ private void validate() {
+ if (isStreaming) {
+ if (startingStrategy == StreamingStartingStrategy.SPECIFIC_START_SNAPSHOT_ID) {
Review comment:
Should we also consider the validation for other `strategy`s ?
* `TABLE_SCAN_THEN_INCREMENTAL`
Will the `startSnapshotId` or `startSnapshotTimestamp` specify the first snapshot to do the regular table scan ? Is there any meaning to set the `startSnapshotTimestamp` ?
* LATEST_SNAPSHOT
As we always read data from the latest available snapshot, so is there any meaning to set the `startSnapshotId`, `startSnapshotTimestamp`, `endSnapshotId`, `asOfTimestamp` ?
* EARLIEST_SNAPSHOT
Ditto
Besides, do we expect the streaming strategy to be a bounded stream in which case we may need to set the `endSnapshotId`, or a unbounded stream ?
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/StreamingStartingStrategy.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.iceberg.flink.source;
+
+/**
+ * Starting strategy for streaming execution. Note that starting snapshot is exclusive in the incremental
+ * split discovery mode. Files appended by the starting snapshot aren't included in split discovery.
+ */
+public enum StreamingStartingStrategy {
+ /**
+ * First do a regular table scan. then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
Review comment:
Agreed. It's more clear to add the `INCREMENTAL` prefix to align with the `TABLE_SCAN_THEN_INCREMENTAL`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r840735875
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/StreamingStartingStrategy.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.iceberg.flink.source;
+
+/**
+ * Starting strategy for streaming execution. Note that starting snapshot is exclusive in the incremental
+ * split discovery mode. Files appended by the starting snapshot aren't included in split discovery.
+ */
+public enum StreamingStartingStrategy {
+ /**
+ * First do a regular table scan. then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from the earliest snapshot
+ */
+ EARLIEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from a specific startSnapshotId
+ */
+ SPECIFIC_START_SNAPSHOT_ID,
Review comment:
`INCREMENTAL_AFTER_SPECIFIC_SNAPSHOT_ID`
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828734682
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
Discussed with @yittg offline
* agree that both earliest and latest should have the same inclusive/exclusive behavior for easier . In the above example from Yi, here are the expectations if we use the exclusive behavior. earliest (starting S3) should discovery only F6 from S4 via the increment scan of (S3, S4]. latest (starting S4) should discover new files committed by future S5 via incremental scan of (s4, s5].
* because the current FlinkSource (`StreamingMonitorFunction`) implements exclusive behavior for `startSnapshotId` (probably matching the Iceberg `appendBetween` behavior), I am favoring keeping the exclusive behavior.
Will get some inputs from other people on the inclusive vs exclusive behavior regarding start snapshot.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828734682
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
Discussed with @yittg offline
* agree that both earliest and latest should have the same inclusive/exclusive behavior for easier . In the above example from Yi, here are the expectations if we use the exclusive behavior. earliest (starting S3) should discovery only F6 from S4 via the increment scan of (S3, S4]. latest (starting S4) should discover new files committed by future S5 via incremental scan of (s4, s5].
* because the current FlinkSource (`StreamingMonitorFunction`) implements exclusive behavior for `startSnapshotId` (probably matching the Iceberg `appendBetween` behavior), I am favoring keeping the exclusive behavior.
* In my opinion, earliest or latest don't have to be precise. E.g., in Kafka case, earliest is subjective to the imprecise Kafka retention purging. Either way (inclusive or exclusive) is probably not a big deal from users' perspective.
Will get some inputs from other people on the inclusive vs exclusive behavior regarding start snapshot.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830177936
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/StreamingStartingStrategy.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.iceberg.flink.source;
+
+/**
+ * Starting strategy for streaming execution. Note that starting snapshot is exclusive in the
+ * incremental split discovery mode. That means files appended by the starting snapshot aren't
+ * included in split discovery.
+ */
+public enum StreamingStartingStrategy {
+ /**
+ * First do a regular table scan. then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from the earliest snapshot
+ */
+ EARLIEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from a specific startSnapshotId
+ */
+ SPECIFIC_START_SNAPSHOT_ID,
Review comment:
Inclusive of the changes in this snapshot?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828133443
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, IcebergEnumeratorConfig enumeratorConfig) {
Review comment:
start snapshot is exclusive. I am thinking that we can document the behavior better for `StartingStrategy` enum class.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828645753
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
i still have a litter concern, let's take an example:
1. Table T initially has some snapshots S1, S2 with data files F1-3;
2. Then table T append F4-5 with S3, and F6 with S4;
3. Now S1, S2 are removed based on retention policy, and table T has snapshots S3, S4 with data files F1-6.
Now S3 is the earliest snapshot, right?
IIUC, the current implementation will scan only F6 and the following append files.
I think we should scan F4-6 for `EARLIEST_SNAPSHOT` strategy to correspond to `LATEST_SNAPSHOT` strategy.
WDYT, @stevenzwu
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r840735652
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/StreamingStartingStrategy.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.iceberg.flink.source;
+
+/**
+ * Starting strategy for streaming execution. Note that starting snapshot is exclusive in the incremental
+ * split discovery mode. Files appended by the starting snapshot aren't included in split discovery.
+ */
+public enum StreamingStartingStrategy {
+ /**
+ * First do a regular table scan. then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
Review comment:
`INCREMENTAL_AFTER_LATEST`?
`INCREMENTAL_AFTER_EARLIEST`?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r840986668
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
@yittg after discussing with @rdblue, we agreed on the inclusive starting behavior. With inclusive behavior, empty or non-empty tables should behave the same. For an empty table, earliest/latest will include all snapshots afterwards.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r827655588
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -200,12 +202,13 @@ ScanContext copyWithAppendsBetween(long newStartSnapshotId, long newEndSnapshotI
.project(schema)
.filters(filters)
.limit(limit)
- .exposeLocality(exposeLocality)
.includeColumnStats(includeColumnStats)
+ .exposeLocality(exposeLocality)
+ .planParallelism(planParallelism)
Review comment:
@stevenzwu i created a hot fix for it #4341
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830190558
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, ScanContext scanContext) {
+ List<HistoryEntry> historyEntries = table.history();
+ HistoryEntry startEntry;
+ switch (scanContext.startingStrategy()) {
+ case TABLE_SCAN_THEN_INCREMENTAL:
+ case LATEST_SNAPSHOT:
+ startEntry = historyEntries.get(historyEntries.size() - 1);
+ break;
+ case EARLIEST_SNAPSHOT:
Review comment:
Use https://github.com/apache/iceberg/blob/master/core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java#L89
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830189397
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, ScanContext scanContext) {
Review comment:
Here you probably want to use `SnapshotUtil`, which handles most of these cases using the current table state's ancestors.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r833902184
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-enumerator-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Snapshot startSnapshot = getStartSnapshot(table, scanContext);
+ LOG.info("Get starting snapshot id {} based on strategy {}",
+ startSnapshot.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshot Id {}",
+ splits.size(), startSnapshot.snapshotId());
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshot.snapshotId())
+ .endSnapshotTimestampMs(startSnapshot.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static Snapshot getStartSnapshot(Table table, ScanContext scanContext) {
Review comment:
good point. it is a corner case. will switch to `Optional` and also add a unit test
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r833903148
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-enumerator-pool-" + threadPoolName, scanContext.planParallelism());
Review comment:
if we use the current naming convention in `FlinkInputFormat`, we can probably change it to `iceberg-plan-worker-pool-<threadPoolName>`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831268086
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/StreamingStartingStrategy.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.iceberg.flink.source;
+
+/**
+ * Starting strategy for streaming execution. Note that starting snapshot is exclusive in the
+ * incremental split discovery mode. That means files appended by the starting snapshot aren't
+ * included in split discovery.
+ */
+public enum StreamingStartingStrategy {
+ /**
+ * First do a regular table scan. then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from the earliest snapshot
+ */
+ EARLIEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from a specific startSnapshotId
+ */
+ SPECIFIC_START_SNAPSHOT_ID,
Review comment:
mentioned the `exclusive` behave at the class-level Javadoc
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r827666268
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/IcebergEnumeratorConfig.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.io.Serializable;
+import java.time.Duration;
+import org.apache.flink.util.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+
+/**
+ * Settings for continuous split enumeration
+ */
+public class IcebergEnumeratorConfig implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public enum StartingStrategy {
+ /**
+ * First do a regular table scan.
+ * then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from the earliest snapshot
+ */
+ EARLIEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from a specific startSnapshotId
+ */
+ SPECIFIC_START_SNAPSHOT_ID,
+
+ /**
+ * Start incremental mode from a specific startTimestamp.
+ * Starting snapshot has a timestamp lower than or equal to the specified timestamp.
+ */
+ SPECIFIC_START_SNAPSHOT_TIMESTAMP
+ }
+
+ // for continuous enumerator
+ private final Duration splitDiscoveryInterval;
+ private final StartingStrategy startingStrategy;
+ private final Long startSnapshotId;
+ private final Long startSnapshotTimeMs;
+
+ private IcebergEnumeratorConfig(Builder builder) {
+ this.splitDiscoveryInterval = builder.splitDiscoveryInterval;
+ this.startingStrategy = builder.startingStrategy;
+ this.startSnapshotId = builder.startSnapshotId;
+ this.startSnapshotTimeMs = builder.startSnapshotTimeMs;
+ }
+
+ public Duration splitDiscoveryInterval() {
+ return splitDiscoveryInterval;
+ }
+
+ public StartingStrategy startingStrategy() {
+ return startingStrategy;
+ }
+
+ public Long startSnapshotId() {
+ return startSnapshotId;
+ }
+
+ public Long startSnapshotTimeMs() {
+ return startSnapshotTimeMs;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("splitDiscoveryInterval", splitDiscoveryInterval)
+ .add("startingStrategy", startingStrategy)
+ .add("startSnapshotId", startSnapshotId)
+ .add("startSnapshotTimeMs", startSnapshotTimeMs)
+ .toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private Duration splitDiscoveryInterval;
+ private StartingStrategy startingStrategy = StartingStrategy.LATEST_SNAPSHOT;
+ private Long startSnapshotId;
+ private Long startSnapshotTimeMs;
+
+ private Builder() {
+ }
+
+ /**
+ * This is required for continuous enumerator in streaming read
+ */
+ public Builder splitDiscoveryInterval(Duration interval) {
+ this.splitDiscoveryInterval = interval;
+ return this;
+ }
+
+ public Builder startingStrategy(StartingStrategy strategy) {
+ this.startingStrategy = strategy;
+ return this;
+ }
Review comment:
Would it be better to use named strategy method accepting required options? like
```suggestion
public Builder startingWithSpecificSnapshot(long startId) {
this.startingStrategy = StartingStrategy.SPECIFIC_START_SNAPSHOT_ID;
this.startSnapshotId = startId;
return this;
}
```
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r827655588
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -200,12 +202,13 @@ ScanContext copyWithAppendsBetween(long newStartSnapshotId, long newEndSnapshotI
.project(schema)
.filters(filters)
.limit(limit)
- .exposeLocality(exposeLocality)
.includeColumnStats(includeColumnStats)
+ .exposeLocality(exposeLocality)
+ .planParallelism(planParallelism)
Review comment:
i created a hot fix for it #4341
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r833901907
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-enumerator-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
Review comment:
I actually like the symmetry of if-else. I searched some existing Iceberg code. I saw many usage of if-else block for throwing exception. so will stay put
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu closed pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu closed pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r835403234
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-plan-worker-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Optional<Snapshot> startSnapshotOptional = getStartSnapshot(table, scanContext);
+ if (!startSnapshotOptional.isPresent()) {
+ // set IcebergEnumeratorPosition to null in this case
+ return new ContinuousEnumerationResult(Collections.emptyList(), null);
+ }
Review comment:
Yes. I also thought about this.
This is only applicable for latest or earliest snapshot. It is also arguable that latest or earliest snapshot (exclusive) needs to be applied to a valid snapshot. Then this behavior is correct.
We don't have a strategy of starting from now. Let's say if we set the `start snapshot timestamp` to now for an empty table. right now, the behavior will throw an exception because there is not a valid snapshot matching the timestamp.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828137470
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
this is the actual difference btw `EARLIEST_SNAPSHOT` and `TABLE_SCAN_THEN_INCREMENTAL`.
Let's say snapshot retention is 7 days and table data retention is 12 months. `TABLE_SCAN_THEN_INCREMENTAL` would scan 12 months of data and then switch to the incremental mode. `EARLIEST_SNAPSHOT` will start the incremental mode from the earliest snapshot from 7 days ago.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831381256
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, ScanContext scanContext) {
Review comment:
will switch
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831611246
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, ScanContext scanContext) {
+ List<HistoryEntry> historyEntries = table.history();
+ HistoryEntry startEntry;
+ switch (scanContext.startingStrategy()) {
+ case TABLE_SCAN_THEN_INCREMENTAL:
+ case LATEST_SNAPSHOT:
+ startEntry = historyEntries.get(historyEntries.size() - 1);
Review comment:
will switch
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, ScanContext scanContext) {
+ List<HistoryEntry> historyEntries = table.history();
+ HistoryEntry startEntry;
+ switch (scanContext.startingStrategy()) {
+ case TABLE_SCAN_THEN_INCREMENTAL:
+ case LATEST_SNAPSHOT:
+ startEntry = historyEntries.get(historyEntries.size() - 1);
+ break;
+ case EARLIEST_SNAPSHOT:
+ startEntry = historyEntries.get(0);
+ break;
+ case SPECIFIC_START_SNAPSHOT_ID:
+ Optional<HistoryEntry> matchedEntry = historyEntries.stream()
Review comment:
will switch
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828120655
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -23,6 +23,7 @@
import java.time.Duration;
import java.util.List;
import java.util.Map;
+import org.apache.flink.annotation.Internal;
Review comment:
yes, because Iceberg doesn't have such annotation. I have been using it extensively in the FLIP-27 source, which is approved by Ryan Blue.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r827300665
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -35,7 +36,8 @@
/**
* Context object with optional arguments for a Flink Scan.
*/
-class ScanContext implements Serializable {
+@Internal
+public class ScanContext implements Serializable {
Review comment:
This is made public because it is accessed by `ContinuousSplitPlannerImpl` class in this PR.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r827678390
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
We should also return splits by scanContext#copyWithSnapshotId(startSnapshotEntry.snapshotId()) for strategy `EARLIEST_SNAPSHOT`?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831615363
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
Review comment:
will update
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] kbendick commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
kbendick commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831627395
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-enumerator-pool-" + threadPoolName, scanContext.planParallelism());
Review comment:
Nit: Would it be more informative to mention `split-planner-pool-**` or something that correlates more to the class name?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830186904
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
Review comment:
I would avoid using "Delta" because that has multiple meanings. Incremental is better.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830194241
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
Review comment:
Can you add to the javadoc that this only returns splits if there is a starting table scan?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu closed pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu closed pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r835777538
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-plan-worker-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Optional<Snapshot> startSnapshotOptional = getStartSnapshot(table, scanContext);
+ if (!startSnapshotOptional.isPresent()) {
+ // set IcebergEnumeratorPosition to null in this case
+ return new ContinuousEnumerationResult(Collections.emptyList(), null);
+ }
Review comment:
agree it is not just the first snapshot. I was using it just to simplify the discussion. it doesn't really matter how many snapshots are committed before the first discovery. semantics are the same.
I was saying `earliest` or `latest` snapshot can be interpreted as the earliest or latest valid snapshot of the table. Let's say when the Flink job started, it is an empty table. initial scan return null.
* case 1: there are 3 snapshots (S1, S2, S3) committed. Now Flink source ran initial scan again. For earliest strategy, S1 will be used as starting snapshot. For latest strategy, S3 will be used as starting snapshot.
* case 2: there is 1 snapshot committed. Now both earliest and latest strategy will discover S1 as starting snapshot
regarding -1 snapshot id, is it a reserved special id? I wouldn't find the usage for snapshot id. Also, `IncrementalDataTableScan` seems to validate the start snapshot id. This may not work.
```
Preconditions.checkArgument(
snapshotIdsRange.contains(newFromSnapshotId),
"from snapshot id %s not in existing snapshot ids range (%s, %s]",
newFromSnapshotId, context().fromSnapshotId(), newToSnapshotId);
```
@yittg I definitely see your perspective, which is a valid interpretation of earliest and latest for empty table. In your interpretation, earliest and latest will behave the same (with some imaginary snapshot as starting point). all future snapshot should be discovered. To implement this model, we need to change `appendsBetween` implementation to support a special starting snapshot id, which is invalid and yet indicates a special starting point.
To me, both interpretations are reasonable. I also think for the practical purpose, how to interpret earliest and latest strategy for an empty table is not that important for streaming job. Most of the streaming job's bootstrap point is not really important, as it is arbitrary anyway. After bootstrapped, checkpoint contains valid snapshot id.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r840736050
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/StreamingStartingStrategy.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.iceberg.flink.source;
+
+/**
+ * Starting strategy for streaming execution. Note that starting snapshot is exclusive in the
+ * incremental split discovery mode. That means files appended by the starting snapshot aren't
+ * included in split discovery.
+ */
+public enum StreamingStartingStrategy {
+ /**
+ * First do a regular table scan. then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from the earliest snapshot
+ */
+ EARLIEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from a specific startSnapshotId
+ */
+ SPECIFIC_START_SNAPSHOT_ID,
+
+ /**
+ * Start incremental mode from a specific startTimestamp.
+ * Starting snapshot has a timestamp lower than or equal to the specified timestamp.
+ */
+ SPECIFIC_START_SNAPSHOT_TIMESTAMP
Review comment:
`INCREMENTAL_AFTER_TIMESTAMP`?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828596901
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
Thanks, got it.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r840989460
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
Thanks for letting me know, good job.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830175052
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/StreamingStartingStrategy.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.iceberg.flink.source;
+
+/**
+ * Starting strategy for streaming execution. Note that starting snapshot is exclusive in the
+ * incremental split discovery mode. That means files appended by the starting snapshot aren't
+ * included in split discovery.
+ */
+public enum StreamingStartingStrategy {
+ /**
+ * First do a regular table scan. then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from the earliest snapshot
+ */
+ EARLIEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from a specific startSnapshotId
+ */
+ SPECIFIC_START_SNAPSHOT_ID,
+
+ /**
+ * Start incremental mode from a specific startTimestamp.
+ * Starting snapshot has a timestamp lower than or equal to the specified timestamp.
+ */
+ SPECIFIC_START_SNAPSHOT_TIMESTAMP
Review comment:
What happens if table history doesn't go back that far? It should probably fail because the user's request can't be satisfied.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830194610
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
Review comment:
And that this is going to return a starting position of the starting snapshot, which is exclusive.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830190401
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, ScanContext scanContext) {
+ List<HistoryEntry> historyEntries = table.history();
+ HistoryEntry startEntry;
+ switch (scanContext.startingStrategy()) {
+ case TABLE_SCAN_THEN_INCREMENTAL:
+ case LATEST_SNAPSHOT:
+ startEntry = historyEntries.get(historyEntries.size() - 1);
+ break;
+ case EARLIEST_SNAPSHOT:
+ startEntry = historyEntries.get(0);
+ break;
+ case SPECIFIC_START_SNAPSHOT_ID:
+ Optional<HistoryEntry> matchedEntry = historyEntries.stream()
+ .filter(entry -> entry.snapshotId() == scanContext.startSnapshotId())
+ .findFirst();
+ if (matchedEntry.isPresent()) {
+ startEntry = matchedEntry.get();
+ } else {
+ throw new IllegalArgumentException(
+ "Snapshot id not found in history: {}" + scanContext.startSnapshotId());
+ }
+ break;
+ case SPECIFIC_START_SNAPSHOT_TIMESTAMP:
Review comment:
Probably use https://github.com/apache/iceberg/blob/master/core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java#L112
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831627048
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/StreamingStartingStrategy.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.iceberg.flink.source;
+
+/**
+ * Starting strategy for streaming execution. Note that starting snapshot is exclusive in the
+ * incremental split discovery mode. That means files appended by the starting snapshot aren't
+ * included in split discovery.
+ */
+public enum StreamingStartingStrategy {
+ /**
+ * First do a regular table scan. then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from the earliest snapshot
+ */
+ EARLIEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from a specific startSnapshotId
+ */
+ SPECIFIC_START_SNAPSHOT_ID,
+
+ /**
+ * Start incremental mode from a specific startTimestamp.
+ * Starting snapshot has a timestamp lower than or equal to the specified timestamp.
+ */
+ SPECIFIC_START_SNAPSHOT_TIMESTAMP
Review comment:
switched to `SnapshotUtil#snapshotIdAsOfTime`, which handles this scenario internally (throwing exception)
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828708104
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
@stevenzwu i don't mean to make the starting inclusive. It should be consistent with the other places in iceberg.
We can compare the similar strategy in kafka.
I mean , it should include the earliest by `earliest`, and it should include the next coming by `latest`.
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
@stevenzwu i don't mean to make the starting inclusive. It should be consistent with the other places in iceberg.
We can compare to the similar strategy in kafka.
I mean , it should include the earliest by `earliest`, and it should include the next coming by `latest`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r827658887
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -23,6 +23,7 @@
import java.time.Duration;
import java.util.List;
import java.util.Map;
+import org.apache.flink.annotation.Internal;
Review comment:
Is it proper to use the flink internal annotation?
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
Review comment:
Does that mean scanContext#monitorInterval should be null, because it is configured in IcebergEnumeratorConfig?
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
Review comment:
We should also return splits by scanContext#copyWithSnapshotId(startSnapshotEntry.snapshotId()) for strategy `EARLIEST_SNAPSHOT`
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/IcebergEnumeratorConfig.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.io.Serializable;
+import java.time.Duration;
+import org.apache.flink.util.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+
+/**
+ * Settings for continuous split enumeration
+ */
+public class IcebergEnumeratorConfig implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public enum StartingStrategy {
+ /**
+ * First do a regular table scan.
+ * then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from the earliest snapshot
+ */
+ EARLIEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from a specific startSnapshotId
+ */
+ SPECIFIC_START_SNAPSHOT_ID,
+
+ /**
+ * Start incremental mode from a specific startTimestamp.
+ * Starting snapshot has a timestamp lower than or equal to the specified timestamp.
+ */
+ SPECIFIC_START_SNAPSHOT_TIMESTAMP
+ }
+
+ // for continuous enumerator
+ private final Duration splitDiscoveryInterval;
+ private final StartingStrategy startingStrategy;
+ private final Long startSnapshotId;
+ private final Long startSnapshotTimeMs;
+
+ private IcebergEnumeratorConfig(Builder builder) {
+ this.splitDiscoveryInterval = builder.splitDiscoveryInterval;
+ this.startingStrategy = builder.startingStrategy;
+ this.startSnapshotId = builder.startSnapshotId;
+ this.startSnapshotTimeMs = builder.startSnapshotTimeMs;
+ }
+
+ public Duration splitDiscoveryInterval() {
+ return splitDiscoveryInterval;
+ }
+
+ public StartingStrategy startingStrategy() {
+ return startingStrategy;
+ }
+
+ public Long startSnapshotId() {
+ return startSnapshotId;
+ }
+
+ public Long startSnapshotTimeMs() {
+ return startSnapshotTimeMs;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("splitDiscoveryInterval", splitDiscoveryInterval)
+ .add("startingStrategy", startingStrategy)
+ .add("startSnapshotId", startSnapshotId)
+ .add("startSnapshotTimeMs", startSnapshotTimeMs)
+ .toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private Duration splitDiscoveryInterval;
+ private StartingStrategy startingStrategy = StartingStrategy.LATEST_SNAPSHOT;
+ private Long startSnapshotId;
+ private Long startSnapshotTimeMs;
+
+ private Builder() {
+ }
+
+ /**
+ * This is required for continuous enumerator in streaming read
+ */
+ public Builder splitDiscoveryInterval(Duration interval) {
+ this.splitDiscoveryInterval = interval;
+ return this;
+ }
+
+ public Builder startingStrategy(StartingStrategy strategy) {
+ this.startingStrategy = strategy;
+ return this;
+ }
Review comment:
Would it be better to use named strategy method accepting required options, like
```suggestion
public Builder startingWithSpecificSnapshot(long startId) {
this.startingStrategy = StartingStrategy.SPECIFIC_START_SNAPSHOT_ID;
this.startSnapshotId = startId;
return this;
}
```
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link IcebergEnumeratorConfig.StartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, config);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), config.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (config.startingStrategy() ==
+ IcebergEnumeratorConfig.StartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, IcebergEnumeratorConfig enumeratorConfig) {
Review comment:
it's a little confused whether the start snapshot is counted or not? it is exclusive based on `TableScan#appendsBetween`. However, it does not match the intuition for strategy `EARLIEST_SNAPSHOT`, even `SPECIFIC_START_SNAPSHOT_ID` and `SPECIFIC_START_SNAPSHOT_TIMESTAMP `
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r835777538
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-plan-worker-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Optional<Snapshot> startSnapshotOptional = getStartSnapshot(table, scanContext);
+ if (!startSnapshotOptional.isPresent()) {
+ // set IcebergEnumeratorPosition to null in this case
+ return new ContinuousEnumerationResult(Collections.emptyList(), null);
+ }
Review comment:
agree it is not just the first snapshot. I was using it just to simplify the discussion. it doesn't really matter how many snapshots are committed before the first discovery. semantics are the same.
I was saying `earliest` or `latest` snapshot can be interpreted as the earliest or latest valid snapshot of the table. Let's say when the Flink job started, it is an empty table. initial scan return null.
* case 1: there are 3 snapshots (S1, S2, S3) committed. Now Flink source ran initial scan again. For earliest strategy, S1 will be used as starting snapshot. For latest strategy, S3 will be used as starting snapshot.
* case 2: there is 1 snapshot committed. Now both earliest and latest strategy will discover S1 as starting snapshot
regarding -1 snapshot id, is it a reserved special id? I wouldn't find the usage for snapshot id. Also, `IncrementalDataTableScan` seems to validate the start snapshot id. This may not work.
```
Preconditions.checkArgument(
snapshotIdsRange.contains(newFromSnapshotId),
"from snapshot id %s not in existing snapshot ids range (%s, %s]",
newFromSnapshotId, context().fromSnapshotId(), newToSnapshotId);
```
@yittg I definitely see your perspective, which is a valid interpretation of earliest and latest for empty table. In your interpretation, earliest and latest will behave the same (with some imaginary snapshot as starting point). all future snapshot should be discovered. To implement this model, we need to change `appendsBetween` implementation to support a special starting snapshot id, which is invalid and yet indicates a special starting point.
To me, both interpretations are reasonable. I also think for the practical purpose, how to interpret earliest and latest strategy for an empty table is not that important for streaming job. For most streaming jobs, the bootstrap point is not really important, as it is arbitrary anyway.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r835403234
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-plan-worker-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Optional<Snapshot> startSnapshotOptional = getStartSnapshot(table, scanContext);
+ if (!startSnapshotOptional.isPresent()) {
+ // set IcebergEnumeratorPosition to null in this case
+ return new ContinuousEnumerationResult(Collections.emptyList(), null);
+ }
Review comment:
Yes. I also thought about this.
This is only applicable for latest or earliest snapshot. With an empty table, the behavior is that the first snapshot (committed after the Flink source started) will be discovered as the starting snapshot. Due to the exclusive behavior, files appended by the first snapshot will be ignored. Only later files will be discovered. It is also arguable that latest or earliest snapshot (exclusive) needs to be applied to a valid snapshot. Then this behavior is correct.
For specific starting snapshot id or timestamp, empty table will result in an exception since there is no snapshot matching the id or timestamp.
@rdblue @kbendick what's your take? is the behavior for latest or earliest snapshot acceptable?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r833902387
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -114,77 +128,100 @@ private ScanContext(boolean caseSensitive, Long snapshotId, Long startSnapshotId
this.includeColumnStats = includeColumnStats;
this.exposeLocality = exposeLocality;
this.planParallelism = planParallelism;
+
+ validate();
+ }
+
+ private void validate() {
+ if (isStreaming) {
+ if (startingStrategy == StreamingStartingStrategy.SPECIFIC_START_SNAPSHOT_ID) {
+ Preconditions.checkArgument(startSnapshotId != null,
+ "startSnapshotId cannot be null for SPECIFIC_START_SNAPSHOT_ID starting strategy");
+ }
+ if (startingStrategy == StreamingStartingStrategy.SPECIFIC_START_SNAPSHOT_TIMESTAMP) {
+ Preconditions.checkArgument(startSnapshotTimestamp != null,
+ "startSnapshotTimestamp cannot be null for SPECIFIC_START_SNAPSHOT_TIMESTAMP starting strategy");
Review comment:
sure. will add them
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] kbendick commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
kbendick commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831623986
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -114,77 +128,100 @@ private ScanContext(boolean caseSensitive, Long snapshotId, Long startSnapshotId
this.includeColumnStats = includeColumnStats;
this.exposeLocality = exposeLocality;
this.planParallelism = planParallelism;
+
+ validate();
+ }
+
+ private void validate() {
+ if (isStreaming) {
+ if (startingStrategy == StreamingStartingStrategy.SPECIFIC_START_SNAPSHOT_ID) {
+ Preconditions.checkArgument(startSnapshotId != null,
+ "startSnapshotId cannot be null for SPECIFIC_START_SNAPSHOT_ID starting strategy");
+ }
+ if (startingStrategy == StreamingStartingStrategy.SPECIFIC_START_SNAPSHOT_TIMESTAMP) {
+ Preconditions.checkArgument(startSnapshotTimestamp != null,
+ "startSnapshotTimestamp cannot be null for SPECIFIC_START_SNAPSHOT_TIMESTAMP starting strategy");
Review comment:
Should we validate that `startSnapshotId` isn't supplied if the user has set the `startingStrategy` to be by timestamp.
As well as making sure there's not a provided `startSnapshotTimestamp` when using snapshot id starting strategy?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831615301
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
Review comment:
will update
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r831296925
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
Review comment:
will update
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830192469
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
Review comment:
Clean up log message?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r827653359
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/ScanContext.java
##########
@@ -200,12 +202,13 @@ ScanContext copyWithAppendsBetween(long newStartSnapshotId, long newEndSnapshotI
.project(schema)
.filters(filters)
.limit(limit)
- .exposeLocality(exposeLocality)
.includeColumnStats(includeColumnStats)
+ .exposeLocality(exposeLocality)
+ .planParallelism(planParallelism)
Review comment:
Thanks for catching this, i think we can move this to another separated hot fix commit?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828206030
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/IcebergEnumeratorConfig.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.io.Serializable;
+import java.time.Duration;
+import org.apache.flink.util.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+
+/**
+ * Settings for continuous split enumeration
+ */
+public class IcebergEnumeratorConfig implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public enum StartingStrategy {
+ /**
+ * First do a regular table scan.
+ * then switch to incremental mode.
+ */
+ TABLE_SCAN_THEN_INCREMENTAL,
+
+ /**
+ * Start incremental mode from the latest snapshot
+ */
+ LATEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from the earliest snapshot
+ */
+ EARLIEST_SNAPSHOT,
+
+ /**
+ * Start incremental mode from a specific startSnapshotId
+ */
+ SPECIFIC_START_SNAPSHOT_ID,
+
+ /**
+ * Start incremental mode from a specific startTimestamp.
+ * Starting snapshot has a timestamp lower than or equal to the specified timestamp.
+ */
+ SPECIFIC_START_SNAPSHOT_TIMESTAMP
+ }
+
+ // for continuous enumerator
+ private final Duration splitDiscoveryInterval;
+ private final StartingStrategy startingStrategy;
+ private final Long startSnapshotId;
+ private final Long startSnapshotTimeMs;
+
+ private IcebergEnumeratorConfig(Builder builder) {
+ this.splitDiscoveryInterval = builder.splitDiscoveryInterval;
+ this.startingStrategy = builder.startingStrategy;
+ this.startSnapshotId = builder.startSnapshotId;
+ this.startSnapshotTimeMs = builder.startSnapshotTimeMs;
+ }
+
+ public Duration splitDiscoveryInterval() {
+ return splitDiscoveryInterval;
+ }
+
+ public StartingStrategy startingStrategy() {
+ return startingStrategy;
+ }
+
+ public Long startSnapshotId() {
+ return startSnapshotId;
+ }
+
+ public Long startSnapshotTimeMs() {
+ return startSnapshotTimeMs;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("splitDiscoveryInterval", splitDiscoveryInterval)
+ .add("startingStrategy", startingStrategy)
+ .add("startSnapshotId", startSnapshotId)
+ .add("startSnapshotTimeMs", startSnapshotTimeMs)
+ .toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private Duration splitDiscoveryInterval;
+ private StartingStrategy startingStrategy = StartingStrategy.LATEST_SNAPSHOT;
+ private Long startSnapshotId;
+ private Long startSnapshotTimeMs;
+
+ private Builder() {
+ }
+
+ /**
+ * This is required for continuous enumerator in streaming read
+ */
+ public Builder splitDiscoveryInterval(Duration interval) {
+ this.splitDiscoveryInterval = interval;
+ return this;
+ }
+
+ public Builder startingStrategy(StartingStrategy strategy) {
+ this.startingStrategy = strategy;
+ return this;
+ }
Review comment:
actually while working on merging the configs to `ScanContext`, I think we need to stay in the simple POJO style for `ScanContext.Builder.fromProperties`
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r828130106
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final IcebergEnumeratorConfig config;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, IcebergEnumeratorConfig config, ScanContext scanContext) {
+ this.table = table;
+ this.config = config;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ validate();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(scanContext.snapshotId() == null,
+ "Can't set snapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.asOfTimestamp() == null,
+ "Can't set asOfTimestamp in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.startSnapshotId() == null,
+ "Can't set startSnapshotId in ScanContext for continuous enumerator");
+ Preconditions.checkArgument(scanContext.endSnapshotId() == null,
+ "Can't set endSnapshotId in ScanContext for continuous enumerator");
Review comment:
that is a good question. I am also pondering maybe we should merge the `IcebergEnumeratorConfig` with `ScanContext`. As you pointed out, there are some overlapped configs, like `monitorInterval`, `startSnapshotId`. Please let me know your preference. Will also get some input from Ryan.
Right now, I am leaning toward merging them.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r830191739
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.HistoryEntry;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext) {
+ this.table = table;
+ this.scanContext = scanContext;
+ // Within a JVM, table name should be unique across sources.
+ // Hence it is used as worker pool thread name prefix.
+ this.workerPool = ThreadPools.newWorkerPool("iceberg-worker-pool-" + table.name(), scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverDeltaSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover delta changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverDeltaSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ HistoryEntry startSnapshotEntry = getStartSnapshot(table, scanContext);
+ LOG.info("get startSnapshotId {} based on starting strategy {}",
+ startSnapshotEntry.snapshotId(), scanContext.startingStrategy());
+ List<IcebergSourceSplit> splits;
+ if (scanContext.startingStrategy() ==
+ StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL) {
+ // do a full table scan first
+ splits = FlinkSplitPlanner.planIcebergSourceSplits(table, scanContext, workerPool);
+ LOG.info("Discovered {} splits from initial full table scan with snapshotId {}",
+ splits.size(), startSnapshotEntry);
+ } else {
+ splits = Collections.emptyList();
+ }
+
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .endSnapshotId(startSnapshotEntry.snapshotId())
+ .endSnapshotTimestampMs(startSnapshotEntry.timestampMillis())
+ .build();
+ return new ContinuousEnumerationResult(splits, position);
+ }
+
+ @VisibleForTesting
+ static HistoryEntry getStartSnapshot(Table table, ScanContext scanContext) {
+ List<HistoryEntry> historyEntries = table.history();
+ HistoryEntry startEntry;
+ switch (scanContext.startingStrategy()) {
+ case TABLE_SCAN_THEN_INCREMENTAL:
+ case LATEST_SNAPSHOT:
+ startEntry = historyEntries.get(historyEntries.size() - 1);
Review comment:
`table.currentSnapshot()`?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] yittg commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
yittg commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r835704005
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-plan-worker-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Optional<Snapshot> startSnapshotOptional = getStartSnapshot(table, scanContext);
+ if (!startSnapshotOptional.isPresent()) {
+ // set IcebergEnumeratorPosition to null in this case
+ return new ContinuousEnumerationResult(Collections.emptyList(), null);
+ }
Review comment:
Empty table is invalid if the strategies must correspond to a certain snapshot, but it's weird to say empty table can not be applied with these two strategies.
There may be more than one snapshots can be committed before next round of discover, so it's not only the first snapshot.
How about returning a position with end snapshot as -1, which i think is idiomatic in iceberg.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] stevenzwu commented on a change in pull request #4329: Flink: FLIP-27 source enumerator help classes
Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #4329:
URL: https://github.com/apache/iceberg/pull/4329#discussion_r835403234
##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.iceberg.flink.source.enumerator;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.flink.source.FlinkSplitPlanner;
+import org.apache.iceberg.flink.source.ScanContext;
+import org.apache.iceberg.flink.source.StreamingStartingStrategy;
+import org.apache.iceberg.flink.source.split.IcebergSourceSplit;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Internal
+public class ContinuousSplitPlannerImpl implements ContinuousSplitPlanner {
+ private static final Logger LOG = LoggerFactory.getLogger(ContinuousSplitPlannerImpl.class);
+
+ private final Table table;
+ private final ScanContext scanContext;
+ private final ExecutorService workerPool;
+
+ public ContinuousSplitPlannerImpl(Table table, ScanContext scanContext, String threadPoolName) {
+ this.table = table;
+ this.scanContext = scanContext;
+ this.workerPool = ThreadPools.newWorkerPool(
+ "iceberg-plan-worker-pool-" + threadPoolName, scanContext.planParallelism());
+ }
+
+ @Override
+ public ContinuousEnumerationResult planSplits(IcebergEnumeratorPosition lastPosition) {
+ table.refresh();
+ if (lastPosition != null) {
+ return discoverIncrementalSplits(lastPosition);
+ } else {
+ return discoverInitialSplits();
+ }
+ }
+
+ /**
+ * Discover incremental changes between @{code lastPosition} and current table snapshot
+ */
+ private ContinuousEnumerationResult discoverIncrementalSplits(IcebergEnumeratorPosition lastPosition) {
+ // incremental discovery mode
+ Snapshot currentSnapshot = table.currentSnapshot();
+ if (currentSnapshot.snapshotId() == lastPosition.endSnapshotId()) {
+ LOG.info("Current table snapshot is already enumerated: {}", currentSnapshot.snapshotId());
+ return new ContinuousEnumerationResult(Collections.emptyList(), lastPosition);
+ } else {
+ ScanContext incrementalScan = scanContext
+ .copyWithAppendsBetween(lastPosition.endSnapshotId(), currentSnapshot.snapshotId());
+ LOG.info("Incremental scan: startSnapshotId = {}, endSnapshotId = {}",
+ incrementalScan.startSnapshotId(), incrementalScan.endSnapshotId());
+ List<IcebergSourceSplit> splits = FlinkSplitPlanner.planIcebergSourceSplits(table, incrementalScan, workerPool);
+ IcebergEnumeratorPosition position = IcebergEnumeratorPosition.builder()
+ .startSnapshotId(lastPosition.endSnapshotId())
+ .startSnapshotTimestampMs(lastPosition.endSnapshotTimestampMs())
+ .endSnapshotId(currentSnapshot.snapshotId())
+ .endSnapshotTimestampMs(currentSnapshot.timestampMillis())
+ .build();
+ LOG.info("Discovered {} splits from incremental scan: {}", splits.size(), position);
+ return new ContinuousEnumerationResult(splits, position);
+ }
+ }
+
+ /**
+ * Discovery initial set of splits based on {@link StreamingStartingStrategy}.
+ *
+ * <li>{@link ContinuousEnumerationResult#splits()} should contain initial splits
+ * discovered from table scan for {@link StreamingStartingStrategy#TABLE_SCAN_THEN_INCREMENTAL}.
+ * For all other strategies, splits collection should be empty.
+ * <li>{@link ContinuousEnumerationResult#position()} points to the starting position
+ * for the next incremental split discovery with exclusive behavior. Meaning files committed
+ * by the snapshot from the position in {@code ContinuousEnumerationResult} won't be included
+ * in the next incremental scan.
+ */
+ private ContinuousEnumerationResult discoverInitialSplits() {
+ Optional<Snapshot> startSnapshotOptional = getStartSnapshot(table, scanContext);
+ if (!startSnapshotOptional.isPresent()) {
+ // set IcebergEnumeratorPosition to null in this case
+ return new ContinuousEnumerationResult(Collections.emptyList(), null);
+ }
Review comment:
Yes. I also thought about this.
This is only applicable for latest or earliest snapshot. It is also arguable that latest or earliest snapshot (exclusive) needs to be applied to a valid snapshot. Then this behavior is correct.
We don't have a strategy of starting from now. Let's say if we set the `start snapshot timestamp` to now for an empty table. right now, the behavior will throw an exception because there is not a valid snapshot matching the timestamp.
Will double check with Ryan and Kyle.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org