GIScience / oshdb

OpenStreetMap History Data Analysis Framework
https://ohsome.org
GNU Lesser General Public License v3.0
110 stars 18 forks source link

[oshdb-api] throw exception if cluster is not in an active state when creating connection #337

Closed tyrasd closed 3 years ago

tyrasd commented 3 years ago

follow up from https://github.com/GIScience/oshdb/pull/335#discussion_r560811798, as suggested by @rtroilo

We should actually check the current cluster().state() and throw an exception right here if it is not in active or active_read_only state. Because in a case when the cluster is actually not active, there will be probably an exception on the first cache operation somewhere which would then be unexpected.

also perhaps to consider is if the (autoclosable) OSHDBIgnite class should (auto)close connections to Ignite when they are passed in as external already-existing connections from outside via the public OSHDBIgnite​(org.apache.ignite.Ignite ignite) constructor.

tyrasd commented 3 years ago

maybe worth to consider is here that some other related checks happen not during the construction of the backend connector, but when an actual query is started, e.g. here:

  public <X extends OSHDBMapReducible> MapReducer<X> createMapReducer(Class<X> forClass) {
    // […]
    if (!allCaches.containsAll(expectedCaches)) {
      throw new OSHDBTableNotFoundException(Joiner.on(", ").join(expectedCaches));
    }

This has the benefit that even for long open connections to Ignite (e.g. as implemented in the ohsome API) the correct state of (the data in) the cluster is checked every time a query is to be started. Maybe these checks can simply be extended to also check for the proper cluster state?