Database file creation

20 views
Skip to first unread message

Sergio B.

unread,
Jul 8, 2010, 12:07:39 PM7/8/10
to hawtdb
Hi guys,

I'm thinking about using HawtDB to implement a static (snapshot-like)
database, where I need to recreate from scratch the database file
several times, so I was wondering: what happens if I call
PageFileFactory#open() method on the same file multiple times (that
is, I always set the same file)?
It seems to always open a new database, discarding old data: can you
confirm this?

Thanks,
Cheers,

Sergio B.

Hiram Chirino

unread,
Jul 8, 2010, 1:16:33 PM7/8/10
to haw...@googlegroups.com
This is the case. The non-transaction page file does not track the
free page allocations. So when it opens an existing page file it
thinks no pages have been allocated, this is why it looks like the old
data has been discarded.

Now, if you close sync the page file to disk and close it properly,
your indexes should stay intact so it should be possible to re-open
it. You would just need to store the free page list externally after
closing the file and restore it after reopening. I've just update the
Allocator API so that it's possible to get that free page list. So
basically you would be calling the following methods:
pageFile.allocator().getFreeRanges()
pageFile.allocator().setFreeRanges()

Regards,
Hiram

--
Regards,
Hiram

Blog: http://hiramchirino.com

Open Source SOA
http://fusesource.com/

Sergio Bossa

unread,
Jul 8, 2010, 2:25:24 PM7/8/10
to hawtdb
One thing I forgot to specify: it seems to open a new database *if* I
also call IndexFactory#create(), obviously.

But, another question coming in my mind: will this combination of
calls delete all previously associated page files?

--
Sergio Bossa
http://www.linkedin.com/in/sergiob

Hiram Chirino

unread,
Jul 8, 2010, 2:53:49 PM7/8/10
to haw...@googlegroups.com
On Thu, Jul 8, 2010 at 2:25 PM, Sergio Bossa <sergio...@gmail.com> wrote:
> One thing I forgot to specify: it seems to open a new database *if* I
> also call IndexFactory#create(), obviously.
>
> But, another question coming in my mind: will this combination of
> calls delete all previously associated page files?
>

Which combination? :) Could you post an example of your call sequence?
if you want to make sure the previous page file is deleted, you could
always just File.delete().

> On Thu, Jul 8, 2010 at 6:07 PM, Sergio B. <sergio...@gmail.com> wrote:
>> Hi guys,
>>
>> I'm thinking about using HawtDB to implement a static (snapshot-like)
>> database, where I need to recreate from scratch the database file
>> several times, so I was wondering: what happens if I call
>> PageFileFactory#open() method on the same file multiple times (that
>> is, I always set the same file)?
>> It seems to always open a new database, discarding old data: can you
>> confirm this?
>>
>> Thanks,
>> Cheers,
>>
>> Sergio B.
>
>
>
> --
> Sergio Bossa
> http://www.linkedin.com/in/sergiob
>

--

Sergio B.

unread,
Jul 9, 2010, 7:30:41 AM7/9/10
to hawtdb
On Jul 8, 8:53 pm, Hiram Chirino <hi...@hiramchirino.com> wrote:

> Could you post an example of your call sequence?

Here it is:

PageFileFactory pageFactory = new PageFileFactory();
pageFactory.setFile(new File("/tmp/hawtdb.test"));
pageFactory.open();
PageFile page = pageFactory.getPageFile();
BTreeIndexFactory<String, String> indexFactory = new
BTreeIndexFactory<String, String>();
SortedIndex<String, String> index = indexFactory.create(page, 0);

As far as I understand, this snippet will create a new database (and
index) every time, discarding old data: is that correct?

> if you want to make sure the previous page file is deleted, you could
> always just File.delete().

Absolutely, but I wanted to understand how page allocation worked.

Thanks,
Cheers,

Sergio B.

Sergio B.

unread,
Jul 9, 2010, 7:44:34 AM7/9/10
to hawtdb
On Jul 8, 7:16 pm, Hiram Chirino <hi...@hiramchirino.com> wrote:

> Now, if you close sync the page file to disk and close it properly,
> your indexes should stay intact so it should be possible to re-open
> it.  

So the question is: how do you properly close the database? :)
Is it just PageFileFactory#close()?

> You would just need to store the free page list externally after
> closing the file and restore it after reopening. I've just update the
> Allocator API so that it's possible to get that free page list.

Isn't it too complicated?
Why should I go that deeper into page management?
The end user should only care about page and index creation and
modification: page management should be internally done, IMHO.
What do you think?

Hiram Chirino

unread,
Jul 9, 2010, 8:36:04 AM7/9/10
to haw...@googlegroups.com
On Fri, Jul 9, 2010 at 7:30 AM, Sergio B. <sergio...@gmail.com> wrote:
> On Jul 8, 8:53 pm, Hiram Chirino <hi...@hiramchirino.com> wrote:
>
>> Could you post an example of your call sequence?
>
> Here it is:
>
> PageFileFactory pageFactory = new PageFileFactory();
> pageFactory.setFile(new File("/tmp/hawtdb.test"));
> pageFactory.open();
> PageFile page = pageFactory.getPageFile();
> BTreeIndexFactory<String, String> indexFactory = new
> BTreeIndexFactory<String, String>();
> SortedIndex<String, String> index = indexFactory.create(page, 0);
>
> As far as I understand, this snippet will create a new database (and
> index) every time, discarding old data: is that correct?
>

yep

>> if you want to make sure the previous page file is deleted, you could
>> always just File.delete().
>
> Absolutely, but I wanted to understand how page allocation worked.
>
> Thanks,
> Cheers,
>
> Sergio B.

--

Reply all
Reply to author
Forward
0 new messages