Hi,
We've got a problem with handling BLOBs with lobInDatabase == true.
We're using latest version of H2 - 1.3.154.
The following program inserts 1000 blobs 100K each and then deletes
them, this is repeated 10 times. It shows on my machine:
----8<----
Working with db: 142003
DB size: 1159737344
DB shutdown: 114439
DB size: 32768
----8<----
Notice that DB size goes to about 1GB instead of expected size ~100MB.
Also, closing the last connection takes around the same time as
insertion / deletion.
For a server use indefinitely growing DB, even if compacted on
shutdown, is really bad... Isn't space taken by deleted BLOBs
reclaimed and reused for new data?
Here is the test program:
----8<----
import java.io.ByteArrayInputStream;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Random;
import static java.lang.System.*;
public class Test
{
private static File dbFile;
public static void main (String[] args) throws Exception
{
dbFile = new File ("./test.h2.db");
dbFile.delete ();
Class.forName ("org.h2.Driver");
Connection connection = DriverManager.getConnection ("jdbc:h2:./
test");
Statement init = connection.createStatement ();
init.execute ("CREATE TABLE TEST (ID IDENTITY, CONTENT BLOB)");
init.close ();
Random random = new Random ();
long t0 = currentTimeMillis();
for (int i = 0; i < 10; i++)
{
PreparedStatement insert = connection.prepareStatement
("INSERT
INTO TEST (CONTENT) VALUES (?)");
PreparedStatement delete = connection.prepareStatement
("DELETE
FROM TEST");
insertBlobs (insert, random);
delete.execute ();
insert.close ();
delete.close ();
}
long t1 = System.currentTimeMillis();
System.out.println ("Working with db: " + (t1 - t0));
printDbSize();
long t2 = System.currentTimeMillis();
connection.close ();
long t3 = System.currentTimeMillis();
System.out.println ("DB shutdown: " + (t3 - t2));
printDbSize();
}
private static void insertBlobs (PreparedStatement insert, Random
random) throws Exception
{
for (int i = 0; i < 1000; i++)
{
byte[] garbage = new byte [100000];
random.nextBytes (garbage);
insert.setBinaryStream (1, new ByteArrayInputStream
(garbage));
insert.execute ();
}
}
private static void printDbSize ()
{
System.out.println ("DB size: " + dbFile.length ());
}
}
----8<----
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.