Finding free space available in database

Jan 4, 2013 at 9:24 PM

I am trying to implement disk based caching solution on top of ESE.  Here the are requirements

  1.  The cache (database) cannot grow more than a specified size. 
  2.  If the database size reaches 80% of specified size, older items must be deleted.
  3.  Database must be online during removal of cache items.

Here are my questions

Are there any solutions that are built on top of Esent for this purpose?

Is there anyway to limit the database growth?

When I delete items from database, the size is unchanged. I did the defragmentation, but that still does not release the space. Is there a way to findout how much free space is claimed after defragmentation?

Is there a way to find out how much space is used by DB and how much space is left for writes with/without defragmenting?

Please clarify.

Thank you

Anil Lingamallu

 

Jan 5, 2013 at 1:17 PM

You can set a hard quota using: 

JetAttachDatabase2 - http://msdn.microsoft.com/en-us/library/gg269322.aspx

You can get the size of the db using:

int databaseSpaceOwned;
Api.JetGetDatabaseInfo(session, dbid, out databaseSpaceOwned, JET_DbInfo.SpaceOwned);
The only way to _release_ disk space to the OS is to do offline compaction using Api.JetCompact

Jan 5, 2013 at 1:17 PM

But note that by deleting items from the db, you are releasing _internal_ space. Which can be reused.  

Jan 8, 2013 at 3:29 PM

thank you ayende for clarification. Is the released internal space after deleting records is reused without calling defragmentation? Should I do defragmentation to reuse the internal free space? Please clarify.

Api.JetGetDatabaseInfo solves my first problem. thank you.

Developer
Jan 9, 2013 at 12:22 AM

A good chunk of the internal released space is available for reuse without doing anything else.

But there is some additional work that can be done with online defrag and dbscan that can perform additional optimizations. Which is your minimum OS you're targetting? Online defrag is in XP, but dbscan is a much newer feature (I think Win7?).

-martin

Jan 9, 2013 at 2:36 PM

Thank you Martin, this helps.

The caching component will be used in Azure and OS is Windows Server 2008 R2. Lastly, can you please share a pointer to using DBScan? 

Jan 10, 2013 at 3:58 PM

I would like to know about that as well. I never heard about DBScan  

Developer
Jan 17, 2013 at 11:41 AM

Blech, it looks like it hasn't been documented on MSDN. It is in esent.h though. And it's accessible in Windows7Grbits:

        /// <summary>
        /// The database engine will initiate automatic background database maintenance upon database attachment.
        /// </summary>
        public const AttachDatabaseGrbit EnableAttachDbBackgroundMaintenance = (AttachDatabaseGrbit)0x800;

        /// <summary>
        /// The database engine will initiate automatic background database maintenance upon database creation.
        /// </summary>
        public const CreateDatabaseGrbit EnableCreateDbBackgroundMaintenance = (CreateDatabaseGrbit)0x800;

There is a little bit alluded at http://blogs.technet.com/b/exchange/archive/2007/12/06/3404504.aspx (see 'JetDatabaseScan'). I'm not trying to be evasive, but I'm pretty busy and don't have time to write a decent response.

-martin

Jan 17, 2013 at 1:56 PM

Thank you martin, this pointer should be good enough. The nice thing it is just a flag I need to set. Thank you much again for helping me out even in your busy schedule.