//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. // //----------------------------------------------------------------------- namespace Microsoft.Isam.Esent.Interop { using System; using System.Runtime.InteropServices; using Microsoft.Isam.Esent.Interop.Windows7; using Microsoft.Isam.Esent.Interop.Windows8; /// /// This class provides static properties to set and get /// per-instance ESENT system parameters. /// public partial class InstanceParameters { /// /// Gets or sets the percentage of version store that can be used by oldest transaction /// before (default = 100). /// public int MaxTransactionSize { get { return this.GetIntegerParameter(Windows8Param.MaxTransactionSize); } set { this.SetIntegerParameter(Windows8Param.MaxTransactionSize, value); } } /// /// Gets or sets a value indicating whether Database Maintenance should run during recovery. /// public int EnableDbScanInRecovery { get { return this.GetIntegerParameter(Windows7Param.EnableDbScanInRecovery); } set { this.SetIntegerParameter(Windows7Param.EnableDbScanInRecovery, value); } } /// /// Gets or sets a value indicating whether database Maintenance /// serialization is enabled for databases sharing the same disk. /// public bool EnableDBScanSerialization { get { return this.GetBoolParameter(Windows8Param.EnableDBScanSerialization); } set { this.SetBoolParameter(Windows8Param.EnableDBScanSerialization, value); } } /// /// Gets or sets the throttling of the database scan, in milliseconds. /// public int DbScanThrottle { get { return this.GetIntegerParameter(Windows7Param.DbScanThrottle); } set { this.SetIntegerParameter(Windows7Param.DbScanThrottle, value); } } /// /// Gets or sets the minimum interval to repeat the database scan, in seconds. /// public int DbScanIntervalMinSec { get { return this.GetIntegerParameter(Windows7Param.DbScanIntervalMinSec); } set { this.SetIntegerParameter(Windows7Param.DbScanIntervalMinSec, value); } } /// /// Gets or sets the maximum interval to allow the database scan to finish, in seconds. /// public int DbScanIntervalMaxSec { get { return this.GetIntegerParameter(Windows7Param.DbScanIntervalMaxSec); } set { this.SetIntegerParameter(Windows7Param.DbScanIntervalMaxSec, value); } } /// /// Gets or sets the per-instance property for relative cache priorities (default = 100). /// public int CachePriority { get { return this.GetIntegerParameter(Windows8Param.CachePriority); } set { this.SetIntegerParameter(Windows8Param.CachePriority, value); } } /// /// Gets or sets the maximum number of I/O operations dispatched for a given purpose. /// public int PrereadIOMax { get { return this.GetIntegerParameter(Windows8Param.PrereadIOMax); } set { this.SetIntegerParameter(Windows8Param.PrereadIOMax, value); } } /// /// Gets the callback for log flush. /// /// The delegate that's called for log flush. internal NATIVE_JET_PFNDURABLECOMMITCALLBACK GetDurableCommitCallback() { NATIVE_JET_PFNDURABLECOMMITCALLBACK pfndurablecommit = null; IntPtr rawValue = this.GetIntPtrParameter(Windows8Param.DurableCommitCallback); if (rawValue != IntPtr.Zero) { pfndurablecommit = (NATIVE_JET_PFNDURABLECOMMITCALLBACK)Marshal.GetDelegateForFunctionPointer(rawValue, typeof(NATIVE_JET_PFNDURABLECOMMITCALLBACK)); } return pfndurablecommit; } /// /// Sets the callback for log flush. /// It is the caller's responsibility to hold a reference to the delegate /// so that it doesn't get GC'ed. /// /// /// The callback. /// internal void SetDurableCommitCallback( NATIVE_JET_PFNDURABLECOMMITCALLBACK callback) { IntPtr nativeDelegate; if (callback != null) { nativeDelegate = Marshal.GetFunctionPointerForDelegate(callback); } else { nativeDelegate = IntPtr.Zero; } this.SetIntPtrParameter(Windows8Param.DurableCommitCallback, nativeDelegate); } /// /// Get a system parameter which is an IntPtr. /// /// The parameter to get. /// The value of the parameter. private IntPtr GetIntPtrParameter(JET_param param) { IntPtr value = IntPtr.Zero; string ignored; Api.JetGetSystemParameter(this.instance, this.sesid, param, ref value, out ignored, 0); return value; } /// /// Set a system parameter which is an IntPtr. /// /// The parameter to set. /// The value to set. private void SetIntPtrParameter(JET_param param, IntPtr value) { Api.JetSetSystemParameter(this.instance, this.sesid, param, value, null); } } }