You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by su...@apache.org on 2021/01/22 16:48:50 UTC

[druid] branch master updated: [Bug Fix] Broker will not wait for its SQL metadata view to fully initialize before starting up, even though set awaitInitializationOnStart true (#10779)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8c6153d  [Bug Fix] Broker will not wait for its SQL metadata view to fully initialize before starting up, even though set awaitInitializationOnStart true (#10779)
8c6153d is described below

commit 8c6153d511e4bd9ea365190a59f4e29bdb402f97
Author: zhangyue19921010 <69...@users.noreply.github.com>
AuthorDate: Sat Jan 23 00:48:21 2021 +0800

    [Bug Fix] Broker will not wait for its SQL metadata view to fully initialize before starting up, even though set awaitInitializationOnStart true (#10779)
    
    * enhance the logic of Start up DruidSchema immediately if there are no segments.
    
    * add UT to test DruidSchema init
    
    Co-authored-by: yuezhang <yu...@freewheel.tv>
---
 .../druid/sql/calcite/schema/DruidSchema.java      |  4 +-
 .../druid/sql/calcite/schema/DruidSchemaTest.java  | 46 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java b/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java
index 215120a..1e4321b 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java
@@ -242,7 +242,9 @@ public class DruidSchema extends AbstractSchema
                       break;
                     }
 
-                    if (isServerViewInitialized) {
+                    // lastFailure != 0L means exceptions happened before and there're some refresh work was not completed.
+                    // so that even ServerView is initialized, we can't let broker complete initialization.
+                    if (isServerViewInitialized && lastFailure == 0L) {
                       // Server view is initialized, but we don't need to do a refresh. Could happen if there are
                       // no segments in the system yet. Just mark us as initialized, then.
                       initialized.countDown();
diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidSchemaTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidSchemaTest.java
index 9b633e8..0863cd9 100644
--- a/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidSchemaTest.java
+++ b/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidSchemaTest.java
@@ -137,6 +137,7 @@ public class DruidSchemaTest extends CalciteTestBase
 
   private SpecificSegmentsQuerySegmentWalker walker = null;
   private DruidSchema schema = null;
+  private DruidSchema schema2 = null;
   private SegmentManager segmentManager;
   private Set<String> segmentDataSourceNames;
   private Set<String> joinableDataSourceNames;
@@ -269,6 +270,38 @@ public class DruidSchemaTest extends CalciteTestBase
       }
     };
 
+    schema2 = new DruidSchema(
+            CalciteTests.createMockQueryLifecycleFactory(walker, conglomerate),
+            serverView,
+            segmentManager,
+            new MapJoinableFactory(ImmutableSet.of(globalTableJoinable), ImmutableMap.of(globalTableJoinable.getClass(), GlobalTableDataSource.class)),
+            PLANNER_CONFIG_DEFAULT,
+            new NoopViewManager(),
+            new NoopEscalator()
+    )
+    {
+
+      boolean throwException = true;
+      @Override
+      protected DruidTable buildDruidTable(String dataSource)
+      {
+        DruidTable table = super.buildDruidTable(dataSource);
+        buildTableLatch.countDown();
+        return table;
+      }
+
+      @Override
+      Set<SegmentId> refreshSegments(final Set<SegmentId> segments) throws IOException
+      {
+        if (throwException) {
+          throwException = false;
+          throw new RuntimeException("Query[xxxx] url[http://xxxx:8083/druid/v2/] timed out.");
+        } else {
+          return super.refreshSegments(segments);
+        }
+      }
+    };
+
     schema.start();
     schema.awaitInitialization();
   }
@@ -290,6 +323,19 @@ public class DruidSchemaTest extends CalciteTestBase
   }
 
   @Test
+  public void testSchemaInit() throws InterruptedException
+  {
+    schema2.start();
+    schema2.awaitInitialization();
+    Map<String, Table> tableMap = schema2.getTableMap();
+    Assert.assertEquals(2, tableMap.size());
+    Assert.assertTrue(tableMap.containsKey("foo"));
+    Assert.assertTrue(tableMap.containsKey("foo2"));
+    schema2.stop();
+  }
+
+
+  @Test
   public void testGetTableMapFoo()
   {
     final DruidTable fooTable = (DruidTable) schema.getTableMap().get("foo");


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org