Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u4c6n-004gwf-O1 for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Apr 2025 08:57:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u4c6l-006m6V-N3 for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Apr 2025 08:57:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u4c6l-006m6M-DZ for pgsql-hackers@lists.postgresql.org; Tue, 15 Apr 2025 08:57:32 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u4c6j-000AHy-1M for pgsql-hackers@lists.postgresql.org; Tue, 15 Apr 2025 08:57:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1744707446; bh=xCqD+T6+oZMrhDhzTF6Jn0q8QVdkC42S4I9j7hGQjnI=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=e1DOSGO6e5lu2rL8VyaXv4eepbbXd6gMpdZNJd2mNaNtSfRQNRODuCAXZeSXSVjm7 upFRL6PcOaBJpY22tmOUY0vafaqUaB5EKotUZqujnniEIV7QohKlLkmAtJi1pW0q9y 1elZJpA/ijHOeZ5Bg1sHvj99xTT6/ZJAPXKX/vOs6novG6n/W30jObRYoEB4sn15xE u37BHW7qjQDeowQf7QxXoJx5g2f54CA4eBehgdk51VYS8+FCDpGOttS+ILb/rErKc4 ZOPYLV+ZuzmCCwZnfL4xBiIcdJ73NDc3T7+37Q87uiqK+znQxXdSfid7HRUYtfyAI9 TmSGwMxiA4j/Q== Received: from [172.30.50.150] (unknown [93.174.131.138]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: y.sokolov@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id BD0166029B; Tue, 15 Apr 2025 11:57:25 +0300 (MSK) Message-ID: <142418c4-5db1-4221-a0a4-cd8aa9a17e83@postgrespro.ru> Date: Tue, 15 Apr 2025 11:57:24 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Built-in Raft replication To: Kirill Reshke , Konstantin Osipov Cc: pgsql-hackers@lists.postgresql.org References: Content-Language: en-US From: Yura Sokolov In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/04/15 04:45:00 #27887313 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 14.04.2025 20:44, Kirill Reshke пишет: > OTOH Raft needs to write its own log, and what's worse, it sometimes > needs to remove already written parts of it (so, it is not appended > only, unlike WAL). If you have a production system which maintains two > kinds of logs with different semantics, it is a very hard system to > maintain.. Raft is log replication protocol which uses log position and term. But... PostgreSQL already have log position and term in its WAL structure. PostgreSQL's timeline is actually the Term. Raft implementer needs just to correct rules for Term/Timeline switching: - instead of "next TimeLine number is just increment of largest known TimeLine number" it needs to be "next TimeLine number is the result of Leader Election". And yes, "it sometimes needs to remove already written parts of it". But... It is exactly what every PostgreSQL's cluster manager software have to do to join previous leader as a follower to new leader - pg_rewind. So, PostgreSQL already have 70-90%% of Raft implementation details. Raft doesn't have to be implemented in PostgreSQL. Raft has to be finished!!! PS: One of the biggest issues is forced snapshot on replica promotion. It really slows down leader switch time. It looks like it is not really needed, or some small workaround should be enough. -- regards Yura Sokolov aka funny-falcon