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 1ncLQe-00070x-AJ for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Apr 2022 06:15:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ncLQd-0001lK-9D for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Apr 2022 06:15:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ncLQc-0001lA-Rg for pgsql-hackers@lists.postgresql.org; Thu, 07 Apr 2022 06:15:35 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ncLQa-0006Ft-Dn for pgsql-hackers@postgresql.org; Thu, 07 Apr 2022 06:15:34 +0000 Received: by mail-pj1-x1029.google.com with SMTP id gt4so4663845pjb.4 for ; Wed, 06 Apr 2022 23:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=TVHsKAw8hjycJcuSikeOOepazJLTuJoRDkIk9acRISM=; b=hqpFvmCX6+VQ4AkaqCoSF59ZiGa8F67HnncVnG8H+4rZUgztZkKTPiLTbDQOhrzpNp vRvMwQAiFZJT0xZsjj4zCwONaTipPtMVaqUj4BruGWJzfaigEVdIjdtHAyaF4zflCQYP F56zkty6PdnbPGzmgiRwMdj1ll+KgYlz+bL7s4dfT3r4B/YCOwyCdc/Y92ex3c5apOl3 mGPPBG6B4i2bnkyFNyXmxRiK5Z6vmWxV3puT2Gr6hWl0vrCa+55Vdn2nIRl6OB8/fPCa wR+JmWfgTf5ANhB+xYzP8pzeIiy3D5OvKXeMLptBxSIM9SSkLW8VbiAfl/x88yWu4/32 oHOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=TVHsKAw8hjycJcuSikeOOepazJLTuJoRDkIk9acRISM=; b=4gkd2q1kBT3T8NWslvlzum4xQHWT387vI0IODv3DOoav04aiMmiTVTEhY4bn3sy0wz YrPSO7OLv8R430srUqoJ3mwrSEhpRUgNo77kmiVb0qTdQ7zQngGOx8DU/Joom/cwtXWL Q5S9bjIxn5ynpye3fP1EKmRINAFBlmmg8UunVARTrargQ7JhOqnuFgGMwddOC+Fff210 0QjuIqFAzn5mSGOxnFj7HRDS8NCYNwm1KtvGpZgTdZIPxhmLUiWOZADSMDWxgeGeCmrB Rtr/QRh8oO/q5DLd0+Psqx7h50dTEL7YOIxNDrAkRnfFl+iyzOrmBxhNO+oWQkkSGq73 Y03g== X-Gm-Message-State: AOAM533OArJ2VbG1YpoKeslzz/uNp/svOaajJY7A0NgAu+2ZUxADOsFa fLoWFawLnBPUxKygze0d2mpYww== X-Google-Smtp-Source: ABdhPJwW9dr0VYcCfH790caal6y3Oyj7GRx/lUJq9NEejrT9DdoXbd8TpB0l0qTBzyPPzrsuWwNTmA== X-Received: by 2002:a17:902:d708:b0:156:1858:71fa with SMTP id w8-20020a170902d70800b00156185871famr12225911ply.92.1649312130170; Wed, 06 Apr 2022 23:15:30 -0700 (PDT) Received: from jdavis.lan (c-73-231-146-4.hsd1.ca.comcast.net. [73.231.146.4]) by smtp.gmail.com with ESMTPSA id x36-20020a634a24000000b0039cc6fff510sm889894pga.58.2022.04.06.23.15.28 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Apr 2022 23:15:29 -0700 (PDT) Message-ID: <2b6e4c0298b51a7dc32cd74b104f43f67880aedb.camel@j-davis.com> Subject: Re: Extensible Rmgr for Table AMs From: Jeff Davis To: Bharath Rupireddy Cc: Andres Freund , Julien Rouhaud , Robert Haas , "pgsql-hackers@postgresql.org" , Amit Kapila , Tom Lane , Simon Riggs Date: Wed, 06 Apr 2022 23:15:27 -0700 In-Reply-To: References: <721eeefbd24c55015739ea75c0a233345e13e0b5.camel@j-davis.com> <20220201043938.r5s35loehsi27saj@jrouhaud> <20220201124550.gnhpw7iytc4da5tq@jrouhaud> <20220203053418.lj5lzsp7yf2mvspw@jrouhaud> <20220204144801.wuwcansdzz3w2nn3@jrouhaud> <20220204145658.qtcmbsdawvn3lg3b@jrouhaud> <211518ee10e5c37014d3a11d744c1aadc43e9f2c.camel@j-davis.com> <20220328180045.nz3nuy5ea2xpxuax@alap3.anarazel.de> <1ae76bc9910df2fc495173b9bf7ed31223721efe.camel@j-davis.com> <3ac6b783ea57e1310c824e436ab693b304877cf8.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2022-04-05 at 15:12 +0530, Bharath Rupireddy wrote: > Yes, I meant this. If we do this, then a global variable > current_max_rmid can be maintained (by RegisterCustomRmgr) and the > other functions RmgrStartup, RmgrCleanup and RegisterCustomRmgr can > avoid for-loops with full range RM_MAX_ID (for (int id = 0; id < > current_max_rmid; id++)). There are only 255 entries, so the loops in those functions aren't a significant overhead. If we expand it, then we can come up a different solution. We can change it easily enough later, because the WAL format changes between releases and so do the APIs for any extension that might be using this. > With the custom rmgrs, now it's time to have it in the documentation > (probably not immediately, even after this patch gets in) describing > what rmgrs are, what are built-in and custom rmgrs and how and when > an > extension needs to register, load and use rmgrs etc. Added a documentation section right after Generic WAL. > With the above, do you mean to say that only the extensions that load > their library via shared_preload_libraries are allowed to have custom > rmgrs? How about extensions using {session, local}_preload_libraries, > LOAD command? How about extensions that don't load the shared library > via {session, local, shared}_preload_libraries or LOAD command and > let > any of its functions load the shared library on first use? Correct. The call to RegisterCustomRmgr *must* happen in the postmaster before any other processes (even the startup process) are launched. Otherwise recovery wouldn't work. The only place to make that happen is shared_preload_libraries. > For instance - extension 1, with id 130 and name 'rmgr_foo' and > extension 2 with id 131 and name 'Rmgr_foo'/'RMGR_FOO'...., then the > following code may not catch it right? Do you want rmgr names to be > case-sensitive/insensitive? You convinced me. pg_waldump.c uses pg_strcasecmp(), so I'll use it as well. > #define RM_N_IDS (UINT8_MAX + 1) > #define RM_N_BUILTIN_IDS (RM_N_IDS / 2) > #define RM_N_CUSTOM_IDS (RM_N_IDS / 2) > #define RM_MAX_ID (RM_N_IDS - 1) > #define RM_MAX_BUILTIN_ID (RM_NEXT_ID - 1) > #define RM_MIN_CUSTOM_ID (RM_N_IDS / 2) > #define RM_MAX_CUSTOM_ID RM_MAX_ID > #define RMID_IS_BUILTIN(rmid) ((rmid) <= RM_MAX_BUILTIN_ID) > #define RMID_IS_CUSTOM(rmid) ((rmid) >= RM_MIN_CUSTOM_ID && (rmid) <= > RM_MAX_CUSTOM_ID) > #define RMID_IS_VALID(rmid) (RMID_IS_BUILTIN((rmid)) || > RMID_IS_CUSTOM((rmid))) I improved this a bit. But I didn't use your version that's based on division, that was more confusing to me. > Yes, an SQL function showing all of the available rmgrs. With the > custom rmgrs, I think, an SQL function like pg_resource_managers() > returning a set of {name, id, (if possible - > loaded_by_extension_name, > rm_redo, rm_desc, rm_identify ... api names)} Added. > > Some more comments: > > 1) Is there any specific reason to have a function to emit a PANIC > message? And it's being used only in one place in GetRmgr. > +void > +RmgrNotFound(RmgrId rmid) Good call -- better to raise an error, and it can get escalated if it happens in the wrong place. Done. > 2) How about "If rm_name is NULL, the corresponding RmgrTable[] entry > is considered invalid."? > + * RmgrTable[] is indexed by RmgrId values (see rmgrlist.h). If > rm_name is > + * NULL, the structure is considered invalid. Done. > 3) How about adding errdetail something like "Custom resource manager > ID must be between %d and %d (both inclusive)", RM_MAX_BUILTIN_ID, > RM_MAX_ID)? > + if (rmid < RM_MIN_CUSTOM_ID) > + ereport(PANIC, errmsg("custom resource manager ID %d is out of > range", rmid)); Done. > 4) How about adding errdetail something like "Custom resource manager > must have a name" > + if (rmgr->rm_name == NULL) > + ereport(PANIC, errmsg("custom resource manager is invalid")); Improved this message. > 5) How about "successfully registered custom resource manager"? > + (errmsg("registered custom resource manager \"%s\" with ID %d", That's a little much, we don't want to sound too excited that it worked ;-) > 6) Shouldn't this be ri <= RM_NEXT_ID? > - for (ri = 0; ri < RM_NEXT_ID; ri++) > + for (ri = 0; ri < RM_MAX_ID; ri++) > > - for (ri = 0; ri < RM_NEXT_ID; ri++) > + for (ri = 0; ri <= RM_MAX_ID; ri++) That would leave out the custom rmgrs. > 7) Unrelated to this patch, why is there always an extra slot > RM_MAX_ID + 1? RM_MAX_ID is 255, but we need 256 entries from 0-255 (inclusive). Good suggestions, thank you for the review! I'm happy with this patch and I committed it. Changes from last version: 1. I came up with a better solution (based on a suggestion from Andres) to handle wal_consistency_checking properly. We can't understand the custom resource managers when the configuration file is first loaded, so if we enounter an unknown resource manager, I set a flag and reprocess it after the shared_preload_libraries are loaded. 2. Added pg_get_wal_resource_managers(). 3. Documentation. Regards, Jeff Davis