| re: Consistency among multiple connections
Sergio wrote:[color=blue]
> it takes advantage from the fact that the disk is
> shared in order to update all the databases as quick as possible when
> it is needed.[/color]
Well, quick is nice, but if you're occasionally causing corruption, the
time taken to recover the database probably puts a dent in any
performance advantage. ;-)
[color=blue]
> 1) It seems to be a consistency problem. Updates that are performed by
> the process that updates the databases are not always seen by the
> clients.[/color]
Each instance of mysqld keeps a cache containing recent modifications to
the database. When you do a query, mysqld may get part of the result
from disk, and also amend that with its current knowledge of updates
that haven't been written to disk yet. This means that a _second_
instance of mysqld accessing the same database directly doesn't have any
way of knowing what, if any, changes are floating in the cache of the
first instance of mysqld.
[color=blue]
> 2) Sometimes, it seems that some tables get corrupted, as clients get
> errors relative to the table handler.[/color]
Not surprising, given the above.
[color=blue]
> Do I need to do something special to ensure the consistency? Does this
> scenario make sense to you?[/color]
This scenario is, as you have discovered, practically guaranteed to
corrupt your databases on a regular basis. I recommend strongly against
accessing databases from more than one MySQL engine. Two engines that
are not synchronizing their operations are very likely to make
conflicting updates to the files.
You said you're using Java to access MySQL. You must specify the
hostname of the database server in your JDBC URLs, so that you can let
the MySQL daemon on that host do the I/O on all the databases running
locally on that server. Like so:
Connection conn = DriverManager.getConnection(
"jdbc:mysql://mydbserver/test?user=mydbuser&password=xxxxxxxx");
This is the most reliable way (perhaps the *only* way) to run client
applications on multiple machines, and access the databases
simultaneously, without corrupting the database. That's why there is a
server hostname field in the JDBC URL!
Regards,
Bill K. |