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

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


The following commit(s) were added to refs/heads/master by this push:
     new cfbef1706b2 [feature](fe) Advance the next id before transfering to 
master (#33817)
cfbef1706b2 is described below

commit cfbef1706b21611029475bba77ce6ee264796027
Author: walter <[email protected]>
AuthorDate: Tue May 14 19:38:58 2024 +0800

    [feature](fe) Advance the next id before transfering to master (#33817)
    
    If the FE metadata needs to be rolled back (such as time travel) and the ID
    generator is rolled back, the corresponding relationship of the metadata in
    BE/MS may be abnormal. This patch attempts to use the latest timestamp to
    advance the next id of ID generator before becoming master each time. This 
can
    ensure that in most scenarios, the rollback of metadata will not cause the 
ID
    generator to be rolled back.
---
 .../main/java/org/apache/doris/common/Config.java  |  8 +++++++
 .../main/java/org/apache/doris/catalog/Env.java    | 25 ++++++++++++++++++++++
 .../org/apache/doris/catalog/MetaIdGenerator.java  |  3 +--
 .../pipeline/cloud_p0/conf/fe_custom.conf          |  4 +++-
 .../pipeline/cloud_p1/conf/fe_custom.conf          |  4 +++-
 5 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java 
b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
index b70c6157d6d..edd79e3512e 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
@@ -2617,6 +2617,14 @@ public class Config extends ConfigBase {
     @ConfField
     public static boolean checkpoint_after_check_compatibility = false;
 
+    // Advance the next id before transferring to the master.
+    @ConfField(description = {
+            "是否在成为 Master 后推进 ID 分配器,保证即使回滚元数据时,它也不会回滚",
+            "Whether to advance the ID generator after becoming Master to 
ensure that the id "
+                    + "generator will not be rolled back even when metadata is 
rolled back."
+    })
+    public static boolean enable_advance_next_id = false;
+
     
//==========================================================================
     //                    begin of cloud config
     
//==========================================================================
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index cbf43b60913..26e24c12ba0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -1507,6 +1507,10 @@ public class Env {
         toMasterProgress = "roll editlog";
         editLog.rollEditLog();
 
+        if (Config.enable_advance_next_id) {
+            advanceNextId();
+        }
+
         // Log meta_version
         long journalVersion = MetaContext.get().getMetaVersion();
         if (journalVersion < FeConstants.meta_version) {
@@ -1602,6 +1606,27 @@ public class Env {
         }
     }
 
+    /*
+     * Advance the id generator, ensuring it doesn't roll back.
+     *
+     * If we need to support time travel, the next id cannot be rolled back to 
avoid
+     * errors in the corresponding relationship of the metadata recorded in 
BE/MS.
+     */
+    void advanceNextId() {
+        long currentId = idGenerator.getBatchEndId();
+        long currentNanos = System.nanoTime();
+        long nextId = currentId + 1;
+        if (nextId < currentNanos) {
+            nextId = currentNanos;
+        }
+
+        // ATTN: Because MetaIdGenerator has guaranteed that each id it 
returns must have
+        // been persisted, there is no need to perform persistence again here.
+        idGenerator.setId(nextId);
+
+        LOG.info("advance the next id from {} to {}", currentId, nextId);
+    }
+
     /*
      * There are something need to do after metadata is replayed, such as
      * 1. bug fix for metadata
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/catalog/MetaIdGenerator.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/MetaIdGenerator.java
index 65e30320c29..07bf263df3f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/MetaIdGenerator.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/MetaIdGenerator.java
@@ -74,8 +74,7 @@ public class MetaIdGenerator {
         }
     }
 
-    // just for checkpoint, so no need to synchronize
-    public long getBatchEndId() {
+    public synchronized long getBatchEndId() {
         return batchEndId;
     }
 
diff --git a/regression-test/pipeline/cloud_p0/conf/fe_custom.conf 
b/regression-test/pipeline/cloud_p0/conf/fe_custom.conf
index 18ed1d27132..d80a2b6b58b 100644
--- a/regression-test/pipeline/cloud_p0/conf/fe_custom.conf
+++ b/regression-test/pipeline/cloud_p0/conf/fe_custom.conf
@@ -37,4 +37,6 @@ cloud_unique_id=cloud_unique_id_sql_server00
 enable_job_schedule_second_for_test=true
 enable_light_index_change=false
 # For debug
-sys_log_verbose_modules = org.apache.doris.service.FrontendServiceImpl
\ No newline at end of file
+sys_log_verbose_modules = org.apache.doris.service.FrontendServiceImpl
+
+enable_advance_next_id = true
diff --git a/regression-test/pipeline/cloud_p1/conf/fe_custom.conf 
b/regression-test/pipeline/cloud_p1/conf/fe_custom.conf
index 199a2bfa870..fb392d5fe73 100644
--- a/regression-test/pipeline/cloud_p1/conf/fe_custom.conf
+++ b/regression-test/pipeline/cloud_p1/conf/fe_custom.conf
@@ -35,4 +35,6 @@ meta_service_endpoint=127.0.0.1:5000
 cloud_unique_id=cloud_unique_id_sql_server00
 enable_light_index_change=false
 # For debug
-sys_log_verbose_modules = org.apache.doris.service.FrontendServiceImpl
\ No newline at end of file
+sys_log_verbose_modules = org.apache.doris.service.FrontendServiceImpl
+
+enable_advance_next_id = true


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to