Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ea02H-000594-Tm for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jan 2018 14:10:22 +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 1ea02H-0005m7-Av for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jan 2018 14:10:21 +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 1ea02G-0005lX-SP for pgsql-hackers@lists.postgresql.org; Fri, 12 Jan 2018 14:10:21 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ea02B-0004TP-JL for pgsql-hackers@postgresql.org; Fri, 12 Jan 2018 14:10:19 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id A320D21C1C41; Fri, 12 Jan 2018 17:10:11 +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 1670C21C1C3F; Fri, 12 Jan 2018 17:10:10 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1515766211; bh=fBr/f9kLJTcJupubAWZFlWkCo4kMqEXB+tSMKc1WTlo=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=p55pIUPY2N0Td8XrgXRgq71nzp/kzbkSGY0Qyp7W47GUlD9UuJL9DCmFYjx1CRx9n 9hzW1TZqQF89KQ/HmI8zNDQQQft9e2fdYxPql+glEcO1UiOq1uBeMsSDeD5Ru7togN 05vbrU8s6eliqKqEIF10r+SkumIG6jO4QBliXCYg= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Fri, 12 Jan 2018 17:10:10 +0300 From: Marina Polyakova To: Fabien COELHO Cc: PostgreSQL Developers , Kevin Grittner , Andres Freund , Alvaro Herrera , Thomas Munro , Robert Haas Subject: Re: WIP Patch: Pgbench Serialization and deadlock errors Organization: Postgres Professional In-Reply-To: References: <894ac29c18f12a4fd6f8c97c9123a152@postgrespro.ru> Message-ID: <372a8e9e65a8c6692e2b58b1f86e81c5@postgrespro.ru> 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 12-01-2018 15:47, Fabien COELHO wrote: > Hello Marina, > > A partial answer, to focus on how the feature may be simplified. Thank you! > I apologise as it seems that I overlooked one of your mail. Changing > the thread has not helped. > >>> I'm wondering whether the whole feature could be simplified by >>> considering that one script is one "transaction" (it is from the >>> report point of view at least), and that any retry is for the full >>> script only, from its beginning. That would remove the trying to >>> guess >>> at transactions begin or end, avoid scanning manually for >>> subcommands, >>> and so on. >>> - Would it make sense? >>> - Would it be ok for your use case? >> >> I'm not sure if this makes sense: if we retry the script from the very >> beginning including successful transactions, there may be errors.. > > What I'm suggesting is to simplify the problem by adding some > restrictions to what kind of case which is handled, so as to simplify > the code a lot. > > I'd start by stating (i.e. documenting) that the features assumes that > one script is just *one* transaction. > > Note that pgbench somehow already assumes that one script is one > transaction when it reports performance anyway. > > If you want 2 transactions, then you have to put them in two scripts, > which looks fine with me. Different transactions are expected to be > independent, otherwise they should be merged into one transaction. Therefore if the script consists of several single statements (= several transactions), you cannot retry them. For example, the script looked like this: UPDATE xy1 SET x = 1 WHERE y = 1; UPDATE xy2 SET x = 2 WHERE y = 2; UPDATE xy3 SET x = 3 WHERE y = 3; If this restriction is ok for you, I'll simplify the code :) > Under these restrictions, ISTM that a retry is something like: > > case ABORTED: > if (we want to retry) { > // do necessary stats > // reset the initial state (random, vars, current command) > state = START_TX; // loop > } > else { > // count as failed... > state = FINISHED; // or done. > } > break; If we successfully complete a failed transaction block and process its end command in CSTATE_END_COMMAND, we may want to make a retry. So do you think that in this case it is ok to go to CSTATE_ABORTED at the end of CSTATE_END_COMMAND?.. > Once this works, maybe it could go a step further by restarting at > savepoints. I'd put restrictions there to ease detecting a savepoint > so that it cannot occur in a compound command for instance. This would > probably require a new state. Fine. We discussed the savepoints earlier in [1]: >> - if there's a failure what savepoint we should rollback to and start >> the >> execution again? > ... >> Maybe to go to the last one, if it is not successful go to the >> previous >> one etc. Retrying the entire transaction may take less time.. > > Well, I do not know that. My 0.02 € is that if there was a savepoint > then > this is natural the restarting point of a transaction which has some > recoverable error. > > A detail: > >>> For file contents, maybe the << 'EOF' here-document syntax would help >>> instead of using concatenated backslashed strings everywhere. >> >> Thanks, but I'm not sure that it is better to open file handlers for >> printing in variables.. > > Perl here-document stuff is just a multiline string, no file is > involved, it is different from the shell. Oh, now googling was successful, thanks) [1] https://www.postgresql.org/message-id/alpine.DEB.2.20.1707141637300.7871%40lancre -- Marina Polyakova Postgres Professional: http://www.postgrespro.com The Russian Postgres Company