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

laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new f630ce148 feat: add new macro definitions (#1429)
f630ce148 is described below

commit f630ce148fb9764c83481b2ebabf2e11944ba41a
Author: liguohao <[email protected]>
AuthorDate: Tue Apr 4 11:06:18 2023 +0800

    feat: add new macro definitions (#1429)
    
    issue: https://github.com/apache/incubator-pegasus/issues/1426
    
    Add some macro definitions & fix a little docker build problem.
---
 docker/pegasus-build-env/centos6/Dockerfile   |  2 +-
 src/geo/lib/geo_client.cpp                    |  5 +----
 src/redis_protocol/proxy_lib/redis_parser.cpp | 21 ++++++++++++---------
 src/utils/errors.h                            | 12 ++++++++++--
 src/utils/fmt_logging.h                       | 14 ++++++++++++++
 5 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/docker/pegasus-build-env/centos6/Dockerfile 
b/docker/pegasus-build-env/centos6/Dockerfile
index 3e042b7d6..18283121f 100644
--- a/docker/pegasus-build-env/centos6/Dockerfile
+++ b/docker/pegasus-build-env/centos6/Dockerfile
@@ -76,7 +76,7 @@ ENV MAVEN_HOME=/opt/rh/rh-maven33/root/usr/
 ENV PATH=$MAVEN_HOME/bin:$JAVA_HOME/bin:$GCC_HOME/bin:$PYTHON2_HOME/bin/:$PATH
 ENV 
LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/amd64/server:$PYTHON2_HOME/lib64/:$LD_LIBRARY_PATH
 
-RUN python -m pip install --user --upgrade pip==20.3.4 && python -m pip 
install --no-cache-dir cmake -i https://pypi.tuna.tsinghua.edu.cn/simple
+RUN python -m pip install --no-cache-dir --user --upgrade pip==20.3.4 && 
python -m pip install --no-cache-dir cmake -i 
https://pypi.tuna.tsinghua.edu.cn/simple
 
 RUN wget --progress=dot:giga 
https://github.com/apache/thrift/archive/refs/tags/0.11.0.tar.gz -P /opt/thrift 
&& \
     cd /opt/thrift && tar xzf 0.11.0.tar.gz && cd thrift-0.11.0 && 
./bootstrap.sh && \
diff --git a/src/geo/lib/geo_client.cpp b/src/geo/lib/geo_client.cpp
index e7a4009b7..335afda62 100644
--- a/src/geo/lib/geo_client.cpp
+++ b/src/geo/lib/geo_client.cpp
@@ -111,10 +111,7 @@ geo_client::geo_client(const char *config_file,
     CHECK_NOTNULL(_geo_data_client, "init pegasus _geo_data_client failed");
 
     dsn::error_s s = _codec.set_latlng_indices(FLAGS_latitude_index, 
FLAGS_longitude_index);
-    CHECK(s.is_ok(),
-          "set_latlng_indices({}, {}) failed",
-          FLAGS_latitude_index,
-          FLAGS_longitude_index);
+    CHECK_OK(s, "set_latlng_indices({}, {}) failed", FLAGS_latitude_index, 
FLAGS_longitude_index);
 }
 
 dsn::error_s geo_client::set_max_level(int level)
diff --git a/src/redis_protocol/proxy_lib/redis_parser.cpp 
b/src/redis_protocol/proxy_lib/redis_parser.cpp
index ba009616c..8712f2345 100644
--- a/src/redis_protocol/proxy_lib/redis_parser.cpp
+++ b/src/redis_protocol/proxy_lib/redis_parser.cpp
@@ -807,14 +807,16 @@ void redis_parser::geo_radius(message_entry &entry)
     // longitude latitude
     double lng_degrees = 0.0;
     const std::string &str_lng_degrees = 
redis_request.sub_requests[2].data.to_string();
-    if (!dsn::buf2double(str_lng_degrees, lng_degrees)) {
-        LOG_WARNING("longitude parameter '{}' is error, use {}", 
str_lng_degrees, lng_degrees);
-    }
+    LOG_WARNING_IF(!dsn::buf2double(str_lng_degrees, lng_degrees),
+                   "longitude parameter '{}' is error, use {}",
+                   str_lng_degrees,
+                   lng_degrees);
     double lat_degrees = 0.0;
     const std::string &str_lat_degrees = 
redis_request.sub_requests[3].data.to_string();
-    if (!dsn::buf2double(str_lat_degrees, lat_degrees)) {
-        LOG_WARNING("latitude parameter '{}' is error, use {}", 
str_lat_degrees, lat_degrees);
-    }
+    LOG_WARNING_IF(!dsn::buf2double(str_lat_degrees, lat_degrees),
+                   "latitude parameter '{}' is error, use {}",
+                   str_lat_degrees,
+                   lat_degrees);
 
     // radius m|km|ft|mi [WITHCOORD] [WITHDIST] [COUNT count] [ASC|DESC]
     double radius_m = 100.0;
@@ -1049,9 +1051,10 @@ void redis_parser::parse_geo_radius_parameters(const 
std::vector<redis_bulk_stri
             WITHHASH = true;
         } else if (dsn::utils::iequals(opt, "COUNT") && base_index + 1 < 
opts.size()) {
             const std::string &str_count = opts[base_index + 
1].data.to_string();
-            if (!dsn::buf2int32(str_count, count)) {
-                LOG_ERROR("'COUNT {}' option is error, use {}", str_count, 
count);
-            }
+            LOG_ERROR_IF(!dsn::buf2int32(str_count, count),
+                         "'COUNT {}' option is error, use {}",
+                         str_count,
+                         count);
         } else if (dsn::utils::iequals(opt, "ASC")) {
             sort_type = geo::geo_client::SortType::asc;
         } else if (dsn::utils::iequals(opt, "DESC")) {
diff --git a/src/utils/errors.h b/src/utils/errors.h
index 6e97ce20d..8cc47a74b 100644
--- a/src/utils/errors.h
+++ b/src/utils/errors.h
@@ -31,6 +31,7 @@
 #include "utils/api_utilities.h"
 #include "utils/error_code.h"
 #include "utils/fmt_logging.h"
+#include "utils/ports.h"
 #include "utils/smart_pointers.h"
 #include "utils/string_view.h"
 
@@ -48,7 +49,7 @@ namespace dsn {
 //
 //   error_s err = open_file("");
 //   if (!err.is_ok()) {
-//       std::cerr << s.description() << std::endl;
+//       std::cerr << err.description() << std::endl;
 //       // print: "ERR_INVALID_PARAMETERS: file name should not be empty"
 //   }
 //
@@ -223,6 +224,13 @@ private:
 #define RETURN_NOT_OK(s)                                                       
                    \
     do {                                                                       
                    \
         const ::dsn::error_s &_s = (s);                                        
                    \
-        if (!_s.is_ok())                                                       
                    \
+        if (dsn_unlikely(!_s.is_ok())) {                                       
                    \
             return _s;                                                         
                    \
+        }                                                                      
                    \
+    } while (false);
+
+#define CHECK_OK(s, ...)                                                       
                    \
+    do {                                                                       
                    \
+        const ::dsn::error_s &_s = (s);                                        
                    \
+        CHECK(_s.is_ok(), fmt::format(__VA_ARGS__));                           
                    \
     } while (false);
diff --git a/src/utils/fmt_logging.h b/src/utils/fmt_logging.h
index 8bc3c5187..4b6b927f6 100644
--- a/src/utils/fmt_logging.h
+++ b/src/utils/fmt_logging.h
@@ -40,6 +40,20 @@
 #define LOG_ERROR(...) dlog_f(LOG_LEVEL_ERROR, __VA_ARGS__)
 #define LOG_FATAL(...) dlog_f(LOG_LEVEL_FATAL, __VA_ARGS__)
 
+#define LOG_WARNING_IF(x, ...)                                                 
                    \
+    do {                                                                       
                    \
+        if (dsn_unlikely(x)) {                                                 
                    \
+            LOG_WARNING(__VA_ARGS__);                                          
                    \
+        }                                                                      
                    \
+    } while (false)
+
+#define LOG_ERROR_IF(x, ...)                                                   
                    \
+    do {                                                                       
                    \
+        if (dsn_unlikely(x)) {                                                 
                    \
+            LOG_ERROR(__VA_ARGS__);                                            
                    \
+        }                                                                      
                    \
+    } while (false)
+
 #define CHECK_EXPRESSION(expression, evaluation, ...)                          
                    \
     do {                                                                       
                    \
         if (dsn_unlikely(!(evaluation))) {                                     
                    \


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

Reply via email to