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

harishgokul01 pushed a commit to branch release-bugs
in repository https://gitbox.apache.org/repos/asf/incubator-resilientdb.git


The following commit(s) were added to refs/heads/release-bugs by this push:
     new be13d693 Refactor server configuration files and update generation 
script
be13d693 is described below

commit be13d693c901aa40267fdb3ebc91d863ef0cc43d
Author: harish876 <[email protected]>
AuthorDate: Fri Oct 31 06:59:27 2025 +0000

    Refactor server configuration files and update generation script
    
    - Removed the old `server.config.json` file and replaced it with a new 
`server.json` file that follows a more structured JSON format.
    - Updated `generate_config.sh` to handle the new configuration file 
structure and added logic to copy the generated JSON to the appropriate output 
directory.
    - Enhanced `server.config` to include additional configuration options and 
improved formatting for better readability.
    - Adjusted the C++ tool `generate_region_config_cc` to utilize 
`JsonPrintOptions` for generating JSON output with better formatting.
---
 server.config.json                        |   1 -
 service/tools/config/generate_config.sh   |  11 ++-
 service/tools/config/server/server.config | 121 +++++++++++++++++++++---------
 service/tools/config/server/server.json   |  91 ++++++++++++++++++++++
 tools/generate_region_config_cc.cpp       |  59 +++++++++------
 5 files changed, 224 insertions(+), 59 deletions(-)

diff --git a/server.config.json b/server.config.json
deleted file mode 100644
index c71f61c8..00000000
--- a/server.config.json
+++ /dev/null
@@ -1 +0,0 @@
-{"region":[{"replicaInfo":[{"id":"1","ip":"127.0.0.1","port":20001},{"id":"2","ip":"127.0.0.1","port":20002},{"id":"3","ip":"127.0.0.1","port":20003},{"id":"4","ip":"127.0.0.1","port":20004}]}]}
\ No newline at end of file
diff --git a/service/tools/config/generate_config.sh 
b/service/tools/config/generate_config.sh
index 92aaa490..d0baa7f5 100755
--- a/service/tools/config/generate_config.sh
+++ b/service/tools/config/generate_config.sh
@@ -96,7 +96,16 @@ do
   idx=$(($idx+1))
 done
 
-${CONFIG_TOOLS_BIN} ./server.config ./server.config.json 
+TEMPLATE_JSON=${output_path}/server/server.config
+
+if [ -f "$TEMPLATE_JSON" ]; then
+  ${CONFIG_TOOLS_BIN} ./server.config ./server.config.json ${TEMPLATE_JSON}
+else
+  ${CONFIG_TOOLS_BIN} ./server.config ./server.config.json
+fi
+
+mkdir -p ${output_path}/server
+cp server.config.json ${output_path}/server/server.json
 mv server.config.json ${output_path}/server/server.config
 mv client.config ${output_path}/interface/service.config
 echo "config done:" ${output_path}/server/server.config
diff --git a/service/tools/config/server/server.config 
b/service/tools/config/server/server.config
index 740bae3a..e0e6fb30 100644
--- a/service/tools/config/server/server.config
+++ b/service/tools/config/server/server.config
@@ -1,38 +1,91 @@
 {
-  region : {
-    replica_info : {
-      id:1,
-      ip:"127.0.0.1",
-      port: 10001,
-    },
-    replica_info : {
-      id:2,
-      ip:"127.0.0.1",
-      port: 10002,
-    },
-    replica_info : {
-      id:3,
-      ip:"127.0.0.1",
-      port: 10003,
-    },
-    replica_info : {
-      id:4,
-      ip:"127.0.0.1",
-      port: 10004,
-    },
-    region_id: 1,
+ "region": [
+  {
+   "replica_info": [
+    {
+     "id": "1",
+     "ip": "127.0.0.1",
+     "port": 10001
+    },
+    {
+     "id": "2",
+     "ip": "127.0.0.1",
+     "port": 10002
+    },
+    {
+     "id": "3",
+     "ip": "127.0.0.1",
+     "port": 10003
+    },
+    {
+     "id": "4",
+     "ip": "127.0.0.1",
+     "port": 10004
+    }
+   ],
+   "region_id": 0
   },
-  self_region_id:1,
-  leveldb_info : {
-    write_buffer_size_mb:128,
-    write_batch_size:1,
-    enable_block_cache: true,
-    block_cache_capacity: 100
+  {
+   "replica_info": [
+    {
+     "id": "1",
+     "ip": "127.0.0.1",
+     "port": 10001
+    },
+    {
+     "id": "2",
+     "ip": "127.0.0.1",
+     "port": 10002
+    },
+    {
+     "id": "3",
+     "ip": "127.0.0.1",
+     "port": 10003
+    },
+    {
+     "id": "4",
+     "ip": "127.0.0.1",
+     "port": 10004
+    }
+   ],
+   "region_id": 0
   },
-  require_txn_validation:true,
-  enable_viewchange:false,
-  enable_resview:true,
-  enable_faulty_switch:false
+  {
+   "replica_info": [
+    {
+     "id": "1",
+     "ip": "127.0.0.1",
+     "port": 10001
+    },
+    {
+     "id": "2",
+     "ip": "127.0.0.1",
+     "port": 10002
+    },
+    {
+     "id": "3",
+     "ip": "127.0.0.1",
+     "port": 10003
+    },
+    {
+     "id": "4",
+     "ip": "127.0.0.1",
+     "port": 10004
+    }
+   ],
+   "region_id": 1
+  }
+ ],
+ "self_region_id": 1,
+ "leveldb_info": {
+  "write_buffer_size_mb": 128,
+  "write_batch_size": 1,
+  "path": "",
+  "enable_block_cache": true,
+  "block_cache_capacity": 100
+ },
+ "enable_viewchange": false,
+ "require_txn_validation": true,
+ "enable_resview": true,
+ "enable_faulty_switch": false
 }
-
-
diff --git a/service/tools/config/server/server.json 
b/service/tools/config/server/server.json
new file mode 100644
index 00000000..e0e6fb30
--- /dev/null
+++ b/service/tools/config/server/server.json
@@ -0,0 +1,91 @@
+{
+ "region": [
+  {
+   "replica_info": [
+    {
+     "id": "1",
+     "ip": "127.0.0.1",
+     "port": 10001
+    },
+    {
+     "id": "2",
+     "ip": "127.0.0.1",
+     "port": 10002
+    },
+    {
+     "id": "3",
+     "ip": "127.0.0.1",
+     "port": 10003
+    },
+    {
+     "id": "4",
+     "ip": "127.0.0.1",
+     "port": 10004
+    }
+   ],
+   "region_id": 0
+  },
+  {
+   "replica_info": [
+    {
+     "id": "1",
+     "ip": "127.0.0.1",
+     "port": 10001
+    },
+    {
+     "id": "2",
+     "ip": "127.0.0.1",
+     "port": 10002
+    },
+    {
+     "id": "3",
+     "ip": "127.0.0.1",
+     "port": 10003
+    },
+    {
+     "id": "4",
+     "ip": "127.0.0.1",
+     "port": 10004
+    }
+   ],
+   "region_id": 0
+  },
+  {
+   "replica_info": [
+    {
+     "id": "1",
+     "ip": "127.0.0.1",
+     "port": 10001
+    },
+    {
+     "id": "2",
+     "ip": "127.0.0.1",
+     "port": 10002
+    },
+    {
+     "id": "3",
+     "ip": "127.0.0.1",
+     "port": 10003
+    },
+    {
+     "id": "4",
+     "ip": "127.0.0.1",
+     "port": 10004
+    }
+   ],
+   "region_id": 1
+  }
+ ],
+ "self_region_id": 1,
+ "leveldb_info": {
+  "write_buffer_size_mb": 128,
+  "write_batch_size": 1,
+  "path": "",
+  "enable_block_cache": true,
+  "block_cache_capacity": 100
+ },
+ "enable_viewchange": false,
+ "require_txn_validation": true,
+ "enable_resview": true,
+ "enable_faulty_switch": false
+}
diff --git a/tools/generate_region_config_cc.cpp 
b/tools/generate_region_config_cc.cpp
index b2147867..81c57669 100644
--- a/tools/generate_region_config_cc.cpp
+++ b/tools/generate_region_config_cc.cpp
@@ -17,6 +17,8 @@
  * under the License.
  */
 
+#include <google/protobuf/util/json_util.h>
+
 #include <cstdlib>
 #include <fstream>
 #include <iostream>
@@ -25,17 +27,17 @@
 #include <string>
 #include <vector>
 
-#include <google/protobuf/util/json_util.h>
 #include "platform/proto/replica_info.pb.h"
 
 namespace {
 
+using google::protobuf::util::JsonParseOptions;
+using google::protobuf::util::JsonPrintOptions;
 using google::protobuf::util::JsonStringToMessage;
 using google::protobuf::util::MessageToJsonString;
-using google::protobuf::util::JsonParseOptions;
-using resdb::ResConfigData;
-using resdb::ReplicaInfo;
 using resdb::RegionInfo;
+using resdb::ReplicaInfo;
+using resdb::ResConfigData;
 
 bool readLines(const std::string& path, std::vector<std::string>* lines) {
   std::ifstream in(path);
@@ -50,6 +52,8 @@ bool readLines(const std::string& path, 
std::vector<std::string>* lines) {
   return true;
 }
 
+// pretty printer no longer needed; using JsonPrintOptions
+
 std::string readFileToString(const std::string& path) {
   std::ifstream in(path);
   if (!in.is_open()) {
@@ -82,38 +86,40 @@ int main(int argc, char** argv) {
 
   ResConfigData config_data;
   std::map<std::string, std::vector<ReplicaInfo>> region_to_replicas;
-  
+
   for (const std::string& line : lines) {
-    if (line.empty() || line.find_first_not_of(" \t\r\n") == 
std::string::npos) {
+    if (line.empty() ||
+        line.find_first_not_of(" \t\r\n") == std::string::npos) {
       continue;
     }
-    
+
     std::istringstream iss(line);
     std::string id_str, ip, port_str, region_id;
-    
+
     if (!(iss >> id_str >> ip >> port_str)) {
       continue;
     }
-    
+
     if (!(iss >> region_id)) {
       region_id = "0";
     }
-    
+
     int64_t id;
     int32_t port;
     try {
       id = std::stoll(id_str);
       port = std::stoi(port_str);
     } catch (const std::exception& e) {
-      std::cerr << "Warning: Failed to parse id or port from line: " << line 
<< "\n";
+      std::cerr << "Warning: Failed to parse id or port from line: " << line
+                << "\n";
       continue;
     }
-    
+
     ReplicaInfo replica;
     replica.set_id(id);
     replica.set_ip(ip);
     replica.set_port(port);
-    
+
     region_to_replicas[region_id].push_back(replica);
   }
 
@@ -125,7 +131,11 @@ int main(int argc, char** argv) {
   }
 
   std::string output_json;
-  MessageToJsonString(config_data, &output_json);
+  JsonPrintOptions print_options;
+  print_options.add_whitespace = true;
+  print_options.preserve_proto_field_names = true;
+  print_options.always_print_primitive_fields = true;
+  MessageToJsonString(config_data, &output_json, print_options);
   std::cerr << "Generated JSON (before template):\n" << output_json << "\n\n";
 
   std::ofstream out(output_path);
@@ -139,33 +149,36 @@ int main(int argc, char** argv) {
   if (!template_path.empty()) {
     std::string base_json = readFileToString(output_path);
     std::cerr << "Read base config:\n" << base_json << "\n\n";
-    
+
     ResConfigData base_config;
     JsonParseOptions parse_options;
     auto status = JsonStringToMessage(base_json, &base_config, parse_options);
     if (!status.ok()) {
-      std::cerr << "Failed to parse generated JSON: " << status.message() << 
"\n";
+      std::cerr << "Failed to parse generated JSON: " << status.message()
+                << "\n";
       return 5;
     }
-    
+
     std::string template_json_str = readFileToString(template_path);
     if (template_json_str.empty()) {
       std::cerr << "Failed to read template file: " << template_path << "\n";
       return 6;
     }
     std::cerr << "Read template config:\n" << template_json_str << "\n\n";
-    
+
     ResConfigData template_config;
-    status = JsonStringToMessage(template_json_str, &template_config, 
parse_options);
+    status =
+        JsonStringToMessage(template_json_str, &template_config, 
parse_options);
     if (!status.ok()) {
-      std::cerr << "Failed to parse template JSON: " << status.message() << 
"\n";
+      std::cerr << "Failed to parse template JSON: " << status.message()
+                << "\n";
       return 7;
     }
-    
+
     base_config.MergeFrom(template_config);
-    
+
     std::string merged_json;
-    MessageToJsonString(base_config, &merged_json);
+    MessageToJsonString(base_config, &merged_json, print_options);
     std::cerr << "Merged JSON (after template):\n" << merged_json << "\n\n";
     std::ofstream out2(output_path);
     if (!out2.is_open()) {

Reply via email to