Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eQQDR-0004Ry-5R for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Dec 2017 04:06:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eQQDO-0006Q8-GC for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Dec 2017 04:06:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eQQDN-0006Py-UZ for pgsql-hackers@lists.postgresql.org; Sun, 17 Dec 2017 04:06:14 +0000 Received: from mail-pl0-x22b.google.com ([2607:f8b0:400e:c01::22b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eQQDK-0006jJ-Oz for pgsql-hackers@postgresql.org; Sun, 17 Dec 2017 04:06:12 +0000 Received: by mail-pl0-x22b.google.com with SMTP id bd8so2790288plb.9 for ; Sat, 16 Dec 2017 20:06:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=KpbljEMKjZkICXcruUaACA6zuv5onh8j+eckj5pUh3M=; b=W5jVhle57WXXcVGxKBrMgFdOBuCH8lhVhdDsItushy6oNXAoczBnJ21avcgIP+FW0g MYyXYp45T//eFd8j0yh9FeYdAQW2IpdrlqsJ5e0eaB0o34LH6IGRHBZ4WPK4BG726NMc NfCi0vHwhueNPYWrWaE20Ze0tWj5LOsJytOjI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=KpbljEMKjZkICXcruUaACA6zuv5onh8j+eckj5pUh3M=; b=QbqTN6X5qLW1pwbuiz2BZzelgyb6vYaGAwH3dohZr6THb2EqKTaHqX8Jp+0ugl5zEW N/GL4UZ8GR/zZ9exqugjVUFkQJ0A73vK90O2nQjZY7y431Ey66rEkoOokdPL5Wn/pLHx wIw4J085R/pQJ39sXu51XUXtOJZ65OZvUPe8DEkxQUUKJ+ErvMmpHTYNd0POK1+tUg0X xFbZB49FBuYpPnU6BfQ2ILqtzl00edH6xG5iWu4Msn/nVLbetYIZzeSE7p/P/CXNbVP4 gKLedkMNMvs/sfSYG0JC9Wia0VzYGAIzBQzt+pMQMhFoF9Fs8WzKHFaEZm9M2IuiWg57 x4vQ== X-Gm-Message-State: AKGB3mJ+JlU2eJYud6TF2cB/X3Ub98al1Kq0S7W8fN8TA8N7rkk72srn FwkQaj7IDaDVmDHZ4hFHbq62mlBQXmw= X-Google-Smtp-Source: ACJfBouJONZSYXEcC4+B6quxbY7cciEwSVBDgWqWpoNNqwBmmVLis275s2hCYSbQib17PoSIXQJC3A== X-Received: by 10.84.214.2 with SMTP id h2mr18757412pli.142.1513483568876; Sat, 16 Dec 2017 20:06:08 -0800 (PST) Received: from rfd.leadboat.com (c-73-158-248-138.hsd1.ca.comcast.net. [73.158.248.138]) by smtp.gmail.com with ESMTPSA id u81sm20829061pfa.70.2017.12.16.20.06.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Dec 2017 20:06:07 -0800 (PST) Date: Sat, 16 Dec 2017 20:06:05 -0800 From: Noah Misch To: pgsql-hackers@postgresql.org Subject: Re: Race to build pg_isolation_regress in "make -j check-world" Message-ID: <20171217040605.GA2421254@rfd.leadboat.com> References: <20171106080752.GA1298146@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="82I3+IH0IqGh5yIs" Content-Disposition: inline In-Reply-To: <20171106080752.GA1298146@rfd.leadboat.com> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --82I3+IH0IqGh5yIs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Nov 06, 2017 at 12:07:52AM -0800, Noah Misch wrote: > I've been enjoying the speed of parallel check-world, but I get spurious > failures from makefile race conditions. Commit c66b438 fixed the simple ones. > More tricky is this problem of multiple "make" processes entering > src/test/regress concurrently, which causes failures like these: > > gcc: error: pg_regress.o: No such file or directory > make[4]: *** [pg_isolation_regress] Error 1 > > /bin/sh: ../../../src/test/isolation/pg_isolation_regress: Permission denied > make -C test_extensions check > make[2]: *** [check] Error 126 > make[2]: Leaving directory `/home/nm/src/pg/backbranch/10/src/test/isolation' > > /bin/sh: ../../../../src/test/isolation/pg_isolation_regress: Text file busy > make[3]: *** [isolationcheck] Error 126 > make[3]: Leaving directory `/home/nm/src/pg/backbranch/10/src/test/modules/snapshot_too_old' > > This is reproducible since commit 2038bf4 or earlier; "make -j check-world" > had worse problems before that era. A workaround is to issue "make -j; make > -j -C src/test/isolation" before the check-world. Commit de0aca6 fixed that problem, but I now see similar trouble from multiple "make" processes running "make -C contrib/test_decoding install" concurrently. This is a risk for any directory named in an EXTRA_INSTALL variable of more than one makefile. Under the right circumstances, this would affect contrib/hstore and others in addition to contrib/test_decoding. That brings me back to the locking idea: > The problem of multiple "make" processes in a directory (especially src/port) > shows up elsewhere. In a cleaned tree, "make -j -C src/bin" or "make -j > installcheck-world" will do it. For more-prominent use cases, src/Makefile > prevents this with ".NOTPARALLEL:" and building first the directories that are > frequent submake targets. Perhaps we could fix the general problem with > directory locking; targets that call "$(MAKE) -C FOO" would first sleep until > FOO's lock is available. That could be tricky to make robust. If one is willing to assume that a lock-holding process never crashes, locking in a shell script is simple: mkdir to lock, rmdir to unlock. I don't want to assume that. The bakery algorithm provides convenient opportunities for checking whether the last locker crashed; I have attached a shell script demonstrating this approach. Better ideas? Otherwise, I'll look into integrating this design into the makefiles. Thanks, nm --82I3+IH0IqGh5yIs Content-Type: application/x-sh Content-Disposition: attachment; filename="bakery.sh" Content-Transfer-Encoding: quoted-printable #! /bin/sh=0A=0A# Demonstrate use of the bakery algorithm for crash-safe mu= tual exclusion in a=0A# shell script. Sample invocation:=0A# (rm -r buil= dlock; for child in `seq 1 10`; do sh bakery.sh & done; wait)=0A=0Aset -u= =0APS4=3D'+$$+ ' # include PID in "set -x" messages=0Asleep=3D':' # busy = wait, because "sleep .01" is a GNU extension=0Amkdir -p buildlock/choosing = buildlock/number=0A=0A# print the contents of a file, or "0" if file is mis= sing or empty=0Alockread() {=0A result=3D`2>/dev/null cat "$1"`=0A test -= z "$result" && result=3D0=0A echo "$result"=0A}=0A=0Afor iter in `seq 1 10= 0`; do=0A=0A# Algorithm and terminology from:=0A# A New Solution of Dijks= tra's Concurrent Programming Problem Communications=0A# of the ACM 17, 8 = (August 1974), 453-455.=0Acd buildlock=0Aecho 1 >choosing/$$=0Aecho "$$ ent= ered the doorway"=0Amax=3D0=0Acd number=0Aecho 0 >$$=0Afor pid in *; do=0A = number=3D`lockread $pid`=0A [ $number -gt $max ] && max=3D$number=0Adone= =0Amy_number=3D$((1 + $max))=0Aecho $my_number >$$=0Acd ../choosing=0Aecho = 0 >$$=0Aecho "$$ in the bakery, number =3D $my_number"=0Afor pid in $(print= f '%s\n' * | sort -n); do=0A while [ `lockread $pid` =3D 1 ]; do=0A 2>/dev= /null kill -0 "$pid" || { rm -f ../number/$pid; rm -f $pid; }; $sleep=0A d= one=0A while :; do=0A number=3D`lockread ../number/$pid`=0A [ $number -ne = 0 -a \=0A \( $number -lt $my_number -o \=0A $number -eq $my_number -a $= pid -lt $$ \) ] || break=0A 2>/dev/null kill -0 "$pid" || { rm -f ../number= /$pid; rm -f $pid; }; $sleep=0A done=0Adone=0Acd ../..=0Aecho "$$ in criti= cal section"=0A# exit # simulate crash=0Aecho "$$ leaving critical section= "=0Arm -f buildlock/number/$$=0Arm -f buildlock/choosing/$$=0A=0Adone=0A --82I3+IH0IqGh5yIs--