[h2] patch: getClientInfo to get server list in clustered configuration
Hi I am using H2 in a clustered configuration where we need some control/detection of which servers are currently in the cluster. I have added functionality to the jdbc connection to get the number of servers currently in the cluster and which servers that are available. Have a look at my patch and tell me what you think. Best regards Nikolaj Fogh -- You received this message because you are subscribed to the Google Groups H2 Database group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To post to this group, send email to h2-database@googlegroups.com. Visit this group at http://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout. Index: src/docsrc/html/advanced.html === --- src/docsrc/html/advanced.html (revision 5747) +++ src/docsrc/html/advanced.html (working copy) @@ -390,6 +390,15 @@ servers is returned, enclosed in single quote. Example: code'server1:9191,server2:9191'/code. /p +pIt is also possible to get the list of servers by using Connection.getClientInfo()./p + +pThe property list returned from codegetClientInfo()/code contains a codenumServers/code property that returns the +number of servers that are in the connection list. To get the actual servers, codegetClientInfo()/code also has +properties codeserver0/code..codeserverX/code, where serverX is the number of servers minus 1. + +pExample: To get the 2nd server in the connection list one uses codegetClientInfo('server1')code. bNote:/b The +codeserverX/code property only returns IP addresses and ports and not hostnames./p + h3Clustering Algorithm and Limitations/h3 p Read-only queries are only executed against the first cluster node, but all other statements are Index: src/main/org/h2/engine/Session.java === --- src/main/org/h2/engine/Session.java (revision 5747) +++ src/main/org/h2/engine/Session.java (working copy) @@ -127,6 +127,10 @@ this.currentSchemaName = Constants.SCHEMA_MAIN; } +public ArrayListString getServers() { +return new ArrayListString(); +} + public boolean setCommitOrRollbackDisabled(boolean x) { boolean old = commitOrRollbackDisabled; commitOrRollbackDisabled = x; Index: src/main/org/h2/engine/SessionInterface.java === --- src/main/org/h2/engine/SessionInterface.java (revision 5747) +++ src/main/org/h2/engine/SessionInterface.java (working copy) @@ -6,6 +6,8 @@ package org.h2.engine; import java.io.Closeable; +import java.util.ArrayList; + import org.h2.command.CommandInterface; import org.h2.message.Trace; import org.h2.store.DataHandler; @@ -17,6 +19,13 @@ public interface SessionInterface extends Closeable { /** + * Get the list of servers for this session. + * + * @return A list of IP:PORT strings for the servers in this session. + */ +ArrayListString getServers(); + +/** * Parse a command and prepare it for execution. * * @param sql the SQL statement Index: src/main/org/h2/engine/SessionRemote.java === --- src/main/org/h2/engine/SessionRemote.java (revision 5747) +++ src/main/org/h2/engine/SessionRemote.java (working copy) @@ -8,6 +8,7 @@ import java.io.IOException; import java.net.Socket; import java.util.ArrayList; +import java.util.List; import org.h2.api.DatabaseEventListener; import org.h2.api.ErrorCode; @@ -95,6 +96,17 @@ this.connectionInfo = ci; } +public ArrayListString getServers() { + ArrayListString serverList = new ArrayListString(); + +for (int i = 0; i transferList.size(); i++) { +Transfer transfer = transferList.get(i); +serverList.add(transfer.getSocket().getInetAddress().getHostAddress().toString() + : + String.valueOf(transfer.getSocket().getPort())); +} + +return serverList; +} + private Transfer initTransfer(ConnectionInfo ci, String db, String server) throws IOException { Socket socket = NetUtils.createSocket(server, Index: src/main/org/h2/jdbc/JdbcConnection.java === --- src/main/org/h2/jdbc/JdbcConnection.java (revision 5747) +++ src/main/org/h2/jdbc/JdbcConnection.java (working copy) @@ -25,6 +25,7 @@ import java.sql.Savepoint; import java.sql.Statement; import java.sql.Struct; +import java.util.ArrayList; import java.util.Map; import java.util.Properties; @@ -47,7 +48,7 @@ import org.h2.value.ValueNull; import org.h2.value.ValueString; -/*## Java 1.7 ## +//## Java 1.7 ## import java.util.concurrent.Executor; //*/ @@ -1715,35 +1716,37 @@ /** * Get the client
Re: [h2] CreateCluster replication speed
Hi Thomas Ok. Thanks for the clarification. I have had a look at the CreateCluster tool. I am working a bit on modifying it to use FTP to copy the database files to make the startup faster when having large databases. I intend to use the FTP server in H2 along with some on-the-fly compression. On Thursday, May 22, 2014 5:49:52 PM UTC+2, Thomas Mueller wrote: Hi, Yes, it's possible to do that. This is basically what the CreateCluster tool does, but it uses a SQL script instead of copying files. For details how to enable clustering, see the CreateCluster tool source code - it is a short program. Regards, Thomas On Mon, May 19, 2014 at 11:15 AM, nfogh nikolajf...@gmail.com wrote: Hi Thomas Is it possible to do a copy of the source database files to the target server (via FTP or other means). Then start H2 on both servers, and enable clustering? Would there be any issues with that? Best regards On Monday, April 14, 2014 8:51:17 PM UTC+2, Thomas Mueller wrote: Hi, The CreateCluster tool will not work well with large databases. Do to the various limitations, the whole clustering solution within probably be replaced at some point, maybe with the H2HA project, and / or with MVStore clustering. I recommend to try the H2HA project. H2HA: https://github.com/shesse/h2ha Regards, Thomas On Wednesday, April 9, 2014, nfogh nikol...@gmail.com wrote: Hi I am using the CreateCluster tool to do replication of a database. I have two servers connected via a 1Gbps LAN. Setting up clustering takes around 1 hour each time for a 10GB database. Can this be right? I suspect that network latency is eating up the throughput, so I modified RunScript to send statements in batches. I noticed that I do not gain much improvement when using batches (addBatch(), executeBatch()) instead of several single execute() statements. Does H2 actually bundle the statements, or is the client just issuing several execute() statements in a loop? Thanks, -- You received this message because you are subscribed to the Google Groups H2 Database group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To post to this group, send email to h2-database@googlegroups.com. Visit this group at http://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups H2 Database group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To post to this group, send email to h2-database@googlegroups.com. Visit this group at http://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups H2 Database group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To post to this group, send email to h2-database@googlegroups.com. Visit this group at http://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout.
Re: [h2] CreateCluster replication speed
Hi Thomas Is it possible to do a copy of the source database files to the target server (via FTP or other means). Then start H2 on both servers, and enable clustering? Would there be any issues with that? Best regards On Monday, April 14, 2014 8:51:17 PM UTC+2, Thomas Mueller wrote: Hi, The CreateCluster tool will not work well with large databases. Do to the various limitations, the whole clustering solution within probably be replaced at some point, maybe with the H2HA project, and / or with MVStore clustering. I recommend to try the H2HA project. H2HA: https://github.com/shesse/h2ha Regards, Thomas On Wednesday, April 9, 2014, nfogh nikol...@gmail.com javascript: wrote: Hi I am using the CreateCluster tool to do replication of a database. I have two servers connected via a 1Gbps LAN. Setting up clustering takes around 1 hour each time for a 10GB database. Can this be right? I suspect that network latency is eating up the throughput, so I modified RunScript to send statements in batches. I noticed that I do not gain much improvement when using batches (addBatch(), executeBatch()) instead of several single execute() statements. Does H2 actually bundle the statements, or is the client just issuing several execute() statements in a loop? Thanks, -- You received this message because you are subscribed to the Google Groups H2 Database group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To post to this group, send email to h2-database@googlegroups.com. Visit this group at http://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups H2 Database group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To post to this group, send email to h2-database@googlegroups.com. Visit this group at http://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout.
[h2] CreateCluster replication speed
Hi I am using the CreateCluster tool to do replication of a database. I have two servers connected via a 1Gbps LAN. Setting up clustering takes around 1 hour each time for a 10GB database. Can this be right? I suspect that network latency is eating up the throughput, so I modified RunScript to send statements in batches. I noticed that I do not gain much improvement when using batches (addBatch(), executeBatch()) instead of several single execute() statements. Does H2 actually bundle the statements, or is the client just issuing several execute() statements in a loop? Thanks, -- You received this message because you are subscribed to the Google Groups H2 Database group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To post to this group, send email to h2-database@googlegroups.com. Visit this group at http://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout.