生产环境是

一主一从一仲裁

3

分片的集群,现在发现其中一个节点比当前时间大了好几天,后使用

NTP

将时间往回调整副本集上。

原来时间是

5

3

日,当前是

4

26

日,对此进行了调整。

[root@cwdtest1 bin]# date

Fri May  3 13:20:31 CST 2019

[root@cwdtest1 bin]# ntpdate -u 10.205.34.171

26 Apr 12:39:23 ntpdate[14568]: step time server 10.205.34.171 offset -607507.747595 sec

[root@cwdtest1 bin]# hwclock --systohc

调整后当前的时间:

[root@cwdtest1 bin]# date

Fri Apr 26 12:39:31 CST 2019

当完成调整时间之后,发现两个问题:

1.

副本集无法同步新的

oplog

,由此出现了延迟

shard2:PRIMARY> db.printSlaveReplicationInfo();

source: 10.3.252.231:27002

syncedTo: Fri May 03 2019 13:24:23 GMT+0800 (CST)

8 secs (0 hrs) behind the primary

2.

查看

oplog

tLast

时间比当前的大

shard2:PRIMARY> db.getReplicationInfo()

{

"logSizeMB" : 1383.3396482467651,

"usedMB" : 154.49,

"timeDiff" : 17015711,

"timeDiffHours" : 4726.59,

"tFirst" : "Thu Oct 18 2018 14:49:20 GMT+0800 (CST)",

"tLast" : "Fri May 03 2019 13:24:31 GMT+0800 (CST)",

"now" : "Fri Apr 26 2019 13:57:01 GMT+0800 (CST)"

}

shard2:PRIMARY> db.printReplicationInfo()

configured oplog size:   1383.3396482467651MB

log length start to end: 17015711secs (4726.59hrs)

oplog first event time:  Thu Oct 18 2018 14:49:20 GMT+0800 (CST)

oplog last event time:   Fri May 03 2019 13:24:31 GMT+0800 (CST)

now:                     Fri Apr 26 2019 15:46:27 GMT+0800 (CST)

查看

db.getReplicationInfo

中,我们找出

tLast

now

两个时间是从哪里得到的?

shard2:PRIMARY> db.getReplicationInfo

function () {

var localdb = this.getSiblingDB("local");

var result = {};

var oplog;

var localCollections = localdb.getCollectionNames();

if (localCollections.indexOf('oplog.rs') >= 0) {

oplog = 'oplog.rs';

} else if (localCollections.indexOf('oplog.$main') >= 0) {

oplog = 'oplog.$main';

} else {

result.errmsg = "neither master/slave nor replica set replication detected";

return result;

}

var ol = localdb.getCollection(oplog);

var ol_stats = ol.stats();

if (ol_stats && ol_stats.maxSize) {

result.logSizeMB = ol_stats.maxSize / (1024 * 1024);

} else {

result.errmsg = "Could not get stats for local." + oplog + " collection. " +

"collstats returned: " + tojson(ol_stats);

return result;

}

result.usedMB = ol_stats.size / (1024 * 1024);

result.usedMB = Math.ceil(result.usedMB * 100) / 100;

var firstc = ol.find().sort({$natural: 1}).limit(1);

var lastc = ol.find().sort({$natural: -1}).limit(1);

if (!firstc.hasNext() || !lastc.hasNext()) {

result.errmsg =

"objects not found in local.oplog.$main -- is this a new and empty db instance?";

result.oplogMainRowCount = ol.count();

return result;

}

var first = firstc.next();

var last = lastc.next();

var tfirst = first.ts;

var tlast = last.ts;

if (tfirst && tlast) {

tfirst = DB.tsToSeconds(tfirst);

tlast = DB.tsToSeconds(tlast);

result.timeDiff = tlast - tfirst;

result.timeDiffHours = Math.round(result.timeDiff / 36) / 100;

result.tFirst = (new Date(tfirst * 1000)).toString();

result.tLast = (new Date(tlast * 1000)).toString();

result.now = Date();

} else {

result.errmsg = "ts element not found in oplog objects";

}

return result;

}

从以上可以看出

:

var ol = localdb.getCollection(oplog);

var lastc = ol.find().sort({$natural: -1}).limit(1);

var last = lastc.next();

var tlast = last.ts;

result.tLast = (new Date(tlast * 1000)).toString();

result.now = Date();

tLast

的时间是获取

oplog.rs

集合中最后一条数据的

ts

时间。

Now

的时间是调用

Date()

函数获取当前时间。

于是,此时我怀疑副本集

无法同步,是因为

oplog

中存放比当前时间大的日志,而当调整时间后新生成的

oplog

日志记录并不是最新的,因此副本集在对比时发现最新的日志一直不变,便无法同步。

大概说下

mongodb

同步的机制(借鉴网络):

1.

执行写语句时,

primary

上完成写操作

2.

primary

上记录一条

oplog

日志,日志中包含一个

ts

字段,值为写操作执行的时间,比如本例中记为

t

3.

secondary

primary

拉取

oplog

,获取到刚才那一次写操作的日志

4.

secondary

按获取到的日志执行相应的写操作

5.

执行完成后,

secondary

再获取新的日志,其向

primary

上拉取

oplog

的条件为

{ts:{$gt:t}}

6.

primary

此时收到

secondary

的请求,了解到

secondary

在请求时间大于

t

的写操作日志,所以他知道操作在

t

之前的日志都已经成功执行了

于是,我在

primary

执行一次插入测试,来验证怀疑。

shard2:PRIMARY> use shtest

switched to db shtest

shard2:PRIMARY> db.coll.insert( {x:3339876})

WriteResult({ "nInserted" : 1 })

查询主节点最后一条操作记录:

rs.debug.getLastOpWritten()

从以上可以看出

:

var ol = localdb.getCollection(oplog);

var lastc = ol.find().sort({$natural: -1}).limit(1);

var last = lastc.next();

var tlast = last.ts;

result.tLast = (new Date(tlast * 1000)).toString();

result.now = Date();

tLast

的时间是获取

oplog.rs

集合中最后一条数据的

ts

时间。

Now

的时间是调用

Date()

函数获取当前时间。

于是,此时我怀疑副本集

无法同步,是因为

oplog

中存放比当前时间大的日志,而当调整时间后新生成的

oplog

日志记录并不是最新的,因此副本集在对比时发现最新的日志一直不变,便无法同步。

大概说下

mongodb

同步的机制(借鉴网络):

1.

执行写语句时,

primary

上完成写操作

2.

primary

上记录一条

oplog

日志,日志中包含一个

ts

字段,值为写操作执行的时间,比如本例中记为

t

3.

secondary

primary

拉取

oplog

,获取到刚才那一次写操作的日志

4.

secondary

按获取到的日志执行相应的写操作

5.

执行完成后,

secondary

再获取新的日志,其向

primary

上拉取

oplog

的条件为

{ts:{$gt:t}}

6.

primary

此时收到

secondary

的请求,了解到

secondary

在请求时间大于

t

的写操作日志,所以他知道操作在

t

之前的日志都已经成功执行了

于是,我在

primary

执行一次插入测试,来验证怀疑。

shard2:PRIMARY> use shtest

switched to db shtest

shard2:PRIMARY> db.coll.insert( {x:3339876})

WriteResult({ "nInserted" : 1 })

查询主节点最后一条操作记录:

rs.debug.getLastOpWritten()

查询副本节点上的最后条操作记录:

发现此时数据可以同步到副本集上,即说明

oplog

日志不存在不同步的问题,也就是实际上集群的同步是正常的。

当时发现,每条

oplog

记录的

ts

一直保持着调整主机时间前的时间,

5

3

日的时间,且一直不变。关于原因,就需要进一步分析了。

linux时间跳变影响,MONGO 集群 修改linux主机时间后的影响相关推荐

  1. kubeadm集群修改k8s证书时间到99年

    kubeadm集群修改k8s证书时间到99年 kubeadm修改证书时间 (1).查看当前的证书时间 # kubeadm alpha certs check-expiration [check-exp ...

  2. Linux上搭建Hadoop2.6.3集群以及WIN7通过Eclipse开发MapReduce的demo

    随笔 - 70  文章 - 0  评论 - 88 Linux上搭建Hadoop2.6.3集群以及WIN7通过Eclipse开发MapReduce的demo 近期为了分析国内航空旅游业常见安全漏洞,想到 ...

  3. 使用LVS(Linux Virtual Server)在Linux上搭建负载均衡的集群服务

    使用LVS(Linux Virtual Server)在Linux上搭建负载均衡的集群服务 一.基于于NAT的LVS的安装与配置. 1. 硬件需求和网络拓扑                       ...

  4. Linux 高可用(HA)集群之Pacemaker详解

    大纲 说明:本来我不想写这篇博文的,因为前几篇博文都有介绍pacemaker,但是我觉得还是得写一下,试想应该会有博友需要,特别是pacemaker 1.1.8(CentOS 6.4)以后,pacem ...

  5. 在Linux上使用Nginx为Solr集群做负载均衡

    在Linux上使用Nginx为Solr集群做负载均衡 在Linux上搭建solr集群时需要用到负载均衡,但测试环境下没有F5 Big-IP负载均衡交换机可以用,于是先后试了weblogic的proxy ...

  6. 【Kafka】测试集群中Broker故障对客户端的影响

    本文主要测试Kafka集群中Broker节点故障对客户端的影响. 集群信息:4个broker.topic:100+(每个topic30个partition).集群加密方式:plaintext.存储:c ...

  7. 技术分享 | mongo 集群连接数暴涨处理案例一则

    作者:任坤 现居珠海,先后担任专职 Oracle 和 MySQL DBA,现在主要负责 MySQL.mongoDB 和 Redis 维护工作. 本文来源:原创投稿 *爱可生开源社区出品,原创内容未经授 ...

  8. linux下安装oracle集群,【Oracle 集群】Linux下Oracle RAC集群搭建之Oracle DataBase安装(八)...

    目录 数据库安装 继oracle集群安装之后,接下来也是最重要的数据库安装,整个数据库安装难度不大,用户以oracle用户身份登录RAC1主节点,对解压后的文件安装.主节点下安装后,其他所有结点自动安 ...

  9. [Eureka集群] 在linux上部署SpringCloudEureka的集群服务端(Dalston.SR5版本)

    搭配使用 logback日志配置: https://blog.csdn.net/a755199443/article/details/92208902 Eureka单机服务端配置: https://b ...

最新文章

  1. 我用python10年后,我发现学python必看这三本书!
  2. Python之路--WEB框架本质
  3. Mashmokh and Numbers CodeForces - 415C
  4. UltraEdit使用注册机激活详解
  5. same things betewen university and companies
  6. CCF BDCI 多人种人脸识别冠军分享
  7. 服务器配置再生龙系统,PXE引导再生龙安装步骤
  8. APP录获取短信+通讯录网站源码
  9. Linux下配置服务器节点上的时区
  10. Navicat Premium 12安装过程
  11. 编译原理完整学习笔记(二):高级程序设计语言
  12. 台式计算机速度变慢的原因,电脑运行速度变慢的原因和解决方法
  13. 日系插画学习笔记(五):日系角色脸部画法-1头部
  14. mysql报错(Not unique table/alias)
  15. 盒子模型与内外边距设置
  16. 开机hidl报错修改
  17. ERP已死,云计算上位
  18. java处理器,JAVA注解处理器
  19. 电话机器人是如何筛选意向客户的
  20. SQL截取字符串(substring与patindex的使用)

热门文章

  1. Java二维数组谷电,java二维数组遍历的2种代码
  2. python运维开发培训_运维架构师-Python 自动化运维开发-014
  3. python怎么变各种颜色_python – 如何淡化颜色
  4. kailinux mysql提权_linux下mysql提权
  5. 实验一 线性表的顺序存储与实现_数据结构篇之单链表的创建以及实现
  6. em算法示例_带有示例HTML'em'标签
  7. scala中map添加值_如何在Scala Map中反转键和值
  8. Kali-Linux-2019.04虚拟机与物理机实现复制粘贴功能
  9. packer build 报错 无任何输出 一直报“skipping line: 1 skipping line: 2 skipping line: 3.....”
  10. python新建txt文件,并逐行写入数据