> You need to read the mongodb documentation with care and make sure > that you honour their API contract. For example: > > mongoc_init():
When it comes to 'mongoc_init' and 'mongoc_clean', they are supposed to be run once per process. If I understand how postfix works correctly, it invokes 'dict_mongodb_open' when it loads the shared-object for the dict (postfix-mongodb.so). I did not Find an init function for the dict libraries, just the open method. That would mean that mongoc_init would be run every time that library is opened (which should be once for postmap and proxymap, unsure about postfix master). When configured with proxymap, the proxymap process will open the library once, run mongoc_init and get the client_pool setup. I have verified this by monitoring number of connections to Mongo cluster. As long as the proxy process is running, the number of connections to my cluster stays at 4 (pooled) while I run multiple queries back to back for aliases, mailboxes and domains, which are technically separate dicts. Also, the documentation reads "Note that mongoc_init() does not reinitialize the driver after mongoc_cleanup().", where is I can use this module with no issues even though I have multiple dicts specified in main.cf for virtual_mailbox_maps, virtual_alias_map, virtual_mailbox_domains and smtpd_sender_login_maps. Please let me know if my understanding is incorrect. Would it be preferred to move this to postfix master process instead of a loadable module? Even if the user does not want to use Mongo? > Perhaps all query keys that are not valid UTF8 should short-circuit to "not > found"? Good suggestion. This is implemented now. >> - Users can search by specifying search keys, OR writing more advanced >> filters. If search_keys >> are specified, value of 'filter' will be ignored if specified. > > Perhaps best to fail if both are specified. The conflict may be missed > by some users. ... >> - Users can specify a return_key for a simplified projection. It would >> default to "result" if not specified. > > Good. Don't know whether "result" is a probable common attribute, > if not, perhaps simply require that exactly one of "return_key" and > "projection" is set. I guess that's a difference in our way of thinking. Personally, it would be easier for me this way, but if you see more value in failing in case both are specified, that's easy to implement. Just let me know. > See db_common_parse_domain(), and its call sites in the LDAP, MySQL and > PostgreSQL drivers. ah, got it. This is added. Question about using variables in main.cf I'm getting 'unused parameter' errors for my mongo variables, where I know I am using them. Is there something I need to do in the module to mark a variable as used while reading it from the config? P.S. Just Fyi, when compiling postfix, I keep running into <stdio.h> missing from src/posttls-finger/posttls-finger.c Adding the stdio header resolves the issue, easy fix. Regards Hamid Maadani June 16, 2022 2:42 PM, "Viktor Dukhovni" <postfix-us...@dukhovni.org> wrote: > On Thu, Jun 16, 2022 at 08:11:20PM +0000, Hamid Maadani wrote: > >> Please let me know if any other adjustments are necessary. > > You need to read the mongodb documentation with care and make sure > that you honour their API contract. For example: > > mongoc_init(): > Initialize the MongoDB C Driver by calling mongoc_init() exactly > once at the beginning of your program. It is responsible for > initializing global state such as process counters, SSL, and > threading primitives. > > And yet you call this function once per table in the "open" routine. > This may make the code unsafe for opening multiple tables. > > Please review the correctness/safety of all the touch points between > MongoDB and the table driver. Does anything special need to be done to > avoid issues with non-utf8 binary inputs? Perhaps all query keys that > are not valid UTF8 should short-circuit to "not found"? > > -- > Viktor.