You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm constructing a Postgres proxy that simulates an actual Postgres server. For this, I've created a custom StartupHandler and AuthSource using pgwire v0.22.0. The implementation is as follows:
pubstructUdiPgpAuthSource{config_tx: mpsc::Sender<Message>,}implUdiPgpAuthSource{pubfnnew(tx: mpsc::Sender<Message>) -> Self{Self{config_tx: tx }}asyncfnread_config(&self) -> UdiPgpResult<UdiPgpConfig>{// this is where I use the `config_tx`
...}}#[async_trait]implAuthSourceforUdiPgpAuthSource{asyncfnget_password(&self,login:&LoginInfo) -> PgWireResult<Password>{let(supplier_id, _) = UdiPgpProcessor::extract_supplier_and_database(login.database())?;
....
}}
When upgrading to pgwire v0.24.2, the challenge arises in delivering the config_tx to the StartupHandler through the new PgWireHandlerFactory.
pubstructUdiPgpProcessorFactory{handler:Arc<UdiPgpProcessor>,}implPgWireHandlerFactoryforUdiPgpProcessorFactory{typeStartupHandler = UdiPgpStartupHandler<UdiPgpAuthSource,UdiPgpParameters>;typeSimpleQueryHandler = UdiPgpProcessor;typeExtendedQueryHandler = UdiPgpProcessor;typeCopyHandler = NoopCopyHandler;fnsimple_query_handler(&self) -> Arc<Self::SimpleQueryHandler>{self.handler.clone()}fnextended_query_handler(&self) -> Arc<Self::ExtendedQueryHandler>{self.handler.clone()}// no way to get the tx to the custom handlerfnstartup_handler(&self) -> Arc<Self::StartupHandler>{letmut parameters = UdiPgpParameters::new();Arc::new(UdiPgpStartupHandler::new(UdiPgpAuthSource::new(tx.clone()),UdiPgpParameters::new(),
tx.clone(),))}fncopy_handler(&self) -> Arc<Self::CopyHandler>{Arc::new(NoopCopyHandler)}}
Do you by chance have a suggestion on how to do this or support passing custom parameters to the PgWireHandlerFactory trait?
Please let me know if you need any further details.
Thanks.
The text was updated successfully, but these errors were encountered:
Hello @Lilit0x , may I know if your startup handler is a stateful one or stateless, in other words, do you need to create new instance of the handlers for each incoming connection?
I have to say my current naming of the trait, PgWireHandlerFactory might be confusing because the methods in trait may not allow you to customize the handler based on incoming connection. So in most case, this factory is only a cache for different set of handlers. If you handlers are stateful, you will need to build these handlers before calling process_socket and cache it in a struct that implements PgWireHandlerFactory. And if it's stateless, you can simply cache them in a global struct or just create it when those handler methods called.
I may rename this PgWireHandlerFactory to PgWireHandlers in next patch release hoping make it a little bit clear.
I'm constructing a Postgres proxy that simulates an actual Postgres server. For this, I've created a custom
StartupHandler
andAuthSource
usingpgwire v0.22.0
. The implementation is as follows:When upgrading to
pgwire v0.24.2
, the challenge arises in delivering theconfig_tx
to theStartupHandler
through the newPgWireHandlerFactory
.Do you by chance have a suggestion on how to do this or support passing custom parameters to the
PgWireHandlerFactory
trait?Please let me know if you need any further details.
Thanks.
The text was updated successfully, but these errors were encountered: