repmgr/repmgr_net.c,

__repmgr_send(): 做send_broadcast, 然后根据policy 对DB_REP_PERMANENT的处理

__repmgr_send_broadcast(): 对每个site, send_connection().

MASTER 发送

log/log_put.c, log_put(),

不接受 REP_CLIENT

__rep_send_message(env, DB_EID_BROADCAST, - REP_NEWFILE, REP_LOG

txn/txn_chkpt.c, __txn_checkpoint()

REP_CLIENT仅在recover时到这里, sync mp后马上退出

在master sync mp之前, 发送给client:

__rep_send_message(env, DB_EID_BROADCAST, REP_START_SYNC

等待 chkpt_delay

写ckp log rec

DB_REP_REREQUEST vs  DB_REP_ANYWHERE

* Gap requests are "new" and can go anywhere, unless
* this is already a re-request.

repmgr_net.c, __repmgr_send()

if ((flags & (DB_REP_ANYWHERE | DB_REP_REREQUEST)) ==DB_REP_ANYWHERE &&

    (site = __repmgr_find_available_peer(env))

发完后, DB_REP_PERMANENT, 检查policy, 需要多少ack 才能返回(for durability).

http://docs.oracle.com/cd/E17076_03/html/api_reference/C/repmgrset_ack_policy.html

默认 DB_REPMGR_ACKS_QUORUM, repmgr_net.c, __repmgr_send(), 可见 (n - 1) / 2 + 1

确定了之后, __repmgr_await_cond(env, got_acks, &perm, rep->ack_timeout, &db_rep->ack_waiters);

=> while (got_acks(env, &perm)) {pthread_cond_timedwait(&db_rep->ack_waiters,rep->ack_timeout)}

repmgr_net.c,  got_acks().

dbinc/rep.h,

struct __db_rep {}

REPMGR_RUNNABLE *selector, **messengers, **elect_threads;

WSAEventSelect

client接收

repmgr_method.c, __repmgr_start_int() - elect/msg/select threads
repmgr_method.c, __repmgr_start_selector()
repmgr_sel.c, __repmgr_select_thread()
repmgr_windows.c, __repmgr_select_loop()
repmgr_windows.c, handle_completion() -
repmgr_sel.c, __repmgr_read_from_site()
repmgr_sel.c, dispatch_msgin() -

放入db_rep->input_queue, __repmgr_signal(&db_rep->msg_avail)

rep.h, struct __db_rep     -    cond_var_t check_election, gmdb_idle, msg_avail;

repmgr_method.c, __repmgr_start_int()
repmgr_method.c, __repmgr_start_msg_threads()
repmgr_msg.c, __repmgr_msg_thread()
message_loop()

while ((ret = __repmgr_queue_get()...

__repmgr_queue_get - while(m = available_work(env)) == NULL), wait 在msg_avail 上
process_message()
repmgr_record.c, __rep_process_message_int()

对 REP_LOG 消息, 调用

rep_log.c, __rep_log()

rep_record.c, __rep_apply():

log.h,  struct log {}  - waiting_lsn,  max_wait_lsn, __db.rep.db, ready_lsn

waiting_lsn:   It is the first LSN that we are holding without putting in the log, because we received one or more log records out of order.

ready_lsn:  It is the next LSN we expect to receive. It's normally equal to "lsn", except at the beginning of a log file, at which point it's set to the LSN of the first record of the new file

若正是我们需要的 下一个log rec, call  __rep_process_rec(); __rep_remfirst/__rep_getnext 接着处理 tmp db里的log; __rep_loggap_req().

若 在我们需要的 log rec后面, 入tmp db, 更新 waiting_lsn, 发送__rep_loggap_req(). 

若 在我们需要的 log rec前面, 收到 重复 log rec. 

rep_record.c, __rep_process_rec(), newfile特殊处理退出. 除ckp,其他先直接写入log 文件

   - DB___txn_prepare:  直接flush log

   - DB___txn_regop:  __rep_process_txn(),  拿到 需要的写锁; 拿到txn对应的所有log rec, 排序, 读出,  db_dispatch(DB_TXN_APPLY

- DB___txn_ckp: 首先在 rep_db(bookkeeping db)中写一个 rec, nooverwrite, 如果已经有, 则其他线程在做ckp, 退出.  sync mp; 写DB_LOG_CHKPNT log rec,  flush log

berkeley db replica机制 - 主从同步的更多相关文章

  1. berkeley db replica机制 - 消息处理

    repmgr_method.c, __repmgr_start_int()repmgr_method.c, __repmgr_start_msg_threads()repmgr_msg.c, __re ...

  2. berkeley db replica机制 - election algorithm

    repmgr_method.c, __repmgr_start_int() 初始2个elect线程. repmgr_elect.c, __repmgr_init_election() __repmgr ...

  3. 了解 Oracle Berkeley DB 可以为您的应用程序带来 NoSQL 优势的原因及方式。

    将 Oracle Berkeley DB 用作 NoSQL 数据存储 作者:Shashank Tiwari 2011 年 2 月发布 “NoSQL”是在开发人员.架构师甚至技术经理中新流行的一个词汇. ...

  4. Linux 安装mysql,mariadb,mysql主从同步

    myariadb安装 centos7 mariadb的学习 在企业里面,多半不会使用阿里云的mariadb版本,因为版本太低,安全性太低,公司会配置myariadb官方的yum仓库 1.手动创建mar ...

  5. redis多实例与主从同步及高级特性(数据过期机制,持久化存储)

    redis多实例 创建redis的存储目录 vim /usr/local/redis/conf/redis.conf #修改redis的配置文件 dir /data/redis/ #将存储路径配置修改 ...

  6. RocketMQ 主从同步机制

    主从同步(HA 高可用) 主从同步原理: 为了保证系统的高可用,消息到达主服务器后,需要将消息同步到从服务器.如果主服务器宕机,消费者可用从从服务器拉取消息. 大体步骤: 1.主服务器启动,监听从服务 ...

  7. Mysql主从同步机制

    1.1 主从同步介绍和优点 *在多台数据服务器中,分为主服务器和从服务器.一台主服务器对应多台从服务器. *主服务器只负责写入数据,从服务器只负责同步主服务器的数据,并让外部程序读取数据 *主服务器写 ...

  8. 【mq学习笔记-分布式篇】主从同步机制

    核心类: 消息消费到达主服务器后需要将消息同步到从服务器,如果主服务器Broker宕机后,消息消费者可以从从服务器拉取消息. HAService:RocketMQ主从同步核心实现类 HAService ...

  9. MySQL数据库的主从同步实现及应用

    >>主从同步机制及应用 读写分离(Read/Write Splitting)让主数据库处理事务性增.改.删操作(INSERT.UPDATE.DELETE),从数据库处理SELECT查询操作 ...

随机推荐

  1. 在c中保存状态

    1. 注册表 注册表是一个普通的table,我们可以将c函数中需要保存的状态都存储在注册表中,注册表是可以被多个c模块共享的. 由于注册表是一个普通table,我们同样可以在栈中对其进行操作,只是这个 ...

  2. 前端开发框架Bootstrap和KnockoutJS

    江湖中那场异常惨烈的厮杀,如今都快被人遗忘了.当年,所有的武林同道为了同一个敌人都拼尽了全力,为数不多的幸存者心灰意冷,隐姓埋名,远赴他乡,他们将唯一的希望寄托给时间.少年子弟江湖老,红颜少女的鬓边也 ...

  3. NHibernate系列文章四:NHibernate运行时监控

    摘要 有三种方式可以实现NHibernate运行时监控,监控的信息包括:执行了的SQL语句.NHibernate执行过程.数据库性能分析.这对我们学习NHibernate有很大的帮助,在工作中也能快速 ...

  4. 字符串str功能介绍

    1.name.__contains__ 包含 name1='eric'result = name.__contains__(er)   #name是否包含er,包含返回true,不包含返回fals p ...

  5. 关于网站高性能中磁盘cpu以及内存对网站性能的影响

    之前和同事聊天的时候,提到了这个硬件方面(包括内存,cpu,以及硬盘的存储选择),个人认为可以从这几个方面来提高底层硬件的性能,从而提高网站的整体吞吐量和速度. 一.主机: (1).CPU:决定处理的 ...

  6. WPF TextBlock文本纵向排列

    一.将TextBlock文本纵向排列输出有两种模式. 1.文字正常放置,只是纵向排列. 2.文字同样旋转90度,纵向排列. 二.详见下文实例 1.文本正常放置,纵向排列. (1)后台代码 string ...

  7. CSS样式的插入方式

    1.外部样式: 当样式需要应用于很多页面时,外部样式表将是理想的选择.<head> <link rel="stylesheet" type="text/ ...

  8. android开发 如何调用SO

    java package com.example.callsodemo; import android.R.integer; import android.R.string; import andro ...

  9. Ubuntu14.04环境下Samba报错排错过程

    排错的方法和思路非常重要,日志非常非常非常非常重要!!! 搭建好Samba之后,windos访问一直下面这个错误,然后傻逼一样一直百度百度,一弄又是几天,但是经过自己一步一步的排错,弄成功之后,那心情 ...

  10. Android WebView 实现缓存网页数据

    WebView中存在着两种缓存:网页数据缓存(存储打开过的页面及资源),H5缓存(即AppCache). 将我们浏览过的网页url已经网页文件(css.图片.js等)保存到数据库表中 缓存模式(5种) ...