This class provides static properties to set and get per-instance ESENT system parameters.
예제 #1
0
        public Instance(string name, string displayName) : base(true)
        {
            JET_INSTANCE instance;
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                // This try block deliberately left blank.
            }
            finally
            {
                // This is the code that we want in a constrained execution region.
                // We need to avoid the situation where JetCreateInstance2 is called
                // but the handle isn't set, so the instance is never terminated.
                // This would happen, for example, if there was a ThreadAbortException
                // between the call to JetCreateInstance2 and the call to SetHandle.
                //
                // If an Esent exception is generated we do not want to call SetHandle
                // because the instance isn't valid. On the other hand if a different 
                // exception (out of memory or thread abort) is generated we still need
                // to set the handle to avoid losing track of the instance. The call to
                // JetCreateInstance2 is in the CER to make sure that the only exceptions
                // which can be generated are from ESENT failures.
                Api.JetCreateInstance2(out instance, name, displayName, CreateInstanceGrbit.None);
                this.SetHandle(instance.Value);
            }

            this.parameters = new InstanceParameters(instance);
        }
예제 #2
0
        public Instance(string name, string displayName) : base(true)
        {
            this.name        = name;
            this.displayName = displayName;

            JET_INSTANCE instance;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                this.SetHandle(JET_INSTANCE.Nil.Value);
            }
            finally
            {
                // This is the code that we want in a constrained execution region.
                // We need to avoid the situation where JetCreateInstance2 is called
                // but the handle isn't set, so the instance is never terminated.
                // This would happen, for example, if there was a ThreadAbortException
                // between the call to JetCreateInstance2 and the call to SetHandle.
                //
                // If an Esent exception is generated we do not want to call SetHandle
                // because the instance isn't valid. On the other hand if a different
                // exception (out of memory or thread abort) is generated we still need
                // to set the handle to avoid losing track of the instance. The call to
                // JetCreateInstance2 is in the CER to make sure that the only exceptions
                // which can be generated are from ESENT failures.
                Api.JetCreateInstance2(out instance, this.name, this.displayName, CreateInstanceGrbit.None);
                this.SetHandle(instance.Value);
            }

            this.parameters = new InstanceParameters(instance);
        }
		public InstanceParameters ConfigureInstance(JET_INSTANCE jetInstance, string path)
		{
			path = Path.GetFullPath(path);
			var logsPath = path;
			if (string.IsNullOrEmpty(configuration.Settings["Raven/Esent/LogsPath"]) == false)
			{
				logsPath = configuration.Settings["Raven/Esent/LogsPath"].ToFullPath();
			}
			var circularLog = GetValueFromConfiguration("Raven/Esent/CircularLog", true);
			var logFileSizeInMb = GetValueFromConfiguration("Raven/Esent/LogFileSize", 64);
			logFileSizeInMb = Math.Max(1, logFileSizeInMb / 4);
			var instanceParameters = new InstanceParameters(jetInstance)
			{
				CircularLog = circularLog,
				Recovery = true,
				NoInformationEvent = false,
				CreatePathIfNotExist = true,
				EnableIndexChecking = true,
				TempDirectory = Path.Combine(logsPath, "temp"),
				SystemDirectory = Path.Combine(logsPath, "system"),
				LogFileDirectory = Path.Combine(logsPath, "logs"),
				MaxVerPages = TranslateToSizeInVersionPages(GetValueFromConfiguration("Raven/Esent/MaxVerPages", 512), 1024 * 1024),
				PreferredVerPages = TranslateToSizeInVersionPages(GetValueFromConfiguration("Raven/Esent/PreferredVerPages", 472), 1024 * 1024),
				BaseName = "RVN",
				EventSource = "Raven",
				LogBuffers = TranslateToSizeInDatabasePages(GetValueFromConfiguration("Raven/Esent/LogBuffers", 8192), 1024),
				LogFileSize = (logFileSizeInMb * 1024),
				MaxSessions = MaxSessions,
				MaxCursors = GetValueFromConfiguration("Raven/Esent/MaxCursors", 2048),
				DbExtensionSize = TranslateToSizeInDatabasePages(GetValueFromConfiguration("Raven/Esent/DbExtensionSize", 8), 1024 * 1024),
				AlternateDatabaseRecoveryDirectory = path
			};

			return instanceParameters;
		}
예제 #4
0
        public void SetJetParameterAsString()
        {
            var jetparam = new JetParameter(JET_param.BaseName, "abc");
            jetparam.SetParameter(this.instance);

            var parameters = new InstanceParameters(this.instance);
            Assert.AreEqual("abc", parameters.BaseName);
        }
예제 #5
0
        public void SetJetParameterAsInteger()
        {
            var jetparam = new JetParameter(JET_param.MaxVerPages, 3000);
            jetparam.SetParameter(this.instance);

            var parameters = new InstanceParameters(this.instance);
            Assert.AreEqual(3000, parameters.MaxVerPages);
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the Instance class. The underlying
 /// JET_INSTANCE is allocated, but not initialized.
 /// </summary>
 /// <param name="name">
 /// The name of the instance. This string must be unique within a
 /// given process hosting the database engine.
 /// </param>
 /// <param name="displayName">
 /// A display name for the instance. This will be used in eventlog
 /// entries.
 /// </param>
 public Instance(string name, string displayName)
     : base(true)
 {
     JET_INSTANCE instance;
     Api.JetCreateInstance2(out instance, name, displayName, CreateInstanceGrbit.None);
     this.SetHandle(instance.Value);
     this.parameters = new InstanceParameters(instance);
 }
        public void Configure(InstanceParameters ip)
        {
            ip.SystemDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            ip.TempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            ip.LogFileDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(ip.SystemDirectory);
            Directory.CreateDirectory(ip.TempDirectory);
            Directory.CreateDirectory(ip.LogFileDirectory);
        }
예제 #8
0
		public InstanceParameters ConfigureInstance(JET_INSTANCE jetInstance, string path)
		{
			path = Path.GetFullPath(path);
			var logsPath = path;
			var configuredLogsPath = Configuration.Settings["Raven/Esent/LogsPath"] ?? Configuration.Settings[Constants.RavenTxJournalPath] ?? Configuration.JournalsStoragePath;
			if (string.IsNullOrEmpty(configuredLogsPath) == false)
			{
				logsPath = configuredLogsPath.ToFullPath();
			}
			var circularLog = GetValueFromConfiguration("Raven/Esent/CircularLog", true);
			var logFileSizeInMb = GetValueFromConfiguration("Raven/Esent/LogFileSize", 64);
			logFileSizeInMb = Math.Max(1, logFileSizeInMb / 4);
			var maxVerPages = GetValueFromConfiguration("Raven/Esent/MaxVerPages", 512);
			
			var maxVerPagesResult = TranslateToSizeInVersionPages(maxVerPages, 1024 * 1024);

			ConfigureInstanceInternal(maxVerPages);

			var instanceParameters = new InstanceParameters(jetInstance)
			{
				CircularLog = circularLog,
				Recovery = true,
				NoInformationEvent = false,
				CreatePathIfNotExist = true,
				EnableIndexChecking = true,
				TempDirectory = Path.Combine(logsPath, "temp"),
				SystemDirectory = Path.Combine(logsPath, "system"),
				LogFileDirectory = Path.Combine(logsPath, "logs"),
				MaxVerPages = maxVerPagesResult,
				PreferredVerPages = TranslateToSizeInVersionPages(GetValueFromConfiguration("Raven/Esent/PreferredVerPages", (int)(maxVerPagesResult * 0.85)), 1024 * 1024),
				BaseName = BaseName,
				EventSource = EventSource,
				LogBuffers = TranslateToSizeInDatabasePages(GetValueFromConfiguration("Raven/Esent/LogBuffers", 8192), 1024),
				LogFileSize = (logFileSizeInMb * 1024),
				MaxSessions = MaxSessions,
				MaxCursors = GetValueFromConfiguration("Raven/Esent/MaxCursors", 2048),
				DbExtensionSize = TranslateToSizeInDatabasePages(GetValueFromConfiguration("Raven/Esent/DbExtensionSize", 8), 1024 * 1024),
				AlternateDatabaseRecoveryDirectory = path
			};

			if (Environment.OSVersion.Version >= new Version(5, 2))
			{
				// JET_paramEnableIndexCleanup is not supported on WindowsXP
				const int JET_paramEnableIndexCleanup = 54;
				Api.JetSetSystemParameter(jetInstance, JET_SESID.Nil, (JET_param)JET_paramEnableIndexCleanup, 1, null);
			}

			Log.Info(@"Esent Settings:
  MaxVerPages      = {0}
  CacheSizeMax     = {1}
  DatabasePageSize = {2}", instanceParameters.MaxVerPages, SystemParameters.CacheSizeMax,
					 SystemParameters.DatabasePageSize);

			return instanceParameters;
		}
예제 #9
0
        public void CreateInstanceWithJetCreateInstance2()
        {
            JET_INSTANCE instance;
            Api.JetCreateInstance2(out instance, Guid.NewGuid().ToString(), "Instance Display Name", CreateInstanceGrbit.None);

            var systemParameters = new InstanceParameters(instance);
            systemParameters.MaxTemporaryTables = 0;
            systemParameters.Recovery = false;
            systemParameters.NoInformationEvent = true;

            Api.JetInit(ref instance);
            Api.JetTerm(instance);
        }
예제 #10
0
        public void VerifyJetVersionIsNotZero()
        {
            JET_INSTANCE instance;
            JET_SESID sesid;
            uint version;

            Api.JetCreateInstance(out instance, "JetGetVersion");
            
            var parameters = new InstanceParameters(instance);
            parameters.Recovery = false;
            parameters.MaxTemporaryTables = 0;
            parameters.NoInformationEvent = true;

            Api.JetInit(ref instance);
            Api.JetBeginSession(instance, out sesid, string.Empty, string.Empty);
            Api.JetGetVersion(sesid, out version);
            Api.JetTerm(instance);

            Assert.AreNotEqual(0, version);
            Console.WriteLine("Version = 0x{0:X}", version);
        }
예제 #11
0
        public InstanceParameters ConfigureInstance(JET_INSTANCE jetInstance, string path)
        {
            path = Path.GetFullPath(path);
            var logsPath = path;
            var circularLog = true;
            var logFileSizeInMb = 64;
            logFileSizeInMb = Math.Max(1, logFileSizeInMb / 4);
            var maxVerPages = 512;
            var maxVerPagesResult = TranslateToSizeInVersionPages(maxVerPages, 1024 * 1024);
            var instanceParameters = new InstanceParameters(jetInstance)
            {
                CircularLog = circularLog,
                Recovery = true,
                NoInformationEvent = false,
                CreatePathIfNotExist = true,
                EnableIndexChecking = true,
                TempDirectory = Path.Combine(logsPath, "temp"),
                SystemDirectory = Path.Combine(logsPath, "system"),
                LogFileDirectory = Path.Combine(logsPath, "logs"),
                MaxVerPages = maxVerPagesResult,
                PreferredVerPages = TranslateToSizeInVersionPages((int)(maxVerPagesResult * 0.85), 1024 * 1024),
                BaseName = "RVN",
                EventSource = "EsentTest",
                LogBuffers = TranslateToSizeInDatabasePages(8192, 1024),
                LogFileSize = (logFileSizeInMb * 1024),
                MaxSessions = MaxSessions,
                MaxCursors = 2048,
                DbExtensionSize = TranslateToSizeInDatabasePages(8, 1024 * 1024),
                AlternateDatabaseRecoveryDirectory = path
            };

            if (Environment.OSVersion.Version >= new Version(5, 2))
            {
                // JET_paramEnableIndexCleanup is not supported on WindowsXP
                const int JET_paramEnableIndexCleanup = 54;
                Api.JetSetSystemParameter(jetInstance, JET_SESID.Nil, (JET_param)JET_paramEnableIndexCleanup, 1, null);
            }

            return instanceParameters;
        }
		public void ConfigureInstance(JET_INSTANCE jetInstance, string path)
		{
			path = Path.GetFullPath(path);

			var logsPath = path;
			if (string.IsNullOrEmpty(settings["Raven/Esent/LogsPath"]) == false)
			{
				logsPath = settings["Raven/Esent/LogsPath"].ToFullPath();
			}

			var instanceParameters = new InstanceParameters(jetInstance)
				                         {
					                         CircularLog = GetValueFromConfiguration("Raven/Esent/CircularLog", true),
					                         Recovery = true,
					                         NoInformationEvent = false,
					                         CreatePathIfNotExist = true,
					                         TempDirectory = Path.Combine(logsPath, "temp"),
					                         SystemDirectory = Path.Combine(logsPath, "system"),
					                         LogFileDirectory = Path.Combine(logsPath, "logs"),
					                         MaxVerPages =
						                         TranslateToSizeInDatabasePages(GetValueFromConfiguration("Raven/Esent/MaxVerPages", 128)),
					                         BaseName = "RFS",
					                         EventSource = "RavenFS",
					                         LogBuffers =
						                         TranslateToSizeInDatabasePages(GetValueFromConfiguration("Raven/Esent/LogBuffers", 16))/2,
					                         LogFileSize = GetValueFromConfiguration("Raven/Esent/LogFileSize", 1)*1024,
					                         MaxSessions = MaxSessions,
					                         MaxCursors = GetValueFromConfiguration("Raven/Esent/MaxCursors", 2048),
					                         DbExtensionSize =
						                         TranslateToSizeInDatabasePages(GetValueFromConfiguration("Raven/Esent/DbExtensionSize",
						                                                                                  16)),
					                         AlternateDatabaseRecoveryDirectory = path
				                         };

			log.Info(@"Esent Settings:
  MaxVerPages      = {0}
  CacheSizeMax     = {1}
  DatabasePageSize = {2}", instanceParameters.MaxVerPages, SystemParameters.CacheSizeMax,
			         SystemParameters.DatabasePageSize);
		}
        public InstanceParameters ConfigureInstance(JET_INSTANCE jetInstance, string path)
        {
            path = Path.GetFullPath(path);
            var logsPath = path;

            var instanceParameters = new InstanceParameters(jetInstance)
            {
                Recovery = true,
                NoInformationEvent = false,
                CreatePathIfNotExist = true,
                EnableIndexChecking = true,
                TempDirectory = Path.Combine(logsPath, "temp"),
                SystemDirectory = Path.Combine(logsPath, "system"),
                LogFileDirectory = Path.Combine(logsPath, "logs"),
                BaseName = "RVN",
                EventSource = "Raven",
                MaxSessions = MaxSessions,
                AlternateDatabaseRecoveryDirectory = path
            };

            return instanceParameters;
        }
예제 #14
0
		public bool Initialize(IUuidGenerator uuidGenerator)
		{
			try
			{
				generator = uuidGenerator;
				var instanceParameters = new TransactionalStorageConfigurator(configuration).ConfigureInstance(instance, path);

				if (configuration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction)
				{
					instanceParameters = new InstanceParameters(instance)
					{
						CircularLog = true,
						Recovery = false,
						NoInformationEvent = false,
						CreatePathIfNotExist = true,
						TempDirectory = Path.Combine(path, "temp"),
						SystemDirectory = Path.Combine(path, "system"),
						LogFileDirectory = Path.Combine(path, "logs"),
						MaxVerPages = 256,
						BaseName = "RVN",
						EventSource = "Raven",
						LogBuffers = 8192,
						LogFileSize = 256,
						MaxSessions = TransactionalStorageConfigurator.MaxSessions,
						MaxCursors = 1024,
						DbExtensionSize = 128,
						AlternateDatabaseRecoveryDirectory = path
					};
				}

				log.Info(@"Esent Settings:
  MaxVerPages      = {0}
  CacheSizeMax     = {1}
  DatabasePageSize = {2}", instanceParameters.MaxVerPages, SystemParameters.CacheSizeMax, SystemParameters.DatabasePageSize);

				Api.JetInit(ref instance);

				var newDb = EnsureDatabaseIsCreatedAndAttachToDatabase();

				SetIdFromDb();

				tableColumnsCache.InitColumDictionaries(instance, database);

				return newDb;
			}
			catch (Exception e)
			{
				Dispose();
				throw new InvalidOperationException("Could not open transactional storage: " + database, e);
			}
		}
예제 #15
0
 public void Setup()
 {
     Api.JetCreateInstance(out this.instance, "InstanceParametersTest");
     this.instanceParameters = new InstanceParameters(this.instance);
 }
예제 #16
0
 public void InstanceParametersToString()
 {
     var value = new InstanceParameters(JET_INSTANCE.Nil);
     Assert.AreEqual("InstanceParameters (0x0)", value.ToString());
 }
예제 #17
0
 public void Setup()
 {
     Api.JetCreateInstance(out this.instance, Guid.NewGuid().ToString());
     this.instanceParameters = new InstanceParameters(this.instance);
 }
예제 #18
0
 /// <summary>
 /// Set the instance path parameters for the given database.
 /// </summary>
 /// <param name="instance">The instance to set the parameters on.</param>
 /// <param name="database">The database the instance will be using or creating.</param>
 private static void SetPathParameters(Instance instance, string database)
 {
     var parameters = new InstanceParameters(instance);
     string directory = Path.GetDirectoryName(Path.GetFullPath(database));
     parameters.SystemDirectory = directory;
     parameters.TempDirectory = directory;
     parameters.LogFileDirectory = directory;
 }
예제 #19
0
        public void InitializeInstanceWithJetInit3AndRstinfo()
        {
            if (!EsentVersion.SupportsVistaFeatures)
            {
                return;
            }

            JET_INSTANCE instance;
            Api.JetCreateInstance2(out instance, Guid.NewGuid().ToString(), "Instance Display Name", CreateInstanceGrbit.None);

            var systemParameters = new InstanceParameters(instance);
            systemParameters.MaxTemporaryTables = 0;
            systemParameters.Recovery = false;
            systemParameters.NoInformationEvent = true;

            VistaApi.JetInit3(ref instance, new JET_RSTINFO(), InitGrbit.None);
            Api.JetTerm(instance);
        }
예제 #20
0
 void SetInstanceParameters()
 {
     var instanceParms = new InstanceParameters(instance);
     instanceParms.CircularLog = true;
     instanceParms.Recovery = true;
     instanceParms.NoInformationEvent = false;
     instanceParms.CreatePathIfNotExist = true;
     instanceParms.TempDirectory = Path.Combine(databaseDirectory, "temp");
     instanceParms.SystemDirectory = Path.Combine(databaseDirectory, "system");
     instanceParms.LogFileDirectory = Path.Combine(databaseDirectory, config.GetSetting(SettingKeys.Database_LogDirectory, "logs"));
     instanceParms.CheckpointDepthMax = 100 * 1024 * 1024;
 }
예제 #21
0
 private void ConfigureInstance(JET_INSTANCE jetInstance)
 {
     var parameters = new InstanceParameters(jetInstance)
     {
         CircularLog = true,
         Recovery = true,
         CreatePathIfNotExist = true,
         TempDirectory = Path.Combine(path, "temp"),
         SystemDirectory = Path.Combine(path, "system"),
         LogFileDirectory = Path.Combine(path, "logs"),
         MaxVerPages = 8192,
         MaxTemporaryTables = 8192,
     };
 }