How do I close Krati store?

61 views
Skip to first unread message

Daniel Canas

unread,
Dec 10, 2010, 7:38:09 PM12/10/10
to Krati
I took the sample code in quickstart section of the web page and tried
a quick test.
This simple program starts up Krati but never exits.
How do I shutdown Krati?
I am using Krati 0.3.5

public class KratiSimpleTest {

public static void main(String[] args) throws Exception {
File storeHome = new File("/tmp/krati.store",
"kratiSimpleTest");
DataStore<byte[], byte[]> ds = new
DynamicDataStore(storeHome, new MappedSegmentFactory());
}

Log file produced:

INFO main krati.core.array.entry.EntryPool - Entry 0 created:
PreFillEntryLong
INFO main krati.core.array.entry.EntryPool - Entry 0 serviceId 0
INFO main krati.core.array.entry.EntryPool - Entry 1 created:
PreFillEntryLong
INFO main krati.core.array.entry.EntryPool - Entry 1 serviceId 1
INFO main krati.core.array.basic.ArrayEntryManager - arrayLength=65536
maxEntries=5 maxEntrySize=10000
INFO main krati.core.array.basic.ArrayFile - indexes.dat header:
version=0 lwmScn=0 hwmScn=0 arrayLength=65536 elementSize=8
INFO main krati.core.array.basic.ArrayFile - indexes.dat loaded in
Time: 362 ms
INFO main krati.core.array.basic.RecoverableArray - length:65536
entrySize:10000 maxEntries:5 directory:/tmp/krati.store/
kratiSimpleTest arrayFile:indexes.dat
INFO main krati.core.segment.SegmentManager - init segHomePath=/tmp/
krati.store/kratiSimpleTest/segs segFileSizeMB=256
INFO main krati.core.segment.SegmentMeta - /tmp/krati.store/
kratiSimpleTest/segs/.meta created
INFO main krati.core.segment.SegmentMeta - workingGeneration=0
liveSegmentCount=0
INFO main krati.core.array.SimpleDataArrayCompactor -
CompactionUpdateBatch 0
INFO main krati.core.segment.MappedSegment - Segment 0 forced:
loadSize=0 appendPosition=16 channelPosition=0 lastForcedTime=Mon Dec
06 12:12:26 CST 2010
INFO main krati.core.segment.MappedSegment - Segment 0 initialized:
loadSize=0 appendPosition=128 channelPosition=128 lastForcedTime=Mon
Dec 06 12:12:26 CST 2010
INFO main krati.core.array.SimpleDataArray - Segment 0 online:
loadSize=0 appendPosition=128 channelPosition=128 lastForcedTime=Mon
Dec 06 12:12:26 CST 2010
INFO main krati.store.DynamicDataStore - level=0 split=0
capacity=65536 loadCount=0 loadFactor=0.0
INFO pool-1-thread-1 krati.core.array.SimpleDataArrayCompactor - cycle
started
INFO pool-1-thread-1 krati.core.array.SimpleDataArrayCompactor - cycle
ended

Jingwei

unread,
Dec 10, 2010, 7:47:20 PM12/10/10
to Krati
You can add the following at the end of your main method.

ds.sync();
System.exit(0);

-jingwei

Daniel Canas

unread,
Dec 13, 2010, 4:55:39 PM12/13/10
to Krati
Yes, that works for this specific example if Krati does not throw an
exception.

I want to use Krati and be able to close it without exiting the whole
program. Is that possible?

Daniel

Jingwei

unread,
Dec 14, 2010, 1:18:47 AM12/14/10
to Krati
In Krati 0.3.5, compactor runs as a non-daemon thread. This prevents
JVM from shutting down cleanly.

The latest dev from https://github.com/jingwei/krati makes compactor
run as a daemon thread so JVM can shutdown nicely.

We are thinking to extend DataStore with open/close methods in the
next release. So the store can be closed before JVM shutdown.

Thanks.

-jingwei

Tatu Saloranta

unread,
Dec 14, 2010, 11:55:04 AM12/14/10
to kr...@googlegroups.com
On Mon, Dec 13, 2010 at 10:18 PM, Jingwei <jingw...@gmail.com> wrote:
> In Krati 0.3.5, compactor runs as a non-daemon thread. This prevents
> JVM from shutting down cleanly.
>
> The latest dev from https://github.com/jingwei/krati makes compactor
> run as a daemon thread so JVM can shutdown nicely.
>
> We are thinking to extend DataStore with open/close methods in the
> next release. So the store can be closed before JVM shutdown.

I think this would be an excellent idea. Life-cycle of a store may
well be shorter than that of the system that uses it.

-+ Tatu +-

Rodolfo M. Raya

unread,
Jun 7, 2011, 9:27:07 AM6/7/11
to kr...@googlegroups.com
Hi Jingwei,
 
I got the latest source code from the repository and the option for cosing databases is working fine. Thanks for implementing it.
 
I have two questions regarding the new feature:
 
Do I need to call sync() before close()?
 
close() can take a while, normally more than the end user would wait. Can the closing operation be done in a background thread?
 
Regards,
Rodolfo

Rodolfo Raya

unread,
Jun 7, 2011, 9:59:12 AM6/7/11
to kr...@googlegroups.com
On Tue, Jun 7, 2011 at 10:27 AM, Rodolfo M. Raya <rmr...@gmail.com> wrote:
 
close() can take a while, normally more than the end user would wait. Can the closing operation be done in a background thread?
 
I placed the call to close() in its own thread for testing and it is fast enough; end users will not notice a delay.

Now I'd like to know if it is safe to do what I did.
Regards,

Jingwei

unread,
Jun 7, 2011, 2:04:51 PM6/7/11
to Krati
Hi Rodolfo,

You do not need to call sync() before close() since the latter
internally calls the former.
In addition, you can delegate call to close() to a background thread.

Thanks.

-jingwei

Jingwei

unread,
Jun 7, 2011, 2:21:32 PM6/7/11
to Krati
Hi Rodolfo,

It is safe to call close() in a background thread. However, calls to
methods get/set/put etc will be impacted and exceptions (such as
NullPointerException) may be thrown.

Thanks.

-jingwei

Rodolfo Raya

unread,
Jun 7, 2011, 6:03:27 PM6/7/11
to kr...@googlegroups.com


On Tue, Jun 7, 2011 at 3:21 PM, Jingwei <jingw...@gmail.com> wrote:
Hi Rodolfo,

It is safe to call close() in a background thread. However, calls to
methods get/set/put etc will be impacted and exceptions (such as
NullPointerException) may be thrown.

 


Many thanks for the feedback, Jinwei.
 
Best regards,
Reply all
Reply to author
Forward
0 new messages