vertx-sql-client icon indicating copy to clipboard operation
vertx-sql-client copied to clipboard

Breaking change

Open hogmuzzle opened this issue 2 years ago • 4 comments

In version 4.2.4 io.vertx.sqlclient.impl.PoolBase had accessible field closeFuture and it was possible to correctly create custom connectionProvider and add ConnectionFactory to close future. List<ConnectionFactory> lst = pgConnectOptions.stream() .map(options -> driver.createConnectionFactory(vertx.getDelegate(), options)) .collect(Collectors.toList()); ConnectionFactory factory = serverSelector(lst); pool.getDelegate().connectionProvider(factory::connect); PgPoolImpl poolBase = (PgPoolImpl) pool.getDelegate(); CloseFuture closeFuture = poolBase.closeFuture(); closeFuture.add(factory); It is no longer possible. Could you please add information to your documentation as to how to create a connection provider. This information used to be in your documentation but it not there any more or complement ConnectionFactory with one more implementation of ConnectionFactory.

static ConnectionFactory failOverSelector(final List<ConnectionFactory> factories) { return factories.size() == 1 ? (ConnectionFactory)factories.get(0) : new ConnectionFactory() { int idx = 0;

        public Future<SqlConnection> connect(Context context) {
            ConnectionFactory f = (ConnectionFactory)factories.get(this.idx);
            return f.connect(context).onFailure(th -> {						
	  idx = (idx + 1) % factories.size();
	});
        }

        public void close(Promise<Void> promise) {
            List<Future> list = new ArrayList(factories.size());
            Iterator var3 = factories.iterator();

            while(var3.hasNext()) {
                ConnectionFactory factory = (ConnectionFactory)var3.next();
                Promise<Void> p = Promise.promise();
                factory.close(p);
                list.add(p.future());
            }

            CompositeFuture.all(list).mapEmpty().onComplete(promise);
        }
    };
}

We use PostgreSQL HA with Patroni and roundRobinSelector is of no use. I have never seen a configuration where roundRobinSelector was used.

hogmuzzle avatar May 23 '23 07:05 hogmuzzle

@hogmuzzle the API changed after https://github.com/eclipse-vertx/vertx-sql-client/pull/1305

There is an example of the new API here: https://vertx.io/docs/vertx-pg-client/java/#_dynamic_connection_configuration

You no longer need access to the CloseFuture because the lifecyle is handled internally.

@vietj can you please update the https://github.com/vert-x3/wiki/wiki/4.4.2-Deprecations-and-breaking-changes ?

tsegismont avatar Jun 12 '23 13:06 tsegismont

that's an internal change, not sure we need to document that

vietj avatar Jun 12 '23 14:06 vietj

@hogmuzzle can you elaborate about exactly what you want to achieve ? it is not clear to me (also the fact you had to use internal stuff from vertx)

vietj avatar Jun 12 '23 14:06 vietj

that's an internal change, not sure we need to document that

Right. I thought we had removed the io.vertx.sqlclient.Pool#connectionProvider method but we haven't. Sorry for the confusion.

@hogmuzzle can you elaborate about exactly what you want to achieve ? it is not clear to me (also the fact you had to use internal stuff from vertx)

I believe they want to create new connections depending on which server in the cluster is currently the leader (in a HA scenario).

tsegismont avatar Jun 12 '23 15:06 tsegismont