Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
juaby committed Mar 17, 2021
1 parent c60c63e commit 3d8fadd
Show file tree
Hide file tree
Showing 65 changed files with 793 additions and 801 deletions.
17 changes: 7 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
[workspace]

members = [
"control-panel",

"data-panel",
"data-panel-common",
"data-panel-database",
"data-panel-cache",
"data-panel-rpc",
"data-panel-mq",

# Internal
"control-panel",
"data-panel",
"data-panel-common",
"data-panel-database",
"data-panel-cache",
"data-panel-rpc",
"data-panel-mq",
]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Martlet Mesh

A Martlet Service Mesh(Database, RPC, MQ, Cache, HTTP1\2 Service Mesh)
2 changes: 1 addition & 1 deletion data-panel-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tokio-stream = "0.1"
bytes = "1.0"

# sqlparser = "0.8"
sqlparser = { git = "https://github.com/juaby/sqlparser-rs", branch = "po/mysql"}
sqlparser = { git = "https://github.com/juaby/sqlparser-rs", branch = "po/mysql" }
# sqlx = { version = "0.4", default-features = false, features = [ "runtime-tokio", "tls", "mysql", "postgres", "bigdecimal", "json", "chrono", "ipnetwork", "uuid" ]}
# sqlx = { version = "0.4", default-features = false, features = [ "runtime-tokio", "macros", "all" ]}
mysql = "20.1"
Expand Down
16 changes: 8 additions & 8 deletions data-panel-cache/etc/app.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[app]
name = "Database Mesh"
host = "localhost"
port = 13306
version = '0.1.0'
name = "Database Mesh"
host = "localhost"
port = 13306
version = '0.1.0'
[control]
pilot = "localhost:6306"
mixer = "localhost:7306"
citadel = "localhost:8306"
pilot = "localhost:6306"
mixer = "localhost:7306"
citadel = "localhost:8306"
[system]
timeout = 5000
timeout = 5000
4 changes: 2 additions & 2 deletions data-panel-cache/etc/dbmesh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ segments:
dis_rules:
distributed_tables:
t_order_item:
dis_keys: []
dis_keys: [ ]
dis_algorithm:
dis_type: HASH
dis_expression: x + y / 3
dis_relatives: []
dis_relatives: [ ]
t_order:
dis_keys:
- user_id
Expand Down
67 changes: 36 additions & 31 deletions data-panel-cache/src/discovery/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use serde::{Serialize, Deserialize};
use std::borrow::Cow;
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Cluster {
name: String,
segments: Segments,
dis_rules: DisRules
dis_rules: DisRules,
}

impl Cluster {
Expand All @@ -24,27 +25,27 @@ pub struct Segments {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct MetaSegment {
primary: Segment,
mirrors: Vec<Segment>
mirrors: Vec<Segment>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct DataSegment {
primary: Segment,
mirrors: Vec<Segment>
mirrors: Vec<Segment>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Segment {
id: u32,
url: String,
username: String,
password: String
password: String,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct DisRules {
distributed_tables: HashMap<String, DisTable>,
replicated_tables: Vec<String>
replicated_tables: Vec<String>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand All @@ -57,23 +58,27 @@ pub struct DisTable {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct DisAlgorithm {
dis_type: DisType,
dis_expression: String
dis_expression: String,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub enum DisType {
HASH, RANGE, CUSTOM
HASH,
RANGE,
CUSTOM,
}

#[cfg(test)]
mod tests {
use std::collections::HashMap;
use crate::discovery::database::{Cluster, Segments, DisRules, MetaSegment, Segment, DataSegment, DisTable, DisAlgorithm, DisType};
use std::borrow::Cow;
use std::collections::HashMap;
use std::fs::File;
use std::io::Read;

use rhai::{Engine, Scope};

use crate::discovery::database::{Cluster, DataSegment, DisAlgorithm, DisRules, DisTable, DisType, MetaSegment, Segment, Segments};

#[test]
fn test_custom_route() {
let engine = Engine::new();
Expand Down Expand Up @@ -117,82 +122,82 @@ mod tests {
id: 0,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
},
mirrors: vec![
Segment {
id: 0,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
},
Segment {
id: 1,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
}
]
],
});
data_segments.insert(200, DataSegment {
primary: Segment {
id: 0,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
},
mirrors: vec![
Segment {
id: 1,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
},
Segment {
id: 2,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
}
]
],
});
data_segments.insert(300, DataSegment {
primary: Segment {
id: 0,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
},
mirrors: vec![
Segment {
id: 0,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
},
Segment {
id: 1,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
}
]
],
});
let mut distributed_tables = HashMap::new();
distributed_tables.insert(String::from("t_order"), DisTable {
dis_keys: vec![String::from("user_id")],
dis_relatives: vec![String::from("t_order_item")],
dis_algorithm: DisAlgorithm {
dis_type: DisType::HASH,
dis_expression: String::from("x + y / 3")
dis_expression: String::from("x + y / 3"),
},
});
distributed_tables.insert(String::from("t_order_item"), DisTable {
dis_keys: vec![],
dis_relatives: vec![],
dis_algorithm: DisAlgorithm {
dis_type: DisType::HASH,
dis_expression: String::from("x + y / 3")
dis_expression: String::from("x + y / 3"),
},
});
let rc = Cluster {
Expand All @@ -203,29 +208,29 @@ mod tests {
id: 0,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
},
mirrors: vec![
Segment {
id: 0,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
},
Segment {
id: 1,
url: String::from("jdbc:mysql://localhost:3306/martlet"),
username: String::from("root"),
password: String::from("root")
password: String::from("root"),
}
]
],
},
data_segments: data_segments
data_segments: data_segments,
},
dis_rules: DisRules {
distributed_tables,
replicated_tables: vec![String::from("t_dept"), String::from("t_root")]
}
replicated_tables: vec![String::from("t_dept"), String::from("t_root")],
},
};
let s = serde_yaml::to_string(&rc).unwrap();
println!("{}", s);
Expand Down
1 change: 0 additions & 1 deletion data-panel-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#[macro_use]
extern crate bitflags;

#[macro_use]
extern crate lazy_static;

Expand Down
7 changes: 3 additions & 4 deletions data-panel-cache/src/service/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use std::error::Error;
use std::sync::atomic::{AtomicU64, Ordering};

use tokio::net::TcpStream;
use async_trait::async_trait;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::TcpListener;
use tokio::io::{AsyncWrite, AsyncRead};
use tokio::net::TcpStream;
use tokio_util::codec::{FramedRead, FramedWrite};
use tokio_util::codec::LengthDelimitedCodec;

use async_trait::async_trait;

use crate::config::config::MeshConfig;
use crate::service::mysql::MySQLService;

Expand Down
2 changes: 1 addition & 1 deletion data-panel-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tokio-stream = "0.1"
bytes = "1.0"

# sqlparser = "0.8"
sqlparser = { git = "https://github.com/juaby/sqlparser-rs", branch = "po/mysql"}
sqlparser = { git = "https://github.com/juaby/sqlparser-rs", branch = "po/mysql" }
# sqlx = { version = "0.4", default-features = false, features = [ "runtime-tokio", "tls", "mysql", "postgres", "bigdecimal", "json", "chrono", "ipnetwork", "uuid" ]}
# sqlx = { version = "0.4", default-features = false, features = [ "runtime-tokio", "macros", "all" ]}
mysql = "20.1"
Expand Down
16 changes: 8 additions & 8 deletions data-panel-common/etc/app.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[app]
name = "Database Mesh"
host = "localhost"
port = 13306
version = '0.1.0'
name = "Database Mesh"
host = "localhost"
port = 13306
version = '0.1.0'
[control]
pilot = "localhost:6306"
mixer = "localhost:7306"
citadel = "localhost:8306"
pilot = "localhost:6306"
mixer = "localhost:7306"
citadel = "localhost:8306"
[system]
timeout = 5000
timeout = 5000
4 changes: 2 additions & 2 deletions data-panel-common/etc/dbmesh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ segments:
dis_rules:
distributed_tables:
t_order_item:
dis_keys: []
dis_keys: [ ]
dis_algorithm:
dis_type: HASH
dis_expression: x + y / 3
dis_relatives: []
dis_relatives: [ ]
t_order:
dis_keys:
- user_id
Expand Down
7 changes: 3 additions & 4 deletions data-panel-common/src/config/config.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use std::fs::File;
use std::io::Read;
use std::sync::{Arc, RwLock};

use lazy_static::lazy_static;
use serde::Deserialize;
use serde::Serialize;

use lazy_static::lazy_static;
use std::sync::{Arc, RwLock};

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct MeshConfig {
app: AppConfig,
control: ControlConfig,
system: SystemConfig
system: SystemConfig,
}

impl MeshConfig {
Expand Down
Loading

0 comments on commit 3d8fadd

Please sign in to comment.