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 d1f3d419a13 [feature](merge-cloud) Add init CloudEnv and
CloudInternalCatalog (#29962)
d1f3d419a13 is described below
commit d1f3d419a1319eb57aab21c5fd0ac128d8fcd2a1
Author: yujun <[email protected]>
AuthorDate: Mon Jan 15 13:51:42 2024 +0800
[feature](merge-cloud) Add init CloudEnv and CloudInternalCatalog (#29962)
---
.../main/java/org/apache/doris/catalog/Env.java | 6 +--
.../java/org/apache/doris/catalog/EnvFactory.java | 61 ++++++++++++++++++++++
.../java/org/apache/doris/catalog/Partition.java | 2 +-
.../java/org/apache/doris/catalog/Replica.java | 2 +-
.../org/apache/doris/cloud/catalog/CloudEnv.java | 29 ++++++++++
.../apache/doris/cloud/catalog/CloudPartition.java | 11 ++--
.../apache/doris/cloud/catalog/CloudReplica.java | 7 ---
.../cloud/datasource/CloudInternalCatalog.java | 29 ++++++++++
.../org/apache/doris/datasource/CatalogMgr.java | 3 +-
.../org/apache/doris/binlog/BinlogManagerTest.java | 3 +-
.../org/apache/doris/catalog/EnvFactoryTest.java | 56 ++++++++++++++++++++
.../statistics/StatisticsAutoCollectorTest.java | 5 +-
12 files changed, 192 insertions(+), 22 deletions(-)
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 cc025656976..5b9676a201d 100755
--- 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
@@ -622,7 +622,7 @@ public class Env {
}
private static class SingletonHolder {
- private static final Env INSTANCE = new Env();
+ private static final Env INSTANCE = EnvFactory.createEnv(false);
}
private Env() {
@@ -630,7 +630,7 @@ public class Env {
}
// if isCheckpointCatalog is true, it means that we should not collect
thread pool metric
- private Env(boolean isCheckpointCatalog) {
+ public Env(boolean isCheckpointCatalog) {
this.catalogMgr = new CatalogMgr();
this.load = new Load();
this.routineLoadManager = new RoutineLoadManager();
@@ -771,7 +771,7 @@ public class Env {
// only checkpoint thread it self will goes here.
// so no need to care about the thread safe.
if (CHECKPOINT == null) {
- CHECKPOINT = new Env(true);
+ CHECKPOINT = EnvFactory.createEnv(true);
}
return CHECKPOINT;
} else {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/EnvFactory.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/EnvFactory.java
new file mode 100644
index 00000000000..a44e9da9c77
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/EnvFactory.java
@@ -0,0 +1,61 @@
+// 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.doris.catalog;
+
+import org.apache.doris.cloud.catalog.CloudEnv;
+import org.apache.doris.cloud.catalog.CloudPartition;
+import org.apache.doris.cloud.catalog.CloudReplica;
+import org.apache.doris.cloud.datasource.CloudInternalCatalog;
+import org.apache.doris.common.Config;
+import org.apache.doris.datasource.InternalCatalog;
+
+
+public class EnvFactory {
+
+ public static Env createEnv(boolean isCheckpointCatalog) {
+ if (Config.isCloudMode()) {
+ return new CloudEnv(isCheckpointCatalog);
+ } else {
+ return new Env(isCheckpointCatalog);
+ }
+ }
+
+ public static InternalCatalog createInternalCatalog() {
+ if (Config.isCloudMode()) {
+ return new CloudInternalCatalog();
+ } else {
+ return new InternalCatalog();
+ }
+ }
+
+ public static Partition createPartition() {
+ if (Config.isCloudMode()) {
+ return new CloudPartition();
+ } else {
+ return new Partition();
+ }
+ }
+
+ public static Replica createReplica() {
+ if (Config.isCloudMode()) {
+ return new CloudReplica();
+ } else {
+ return new Replica();
+ }
+ }
+}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Partition.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Partition.java
index 755e5f14a29..cf4ac871c40 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Partition.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Partition.java
@@ -331,7 +331,7 @@ public class Partition extends MetaObject implements
Writable {
}
public static Partition read(DataInput in) throws IOException {
- Partition partition = new Partition();
+ Partition partition = EnvFactory.createPartition();
partition.readFields(in);
return partition;
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Replica.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Replica.java
index 66d84d117f9..e6b9066af78 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Replica.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Replica.java
@@ -671,7 +671,7 @@ public class Replica implements Writable {
}
public static Replica read(DataInput in) throws IOException {
- Replica replica = new Replica();
+ Replica replica = EnvFactory.createReplica();
replica.readFields(in);
return replica;
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudEnv.java
b/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudEnv.java
new file mode 100644
index 00000000000..8d49783f3ca
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudEnv.java
@@ -0,0 +1,29 @@
+// 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.doris.cloud.catalog;
+
+import org.apache.doris.catalog.Env;
+
+public class CloudEnv extends Env {
+
+ public CloudEnv(boolean isCheckpointCatalog) {
+ super(isCheckpointCatalog);
+ }
+
+}
+
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudPartition.java
b/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudPartition.java
index fba1daa512f..03e7fef0f4d 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudPartition.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudPartition.java
@@ -385,12 +385,11 @@ public class CloudPartition extends Partition {
return null;
}
- public static CloudPartition read(DataInput in) throws IOException {
- CloudPartition partition = new CloudPartition();
- partition.readFields(in);
- partition.setDbId(in.readLong());
- partition.setTableId(in.readLong());
- return partition;
+ @Override
+ public void readFields(DataInput in) throws IOException {
+ super.readFields(in);
+ this.dbId = in.readLong();
+ this.tableId = in.readLong();
}
@Override
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.java
b/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.java
index cf503d9bc40..5054fa7e41e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.java
@@ -354,13 +354,6 @@ public class CloudReplica extends Replica {
}
}
- public static CloudReplica read(DataInput in) throws IOException {
- CloudReplica replica = new CloudReplica();
- replica.readFields(in);
- // TODO(luwei): persist and fill-up clusterToBackends to take full
advantage of data cache
- return replica;
- }
-
public long getDbId() {
return dbId;
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/cloud/datasource/CloudInternalCatalog.java
b/fe/fe-core/src/main/java/org/apache/doris/cloud/datasource/CloudInternalCatalog.java
new file mode 100644
index 00000000000..5db352f8526
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/cloud/datasource/CloudInternalCatalog.java
@@ -0,0 +1,29 @@
+// 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.doris.cloud.datasource;
+
+import org.apache.doris.datasource.InternalCatalog;
+
+public class CloudInternalCatalog extends InternalCatalog {
+
+ public CloudInternalCatalog() {
+ super();
+ }
+
+}
+
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
index d727ee620f6..2ad27c87f22 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
@@ -27,6 +27,7 @@ import org.apache.doris.analysis.ShowCatalogStmt;
import org.apache.doris.analysis.ShowCreateCatalogStmt;
import org.apache.doris.catalog.DatabaseIf;
import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.EnvFactory;
import org.apache.doris.catalog.Resource;
import org.apache.doris.catalog.Resource.ReferenceType;
import org.apache.doris.catalog.TableIf;
@@ -113,7 +114,7 @@ public class CatalogMgr implements Writable,
GsonPostProcessable {
}
private void initInternalCatalog() {
- internalCatalog = new InternalCatalog();
+ internalCatalog = EnvFactory.createInternalCatalog();
addCatalog(internalCatalog);
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/binlog/BinlogManagerTest.java
b/fe/fe-core/src/test/java/org/apache/doris/binlog/BinlogManagerTest.java
index dabd8bfc1e4..03f8d325d77 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/binlog/BinlogManagerTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/binlog/BinlogManagerTest.java
@@ -20,6 +20,7 @@ package org.apache.doris.binlog;
import org.apache.doris.catalog.BinlogConfig;
import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.EnvFactory;
import org.apache.doris.common.Config;
import org.apache.doris.common.Pair;
import org.apache.doris.datasource.InternalCatalog;
@@ -118,7 +119,7 @@ public class BinlogManagerTest {
new MockUp<Env>() {
@Mock
public InternalCatalog getCurrentInternalCatalog() {
- return new InternalCatalog();
+ return EnvFactory.createInternalCatalog();
}
};
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/catalog/EnvFactoryTest.java
b/fe/fe-core/src/test/java/org/apache/doris/catalog/EnvFactoryTest.java
new file mode 100644
index 00000000000..ddd3b9441a5
--- /dev/null
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/EnvFactoryTest.java
@@ -0,0 +1,56 @@
+// 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.doris.catalog;
+
+import org.apache.doris.cloud.catalog.CloudEnv;
+import org.apache.doris.cloud.catalog.CloudPartition;
+import org.apache.doris.cloud.catalog.CloudReplica;
+import org.apache.doris.cloud.datasource.CloudInternalCatalog;
+import org.apache.doris.common.Config;
+import org.apache.doris.datasource.InternalCatalog;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class EnvFactoryTest {
+
+ @Test
+ public void testCreate() throws Exception {
+ Config.cloud_unique_id = "";
+ Assert.assertTrue(Env.getCurrentEnv() instanceof Env);
+ Assert.assertFalse(Env.getCurrentEnv() instanceof CloudEnv);
+ Assert.assertTrue(Env.getCurrentInternalCatalog() instanceof
InternalCatalog);
+ Assert.assertFalse(Env.getCurrentInternalCatalog() instanceof
CloudInternalCatalog);
+ Assert.assertTrue(EnvFactory.createEnv(false) instanceof Env);
+ Assert.assertFalse(EnvFactory.createEnv(false) instanceof CloudEnv);
+ Assert.assertTrue(EnvFactory.createInternalCatalog() instanceof
InternalCatalog);
+ Assert.assertFalse(EnvFactory.createInternalCatalog() instanceof
CloudInternalCatalog);
+ Assert.assertTrue(EnvFactory.createPartition() instanceof Partition);
+ Assert.assertFalse(EnvFactory.createPartition() instanceof
CloudPartition);
+ Assert.assertTrue(EnvFactory.createReplica() instanceof Replica);
+ Assert.assertFalse(EnvFactory.createReplica() instanceof CloudReplica);
+
+ Config.cloud_unique_id = "test_cloud";
+ Assert.assertTrue(EnvFactory.createEnv(false) instanceof CloudEnv);
+ Assert.assertTrue(EnvFactory.createInternalCatalog() instanceof
CloudInternalCatalog);
+ Assert.assertTrue(EnvFactory.createPartition() instanceof
CloudPartition);
+ Assert.assertTrue(EnvFactory.createReplica() instanceof CloudReplica);
+ }
+
+}
+
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/statistics/StatisticsAutoCollectorTest.java
b/fe/fe-core/src/test/java/org/apache/doris/statistics/StatisticsAutoCollectorTest.java
index 2455581c29c..bffdfbd2c68 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/statistics/StatisticsAutoCollectorTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/statistics/StatisticsAutoCollectorTest.java
@@ -21,6 +21,7 @@ import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.DatabaseIf;
import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.EnvFactory;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.Table;
@@ -464,7 +465,7 @@ public class StatisticsAutoCollectorTest {
@Test
public void testDisableAuto1() throws Exception {
- InternalCatalog catalog1 = new InternalCatalog();
+ InternalCatalog catalog1 = EnvFactory.createInternalCatalog();
List<CatalogIf> catalogs = Lists.newArrayList();
catalogs.add(catalog1);
@@ -492,7 +493,7 @@ public class StatisticsAutoCollectorTest {
@Test
public void testDisableAuto2() throws Exception {
- InternalCatalog catalog1 = new InternalCatalog();
+ InternalCatalog catalog1 = EnvFactory.createInternalCatalog();
List<CatalogIf> catalogs = Lists.newArrayList();
catalogs.add(catalog1);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]