[RFC][Lunr] Gravity: add flag to persist MySQL query hint

Review Request #489 — Created Jan. 27, 2017 and discarded

tardypad
Lunr
mysql_connection_persist_query_hint
lunr

Not really happy with this solution because it might be confusing in its usage in the following scenario for example:
- run_on_master with persist on
- all the following queries are then run on master (as expected)
- run_on_slave with persist off
- next query is run on the slave (as expected)
- following queries are run either on master or slave (not sure if this is expected)

Maybe it is better to keep the run_on_master, run_on_slave,... functions only affecting the next query
And have a separate "global query hint" property management:
- new property global_query_hint with master/slave setter functions
- the query functions would use that global query hint by default unless there is a temporary one set from the run_on_master/slave functions

none

pprkut
  1. I would wire it differently. To rehash the problem:

    We have DAOs with queries that are run in a context where they should run on the master, but the same queries are also run in a context where it wouldn't matter.

    I think a better way to approach this is using run_on_last_used(), and hide the "persist" flag from the user.

    So, run_on_master() and run_on_slave() would always set it, to "master" and "slave" respectively. If a query is executed without a hint, it would reset it to "NULL".
    That way the usage would be as expected.

    run_on_master() # -> master
    query() # -> any
    run_on_slave() # -> slave
    query() # -> any
    run_on_master() # -> master
    run_on_last_used # -> master
    run_on_slave # -> slave
    run_on_last_used # -> slave
    query() # -> any
    run_on_last_used # -> any

    What do you think?

    1. This would not be really usable for what we need to do in the end.
      We need to have all the queries of a specific call to be run on master.

      With this approach, I would need to modify all the DAOs to use run_on_last_used (after having set the first call to be run on master)
      And it would be really fragile, if another query gets added later without the run_on_last_used, it would break the following ones.

    2. I think better than this hacky approach would then simply be to use different connection classes.

      For example something like this:

      $db = $this->locator->masterconnection()
      
      $this->locator->override('mysqlconnection', $db);
      

      the only requirement for this to work is that this needs to be done before any DAO is instantiated.

    3. yep it looks better to me than all the other options we considered

  2. 
      
tardypad
Review request changed

Status: Discarded

Loading...