> How to set up H2 in-memory database in GAE and perform ACID opertions
> using SQL in my app?
The problem with ACID and in-memory databases is that in-memory
database are not persisted, so you can't have durability.
> Could you provide some tutorial with examples?
See the source code, for example:
http://code.google.com/p/h2database/source/browse/#svn/trunk/h2/src/test/org/h2/samples%3Fstate%3Dclosed
> Which SQL commands are supported in GAE?
All statements, except those that require a file system.
Regards,
Thomas
> (1) getting it to work properly in a distributed environment
> with multiple GAE application instances accessing the same database;
That will be hard, and in some cases it's the wrong solution... I
guess a more scalable solution is to use 'linked tables' that are
backed by the Google DataStore.
But having a stable virtual file system backed by the Google DataStore
will help others as well, not only H2.
Files greater than 1 MB is the most important missing piece I think.
Some kind of file locking support would be great. Currently H2 doesn't
use file locking to ensure the database is only opened in one process,
instead it uses it's own 'cooperative file locking' protocol. But
regular file locking is relatively easy to add (in the class
FileLock).
> Is anyone interested in this?
I'm interested, and I'm sure others are interested as well.
Regards,
Thomas
> I've just released a new version of GaeVFS (version 0.3) that supports
> files greater than 1 MB and also adds support for random read/write
> file access (both of these were added for H2).
That's great!
> 1) Implement a distributed file locking mechanism for GaeVFS that
> works across multiple JVM instances; implement exclusive write access
> to files across multiple JVMs. (I'll look at the H2 FileLock class as
> you suggest, but would like a general solution for GaeVFS that isn't
> just for H2).
H2 currently uses a special 'cooperative locking mechanism', probably
it doesn't make sense if you try to emulate this. Instead, I guess it
would make more sense to support just 'lock' and 'unlock', in the
spirit of:
http://java.sun.com/javase/6/docs/api/java/nio/channels/FileChannel.html#tryLock()
http://java.sun.com/javase/6/docs/api/java/nio/channels/FileLock.html#release()
This can then be adapted to H2.
> 2) Create an H2 WriterThread implementation based on GAE Task Queues
> (as soon as Google provides support for this in Java).
I didn't know about this... interesting. I would wait to implement
this until Google supports it.
> 3) Investigate what sort of caching might make sense for GaeVFS/H2
> based on the GAE memcache API.
Maybe the file system could be made faster if the last few write
operations are first only written to the memcache API? Not just for
H2, but I guess many applications that use a file system could benefit
from a 'write behind cache'. Or maybe first cache writes in the local
memory, after some delay apply them in the memcache, and still later
apply them in the data store. Many applications don't require that the
changes are written to disk immediately. The biggest benefit would
probably be for application that don't buffer writes.
Regards,
Thomas
No. GAE does not allow applications to open network ports, nor does it
allow applications to create background threads. Either of these
limitations would prevent H2 from running in Server Mode.
> 2) If not is it possible to generate backup (like by SQL commands
> BACKUP, SCRIPT) and not to store it on local file system but sent it
> e.g. like backup-servlet response ?
> 3) Last possible way I thing will work is that I program the backup
> manually querying every table as a response of backup-servlet.
>
> 4) I have I fundamental question if H2 can be runned as memory-only
> database on GAE, I do not know if GAE is not running my application as
> cluster on several JVM's so then H2 in memory-only mode is not
> functional because it can be used only on the same JVM/class loader
> (mentioned in http://www.h2database.com/html/features.html#memory_only_databases:
> Accessing the same database in this way only works within the same
> virtual machine and class loader environment.)
That is correct. GAE may launch several instances of your web
application, each instance running within a separate JVM. However, you
have no way of knowing (and no control over) how many instances are
running at any given time. If you use H2 in memory-only mode, each
instance of your web application--in its separate JVM--will have a
separate in-memory copy of H2. If your database is read-only then this
will work, but as soon as you write to the database your separate web
application instances will be using different data.
Our goal for the H2-GAE project is to get H2 working properly within
the GAE distributed environment using the GaeVFS virtual file system:
http://code.google.com/p/gaevfs/wiki/H2GAE
We still have a lot of work to do before we can claim success, but the
results so far are encouraging.