Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WsyZG-0003Ow-B4 for pgsql-bugs@arkaria.postgresql.org; Fri, 06 Jun 2014 18:08:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WsyZF-0000YI-QF for pgsql-bugs@arkaria.postgresql.org; Fri, 06 Jun 2014 18:08:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WsyZE-0000YA-Pe for pgsql-bugs@postgresql.org; Fri, 06 Jun 2014 18:08:40 +0000 Received: from smtprelay0146.b.hostedemail.com ([64.98.42.146] helo=smtprelay.b.hostedemail.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WsyZ6-0001KO-50 for pgsql-bugs@postgresql.org; Fri, 06 Jun 2014 18:08:39 +0000 Received: from filter.hostedemail.com (b-bigip1 [10.5.19.254]) by smtprelay04.b.hostedemail.com (Postfix) with ESMTP id 995B27B61A; Fri, 6 Jun 2014 18:08:30 +0000 (UTC) X-Session-Marker: 616C76686572726540616C76682E6E6F2D69702E6F7267 X-Spam-Summary: 13, 1.2, 0, , d41d8cd98f00b204, alvherre@alvh.no-ip.org, :::::, RULES_HIT:41:355:379:599:800:871:960:967:973:988:989:1260:1311:1312:1313:1314:1345:1359:1431:1437:1515:1516:1518:1519:1535:1541:1575:1594:1595:1596:1711:1730:1747:1764:1777:1792:2194:2198:2199:2200:2393:2525:2560:2563:2682:2685:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4605:4659:5007:6119:6261:6748:7281:7903:9025:9038:9121:10008:10400:10848:11026:11232:11256:11257:11473:11604:11658:11914:12043:12438:12517:12519:12663:13255:13894:13895, 0, RBL:none, CacheIP:none, Bayesian:0.5, 0.5, 0.5, Netcheck:none, DomainCache:0, MSF:not bulk, SPF:fn, MSBL:0, DNSBL:none, Custom_rules:0:1:0 X-HE-Tag: fire47_fc4de89eea0c X-Filterd-Recvd-Size: 6505 Received: from eldon.alvh.no-ip.org (pc-65-79-161-190.cm.vtr.net [190.161.79.65]) (Authenticated sender: alvherre@alvh.no-ip.org) by omf04.b.hostedemail.com (Postfix) with ESMTPA; Fri, 6 Jun 2014 18:08:28 +0000 (UTC) Received: by eldon.alvh.no-ip.org (Postfix, from userid 1000) id CD9EF1FC9; Fri, 6 Jun 2014 14:08:26 -0400 (CLT) Date: Fri, 6 Jun 2014 14:08:26 -0400 From: Alvaro Herrera To: Tom Lane Cc: Serge Negodyuck , pgsql-bugs@postgresql.org Subject: Re: BUG #8673: Could not open file "pg_multixact/members/xxxx" on slave during hot_standby Message-ID: <20140606180826.GW5146@eldon.alvh.no-ip.org> References: <20131209142525.GA1123@awork2.anarazel.de> <20131209150345.GB1123@awork2.anarazel.de> <20131209182701.GD9519@awork2.anarazel.de> <20140103014616.GB7035@eldon.alvh.no-ip.org> <20140606013943.GT5146@eldon.alvh.no-ip.org> <20140606164727.GU5146@eldon.alvh.no-ip.org> <6687.1402074269@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="LSp5EJdfMPwZcMS1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6687.1402074269@sss.pgh.pa.us> User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --LSp5EJdfMPwZcMS1 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Tom Lane wrote: > Alvaro Herrera writes: > > After some simplification I think it should be clearer. Thanks Andres > > for commenting offlist. > > I find this not only unreadable but a bit scary: > > ! if (offset + MAX_MEMBERS_IN_LAST_MEMBERS_PAGE < offset) > > I'm worried whether some compilers might not decide that that's a > can't-happen situation, and optimize the test away entirely. I think > Andres' proposal is probably safer (though it needs comments). Well, somebody would have to work it out fully and test it -- I can't spend more time on this issue. If somebody is interested in doing that, I used this little program and make sure that it "zeroes" all pages, for various block sizes, initial offsets and "step sizes" (#members in each multi) -- I was able to reproduce Serge's issues with the original coding, and then watch issues fly by as I tried several approaches until I settled on the patch as submitted. -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --LSp5EJdfMPwZcMS1 Content-Type: text/x-csrc; charset=us-ascii Content-Disposition: attachment; filename="multixact.c" #include #include #define BLCKSZ (8192 * 1) typedef char bool; typedef unsigned int uint32; typedef uint32 TransactionId; typedef uint32 MultiXactOffset; typedef unsigned long int uint64; #define MaxMultiXactOffset ((MultiXactOffset) 0xFFFFFFFF) #define Min(x, y) ((x) < (y) ? (x) : (y)) #define true ((bool) 1) #define false ((bool) 0) #define SLRU_PAGES_PER_SEGMENT 32 #define MXACT_MEMBER_BITS_PER_XACT 8 #define MXACT_MEMBER_FLAGS_PER_BYTE 1 #define MXACT_MEMBER_XACT_BITMASK ((1 << MXACT_MEMBER_BITS_PER_XACT) - 1) /* how many full bytes of flags are there in a group? */ #define MULTIXACT_FLAGBYTES_PER_GROUP 4 #define MULTIXACT_MEMBERS_PER_MEMBERGROUP \ (MULTIXACT_FLAGBYTES_PER_GROUP * MXACT_MEMBER_FLAGS_PER_BYTE) /* size in bytes of a complete group */ #define MULTIXACT_MEMBERGROUP_SIZE \ (sizeof(TransactionId) * MULTIXACT_MEMBERS_PER_MEMBERGROUP + MULTIXACT_FLAGBYTES_PER_GROUP) #define MULTIXACT_MEMBERGROUPS_PER_PAGE (BLCKSZ / MULTIXACT_MEMBERGROUP_SIZE) #define MULTIXACT_MEMBERS_PER_PAGE \ (MULTIXACT_MEMBERGROUPS_PER_PAGE * MULTIXACT_MEMBERS_PER_MEMBERGROUP) /* * Because the number of items per page is not a divisor of the last item * number (member 0xFFFFFFFF), the last segment does not use the maximum number * of pages, and moreover the last used page therein does not use the same * number of items as previous pages. (Another way to say it is that the * 0xFFFFFFFF member is somewhere in the middle of the last page, so the page * has some empty space after that item.) * * This constant is the number of members in the last page of the last segment. */ #define MAX_MEMBERS_IN_LAST_MEMBERS_PAGE \ ((uint32) ((0xFFFFFFFF % MULTIXACT_MEMBERS_PER_PAGE) + 1)) /* page in which a member is to be found */ #define MXOffsetToMemberPage(xid) ((xid) / (TransactionId) MULTIXACT_MEMBERS_PER_PAGE) #define MXOffsetToFlagsOffset(xid) \ ((((xid) / (TransactionId) MULTIXACT_MEMBERS_PER_MEMBERGROUP) % \ (TransactionId) MULTIXACT_MEMBERGROUPS_PER_PAGE) * \ (TransactionId) MULTIXACT_MEMBERGROUP_SIZE) #define MXOffsetToFlagsBitShift(xid) \ (((xid) % (TransactionId) MULTIXACT_MEMBERS_PER_MEMBERGROUP) * \ MXACT_MEMBER_BITS_PER_XACT) static void ZeroMultiXactMemberPage(int pageno, bool writeXlog) { printf("zeroing page %u: page %u in segment %05X\n", pageno, pageno % SLRU_PAGES_PER_SEGMENT, pageno / SLRU_PAGES_PER_SEGMENT); } static void ExtendMultiXactMember(MultiXactOffset offset, int nmembers) { while (nmembers > 0) { int flagsoff; int flagsbit; uint64 diff64; uint32 difference; flagsoff = MXOffsetToFlagsOffset(offset); flagsbit = MXOffsetToFlagsBitShift(offset); if (flagsoff == 0 && flagsbit == 0) { int pageno; pageno = MXOffsetToMemberPage(offset); ZeroMultiXactMemberPage(pageno, true); } if (offset + MAX_MEMBERS_IN_LAST_MEMBERS_PAGE < offset) { difference = MaxMultiXactOffset - offset + 1; } else difference = MULTIXACT_MEMBERS_PER_PAGE - offset % MULTIXACT_MEMBERS_PER_PAGE; nmembers -= difference; offset += difference; } } int main(int argc, char **argv) { MultiXactOffset offset; int stepsize; if (argc != 3) { fprintf(stderr, "arguments: initial_offset step_size\n"); exit(0); } offset = strtoul(argv[1], NULL, 10); printf("initial offset: %u\n", offset); stepsize = strtoul(argv[2], NULL, 10); printf("step size: %d\n", stepsize); for (; ; offset += stepsize) ExtendMultiXactMember(offset, stepsize); return 0; } --LSp5EJdfMPwZcMS1 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --LSp5EJdfMPwZcMS1--