Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Abnormal master-slave switching in sentinelmode

Đang mở
#2,841 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp, redis

Hướng nghiên cứu

Sử dụng ConnectionMultiplexer.Connect(...) của mẫu C# với serviceName=mymaster và ba endpoint Sentinel để tái hiện quá trình failover. Trước tiên, hãy theo dõi cách các thay đổi vai trò của Sentinel được quan sát sau khi A quay lại và cách GetDatabase() định tuyến StringIncrementAsync. Hoàn tất có nghĩa là các thao tác không được gửi đến A trong khi A đang tham gia lại với tư cách là một replica.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Thank you very much for your contribution. I encountered some difficulties when using it and would like to ask for advice.

My redis configuration is 1 master A, 1 slave B, 3 sentinels.

In sentinel mode, I found that after node A went offline, node B was upgraded to the master node.
There was no problem in this process.

But when the old master node A comes online again, stackExchange.redis will briefly mark both nodes as primary, and use the old master node A.
But A is converting to a slave node at this time and synchronizing new data. This will lead to the error of reading and writing A at this time.

The program will mark A as a replica later, and the error will be corrected.

Regarding this problem, how should I solve it? Is there any relevant configuration that can solve this problem?

MyTestCode

using StackExchange.Redis;
using static StackExchange.Redis.Role;

namespace ConsoleApp3
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello, World!");

            ConnectionMultiplexer masterConnection = ConnectionMultiplexer.Connect("172.16.184.197:26379,172.16.184.198:26379,172.16.0.29:26379,serviceName=mymaster");
            while (true)
            {
                try
                {
                    IDatabase database = masterConnection.GetDatabase();
                    await database.StringIncrementAsync("SomeKey", 1);
                    System.Console.WriteLine(masterConnection.GetStatus());
                    System.Console.WriteLine(DateTime.Now.ToString("yyyyMMddHHmmss::") + await database.StringGetAsync("SomeKey"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                await Task.Delay(1000);
            }
        }
    }
}

Start

Image

stop A and switch to B

Image

start A and the data is dirty

Image

recover normal

Image

Ngôn ngữ chính
C#
Star
6.2k
Fork
1.6k
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
27

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của StackExchange/StackExchange.Redis

Tất cả issue của StackExchange/StackExchange.Redis

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.