You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/09/26 08:05:54 UTC

(shardingsphere) branch master updated: Refactor openGauss WAL loop high-frequency annotation scope (#39965)

This is an automated email from the ASF dual-hosted git repository.

terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new efb7a8dd91c Refactor openGauss WAL loop high-frequency annotation scope (#39965)
efb7a8dd91c is described below

commit efb7a8dd91ce4ce099d3f0d9ee5f6f6bbea48dd0
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Sep 26 16:05:46 2026 +0800

    Refactor openGauss WAL loop high-frequency annotation scope (#39965)
---
 .../execute/AbstractPipelineLifecycleRunnable.java |  2 +
 .../dumper/OpenGaussIncrementalDumper.java         | 60 +++++++++++-----------
 2 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/AbstractPipelineLifecycleRunnable.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/AbstractPipelineLifecycleRunnable.java
index bc4c8130bfd..d2c60b856cf 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/AbstractPipelineLifecycleRunnable.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/AbstractPipelineLifecycleRunnable.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.data.pipeline.core.execute;
 
 import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
 import org.apache.shardingsphere.infra.util.datetime.DateTimeFormatterFactory;
 
 import java.time.Instant;
@@ -35,6 +36,7 @@ public abstract class AbstractPipelineLifecycleRunnable implements PipelineLifec
     
     private volatile long startTimeMillis;
     
+    @HighFrequencyInvocation
     protected boolean isRunning() {
         Boolean running = this.running.get();
         return null != running && running;
diff --git a/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/incremental/dumper/OpenGaussIncrementalDumper.java b/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/incremental/dumper/OpenGaussIncrementalDumper.java
index 090e91e9c06..d72e4a9d245 100644
--- a/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/incremental/dumper/OpenGaussIncrementalDumper.java
+++ b/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/incremental/dumper/OpenGaussIncrementalDumper.java
@@ -94,7 +94,6 @@ public final class OpenGaussIncrementalDumper extends AbstractPipelineLifecycleR
         decodeWithTX = dumperContext.isDecodeWithTX();
     }
     
-    @HighFrequencyInvocation
     @SneakyThrows(InterruptedException.class)
     @Override
     protected void runBlocking() {
@@ -124,20 +123,7 @@ public final class OpenGaussIncrementalDumper extends AbstractPipelineLifecycleR
             stream = logicalReplication.createReplicationStream(
                     connection, walPosition.get().getLogSequenceNumber(), PostgreSQLSlotNameGenerator.getUniqueSlotName(connection, dumperContext.getJobId()), majorVersion);
             DecodingPlugin decodingPlugin = new MppdbDecodingPlugin(new OpenGaussTimestampUtils(connection.getTimestampUtils()), decodeWithTX, majorVersion >= 3);
-            while (isRunning()) {
-                ByteBuffer message = stream.readPending();
-                if (null == message) {
-                    Thread.sleep(10L);
-                    continue;
-                }
-                AbstractWALEvent event = decodingPlugin.decode(message, new OpenGaussLogSequenceNumber(stream.getLastReceiveLSN()));
-                if (decodeWithTX) {
-                    processEventWithTX(event, majorVersion);
-                } else {
-                    processEventIgnoreTX(event);
-                }
-                walPosition.set(new WALPosition(event.getLogSequenceNumber()));
-            }
+            consumeWALEvents(stream, decodingPlugin, majorVersion);
         } finally {
             if (null != stream) {
                 try {
@@ -164,17 +150,32 @@ public final class OpenGaussIncrementalDumper extends AbstractPipelineLifecycleR
         Matcher matcher = VERSION_PATTERN.matcher(versionText);
         boolean isFind = matcher.find();
         log.info("openGauss major version={}, `select version()`={}", isFind ? matcher.group(1) : DEFAULT_VERSION, versionText);
-        if (isFind) {
-            return Integer.parseInt(matcher.group(1));
-        }
-        return DEFAULT_VERSION;
+        return isFind ? Integer.parseInt(matcher.group(1)) : DEFAULT_VERSION;
     }
     
     private PgConnection getReplicationConnectionUnwrap() throws SQLException {
         return logicalReplication.createConnection((StandardPipelineDataSourceConfiguration) dumperContext.getCommonContext().getDataSourceConfig()).unwrap(PgConnection.class);
     }
     
-    private void processEventWithTX(final AbstractWALEvent event, final int majorVersion) {
+    @HighFrequencyInvocation
+    private void consumeWALEvents(final PGReplicationStream stream, final DecodingPlugin decodingPlugin, final int majorVersion) throws SQLException, InterruptedException {
+        while (isRunning()) {
+            ByteBuffer message = stream.readPending();
+            if (null == message) {
+                Thread.sleep(10L);
+                continue;
+            }
+            AbstractWALEvent event = decodingPlugin.decode(message, new OpenGaussLogSequenceNumber(stream.getLastReceiveLSN()));
+            if (decodeWithTX) {
+                processEventWithTransaction(event, majorVersion);
+            } else {
+                processEventIgnoreTransaction(event);
+            }
+            walPosition.set(new WALPosition(event.getLogSequenceNumber()));
+        }
+    }
+    
+    private void processEventWithTransaction(final AbstractWALEvent event, final int majorVersion) {
         if (event instanceof BeginTXEvent) {
             if (majorVersion < 3) {
                 return;
@@ -185,12 +186,6 @@ public final class OpenGaussIncrementalDumper extends AbstractPipelineLifecycleR
             currentCsn.set(((BeginTXEvent) event).getCsn());
             return;
         }
-        if (event instanceof AbstractRowEvent) {
-            AbstractRowEvent rowEvent = (AbstractRowEvent) event;
-            rowEvent.setCsn(currentCsn.get());
-            rowEvents.add(rowEvent);
-            return;
-        }
         if (event instanceof CommitTXEvent) {
             List<Record> records = new LinkedList<>();
             for (AbstractRowEvent each : rowEvents) {
@@ -203,14 +198,19 @@ public final class OpenGaussIncrementalDumper extends AbstractPipelineLifecycleR
             channel.push(records);
             rowEvents = new LinkedList<>();
             currentCsn.set(null);
+            return;
+        }
+        if (event instanceof AbstractRowEvent) {
+            AbstractRowEvent rowEvent = (AbstractRowEvent) event;
+            rowEvent.setCsn(currentCsn.get());
+            rowEvents.add(rowEvent);
         }
     }
     
-    private void processEventIgnoreTX(final AbstractWALEvent event) {
-        if (event instanceof BeginTXEvent) {
-            return;
+    private void processEventIgnoreTransaction(final AbstractWALEvent event) {
+        if (!(event instanceof BeginTXEvent)) {
+            channel.push(Collections.singletonList(walEventConverter.convert(event)));
         }
-        channel.push(Collections.singletonList(walEventConverter.convert(event)));
     }
     
     @Override