Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fT2bi-00015b-W7 for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Jun 2018 10:02:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fT2bh-0002b1-F4 for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Jun 2018 10:02:25 +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.89) (envelope-from ) id 1fT2bf-0002aM-EH for pgsql-hackers@lists.postgresql.org; Wed, 13 Jun 2018 10:02:25 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fT2bW-0005d0-U6 for pgsql-hackers@postgresql.org; Wed, 13 Jun 2018 10:02:21 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id C75A521C05A2; Wed, 13 Jun 2018 13:02:07 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from mail.postgrespro.ru (cyclops.l.postgrespro.ru [192.168.27.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 8D2F221C0577; Wed, 13 Jun 2018 13:02:07 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1528884127; bh=1aLJCbuDBuLwxbZC0fIRPywNASCi+RFGOSo0pUsgNn4=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=YANKNMc8CCGB/MqHnDzXvS60nW/jMD06uL3B5oCGGGOO1yG7ypxAzeMzOC8WGd9O8 snngfS7Wg14eJ+labGyAjOQzqvaTkZx7LG15HxIDF1wiJdmYkgyaXTOhzlA8hZGVmb shTSlgZlobH3sh882jBCWyzr9UF5CsSEpy1pzW2c= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Wed, 13 Jun 2018 13:02:07 +0300 From: Marina Polyakova To: Fabien COELHO Cc: Alvaro Herrera , pgsql-hackers@postgresql.org, Ildus Kurbangaliev , Teodor Sigaev Subject: Re: [HACKERS] WIP Patch: Pgbench Serialization and deadlock errors Organization: Postgres Professional In-Reply-To: References: <20180508193621.dphlgwrd5yz67o2z@alvherre.pgsql> <0569c5309cf536a839e2a3a1433bd113@postgrespro.ru> Message-ID: X-Sender: m.polyakova@postgrespro.ru User-Agent: Roundcube Webmail/1.2.4 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 10-06-2018 10:38, Fabien COELHO wrote: > Hello Marina, Hello! >> v9-0003-Pgbench-errors-use-the-ereport-macro-to-report-de.patch >> - a patch for the ereport() macro (this is used to report client >> failures that do not cause an aborts and this depends on the level of >> debugging). > > ISTM that abort() is called under FATAL. If you mean abortion of the client, this is not an abortion of the main program. >> - implementation: if possible, use the local ErrorData structure >> during the errstart()/errmsg()/errfinish() calls. Otherwise use a >> static variable protected by a mutex if necessary. To do all of this >> export the function appendPQExpBufferVA from libpq. > > This patch applies cleanly on top of the other ones (there are minimal > interactions), compiles cleanly, global & pgbench "make check" are ok. :-) > IMO this patch is more controversial than the other ones. > > It is not really related to the aim of the patch series, which could > do without, couldn't it? > I'd suggest that it should be an independent submission, unrelated to > the pgbench error management patch. I suppose that this is related; because of my patch there may be a lot of such code (see v7 in [1]): - fprintf(stderr, - "malformed variable \"%s\" value: \"%s\"\n", - var->name, var->svalue); + if (debug_level >= DEBUG_FAILS) + { + fprintf(stderr, + "malformed variable \"%s\" value: \"%s\"\n", + var->name, var->svalue); + } - if (debug) + if (debug_level >= DEBUG_ALL) fprintf(stderr, "client %d sending %s\n", st->id, sql); That's why it was suggested to make the error function which hides all these things (see [2]): There is a lot of checks like "if (debug_level >= DEBUG_FAILS)" with corresponding fprintf(stderr..) I think it's time to do it like in the main code, wrap with some function like log(level, msg). > Moreover, it changes pgbench current > behavior, which might be admissible, but should be discussed clearly. > The semantics of the existing code is changed, the FATAL levels calls > abort() and replace existing exit(1) calls. Maybe you want an ERROR > level as well. Oh, thanks, I agree with you. And I do not want to change the program exit code without good reasons, but I'm sorry I may not know all pros and cons in this matter.. Or did you also mean other changes? > The code adapts/duplicates existing server-side "ereport" stuff and > brings it to the frontend, where the logging needs are somehow quite > different. > > I'd prefer to avoid duplication and/or have some code sharing. I was recommended to use the same interface in [3]: On elog/errstart: we already have a convention for what ereport() calls look like; I suggest to use that instead of inventing your own. > If it > really needs to be duplicated, I'd suggest to put all this stuff in > separated files. If we want to do that, I think that it would belong > to fe_utils, and where it could/should be used by all front-end > programs. I'll try to do it.. > I do not understand why names are changed, eg ELEVEL_FATAL instead of > FATAL. ISTM that part of the point of the move would be to be > homogeneous, which suggests that the same names should be reused. Ok! > For logging purposes, ISTM that the "elog" macro interface is nicer, > closer to the existing "fprintf(stderr", as it would not introduce the > additional parentheses hack for "rest". I was also recommended to use ereport() instead of elog() in [3]: With that, is there a need for elog()? In the backend we have it because $HISTORY but there's no need for that here -- I propose to lose elog() and use only ereport everywhere. > I see no actual value in creating on the fly a dynamic buffer through > plenty macros and functions as the end result is just to print the > message out to stderr in the end. > > errfinishImpl: fprintf(stderr, "%s", error->message.data); > > This looks like overkill. From reading the code, this does not look > like an improvement: > > fprintf(stderr, "invalid socket: %s", PQerrorMessage(st->con)); > > vs > > ereport(ELEVEL_LOG, (errmsg("invalid socket: %s", > PQerrorMessage(st->con)))); > > The whole complexity of the server-side interface only make sense > because TRY/CATCH stuff and complex logging requirements (eg several > outputs) in the backend. The patch adds quite some code and complexity > without clear added value that I can see. > My 0.02€: maybe you just want to turn > > fprintf(stderr, format, ...); > // then possibly exit or abort depending... > > into > > elog(level, format, ...); > > which maybe would exit or abort depending on level, and possibly not > actually report under some levels and/or some conditions. For that, it > could enough to just provide an nice "elog" function. I agree that elog() can be coded in this way. To use ereport() I need a structure to store the error level as a condition to exit. > In conclusion, which you can disagree with because maybe I have missed > something... anyway I currently think that: > > - it should be an independent submission > > - possibly at "fe_utils" level > > - possibly just a nice "elog" function is enough, if so just do that. I hope I answered all this above.. [1] https://www.postgresql.org/message-id/453fa52de88477df2c4a2d82e09e461c%40postgrespro.ru [2] https://www.postgresql.org/message-id/20180405180807.0bc1114f%40wp.localdomain [3] https://www.postgresql.org/message-id/20180508105832.6o3uf3npfpjgk5m7%40alvherre.pgsql -- Marina Polyakova Postgres Professional: http://www.postgrespro.com The Russian Postgres Company