H2 and gerrit

1,436 views
Skip to first unread message

Kevin Lyda

unread,
Aug 12, 2011, 7:57:20 AM8/12/11
to repo-d...@googlegroups.com
I have two servers - caliente and poker.  Poker is currently the gerrit/git server.  I would like to have it replicate data to poker.

I have set up ssh keys and will use that to replicate the git repository.  I plan to set up the H2 server and have the database replicate as described in the docs.  In order to do this I will need to change gerrit's database configs from:

  type = H2
  database = db/ReviewDB

to

  type = JDBC
  database = jdbc:h2:tcp://localhost/~/db/ReviewDB

From what I've read, it will not be possible to run gerrit on caliente (the standby server).  But it might be possible to run it as a slave?  How exactly is the slave used?

I'm also wondering if it would be possible to migrate from H2 to MySQL - and if so what tool would I use to migrate from H2 to MySQL?  Hunting around didn't find much of anything hopeful.

Lastly I read somewhere that I can't find at the moment that gerrit is possibly moving from a database backend to a git based one.  Is this correct?  If so I'll just stick with H2.

Kevin

Shawn Pearce

unread,
Aug 12, 2011, 12:23:09 PM8/12/11
to repo-d...@googlegroups.com
On Fri, Aug 12, 2011 at 04:57, Kevin Lyda <ly...@google.com> wrote:
> I have two servers - caliente and poker.  Poker is currently the gerrit/git
> server.  I would like to have it replicate data to poker.
> I have set up ssh keys and will use that to replicate the git repository.  I
> plan to set up the H2 server and have the database replicate as described in
> the docs.  In order to do this I will need to change gerrit's database
> configs from:
>   type = H2
>   database = db/ReviewDB
> to
>   type = JDBC
>   database = jdbc:h2:tcp://localhost/~/db/ReviewDB
> From what I've read, it will not be possible to run gerrit on caliente (the
> standby server).  But it might be possible to run it as a slave?  How
> exactly is the slave used?

Yes, on caliente you can run `java -jar gerrit.war daemon -d site_dir
--slave`. This will setup an SSH server that clients can use to fetch
Git repositories, but they cannot push or execute other commands like
`gerrit review`. We created slave to enable very busy sites to handle
lots of read traffic through slaves, while the less frequent write
traffic goes to the master.

> I'm also wondering if it would be possible to migrate from H2 to MySQL - and
> if so what tool would I use to migrate from H2 to MySQL?  Hunting around
> didn't find much of anything hopeful.

The H2 database backup thing is a SQL script (but may be compressed
into a ZIP). You might be able to convince this to load in MySQL.
Gerrit uses very simple SQL constructs... but I don't know of any tool
to do this automatically.

> Lastly I read somewhere that I can't find at the moment that gerrit is
> possibly moving from a database backend to a git based one.  Is this
> correct?  If so I'll just stick with H2.

This is likely. 2.2.x already moved the project information to Git. We
still need to move the review information and account/group data.

Kevin Lyda

unread,
Aug 26, 2011, 8:18:58 AM8/26/11
to repo-d...@googlegroups.com
I set up a test system and ran two database servers:

java -cp /usr/local/gerrit/lib/h2-1.3.159.jar org.h2.tools.Server -tcp -tcpPort 9101 -baseDir /usr/local/gerrit/db
java -cp /usr/local/gerrit/lib/h2-1.3.159.jar org.h2.tools.Server -tcp -tcpPort 9102 -baseDir /usr/local/gerrit/db

I created the cluster:

java -cp /usr/local/gerrit/lib/lib/h2-1.3.159.jar org.h2.tools.CreateCluster -urlSource 'jdbc:h2:tcp://localhost:9101/ReviewDB' -urlTarget 'jdbc:h2:tcp://localhost:9102/ReviewDB' -user '' -serverList localhost:9101,localhost:9102

And I modified the config:

[database]
  type = JDBC
  database = jdbc:h2:tcp://localhost:9101,localhost:9102/ReviewDB

Gerrit then refuses to start up with this in the logs:

1) Error injecting constructor, java.lang.IllegalArgumentException: No database.driver configured

Am I the only one trying to do this?  I'd rather not set up postgres or mysql to get this to work, but if no one else is using H2 this way I suppose that's my only option.

Kevin

Shawn Pearce

unread,
Aug 26, 2011, 1:11:51 PM8/26/11
to repo-d...@googlegroups.com
On Fri, Aug 26, 2011 at 05:18, Kevin Lyda <ly...@google.com> wrote:
> I set up a test system and ran two database servers:
> java -cp /usr/local/gerrit/lib/h2-1.3.159.jar org.h2.tools.Server -tcp
> -tcpPort 9101 -baseDir /usr/local/gerrit/db
> java -cp /usr/local/gerrit/lib/h2-1.3.159.jar org.h2.tools.Server -tcp
> -tcpPort 9102 -baseDir /usr/local/gerrit/db
> I created the cluster:
> java -cp /usr/local/gerrit/lib/lib/h2-1.3.159.jar org.h2.tools.CreateCluster
> -urlSource 'jdbc:h2:tcp://localhost:9101/ReviewDB' -urlTarget
> 'jdbc:h2:tcp://localhost:9102/ReviewDB' -user '' -serverList
> localhost:9101,localhost:9102
>
> And I modified the config:
> [database]
>   type = JDBC
>   database = jdbc:h2:tcp://localhost:9101,localhost:9102/ReviewDB

Incorrect configuration for type = JDBC. You need a driver and url key:

[database]
type = JDBC
driver = org.h2.Driver
url = jdbc:h2:tcp://localhost:9101,localhost:9102/ReviewDB

Kevin Lyda

unread,
Aug 29, 2011, 10:19:32 AM8/29/11
to repo-d...@googlegroups.com
Thanks - almost there!  I have it working in an unclustered setup.  However once I enable clustering, it fails.  The error is:

[2011-08-29 14:14:18,450] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
java.lang.StackOverflowError
        at java.net.AbstractPlainSocketImpl.acquireFD(AbstractPlainSocketImpl.java:556)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:107)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at java.io.DataOutputStream.flush(DataOutputStream.java:123)
        at org.h2.value.Transfer.flush(Transfer.java:89)
        at org.h2.engine.SessionRemote.done(SessionRemote.java:535)
        at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:184)
        at org.h2.engine.SessionRemote.setAutoCommitSend(SessionRemote.java:210)
        at org.h2.engine.SessionRemote.setAutoCommitFromServer(SessionRemote.java:180)
        at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:191)
        at org.h2.engine.SessionRemote.setAutoCommitSend(SessionRemote.java:210)
**** (last three lines repeat 300+ times) ****
        at org.h2.engine.SessionRemote.setAutoCommitFromServer(SessionRemote.java:180)
        at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:191)
        at org.h2.engine.SessionRemote.setAutoCommitSend(SessionRemote.java:210)

Is the comma causing problems in parsing the arguments?

Kevin

Shawn Pearce

unread,
Aug 29, 2011, 10:21:36 AM8/29/11
to repo-d...@googlegroups.com

Yikes. That is a bug in H2. I wonder if the H2 folks have fixed it
already, and Gerrit is just out-of-date?

Kevin Lyda ⚛

unread,
Aug 29, 2011, 10:24:05 AM8/29/11
to Shawn Pearce, repo-d...@googlegroups.com
I'm using gerrit 2.2.1. I have no problem with that connect string
using org.h2.tools.Shell in H2 version 1.3.159.

Kevin

> --
> To unsubscribe, email repo-discuss...@googlegroups.com
> More info at http://groups.google.com/group/repo-discuss?hl=en
>

Kevin Lyda ⚛

unread,
Aug 29, 2011, 11:56:55 AM8/29/11
to Shawn Pearce, repo-d...@googlegroups.com
OK. Sorted it out. I did the following:

# Get the appropriate version of the library:
java -jar bin/gerrit.war cat lib/h2-1.2.147.jar > lib/h2-1.2.147.jar
# Start the two DB servers.
java -cp /usr/local/foo/lib/h2-1.2.147.jar \
org.h2.tools.Server -tcp -tcpPort 9101 -baseDir /usr/local/foo/db &
java -cp /usr/local/foo/lib/h2-1.2.147.jar \
org.h2.tools.Server -tcp -tcpPort 9102 -baseDir /usr/local/foo/db2 &
# Create the cluster:
java -cp /usr/local/foo/lib/h2-1.2.147.jar \


org.h2.tools.CreateCluster \
-urlSource 'jdbc:h2:tcp://localhost:9101/ReviewDB' \
-urlTarget 'jdbc:h2:tcp://localhost:9102/ReviewDB' \
-user '' -serverList localhost:9101,localhost:9102

# Start gerrit:
/usr/local/foo/bin/gerrit.sh start

My mistake was using the wrong version of the h2 library. Using the
one embedded in the .war file (unzip -l | grep h2 finds it) works
fine.

You can connect to the db from the shell prompt like so:

java -cp /usr/local/foo/lib/h2-1.2.147.jar \
org.h2.tools.Shell -url 'jdbc:h2:tcp://localhost:9101,localhost:9102/ReviewDB'

Perhaps putting something like this in the docs would be nice...

Kevin

Kevin Lyda

unread,
Aug 3, 2012, 1:14:59 PM8/3/12
to Tariq Mehmood, Razvan Musaloiu-E., repo-d...@googlegroups.com, Shawn Pearce
I didn't; razvanm did it. IIRC he started fresh and then imported the data.

Kevin

On Mon, Jul 30, 2012 at 10:51 AM, Tariq Mehmood <tari...@gmail.com> wrote:
> Hi, Kevin
>
> Just wondering did you get the H2 to mySql data migration issue sorted?
> If yes.................
>
> I have two linux VM's one with H2 and other setup with mySql.
> mySql empty tables have already been created exactly what is on H2.
> my problem is to to copy all the data from H2 VM to mySql VM.
>
> Any help is appriciated.
>
> Thanks in advance for your time.
>
> Best Regards,
> Tariq
Reply all
Reply to author
Forward
0 new messages