存储过程是用户定义的一系列sql语句的集合,涉及特定表或其它对象的任务,用户可以调用存储过程,而函数通常是数据库已定义的方法,它接收参数并返回某种类型的值并且不涉及特定用户表。

记录我自己的工作

    Group Replication is know as an up to
date HA(High Availablity) solution which is supported in official version of MySQL 5.7 since Dec. 2016.It’s
similar with the other two tools —— MHA(By Yoshinorim) & PXC(By
Percona),but not as same as them. Group Replication(I’ll call it MGR
later) provides features below:

存储过程和函数存在以下几个区别:

get 请求  ,携带 请求头 header (token)  

 

1)一般来说,存储过程实现的功能要复杂一点,而函数的实现的功能针对性比较强。存储过程,功能强大,可以执行包括修改表等一系列数据库操作;用户定义函数不能用于执行一组修改全局数据库状态的操作。

2)对于存储过程来说可以返回参数,如记录集,而函数只能返回值或者表对象。函数只能返回一个变量;而存储过程可以返回多个。存储过程的参数可以有IN,OUT,INOUT三种类型,而函数只能有IN类~~存储过程声明时不需要返回类型,而函数声明时需要描述返回类型,且函数体中必须包含一个有效的RETURN语句。

3)存储过程,可以使用非确定函数,不允许在用户定义函数主体中内置非确定函数。

4)存储过程一般是作为一个独立的部分来执行( EXECUTE 语句执行),而函数可以作为查询语句的一个部分来调用(SELECT调用),由于函数可以返回一个表对象,因此它可以在查询语句中位于FROM关键字的后面。 SQL语句中不可用存储过程,而可以使用函数。

url 根据参数 动态拼接

  • *high consistency
    *

 

参数   放入 map  动态拼接

 

private String lclUrl = "http://xxx.xxxx.com/lcl";

    MGR protocol lies on the algorithm of
Paxos(Which is a kind of consensus protocol usually be used in
distributed system and presented by Mr.Lamport.) to guarantee data
consistency.What’s Paxos?There’s something about it
below:

  

    theory of Paxos: http://www.the-paper-trail.org/post/2009-02-03-consensus-protocols-paxos/

private String TOKEN360FOB_URL = "http://xxx.xxxxxx.com/token?username={name}&password={password}";

    Mr Lamport’s introduction on
wiki: 

  

    MGR provides a
built-in membership 

1 public JSONObject get360fobToken() {
2         String json = restTemplate.getForObject(TOKEN360FOB_URL, String.class, username, password);
3         JSONObject json1 = JSONObject.fromObject(json);
4         return json1;
5     }

service which can strongly coordinate the
servers in the same group to do switchover between master and slave
automatically with high efficiency and strong consistency.All members in
the same group will communicate with each other from time to time by GSC
protocols.The group members always come up to an agreement in an order
of global transaction sequence in order to decide whether to commit or
abort transactions when commit operations happen.

 

 

 1 /**
 2      * 拼箱
 3      *
 4      * @param departure
 5      * @param departureDate
 6      * @param destination
 7      * @param destCountry
 8      * @param lsps
 9      * @param sortBy
10      * @param pageNum
11      * @param pageSize
12      * @return
13      */
14     public JSONObject getLclFreight(String departure, String departureDate, String destination, String destCountry, String lsps, String sortBy, int pageNum, int pageSize) {
15         return this.getFclAndLcl(departure, departureDate, destination,
16                 destCountry, lsps, sortBy, pageNum, pageSize, lclUrl);
17     }
  • *high flexibility
    *

 

 
  

 1 /**
 2      * 共同代码抽取
 3      *
 4      * @param departure
 5      * @param departureDate
 6      * @param destination
 7      * @param destCountry
 8      * @param lsps
 9      * @param sortBy
10      * @param pageNum
11      * @param pageSize
12      * @param xxxUrl
13      * @return
14      */
15     private JSONObject getFclAndLcl(String departure, String departureDate, String destination,
16                                     String destCountry, String lsps, String sortBy, int pageNum, int pageSize, String xxxUrl) {
17         JSONObject json = this.get360fobToken();
18         String t = json.getString("content");
19         String token = "Bearer " + t;
       // 将token 放入请求头
20         HttpHeaders requestHeaders = new HttpHeaders();
21         requestHeaders.add("Authorization", token);
22 
23         //参数
24         Map<String, Object> uriVariables = new HashMap<String, Object>();
25         //拼接url
26         StringBuffer buffer = new StringBuffer();
27         buffer.append("?");
28         if (StringUtils.isNotBlank(departure)) {
29             buffer.append("departure={departure}").append("&");
30             uriVariables.put("departure", departure);
31         }
32         if (StringUtils.isNotBlank(departureDate)) {
33             buffer.append("departureDate={departureDate}").append("&");
34             uriVariables.put("departureDate", departureDate);
35         }
36         if (StringUtils.isNotBlank(destination)) {
37             buffer.append("destination={destination}").append("&");
38             uriVariables.put("destination", destination);
39         }
40         if (StringUtils.isNotBlank(destCountry)) {
41             buffer.append("destCountry={destCountry}").append("&");
42             uriVariables.put("destCountry", destCountry);
43         }
44         if (StringUtils.isNotBlank(lsps)) {
45             buffer.append("lsps={lsps}").append("&");
46             uriVariables.put("lsps", lsps);
47         }
48         if (StringUtils.isNotBlank(sortBy)) {
49             buffer.append("sortBy={sortBy}").append("&");
50             uriVariables.put("sortBy", sortBy);
51         }
52 
53         buffer.append("pageNum={pageNum}").append("&");
54         buffer.append("pageSize={pageSize}");
55         uriVariables.put("pageNum", pageNum);
56         uriVariables.put("pageSize", pageSize);
57         String url = xxxUrl + buffer.toString();
58 
59         HttpEntity<String> requestEntity = new HttpEntity<String>(null, requestHeaders);
60 
61         ResponseEntity<String> response =
62                 restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class, uriVariables);
63         String resBody = response.getBody();
64         JSONObject temp = JSONObject.fromObject(resBody);
65 
66 
67         return temp;
68     }

    MGR
supports both single-primary and multi-primary mode.In the
single-primary mode,there’s a machenism called “primary election”
automatically while failure is detected and only the primary server can
update data simultanuously.In the multi-primary mode,update can be done
on all the servers in the group even though they update data
concurrently.You can choose the appropriate way to implement your MySQL
Servers.

工作疑问:

 

可以用更简洁的方法 拼接 url 吗

  • ***high fault-tolerance

个人qq : 332893400

发表评论

电子邮件地址不会被公开。 必填项已用*标注