Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ogPCc-0003tj-Hy for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Oct 2022 11:38:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ogPCb-0006X2-E3 for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Oct 2022 11:38:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ogPCa-0006Wt-V0 for pgsql-hackers@lists.postgresql.org; Thu, 06 Oct 2022 11:38:09 +0000 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ogPCY-0001jD-DR for pgsql-hackers@lists.postgresql.org; Thu, 06 Oct 2022 11:38:07 +0000 Received: by mail-yb1-xb29.google.com with SMTP id 207so1914534ybn.1 for ; Thu, 06 Oct 2022 04:38:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=xBORu093x5BeS5gBZ012TKp5VpSnP6pYpu9v4hnvC4k=; b=N1jfGuTm00caOWLnPDp1f/dykB28E1sYWejvVH06ytaMi0RjujCDNd5d7GN1xuZ5lE +iSlmkz6i1AxgBAKTeBfC1wdxtAzNFJKQFCQfmL+g9SpnorGcylhIidXiXNHwjSIU4Fk XzfPiIxUB5Wy+L700KvzkMnf30p59jo+cwSQ2W7bL82dtUow27MvFE4aiAPip1QXyObB PnX/x2g3o3lxwc6XzmJqSu/ty+vm/kyYY4JiCECeTNsL1AyolfDkf1rTp6FUzJ3S6Q1w X6jdYX3Uc4ap0QDuCi9E835V8RJBHp+1t+thDntz/VKtFRRXNchFsnJWuWukoqheWaWj 2UXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=xBORu093x5BeS5gBZ012TKp5VpSnP6pYpu9v4hnvC4k=; b=LmG8wTMZYaQhTmIcQVDBvwWjq8rVkhUhAGgRne6orm/i8ax8xLz9Ue47Gzd7XFGlBl CRDcr87ubgxInogYOrdU1gX2XvW7APp+QFrxDjwco/t3oSD5g8a4aynavYJAyQtTYowD IK0HuN6sgvo57ZEsRO2cqld0HJIR/BP1NUNAJyJSU8HNBKjY5oUuWBeh0ovbuq1daUqt A+1817+bswhWqSBF2ByNnZTH+yEp95gvocCj/zUJGEbR5FeHUJARji/TXaz9IkRmHUEr Z77DYleG56cVQ4H4Wag8nboTnJL/l+prTi7tlNF5GTscy7rFooFJRnNlmEB0i+c3b9UL a+/A== X-Gm-Message-State: ACrzQf1yeSYyyX7oDk29pnNll15ELsNmqG+zxq44h6eWvRL0b7ZCHyU8 5vdCVL0flyc/BncNr8hSrVJxEnktliTXNPadpOM= X-Google-Smtp-Source: AMsMyM5kpKIIKxeNVponGVDIg7/G4lXyn24/JrKT5CucU8uGoqUJUvbbbsgIGNPB/E6s5LFhVA81ITDZIZnRm/42c9k= X-Received: by 2002:a05:6902:15cf:b0:67c:1ee7:149 with SMTP id l15-20020a05690215cf00b0067c1ee70149mr4212987ybu.594.1665056285531; Thu, 06 Oct 2022 04:38:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Thu, 6 Oct 2022 17:07:53 +0530 Message-ID: Subject: Re: Perform streaming logical transactions by background workers and parallel apply To: Peter Smith Cc: "houzj.fnst@fujitsu.com" , "wangw.fnst@fujitsu.com" , Dilip Kumar , Masahiko Sawada , "shiy.fnst@fujitsu.com" , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Sep 30, 2022 at 1:56 PM Peter Smith wrote: > > Here are my review comments for the v35-0001 patch: > > ====== > > 3. GENERAL > > (this comment was written after I wrote all the other ones below so > there might be some unintended overlaps...) > > I found the mixed use of the same member names having different > meanings to be quite confusing. > > e.g.1 > PGOutputData 'streaming' is now a single char internal representation > the subscription parameter streaming mode ('f','t','p') > - bool streaming; > + char streaming; > > e.g.2 > WalRcvStreamOptions 'streaming' is a C string version of the > subscription streaming mode ("on", "parallel") > - bool streaming; /* Streaming of large transactions */ > + char *streaming; /* Streaming of large transactions */ > > e.g.3 > SubOpts 'streaming' is again like the first example - a single char > for the mode. > - bool streaming; > + char streaming; > > > IMO everything would become much simpler if you did: > > 3a. > Rename "char streaming;" -> "char streaming_mode;" > > 3b. > Re-designed the "char *streaming;" code to also use the single char > notation, then also call that member 'streaming_mode'. Then everything > will be consistent. > Won't this impact the previous version publisher which already uses on/off? We may need to maintain multiple values which would be confusing. > > 9. - parallel_apply_can_start > > +/* > + * Returns true, if it is allowed to start a parallel apply worker, false, > + * otherwise. > + */ > +static bool > +parallel_apply_can_start(TransactionId xid) > > (The commas are strange) > > SUGGESTION > Returns true if it is OK to start a parallel apply worker, false otherwise. > +1 for this. > > 28. - logicalrep_worker_detach > > + /* Stop the parallel apply workers. */ > + if (am_leader_apply_worker()) > + { > > Should that comment rather say like below? > > /* If this is the leader apply worker then stop all of its parallel > apply workers. */ > I think this would be just saying what is apparent from the code, so not sure if it is an improvement. > > 38. - apply_handle_commit_prepared > > + * > + * Note that we don't need to wait here if the transaction was prepared in a > + * parallel apply worker. Because we have already waited for the prepare to > + * finish in apply_handle_stream_prepare() which will ensure all the operations > + * in that transaction have happened in the subscriber and no concurrent > + * transaction can create deadlock or transaction dependency issues. > */ > static void > apply_handle_commit_prepared(StringInfo s) > > "worker. Because" -> "worker because" > I think this will make this line too long. Can we think of breaking it in some way? > > 43. > > /* > - * Initialize the worker's stream_fileset if we haven't yet. This will be > - * used for the entire duration of the worker so create it in a permanent > - * context. We create this on the very first streaming message from any > - * transaction and then use it for this and other streaming transactions. > - * Now, we could create a fileset at the start of the worker as well but > - * then we won't be sure that it will ever be used. > + * For the first stream start, check if there is any free parallel apply > + * worker we can use to process this transaction. > */ > - if (MyLogicalRepWorker->stream_fileset == NULL) > + if (first_segment) > + parallel_apply_start_worker(stream_xid); > > This comment update seems misleading. The > parallel_apply_start_worker() isn't just checking if there is a free > worker. All that free worker logic stuff is *inside* the > parallel_apply_start_worker() function, so maybe no need to mention > about it here at the caller. > It will be good to have some comments here instead of completely removing it. > > 39. - apply_handle_stream_abort > > + /* We receive abort information only when we can apply in parallel. */ > + if (MyLogicalRepWorker->parallel_apply) > + read_abort_info = true; > > 44a. > SUGGESTION > We receive abort information only when the publisher can support parallel apply. > The existing comment seems better to me in this case. > > 55. - LogicalRepWorker > > + /* Indicates whether apply can be performed parallelly. */ > + bool parallel_apply; > + > > 55a. > "parallelly" - ?? is there a better way to phrase this? IMO that is an > uncommon word. > How about ".. can be performed in parallel."? > ~ > > 55b. > IMO this member name should be named slightly different to give a > better feel for what it really means. > > Maybe something like one of: > "parallel_apply_ok" > "parallel_apply_enabled" > "use_parallel_apply" > etc? > The extra word doesn't seem to be useful here. > 58. > > --- fail - streaming must be boolean > +-- fail - streaming must be boolean or 'parallel' > CREATE SUBSCRIPTION regress_testsub CONNECTION > 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = > false, streaming = foo); > > I think there are tests already for explicitly create/set the > subscription parameter streaming = on/off/parallel > > But what about when there is no value explicitly specified? Shouldn't > there also be tests like below to check that *implied* boolean true > still works for this enum? > > CREATE SUBSCRIPTION ... WITH (streaming) > ALTER SUBSCRIPTION ... SET (streaming) > I think before adding new tests for this, please check if we have any similar tests for other boolean options. -- With Regards, Amit Kapila.