You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/08/12 07:16:49 UTC

[GitHub] [inlong] thesumery commented on a diff in pull request #5513: [INLONG-5469][Sort] Add metric for hive with flink metrics group and audit sdk

thesumery commented on code in PR #5513:
URL: https://github.com/apache/inlong/pull/5513#discussion_r944179135


##########
inlong-sort/sort-connectors/hive/src/main/java/org/apache/inlong/sort/hive/filesystem/AbstractStreamingWriter.java:
##########
@@ -0,0 +1,220 @@
+/*
+ *  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.inlong.sort.hive.filesystem;
+
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.runtime.state.StateInitializationContext;
+import org.apache.flink.runtime.state.StateSnapshotContext;
+import org.apache.flink.streaming.api.functions.sink.filesystem.Bucket;
+import org.apache.flink.streaming.api.functions.sink.filesystem.BucketLifeCycleListener;
+import org.apache.flink.streaming.api.functions.sink.filesystem.Buckets;
+import org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink;
+import org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSinkHelper;
+import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
+import org.apache.flink.streaming.api.operators.BoundedOneInput;
+import org.apache.flink.streaming.api.operators.ChainingStrategy;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+import org.apache.inlong.audit.AuditImp;
+import org.apache.inlong.sort.base.Constants;
+import org.apache.inlong.sort.base.metric.SinkMetricData;
+import org.apache.inlong.sort.base.metric.ThreadSafeCounter;
+
+import javax.annotation.Nullable;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.HashSet;
+
+import static org.apache.inlong.sort.base.Constants.DELIMITER;
+
+/**
+ * Operator for file system sink. It is a operator version of {@link StreamingFileSink}. It can send
+ * file and bucket information to downstream.
+ */
+public abstract class AbstractStreamingWriter<IN, OUT> extends AbstractStreamOperator<OUT>
+        implements OneInputStreamOperator<IN, OUT>, BoundedOneInput {
+
+    private static final long serialVersionUID = 1L;
+
+    // ------------------------ configuration fields --------------------------
+
+    private final long bucketCheckInterval;
+
+    private final StreamingFileSink.BucketsBuilder<
+            IN, String, ? extends StreamingFileSink.BucketsBuilder<IN, String, ?>>
+            bucketsBuilder;
+
+    @Nullable
+    private String inLongMetric;
+
+    @Nullable
+    private String auditHostAndPorts;
+
+    // --------------------------- runtime fields -----------------------------
+
+    private transient Buckets<IN, String> buckets;
+
+    private transient StreamingFileSinkHelper<IN> helper;
+
+    private transient long currentWatermark;
+
+    @Nullable
+    private transient SinkMetricData metricData;
+
+    private transient String inLongGroupId;
+
+    private transient String inLongStreamId;
+
+    public AbstractStreamingWriter(
+            long bucketCheckInterval,
+            StreamingFileSink.BucketsBuilder<
+                    IN, String, ? extends StreamingFileSink.BucketsBuilder<IN, String, ?>>
+                    bucketsBuilder,
+            String inLongMetric,
+            String auditHostAndPorts) {
+        this.bucketCheckInterval = bucketCheckInterval;
+        this.bucketsBuilder = bucketsBuilder;
+        this.inLongMetric = inLongMetric;
+        this.auditHostAndPorts = auditHostAndPorts;
+        setChainingStrategy(ChainingStrategy.ALWAYS);
+    }
+
+    /** Notifies a partition created. */
+    protected abstract void partitionCreated(String partition);
+
+    /**
+     * Notifies a partition become inactive. A partition becomes inactive after all the records
+     * received so far have been committed.
+     */
+    protected abstract void partitionInactive(String partition);
+
+    /**
+     * Notifies a new file has been opened.
+     *
+     * <p>Note that this does not mean that the file has been created in the file system. It is only
+     * created logically and the actual file will be generated after it is committed.
+     */
+    protected abstract void onPartFileOpened(String partition, Path newPath);
+
+    /** Commit up to this checkpoint id. */
+    protected void commitUpToCheckpoint(long checkpointId) throws Exception {
+        helper.commitUpToCheckpoint(checkpointId);
+    }
+
+    @Override
+    public void open() throws Exception {
+        super.open();
+        if (inLongMetric != null) {
+            String[] inLongMetricArray = inLongMetric.split(DELIMITER);
+            inLongGroupId = inLongMetricArray[0];
+            inLongStreamId = inLongMetricArray[1];
+            String nodeId = inLongMetricArray[2];
+            metricData = new SinkMetricData(
+                    inLongGroupId, inLongStreamId, nodeId, getRuntimeContext().getMetricGroup(), auditHostAndPorts);
+            metricData.registerMetricsForDirtyBytes(new ThreadSafeCounter());
+            metricData.registerMetricsForDirtyRecords(new ThreadSafeCounter());

Review Comment:
   Here in sink node computing dirtyRecords is meaningless. Beacuse any data in memroy here must be able to serialize successfully(dirty data what  I understand is cannot serialize successfully),other 
    exception like IOException is not the cause of data is dirty, so should not catch them and inc dirty metric counter.



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org