patroni 部分源码阅读

news2025/1/16 6:00:24

问题1

在这里插入图片描述
/usr/local/lib/python3.9/site-packages/patroni/postgresql/init.py

964     @contextmanager
965     def get_replication_connection_cursor(self, host=None, port=5432, **kwargs):
966         conn_kwargs = self.config.replication.copy()
967         conn_kwargs.update(host=host, port=int(port) if port else None, user=conn_kwargs.pop('username'),
968                            connect_timeout=3, replication=1, options='-c statement_timeout=2000')
969         with get_connection_cursor(**conn_kwargs) as cur:
970             yield cur
971
972     def get_replica_timeline(self):
973         try:
974             with self.get_replication_connection_cursor(**self.config.local_replication_address) as cur:
975                 cur.execute('IDENTIFY_SYSTEM')
976                 return cur.fetchone()[1]
977         except Exception:
978             logger.exception('Can not fetch local timeline and lsn from replication connection')

/usr/local/lib/python3.9/site-packages/patroni/postgresql/connection.py

      1 import logging
      2
      3 from contextlib import contextmanager
      4 from threading import Lock
      5
      6 from .. import psycopg
      7
      8 logger = logging.getLogger(__name__)
      9
     10
     11 class Connection(object):
     12
     13     def __init__(self):
     14         self._lock = Lock()
     15         self._connection = None
     16         self._cursor_holder = None
     17
     18     def set_conn_kwargs(self, conn_kwargs):
     19         self._conn_kwargs = conn_kwargs
     20
     21     def get(self):
     22         with self._lock:
     23             if not self._connection or self._connection.closed != 0:
     24                 self._connection = psycopg.connect(**self._conn_kwargs)
     25                 self.server_version = self._connection.server_version
     26         return self._connection
     27
     28     def cursor(self):
     29         if not self._cursor_holder or self._cursor_holder.closed or self._cursor_holder.connection.closed != 0:
     30             logger.info("establishing a new patroni connection to the postgres cluster")
     31             self._cursor_holder = self.get().cursor()
     32         return self._cursor_holder
     33
     34     def close(self):
     35         if self._connection and self._connection.closed == 0:
     36             self._connection.close()
     37             logger.info("closed patroni connection to the postgresql cluster")
     38         self._cursor_holder = self._connection = None
     39
     40
     41 @contextmanager
     42 def get_connection_cursor(**kwargs):
     43     conn = psycopg.connect(**kwargs)
     44     with conn.cursor() as cur:
     45         yield cur
     46     conn.close()

/usr/local/lib/python3.9/site-packages/patroni/psycopg.py

      1 __all__ = ['connect', 'quote_ident', 'quote_literal', 'DatabaseError', 'Error', 'OperationalError', 'ProgrammingError']
      2
      3 _legacy = False
      4 try:
      5     from psycopg2 import __version__
      6     from . import MIN_PSYCOPG2, parse_version
      7     if parse_version(__version__) < MIN_PSYCOPG2:
      8         raise ImportError
      9     from psycopg2 import connect as _connect, Error, DatabaseError, OperationalError, ProgrammingError
     10     from psycopg2.extensions import adapt
     11
     12     try:
     13         from psycopg2.extensions import quote_ident as _quote_ident
     14     except ImportError:
     15         _legacy = True
     16
     17     def quote_literal(value, conn=None):
     18         value = adapt(value)
     19         if conn:
     20             value.prepare(conn)
     21         return value.getquoted().decode('utf-8')
     22 except ImportError:
     23     from psycopg import connect as __connect, sql, Error, DatabaseError, OperationalError, ProgrammingError
     24
     25     def _connect(*args, **kwargs):
     26         ret = __connect(*args, **kwargs)
     27         ret.server_version = ret.pgconn.server_version  # compatibility with psycopg2
     28         return ret
     29
     30     def _quote_ident(value, conn):
     31         return sql.Identifier(value).as_string(conn)
     32
     33     def quote_literal(value, conn=None):
     34         return sql.Literal(value).as_string(conn)
     35
     36
     37 def connect(*args, **kwargs):
     38     if kwargs and 'replication' not in kwargs and kwargs.get('fallback_application_name') != 'Patroni ctl':
     39         options = [kwargs['options']] if 'options' in kwargs else []
     40         options.append('-c search_path=pg_catalog')
     41         kwargs['options'] = ' '.join(options)
     42     ret = _connect(*args, **kwargs)
     43     ret.autocommit = True
     44     return ret
     45
     46
     47 def quote_ident(value, conn=None):
     48     if _legacy or conn is None:
     49         return '"{0}"'.format(value.replace('"', '""'))
     50     return _quote_ident(value, conn)

/usr/lib64/python3.9/site-packages/psycopg2/init.py

     80 def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs):
     81     """
     82     Create a new database connection.
     83
     84     The connection parameters can be specified as a string:
     85
     86         conn = psycopg2.connect("dbname=test user=postgres password=secret")
     87
     88     or using a set of keyword arguments:
     89
     90         conn = psycopg2.connect(database="test", user="postgres", password="secret")
     91
     92     Or as a mix of both. The basic connection parameters are:
     93
     94     - *dbname*: the database name
     95     - *database*: the database name (only as keyword argument)
     96     - *user*: user name used to authenticate
     97     - *password*: password used to authenticate
     98     - *host*: database host address (defaults to UNIX socket if not provided)
     99     - *port*: connection port number (defaults to 5432 if not provided)
    100
    101     Using the *connection_factory* parameter a different class or connections
    102     factory can be specified. It should be a callable object taking a dsn
    103     argument.
    104
    105     Using the *cursor_factory* parameter, a new default cursor factory will be
    106     used by cursor().
    107
    108     Using *async*=True an asynchronous connection will be created. *async_* is
    109     a valid alias (for Python versions where ``async`` is a keyword).
    110
    111     Any other keyword parameter will be passed to the underlying client
    112     library: the list of supported parameters depends on the library version.
    113
    114     """
    115     kwasync = {}
    116     if 'async' in kwargs:
    117         kwasync['async'] = kwargs.pop('async')
    118     if 'async_' in kwargs:
    119         kwasync['async_'] = kwargs.pop('async_')
    120
    121     dsn = _ext.make_dsn(dsn, **kwargs)
    122     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
    123     if cursor_factory is not None:
    124         conn.cursor_factory = cursor_factory
    125
    126     return conn

问题2

在这里插入图片描述

 0 [BACKEND] LOG:  shared memory 30603 Mbytes, memory context 133220 Mbytes, max process memory 163840 Mbytes
[2024-04-23 18:21:54.541][214][][gs_ctl]: gs_ctl status,datadir is /pgdata/data/opengauss-55634e8f 
gs_ctl: server is running (PID: 203)
/usr/local/opengauss/bin/gaussdb "-D" "/pgdata/data/opengauss-55634e8f" "--config-file=/pgdata/data/opengauss-55634e8f/postgresql.conf" "-M" "standby"
2024-04-23 18:21:54,551 INFO: is_update=true
2024-04-23 18:21:54,551 INFO: is_running
2024-04-23 18:21:54,551 INFO: cluster_member = ({'opengauss-55634e8f-0-0': '245.0.2.54'})
2024-04-23 18:21:54,552 INFO: configuration = ({'listen_addresses': '0.0.0.0', 'port': '5432', 'wal_level': 'hot_standby', 'hot_standby': 'on', 'max_connections': 8800, 'max_wal_senders': 10, 'max_prepared_transactions': 0, 'max_locks_per_transaction': 64, 'archive_command': 'sh /home/postgres/bin/opengauss_archive_push.sh %p %f opengauss-55634e8f qfusion-admin opengauss', 'archive_mode': True, 'datestyle': 'iso, mdy', 'enable_cbm_tracking': True, 'enable_page_lsn_check': True, 'log_destination': 'csvlog', 'log_directory': '/pglog', 'log_filename': 'postgresql-%a.log', 'log_min_duration_statement': -1, 'log_timezone': 'PRC', 'log_truncate_on_rotation': 'on', 'logging_collector': True, 'pgaudit.log': 'none', 'synchronous_commit': True, 'synchronous_standby_names': '', 'sysadmin_reserved_connections': 20, 'timezone': 'PRC', 'unix_socket_directory': '/tmp', 'application_name': 'opengauss-55634e8f-0-0', 'wal_keep_segments': 8})
[2024-04-23 18:21:54.564][218][][gs_ctl]: gs_ctl reload ,datadir is /pgdata/data/opengauss-55634e8f 
server signaled
2024-04-23 18:21:54,565 INFO: self._async_executor.busy =(False)
2024-04-23 18:21:54,566 INFO: establishing a new patroni connection to the postgres cluster
2024-04-23 18:21:54,641 ERROR: get_postgresql_status
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/patroni/api.py", line 743, in query
    with self.patroni.postgresql.connection().cursor() as cursor:
  File "/usr/local/lib/python3.9/site-packages/patroni/postgresql/__init__.py", line 321, in connection
    return self._connection.get()
  File "/usr/local/lib/python3.9/site-packages/patroni/postgresql/connection.py", line 24, in get
    self._connection = psycopg.connect(**self._conn_kwargs)
  File "/usr/local/lib/python3.9/site-packages/patroni/psycopg.py", line 42, in connect
    ret = _connect(*args, **kwargs)
  File "/usr/lib64/python3.9/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not receive data from server, error: Connection reset by peer, remote datanode: (null)


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/patroni/api.py", line 672, in get_postgresql_status
    row = self.query(stmt.format(postgresql.wal_name, postgresql.lsn_name), retry=retry)[0]
  File "/usr/local/lib/python3.9/site-packages/patroni/api.py", line 655, in query
    return self.server.query(sql, *params)
  File "/usr/local/lib/python3.9/site-packages/patroni/api.py", line 749, in query
    raise PostgresConnectionException('connection problems')
patroni.exceptions.PostgresConnectionException: 'connection problems'
2024-04-23 18:21:55,414 INFO: establishing a new patroni connection to the postgres cluster
2024-04-23 18:21:55,414 WARNING: Retry got exception: 'connection problems'
[2024-04-23 18:21:55.425][223][][gs_ctl]: gs_ctl status,datadir is /pgdata/data/opengauss-55634e8f 
no server running
2024-04-23 18:21:55,426 WARNING: Failed to determine PostgreSQL state from the connection, falling back to cached role
2024-04-23 18:21:55,427 WARNING: Failed to determine PostgreSQL state from the connection, falling back to cached role

问题3

2024-05-20 09:49:35,269 INFO: Local timeline=2 lsn=0/7000000
2024-05-20 09:49:35,271 ERROR: Exception when working with leader
Traceback (most recent call last):
  File "/usr/local/bin/patroni/patroni/postgresql/rewind.py", line 79, in check_leader_is_not_in_recovery
    with get_connection_cursor(connect_timeout=3, options='-c statement_timeout=2000', **conn_kwargs) as cur:
  File "/usr/lib64/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/usr/local/bin/patroni/patroni/postgresql/connection.py", line 48, in get_connection_cursor
    conn = psycopg.connect(**kwargs)
  File "/usr/local/bin/patroni/patroni/psycopg.py", line 103, in connect
    ret = _connect(*args, **kwargs)
  File "/usr/lib64/python3.9/site-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL:  the database system is shutting down

在这里插入图片描述

/pglog/xxx.csv

could not receive data from WAL stream: ERROR:  requested WAL segment 000000030000000000000007 has already been removed 

在这里插入图片描述

pip3 install cdiff

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1682974.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【Kubernetes】kubectl详解

陈述式资源管理方法&#xff1a; 1.kubernetes 集群管理集群资源的唯一入口是通过相应的方法调用 apiserver 的接口 2.kubectl 是官方的CLI命令行工具&#xff0c;用于与 apiserver 进行通信&#xff0c;将用户在命令行输入的命令&#xff0c;组织并转化为 apiserver 能识别的…

JavaWeb基础(HTML,CSS,JS)

这些知识用了三四天左右学完&#xff0c;因为是JavaWeb&#xff0c;并不是前端&#xff0c;所以只是够用&#xff0c;不是深入&#xff0c;但是这确实是学校一个学期交的东西&#xff08;JavaWeb课程&#xff09;。 总结一下网页分为三部分&#xff1a;HTML(内容结构),CSS&…

HTML | 在IDEA中配置Tomcat时遇到的一些问题的解决办法

目录 IDEA中没有web文件夹目录 Tomcat在哪里配置服务器 IDEA中没有web文件夹目录 首先说在IDEA中没有web这个文件夹的解决办法 在菜单栏中帮助中点击查找操作搜索添加框架支持&#xff08;因为我的IDEA会出现无法点击这个操作&#xff0c;所以我对该操作添加了快捷键&#xf…

linux系统内存持续飙高的排查方法

目录 前言&#xff1a; 1、查看系统内存的占用情况 2、找出占用内存高的进程 3、解决方法 4、补充&#xff1a;如果物理内存使用完了&#xff0c;会发生的情况 前言&#xff1a; 如果一台服务器内存使用率持续处于一个高峰值&#xff0c;服务器可能会出现响应慢问题。例如s…

03:PostgreSQL逻辑结构(表空间、数据库、模式、表、索引)

环境规划&#xff1a; 操作系统&#xff1a;CentOS 7.9 64bitPostgreSQL 版本&#xff1a;16.x 或 15.x安装用户&#xff1a;postgres软件安装目标路径&#xff1a;/usr/pgsql-<version>数据库数据目录&#xff1a;/pgdata 目录 表空间Tablespace 默认表空间 手动创建…

【Vue】性能优化

使用 key 对于通过循环生成的列表&#xff0c;应给每个列表项一个稳定且唯一的 key&#xff0c;这有利于在列表变动时&#xff0c;尽量少的删除和新增元素。 使用冻结的对象 冻结的对象&#xff08;Object.freeze(obj)&#xff09;不会被响应化&#xff0c;不可变。 使用函…

【贪心算法题目】

1. 柠檬水找零 这一个题目是一个比较简单的模拟算法&#xff0c;只需要根据手里的钱进行找零即可&#xff0c;对于贪心的这一点&#xff0c;主要是在20元钱找零的情况下&#xff0c;此时会出现两种情况&#xff1a;10 5 的组合 和 5 5 5 的组合&#xff0c;根据找零的特点&a…

通过管理系统完成商品属性维护

文章目录 1.数据库表设计1.商品属性表 2.renren-generator生成CRUD1.基本配置检查1.generator.properties2.application.yml 2.启动RenrenGeneratorApplication.java生成CRUD1.启动后访问localhost:812.生成商品属性表的crud 3.将crud代码集成到项目中1.解压&#xff0c;找到ma…

Gittee

前言&#xff1a; 海鸥禁止 git简述 分布式版本控制系统 版本管理 集中式只有一个档案馆 分布式可以每人有一个档案馆&#xff0c;版本合并 协同工作 github&#xff0c;gitlab&#xff0c;gitee是git的托管平台 安装git 略 添加&#xff0c;提交文件 推到远程仓库 常…

vscode安装多版本esp-idf

安装 离线安装 vscode设置 建立一个新的配置文件, 这里面的插件是全新的 安装esp-idf 官网下载espidf 安装这一个 选项默认即可 记住各一个路径, 之后要用到 vscode安装插件 安装以后会进入这一个界面, 也可以CtrlShiftP输入ESP-IDFextension进入 使用espressif 问题 这一个…

微信小程序---小程序文档配置(2)

一、小程序文档配置 1、小程序的目录结构 1.1、目录结构 小程序包含一个描述整体程序的 app 和多个描述各自页面的 page 一个小程序主体部分由三个文件组成&#xff0c;必须放在项目的根目录 比如当前我们的《第一个小程序》项目根目录下就存在这三个文件&#xff1a; 1…

【论文速读】|探索ChatGPT在软件安全应用中的局限性

本次分享论文&#xff1a;Exploring the Limits of ChatGPT in Software Security Applications 基本信息 原文作者&#xff1a;Fangzhou Wu, Qingzhao Zhang, Ati Priya Bajaj, Tiffany Bao, Ning Zhang, Ruoyu "Fish" Wang, Chaowei Xiao 作者单位&#xff1a;威…

day08-Java常用API

day08——Java常用API 一、今日内容介绍、API概述 各位同学&#xff0c;我们前面已经学习了面向对象编程&#xff0c;使用面向编程这个套路&#xff0c;我们需要自己写类&#xff0c;然后创建对象来解决问题。但是在以后的实际开发中&#xff0c;更多的时候&#xff0c;我们是…

Linux软硬链接及动静态库

软硬链接与动静态库 软连接 创建链接的方法&#xff1a; ln -s test1.txt test2.txt 其中ln 是link(链接)&#xff0c;-s 是soft(软)&#xff0c;后者链接前者。 此时打开test2.txt&#xff0c;发现其中内容与test.txt一致。那么软连接到底建立了什么联系&#xff1f;…

Python函数进阶:四大高阶函数、匿名函数、枚举、拉链与递归详解

系列文章目录 Python数据类型&#xff1a;编程新手的必修课深入探索Python字符串&#xff1a;技巧、方法与实战Python 函数基础详解Python正则表达式详解&#xff1a;掌握文本匹配的魔法Python文件操作宝典&#xff1a;一步步教你玩转文件读写Python面向对象基础与魔法方法详解…

添加webpack.config.js配置

webpack 命令默认会去根目录查找webpack.config.js配置文件&#xff0c;如果没有&#xff0c;则会使用webpack默认的零配置打包规则进行打包&#xff0c;默认的零配置打包规则主要包括下面这几点&#xff1a; 1. 默认入口文件&#xff1a;Webpack 默认会将 ./src/index.js 作为…

“壕无人性”的沙特也要买量子计算机!巨头沙特阿美的合作方竟是它?

内容来源&#xff1a;量子前哨&#xff08;ID&#xff1a;Qforepost&#xff09; 文丨浪味仙 排版丨沛贤 深度好文&#xff1a;1200字丨5分钟阅读 摘要&#xff1a;石油巨头沙特阿美与 Pasqal 开启合作&#xff0c;计划于 2025 年部署一台 200 量子比特的量子计算机&#xff…

开源大模型与闭源大模型:技术哲学的较量

目录 前言一、 开源大模型的优势1. 社区支持与合作1.1 全球协作网络1.2 快速迭代与创新1.3 共享最佳实践 2. 透明性与可信赖性2.1 审计与验证2.2 减少偏见与错误2.3 安全性提升 3. 低成本与易访问性3.1 降低研发成本3.2 易于定制化3.3 教育资源丰富 4. 促进标准化5. 推动技术进…

【qt】QDockWidget 浮动窗口

QDockWidget 浮动窗口 一.QDockWidget 的用法 前言&#xff1a;很简单&#xff0c;放心食用 一.QDockWidget 的用法 太简单了&#xff0c;直接来吧&#xff01; 直接做个小项目来了解QDockWidget 的用法 目标效果图&#xff1a; 开始拖放&#xff1a; 开始布局&#xff1a; …

Jenkins pipeline发布前端项目

说明&#xff1a;第一次使用jenkins生成pipeline片段&#xff0c;做个记录... 1.全局工具配置添加自定义node版本 2.系统管理添加前端应用部署服务器 2.1 点击高级选择账号密码验证方式&#xff0c;添加服务器的用户和密码 3.系统管理--凭据--系统--全局凭据--添加自己的git凭据…