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

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit e55ba7ee8516c1ec86efe735029d4bd25a28d288
Author: Pxl <pxl...@qq.com>
AuthorDate: Thu Aug 31 12:35:38 2023 +0800

    [Bug](materialized-view) fix load db use analyzer to analyze diffrent 
metaindex (#23673)
    
    fix load db use analyzer to analyze diffrent metaindex
---
 be/src/agent/heartbeat_server.cpp                  | 53 +++++++++-------------
 be/src/common/status.h                             |  4 +-
 be/src/http/action/tablet_migration_action.cpp     |  6 +--
 be/src/olap/tablet_schema.h                        |  2 +-
 be/src/runtime/types.cpp                           |  2 +-
 be/src/vec/exec/scan/new_olap_scanner.cpp          |  7 ++-
 .../java/org/apache/doris/catalog/Database.java    |  5 +-
 .../java/org/apache/doris/catalog/OlapTable.java   |  7 ++-
 .../main/java/org/apache/doris/catalog/Table.java  |  3 +-
 .../apache/doris/datasource/InternalCatalog.java   |  6 +--
 10 files changed, 43 insertions(+), 52 deletions(-)

diff --git a/be/src/agent/heartbeat_server.cpp 
b/be/src/agent/heartbeat_server.cpp
index 92b121414c..855be182ff 100644
--- a/be/src/agent/heartbeat_server.cpp
+++ b/be/src/agent/heartbeat_server.cpp
@@ -92,20 +92,16 @@ Status HeartbeatServer::_heartbeat(const TMasterInfo& 
master_info) {
     if (_master_info->cluster_id == -1) {
         LOG(INFO) << "get first heartbeat. update cluster id";
         // write and update cluster id
-        auto st = _olap_engine->set_cluster_id(master_info.cluster_id);
-        if (!st.ok()) {
-            LOG(WARNING) << "fail to set cluster id. status=" << st;
-            return Status::InternalError("fail to set cluster id.");
-        } else {
-            _master_info->cluster_id = master_info.cluster_id;
-            LOG(INFO) << "record cluster id. host: " << 
master_info.network_address.hostname
-                      << ". port: " << master_info.network_address.port
-                      << ". cluster id: " << master_info.cluster_id;
-        }
+        RETURN_IF_ERROR(_olap_engine->set_cluster_id(master_info.cluster_id));
+
+        _master_info->cluster_id = master_info.cluster_id;
+        LOG(INFO) << "record cluster id. host: " << 
master_info.network_address.hostname
+                  << ". port: " << master_info.network_address.port
+                  << ". cluster id: " << master_info.cluster_id;
     } else {
         if (_master_info->cluster_id != master_info.cluster_id) {
-            LOG(WARNING) << "invalid cluster id: " << master_info.cluster_id 
<< ". ignore.";
-            return Status::InternalError("invalid cluster id. ignore.");
+            return Status::InternalError("invalid cluster id. ignore. 
cluster_id={}",
+                                         master_info.cluster_id);
         }
     }
 
@@ -132,10 +128,9 @@ Status HeartbeatServer::_heartbeat(const TMasterInfo& 
master_info) {
                 std::vector<InetAddress> hosts;
                 status = get_hosts(&hosts);
                 if (!status.ok() || hosts.empty()) {
-                    std::stringstream ss;
-                    ss << "the status was not ok when get_hosts, error is " << 
status.to_string();
-                    LOG(WARNING) << ss.str();
-                    return Status::InternalError(ss.str());
+                    return Status::InternalError(
+                            "the status was not ok when get_hosts, error is 
{}",
+                            status.to_string());
                 }
 
                 //step4: check if the IP of FQDN belongs to the current 
machine and update BackendOptions._s_localhost
@@ -149,12 +144,10 @@ Status HeartbeatServer::_heartbeat(const TMasterInfo& 
master_info) {
                 }
 
                 if (!set_new_localhost) {
-                    std::stringstream ss;
-                    ss << "the host recorded in master is " << 
master_info.backend_ip
-                       << ", but we cannot found the local ip that mapped to 
that host."
-                       << BackendOptions::get_localhost();
-                    LOG(WARNING) << ss.str();
-                    return Status::InternalError(ss.str());
+                    return Status::InternalError(
+                            "the host recorded in master is {}, but we cannot 
found the local ip "
+                            "that mapped to that host. backend={}",
+                            master_info.backend_ip, 
BackendOptions::get_localhost());
                 }
             } else {
                 // if is ip,not check anything,use it
@@ -179,12 +172,11 @@ Status HeartbeatServer::_heartbeat(const TMasterInfo& 
master_info) {
                       << ". port: " << _master_info->network_address.port
                       << ". epoch: " << _fe_epoch;
         } else {
-            LOG(WARNING) << "epoch is not greater than local. ignore 
heartbeat. host: "
-                         << _master_info->network_address.hostname
-                         << " port: " << _master_info->network_address.port
-                         << " local epoch: " << _fe_epoch
-                         << " received epoch: " << master_info.epoch;
-            return Status::InternalError("epoch is not greater than local. 
ignore heartbeat.");
+            return Status::InternalError(
+                    "epoch is not greater than local. ignore heartbeat. host: 
{}, port: {}, local "
+                    "epoch: {}, received epoch: {}",
+                    _master_info->network_address.hostname, 
_master_info->network_address.port,
+                    _fe_epoch, master_info.epoch);
         }
     } else {
         // when Master FE restarted, host and port remains the same, but epoch 
will be increased.
@@ -200,9 +192,8 @@ Status HeartbeatServer::_heartbeat(const TMasterInfo& 
master_info) {
             _master_info->__set_token(master_info.token);
             LOG(INFO) << "get token. token: " << _master_info->token;
         } else if (_master_info->token != master_info.token) {
-            LOG(WARNING) << "invalid token. local_token:" << 
_master_info->token
-                         << ". token:" << master_info.token;
-            return Status::InternalError("invalid token.");
+            return Status::InternalError("invalid token. local_token: {}, 
token: {}",
+                                         _master_info->token, 
master_info.token);
         }
     }
 
diff --git a/be/src/common/status.h b/be/src/common/status.h
index a860236f2e..a2ddbaaa46 100644
--- a/be/src/common/status.h
+++ b/be/src/common/status.h
@@ -312,7 +312,9 @@ constexpr bool capture_stacktrace(int code) {
         && code != ErrorCode::TOO_MANY_TRANSACTIONS
         && code != ErrorCode::TRANSACTION_ALREADY_COMMITTED
         && code != ErrorCode::KEY_NOT_FOUND
-        && code != ErrorCode::KEY_ALREADY_EXISTS;
+        && code != ErrorCode::KEY_ALREADY_EXISTS
+        && code != ErrorCode::CANCELLED
+        && code != ErrorCode::UNINITIALIZED;
 }
 // clang-format on
 
diff --git a/be/src/http/action/tablet_migration_action.cpp 
b/be/src/http/action/tablet_migration_action.cpp
index 9720b8863d..3d5b40ae18 100644
--- a/be/src/http/action/tablet_migration_action.cpp
+++ b/be/src/http/action/tablet_migration_action.cpp
@@ -171,9 +171,9 @@ Status TabletMigrationAction::_check_param(HttpRequest* 
req, int64_t& tablet_id,
         tablet_id = std::stoull(req_tablet_id);
         schema_hash = std::stoul(req_schema_hash);
     } catch (const std::exception& e) {
-        LOG(WARNING) << "invalid argument.tablet_id:" << req_tablet_id
-                     << ", schema_hash:" << req_schema_hash;
-        return Status::InternalError("Convert failed, {}", e.what());
+        return Status::InternalError(
+                "Convert failed:{}, invalid argument.tablet_id: {}, 
schema_hash: {}", e.what(),
+                req_tablet_id, req_schema_hash);
     }
     dest_disk = req->param("disk");
     goal = req->param("goal");
diff --git a/be/src/olap/tablet_schema.h b/be/src/olap/tablet_schema.h
index 06ef1a8344..715af14191 100644
--- a/be/src/olap/tablet_schema.h
+++ b/be/src/olap/tablet_schema.h
@@ -301,7 +301,7 @@ public:
             if (str.size() > 1) {
                 str += ", ";
             }
-            str += p.first;
+            str += p.first + "(" + std::to_string(_cols[p.second].unique_id()) 
+ ")";
         }
         str += "]";
         return str;
diff --git a/be/src/runtime/types.cpp b/be/src/runtime/types.cpp
index a919995369..1b8870286e 100644
--- a/be/src/runtime/types.cpp
+++ b/be/src/runtime/types.cpp
@@ -40,7 +40,7 @@ TypeDescriptor::TypeDescriptor(const std::vector<TTypeNode>& 
types, int* idx)
     switch (node.type) {
     case TTypeNodeType::SCALAR: {
         DCHECK(node.__isset.scalar_type);
-        const TScalarType scalar_type = node.scalar_type;
+        const TScalarType& scalar_type = node.scalar_type;
         type = thrift_to_type(scalar_type.type);
         if (type == TYPE_CHAR || type == TYPE_VARCHAR || type == TYPE_HLL) {
             DCHECK(scalar_type.__isset.len);
diff --git a/be/src/vec/exec/scan/new_olap_scanner.cpp 
b/be/src/vec/exec/scan/new_olap_scanner.cpp
index fa3fb70e21..5ddc56bcb7 100644
--- a/be/src/vec/exec/scan/new_olap_scanner.cpp
+++ b/be/src/vec/exec/scan/new_olap_scanner.cpp
@@ -429,10 +429,9 @@ Status NewOlapScanner::_init_return_columns() {
                                 : 
_tablet_schema->field_index(slot->col_name());
 
         if (index < 0) {
-            std::stringstream ss;
-            ss << "field name is invalid. field=" << slot->col_name()
-               << ", field_name_to_index=" << 
_tablet_schema->get_all_field_names();
-            return Status::InternalError(ss.str());
+            return Status::InternalError(
+                    "field name is invalid. field={}, field_name_to_index={}, 
col_unique_id={}",
+                    slot->col_name(), _tablet_schema->get_all_field_names(), 
slot->col_unique_id());
         }
         _return_columns.push_back(index);
         if (slot->is_nullable() && 
!_tablet_schema->column(index).is_nullable()) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
index 7c2981e239..0fc63253d9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
@@ -17,7 +17,6 @@
 
 package org.apache.doris.catalog;
 
-import org.apache.doris.analysis.Analyzer;
 import org.apache.doris.catalog.TableIf.TableType;
 import org.apache.doris.cluster.ClusterNamespace;
 import org.apache.doris.common.AnalysisException;
@@ -613,9 +612,9 @@ public class Database extends MetaObject implements 
Writable, DatabaseIf<Table>
         }
     }
 
-    public void analyze(Analyzer analyzer) {
+    public void analyze() {
         for (Table table : nameToTable.values()) {
-            table.analyze(analyzer);
+            table.analyze(getFullName());
         }
     }
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
index 9a7866f83a..8a4026bbca 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
@@ -46,6 +46,7 @@ import org.apache.doris.common.io.DeepCopy;
 import org.apache.doris.common.io.Text;
 import org.apache.doris.common.util.PropertyAnalyzer;
 import org.apache.doris.common.util.Util;
+import org.apache.doris.qe.ConnectContext;
 import org.apache.doris.qe.OriginStatement;
 import org.apache.doris.resource.Tag;
 import org.apache.doris.statistics.AnalysisInfo;
@@ -2228,9 +2229,13 @@ public class OlapTable extends Table {
     }
 
     @Override
-    public void analyze(Analyzer analyzer) {
+    public void analyze(String dbName) {
         for (MaterializedIndexMeta meta : indexIdToMeta.values()) {
             try {
+                ConnectContext connectContext = new ConnectContext();
+                connectContext.setCluster(SystemInfoService.DEFAULT_CLUSTER);
+                connectContext.setDatabase(dbName);
+                Analyzer analyzer = new Analyzer(Env.getCurrentEnv(), 
connectContext);
                 meta.parseStmt(analyzer);
             } catch (IOException e) {
                 e.printStackTrace();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
index a6d1b11d78..0c50fc42b4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
@@ -18,7 +18,6 @@
 package org.apache.doris.catalog;
 
 import org.apache.doris.alter.AlterCancelException;
-import org.apache.doris.analysis.Analyzer;
 import org.apache.doris.analysis.CreateTableStmt;
 import org.apache.doris.common.DdlException;
 import org.apache.doris.common.MetaNotFoundException;
@@ -556,6 +555,6 @@ public abstract class Table extends MetaObject implements 
Writable, TableIf {
         return Optional.empty();
     }
 
-    public void analyze(Analyzer analyzer) {
+    public void analyze(String dbName) {
     }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
index ac10fa32a2..6ebf5a6673 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
@@ -3078,11 +3078,7 @@ public class InternalCatalog implements 
CatalogIf<Database> {
             fullNameToDb.put(db.getFullName(), db);
             
Env.getCurrentGlobalTransactionMgr().addDatabaseTransactionMgr(db.getId());
 
-            ConnectContext connectContext = new ConnectContext();
-            connectContext.setCluster(SystemInfoService.DEFAULT_CLUSTER);
-            connectContext.setDatabase(db.getFullName());
-            Analyzer analyzer = new Analyzer(Env.getCurrentEnv(), 
connectContext);
-            db.analyze(analyzer);
+            db.analyze();
         }
         // ATTN: this should be done after load Db, and before loadAlterJob
         recreateTabletInvertIndex();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to