Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZ7BC-00005N-GP for pgsql-hackers@arkaria.postgresql.org; Thu, 14 May 2020 06:17:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jZ7B9-0004me-7g for pgsql-hackers@arkaria.postgresql.org; Thu, 14 May 2020 06:17:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZ7B8-0004mW-UL for pgsql-hackers@lists.postgresql.org; Thu, 14 May 2020 06:17:11 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jZ7B2-0004Uf-CP for pgsql-hackers@postgresql.org; Thu, 14 May 2020 06:17:09 +0000 Received: by mail-pg1-x543.google.com with SMTP id t11so838929pgg.2 for ; Wed, 13 May 2020 23:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=IAGAWXxeSTSrjn4mhPfiI/ccFAR+ugfFIkkC4hQMyi8=; b=Oz6DNOzTyG0pZdl3mun/qkVNPwSLCEDrnS/Xdv3tEj9Ux1WlCRxiCK4usbBJo5zieE 1LscOJFLet8zsegcBsvRu2JtMos/VnxgxX+ITEi8fYz27YtThIEghncpKtMhSrL6GPkw LGYV4ZrwrRMgbp9WkxYm/u7if6N4vBxy8zJXzh+k3C+UCCUVBYHTH8mSx1yYC3AN6EZ+ i3fkWrnPYNVMqqGsi23SyXQys+kiC6Ybtkxgyc4Yg/fI44UtKem+bMRbAw1a3R11n7be CqHDLcBYI3iiAWLgPPMon9UUMjeO+BKt/9r38vvx7HQ8t0C1E0mSCyEt7p2lYWpUoR66 Yeww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=IAGAWXxeSTSrjn4mhPfiI/ccFAR+ugfFIkkC4hQMyi8=; b=joSJKJ8+IPV7XPZ+z/lklQp/cMoJ+EuBVbdfdu3FSPoUlVmbt2qe1U78erUCik/JZu z4U/APyuzagio35TL+P+5iOAVa/QDAfyEeQudqmWwyWlOU02bvO4RyJyOUV2wmcBtfMu 3hTPbXJpx34cblafA3Bb07JmRPosjc8igoOVM71qCWKdwyG1lgI2jm3gFXs4o4ChwNJG VoB4TX4UTG+XxK5axuLN5wCZQXtZUJ8WcuCJyql4YD6qeiYaVJNY/u1hS1+BWXXohJaD 0O345u5SE2Dh1HCroTZMif444Oqiw6zkefFR2tdVcdgeUw6zXSYmmocPeOaFgMBXFHg7 4amw== X-Gm-Message-State: AOAM5318IyH1rjasJlUSxLcm9q/jGEdO4rBlGZOsTGydBeMKQfjaguQN 2grtDUIxX6O9cvXdDtittFQ= X-Google-Smtp-Source: ABdhPJzBjY2fxZhRMWKnYZJSIKy0DbBW4TMMz4oSZJxkcKZkKl1qVas6xGEQLIDZA1KORk9pciH0CQ== X-Received: by 2002:a62:3607:: with SMTP id d7mr2836960pfa.245.1589437023088; Wed, 13 May 2020 23:17:03 -0700 (PDT) Received: from localhost (ag027197.dynamic.ppp.asahi-net.or.jp. [157.107.27.197]) by smtp.gmail.com with ESMTPSA id t20sm16790386pjo.13.2020.05.13.23.17.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 23:17:02 -0700 (PDT) Date: Thu, 14 May 2020 15:16:59 +0900 (JST) Message-Id: <20200514.151659.1224056315528271804.horikyota.ntt@gmail.com> To: x4mmm@yandex-team.ru Cc: pgsql-hackers@postgresql.org Subject: Re: MultiXact\SLRU buffers configuration From: Kyotaro Horiguchi In-Reply-To: <3B099683-ECCD-43CD-A3D6-F08C3745002A@yandex-team.ru> References: <20200514.102526.1602501255796880628.horikyota.ntt@gmail.com> <3B099683-ECCD-43CD-A3D6-F08C3745002A@yandex-team.ru> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk At Thu, 14 May 2020 10:19:42 +0500, "Andrey M. Borodin" wrote in > >> I'm looking more at MultiXact and it seems to me that we have a race condition there. > >> > >> When we create a new MultiXact we do: > >> 1. Generate new MultiXactId under MultiXactGenLock > >> 2. Record new mxid with members and offset to WAL > >> 3. Write offset to SLRU under MultiXactOffsetControlLock > >> 4. Write members to SLRU under MultiXactMemberControlLock > > > > But, don't we hold exclusive lock on the buffer through all the steps > > above? > Yes...Unless MultiXact is observed on StandBy. This could lead to observing inconsistent snapshot: one of lockers committed tuple delete, but standby sees it as alive. Ah, right. I looked from GetNewMultiXactId. Actually XLOG_MULTIXACT_CREATE_ID is not protected from concurrent reference to the creating mxact id. And GetMultiXactIdMembers is considering that case. > >> When we read MultiXact we do: > >> 1. Retrieve offset by mxid from SLRU under MultiXactOffsetControlLock > >> 2. If offset is 0 - it's not filled in at step 4 of previous algorithm, we sleep and goto 1 > >> 3. Retrieve members from SLRU under MultiXactMemberControlLock > >> 4. ..... what we do if there are just zeroes because step 4 is not executed yet? Nothing, return empty members list. > > > > So transactions never see such incomplete mxids, I believe. > I've observed sleep in step 2. I believe it's possible to observe special effects of step 4 too. > Maybe we could add lock on standby to dismiss this 1000us wait? Sometimes it hits hard on Standbys: if someone is locking whole table on primary - all seq scans on standbys follow him with MultiXactOffsetControlLock contention. GetMultiXactIdMembers believes that 4 is successfully done if 2 returned valid offset, but actually that is not obvious. If we add a single giant lock just to isolate ,say, GetMultiXactIdMember and RecordNewMultiXact, it reduces concurrency unnecessarily. Perhaps we need finer-grained locking-key for standby that works similary to buffer lock on primary, that doesn't cause confilicts between irrelevant mxids. regards. -- Kyotaro Horiguchi NTT Open Source Software Center