Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iO1gb-0007Cw-VM for pgsql-general@arkaria.postgresql.org; Fri, 25 Oct 2019 15:39:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iO1fb-000515-GY for pgsql-general@arkaria.postgresql.org; Fri, 25 Oct 2019 15:38:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iO1fb-00050y-1p for pgsql-general@lists.postgresql.org; Fri, 25 Oct 2019 15:38:31 +0000 Received: from [212.85.157.172] (helo=mail.dalibo.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iO1fX-0004fD-Ta for pgsql-general@postgresql.org; Fri, 25 Oct 2019 15:38:29 +0000 Received: from firost (unknown [88.190.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 1F8B41F7B6; Fri, 25 Oct 2019 17:38:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1572017903; bh=Bjidzdv+yZY8IQfSeOVD9JawGIDdgzfFsp+p7K/hwxM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DOnRO6AhJx66smPKN2IJbiE8hqwTf86E3P8xXmTtAu7DnhcPWGg4MWfiQoaRUu4u4 r7cziqGYhR1qgadtD/iDm2YxXX5YR86lP+S3Zug77kD1PQuIqFZFtCJYZNb3wEe1FE Zhm0gHuP9bJiGwDQg1PXZkOhBplnqoc25WbWW9nw= Date: Fri, 25 Oct 2019 17:38:21 +0200 From: Jehan-Guillaume de Rorthais To: Peter Eisentraut , Tom Lane Cc: Alvaro Herrera , Tim Clarke , PostgreSQL General List Subject: Re: logical replication - negative bitmapset member not allowed Message-ID: <20191025173821.6bd76407@firost> In-Reply-To: <20191010151546.69d4f0e9@firost> References: <20190401214304.GA29208@alvherre.pgsql> <4a16af4e-ba61-e46d-6d69-0a20ef7ed97d@2ndquadrant.com> <20191010151546.69d4f0e9@firost> Organization: Dalibo MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/=Ag+zDO8.wolmQqQPfYqLtJ" X-Host-Lookup-Failed: Reverse DNS lookup failed for 212.85.157.172 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --MP_/=Ag+zDO8.wolmQqQPfYqLtJ Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline On Thu, 10 Oct 2019 15:15:46 +0200 Jehan-Guillaume de Rorthais wrote: [...] > Here is a script to reproduce it under version 10, 11 and 12: I investigated on this bug while coming back from pgconf.eu. Bellow what I found so far. The message "negative bitmapset member not allowed" comes from logicalrep_rel_open(). Every field that are unknown, dropped or generated are mapped to remote attnum -1. See backend/replication/logical/relation.c: if (attr->attisdropped || attr->attgenerated) { entry->attrmap[i] = -1; continue; } attnum = logicalrep_rel_att_by_name(remoterel, NameStr(attr->attname)); Note that logicalrep_rel_att_by_name returns -1 on unknown fields. Later in the same function, we check if fields belonging to some PK or unique index appears in remote keys as well: while ((i = bms_next_member(idkey, i)) >= 0) { [...] if (!bms_is_member(entry->attrmap[attnum], remoterel->attkeys)) { entry->updatable = false; break; } } However, before checking if the local attribute belong to the remote keys, it should check if it actually mapped to a remote one. In other words, I suppose we should check entry->attrmap[attnum] > 0 before calling bms_is_member(). The trivial patch would be: - if (!bms_is_member(entry->attrmap[attnum], remoterel->attkeys)) + if (entry->attrmap[attnum] < 0 || + !bms_is_member(entry->attrmap[attnum], remoterel->attkeys)) { entry->updatable = false; break; } I tested with the attached scenario and it sound to work correctly. Note that while trying to fix this bug, I found a segment fault while compiling with asserts. You might want to review/test without --enable-cassert. I will report in another thread as this seems not related to this bug or fix. --MP_/=Ag+zDO8.wolmQqQPfYqLtJ Content-Type: application/octet-stream; name=negative_bitmap_error-fix.bash Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=negative_bitmap_error-fix.bash IyEvdXNyL2Jpbi9iYXNoCgojIGVudgpQR0JJTj0vdG1wL2ZpeC9iaW4KI1BHQklOPS91c3IvbGli L3Bvc3RncmVzcWwvMTIvYmluClBVQj0vdG1wL3B1YgpTVUI9L3RtcC9zdWIKUFVCX1BPUlQ9NTQz MgpTVUJfUE9SVD01NDMzClRTPSQoZGF0ZSArJUZUJVQpClBVQl9MT0c9IiRQVUIiLSIkVFMiLmxv ZwpTVUJfTE9HPSIkU1VCIi0iJFRTIi5sb2cKCnVuc2V0IFBHUE9SVCBQR0hPU1QgUEdEQVRBQkFT RSBQR0RBVEEgTERfTElCUkFSWV9QQVRICmV4cG9ydCBQR1VTRVI9cG9zdGdyZXMKZXhwb3J0IFBH T1BUSU9OUz0iLWMgY2xpZW50X21pbl9tZXNzYWdlcz1FUlJPUiIKZXhwb3J0IFBBVEg9IiR7UEdC SU59OiR7UEFUSH0iCgpmdW5jdGlvbiBsb2cgewogICAgTD0kMTsgc2hpZnQKICAgIGVjaG8gIiQo ZGF0ZSArJyVGICVUJykgJHtMfTogICRAIgp9CgojIGNsZWFudXAKcGtpbGwgInBnYmVuY2giCgpm b3IgaSBpbiAiJFBVQiIgIiRTVUIiOyBkbwogICAgdGVzdCAtZCAiJGkiIHx8IGNvbnRpbnVlCiAg ICB0ZXN0IC1mICIkaSIvcG9zdG1hc3Rlci5waWQgJiYgIiRQR0JJTiIvcGdfY3RsIC13IC1zIC1E ICIkaSIgLW0gaW1tZWRpYXRlIHN0b3A7CiAgICBsb2cgTE9HICJzdG9wcGVkIG9sZCBpbnN0YW5j ZSBpbiAkaTogJD8iCiAgICBybSAtciAiJGkiCmRvbmUKCiMgY2x1c3RlcgoiJFBHQklOIi9pbml0 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