• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# StorageEnvironment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中StorageEnvironment的典型用法代码示例。如果您正苦于以下问题:C# StorageEnvironment类的具体用法?C# StorageEnvironment怎么用?C# StorageEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StorageEnvironment类属于命名空间,在下文中一共展示了StorageEnvironment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Transaction

		public Transaction(StorageEnvironment env, long id, TransactionFlags flags, IFreeSpaceHandling freeSpaceHandling)
		{
			_dataPager = env.Options.DataPager;
			_env = env;
			_journal = env.Journal;
			_id = id;
			_freeSpaceHandling = freeSpaceHandling;
			Flags = flags;
			var scratchPagerStates = env.ScratchBufferPool.GetPagerStatesOfAllScratches();

			foreach (var scratchPagerState in scratchPagerStates.Values)
			{
				scratchPagerState.AddRef();
				_pagerStates.Add(scratchPagerState);
			}

            
			if (flags.HasFlag(TransactionFlags.ReadWrite) == false)
			{
                // for read transactions, we need to keep the pager state frozen
                // for write transactions, we can use the current one (which == null)
				_scratchPagerStates = scratchPagerStates;

				_state = env.State.Clone(this);
				_journal.GetSnapshots().ForEach(AddJournalSnapshot);
				return;
			}

			_state = env.State.Clone(this);

			InitTransactionHeader();

			MarkTreesForWriteTransaction();
		}
开发者ID:jrusbatch,项目名称:ravendb,代码行数:34,代码来源:Transaction.cs


示例2: Can_split_merged_transaction_to_multiple_tx

        public void Can_split_merged_transaction_to_multiple_tx()
        {
            _tempDir = Guid.NewGuid().ToString();
            var storageEnvironmentOptions = StorageEnvironmentOptions.ForPath(_tempDir);
            storageEnvironmentOptions.IncrementalBackupEnabled = true;
            storageEnvironmentOptions.MaxNumberOfPagesInMergedTransaction = 8;
            using (var envToSnapshot = new StorageEnvironment(storageEnvironmentOptions))
            {
                for (int xi = 0; xi < 100; xi++)
                {
                    using (var tx = envToSnapshot.NewTransaction(TransactionFlags.ReadWrite))
                    {
                        var tree = envToSnapshot.CreateTree(tx, "test");

                        for (int i = 0; i < 1000; i++)
                        {
                            tree.Add("users/" + i, "john doe/" + i);
                        }

                        tx.Commit();
                    }
                }

                var snapshotWriter = new MinimalIncrementalBackup();
                var backupPath = Path.Combine(_tempDir, "1.snapshot");
                snapshotWriter.ToFile(envToSnapshot, backupPath);

                using (var stream = File.OpenRead(backupPath))
                using (var zip = new ZipArchive(stream, ZipArchiveMode.Read))
                {
                    Assert.True(zip.Entries.Count > 1);
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:34,代码来源:MinimalIncrementalBackupTests.cs


示例3: DataIsKeptAfterRestart_OnDisk

        public void DataIsKeptAfterRestart_OnDisk()
        {
            if (Directory.Exists("test.data"))
                Directory.Delete("test.data", true);
            using (var pager = StorageEnvironmentOptions.ForPath("test.data"))
            {
                pager.OwnsPagers = false;
                using (var env = new StorageEnvironment(pager))
                {
                    using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                    {
                        tx.State.Root.Add("test/1", new MemoryStream());
                        tx.Commit();
                    }
                    using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                    {
                        tx.State.Root.Add("test/2", new MemoryStream());
                        tx.Commit();
                    }
                }

                using (var env = new StorageEnvironment(pager))
                {
                    using (var tx = env.NewTransaction(TransactionFlags.Read))
                    {
                        Assert.NotNull(tx.State.Root.Read("test/1"));
                        Assert.NotNull(tx.State.Root.Read("test/2"));
                        tx.Commit();
                    }
                }
            }
        }
开发者ID:jrusbatch,项目名称:ravendb,代码行数:32,代码来源:Restarts.cs


示例4: Execute

		public static void Execute(StorageEnvironmentOptions srcOptions, StorageEnvironmentOptions.DirectoryStorageEnvironmentOptions compactOptions, Action<CompactionProgress> progressReport = null)
		{
			if (srcOptions.IncrementalBackupEnabled)
				throw new InvalidOperationException(CannotCompactBecauseOfIncrementalBackup);

			long minimalCompactedDataFileSize;

			srcOptions.ManualFlushing = true; // prevent from flushing during compaction - we shouldn't touch any source files
			compactOptions.ManualFlushing = true; // let us flush manually during data copy

			using(var existingEnv = new StorageEnvironment(srcOptions))
			using (var compactedEnv = new StorageEnvironment(compactOptions))
			{
				CopyTrees(existingEnv, compactedEnv, progressReport);

				compactedEnv.FlushLogToDataFile(allowToFlushOverwrittenPages: true);

				compactedEnv.Journal.Applicator.SyncDataFile(compactedEnv.OldestTransaction);
				compactedEnv.Journal.Applicator.DeleteCurrentAlreadyFlushedJournal();

				minimalCompactedDataFileSize = compactedEnv.NextPageNumber*AbstractPager.PageSize;
			}

			using (var compactedDataFile = new FileStream(Path.Combine(compactOptions.BasePath, Constants.DatabaseFilename), FileMode.Open, FileAccess.ReadWrite))
			{
				compactedDataFile.SetLength(minimalCompactedDataFileSize);
			}
		}
开发者ID:jrusbatch,项目名称:ravendb,代码行数:28,代码来源:StorageCompaction.cs


示例5: IterationShouldNotFindAnyRecordsAndShouldNotThrowWhenNumberOfEntriesOnPageIs1AndKeyDoesNotMatch

		public void IterationShouldNotFindAnyRecordsAndShouldNotThrowWhenNumberOfEntriesOnPageIs1AndKeyDoesNotMatch()
		{
			using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
			{
				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					env.CreateTree(tx, "tree");

					tx.Commit();
				}

				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					var tree = tx.ReadTree("tree");
					tree.Add(@"Raven\Database\1", StreamFor("123"));

					tx.Commit();
				}

				using (var snapshot = env.CreateSnapshot())
				using (var iterator = snapshot.Iterate("tree"))
				{
					Assert.False(iterator.Seek(@"Raven\Filesystem\"));
				}
			}
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:26,代码来源:Iterating.cs


示例6: TableStorage

		public TableStorage(StorageEnvironment environment, IBufferPool bufferPool)
		{
			this.bufferPool = bufferPool;
			env = environment;

			Initialize();
		}
开发者ID:jrusbatch,项目名称:ravendb,代码行数:7,代码来源:TableStorage.cs


示例7: CanAddMultiValuesUnderTheSameKeyToBatch

        public void CanAddMultiValuesUnderTheSameKeyToBatch()
        {
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                var rand = new Random();
                var testBuffer = new byte[168];
                rand.NextBytes(testBuffer);

                CreateTrees(env, 1, "multitree");

                var batch = new WriteBatch();

                batch.MultiAdd("key", "value1", "multitree0");
                batch.MultiAdd("key", "value2", "multitree0");

                env.Writer.Write(batch);

                using (var tx = env.NewTransaction(TransactionFlags.Read))
                {
                    var tree = tx.Environment.CreateTree(tx,"multitree0");
                    using (var it = tree.MultiRead("key"))
                    {
                        Assert.True(it.Seek(Slice.BeforeAllKeys));

                        Assert.Equal("value1", it.CurrentKey.ToString());
                        Assert.True(it.MoveNext());

                        Assert.Equal("value2", it.CurrentKey.ToString());
                    }
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:32,代码来源:MultiAdds.cs


示例8: AllScratchPagesShouldBeReleased

        public void AllScratchPagesShouldBeReleased()
        {
            var options = StorageEnvironmentOptions.CreateMemoryOnly();
            options.ManualFlushing = true;
            using (var env = new StorageEnvironment(options))
            {
                using (var txw = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    env.CreateTree(txw, "test");

                    txw.Commit();
                }

                using (var txw = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    var tree = txw.Environment.CreateTree(txw, "test");

                    tree.Add("key/1", new MemoryStream(new byte[100]));
                    tree.Add("key/1", new MemoryStream(new byte[200]));
                    txw.Commit();
                }

                env.FlushLogToDataFile(); // non read nor write transactions, so it should flush and release everything from scratch

                // we keep track of the pages in scratch for one additional transaction, to avoid race
                // condition with FlushLogToDataFile concurrently with new read transactions
                Assert.Equal(2, env.ScratchBufferPool.GetNumberOfAllocations(0));
            }
        }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:29,代码来源:InvalidReleasesOfScratchPages.cs


示例9: DataIsKeptAfterRestart

        public void DataIsKeptAfterRestart()
        {
            using (var pureMemoryPager = StorageEnvironmentOptions.CreateMemoryOnly())
            {
                pureMemoryPager.OwnsPagers = false;
                using (var env = new StorageEnvironment(pureMemoryPager))
                {
                    using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                    {
                        tx.Root.Add			("test/1", new MemoryStream());
                        tx.Commit();
                    }
                    using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                    {
                        tx.Root.Add			("test/2", new MemoryStream());
                        tx.Commit();
                    }
                }

                using (var env = new StorageEnvironment(pureMemoryPager))
                {
                    using (var tx = env.NewTransaction(TransactionFlags.Read))
                    {
                        Assert.NotNull(tx.Root.Read("test/1"));
                        Assert.NotNull(tx.Root.Read("test/2"));
                        tx.Commit();
                    }
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:30,代码来源:Restarts.cs


示例10: ValidateMulti

		private void ValidateMulti(StorageEnvironment env, IEnumerable<string> trees)
		{
			using (var snapshot = env.CreateSnapshot())
			{
				foreach (var tree in trees)
				{
					using (var iterator = snapshot.MultiRead(tree, "test/0/user-50"))
					{
						Assert.True(iterator.Seek(Slice.BeforeAllKeys));

						var keys = new HashSet<string>();

						var count = 0;
						do
						{
							keys.Add(iterator.CurrentKey.ToString());
							Guid.Parse(iterator.CurrentKey.ToString());

							count++;
						}
						while (iterator.MoveNext());

						Assert.Equal(2, count);
						Assert.Equal(2, keys.Count);
					}
				}
			}
		}
开发者ID:randacc,项目名称:ravendb,代码行数:28,代码来源:TreeRebalancer.cs


示例11: ShouldWork

        public void ShouldWork()
        {
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    var s = new string('0', 500);
                    var tree = env.CreateTree(tx, "data");
                    for (int i = 0; i < 10; i++)
                    {
                        tree.Add("users-" + i + "-" + s, new byte[0]);
                    }
                    tx.Commit();
                }

                using (var tx = env.NewTransaction(TransactionFlags.Read))
                {
                    var tree = tx.State.GetTree(tx, "data");
                    using (var it = tree.Iterate())
                    {
                        Assert.True(it.Seek("users-7"));

                        for (int i = 0; i < 10; i++)
                        {
                            Assert.True(it.Seek("users-"+i),i.ToString());
                        }
                    }
                }
            }
        }
开发者ID:cocytus,项目名称:ravendb,代码行数:30,代码来源:StartsWithSearch.cs


示例12: ValidateRecords

        private void ValidateRecords(StorageEnvironment env, IEnumerable<string> trees, IList<string> ids)
        {
            using (var snapshot = env.CreateSnapshot())
            {
                foreach (var tree in trees)
                {
                    using (var iterator = snapshot.Iterate(tree))
                    {
                        Assert.True(iterator.Seek(Slice.BeforeAllKeys));

                        var keys = new HashSet<string>();

                        var count = 0;
                        do
                        {
                            keys.Add(iterator.CurrentKey.ToString());
                            Assert.True(ids.Contains(iterator.CurrentKey.ToString()), "Unknown key: " + iterator.CurrentKey);
                            Assert.NotNull(snapshot.Read(tree, iterator.CurrentKey));

                            count++;
                        }
                        while (iterator.MoveNext());

                        Assert.Equal(ids.Count, snapshot.Transaction.Environment.CreateTree(snapshot.Transaction,tree).State.EntriesCount);
                        Assert.Equal(ids.Count, count);
                        Assert.Equal(ids.Count, keys.Count);
                    }
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:30,代码来源:LargeValues.cs


示例13: AllScratchPagesShouldBeReleased

        public void AllScratchPagesShouldBeReleased()
        {
            var options = StorageEnvironmentOptions.CreateMemoryOnly();
            options.ManualFlushing = true;
            using (var env = new StorageEnvironment(options))
            {
                using (var txw = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    env.CreateTree(txw, "test");

                    txw.Commit();
                }

                using (var txw = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    var tree = txw.Environment.State.GetTree(txw, "test");

                    tree.Add("key/1", new MemoryStream(new byte[100]));
                    tree.Add("key/1", new MemoryStream(new byte[200]));
                    txw.Commit();
                }

                env.FlushLogToDataFile(); // non read nor write transactions, so it should flush and release everything from scratch

                Assert.Equal(0, env.ScratchBufferPool.GetNumberOfAllocations(0));
            }
        }
开发者ID:mattwarren,项目名称:LinqToMemory,代码行数:27,代码来源:InvalidReleasesOfScratchPages.cs


示例14: StorageRecoveryShouldWorkWhenThereAreCommitedAndUncommitedTransactions

		public void StorageRecoveryShouldWorkWhenThereAreCommitedAndUncommitedTransactions()
		{
			var path = "test2.data";

			DeleteDirectory(path);

			using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(path)))
			{
				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					env.CreateTree(tx, "tree");

					tx.Commit();
				}

				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					for (var i = 0; i < 10000; i++)
					{
						tx.Environment.State.GetTree(tx,"tree").Add("a" + i, new MemoryStream());
					}
				}
			}

			using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(path)))
			{
			}

			DeleteDirectory(path);
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:30,代码来源:Recovery.cs


示例15: StorageEnvironment_Two_Different_Tx_Should_be_shipped_properly1

		public void StorageEnvironment_Two_Different_Tx_Should_be_shipped_properly1()
		{
			var transactionsToShip = new ConcurrentQueue<TransactionToShip>();
			Env.Journal.OnTransactionCommit += tx =>
			{
				tx.CreatePagesSnapshot();
				transactionsToShip.Enqueue(tx);
			};

			using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
			{
				var tree = Env.CreateTree(tx, "TestTree");
				tree.Add("ABC", "Foo");
				tx.Commit();
			}

			using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
			{
				var tree = Env.CreateTree(tx, "TestTree2");
				tree.Add("ABC", "Foo");
				tx.Commit();
			}

			using (var shippingDestinationEnv = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
			{
				TransactionToShip tx;
				transactionsToShip.TryDequeue(out tx);
				shippingDestinationEnv.Journal.Shipper.ApplyShippedLog(tx.PagesSnapshot);

				using (var snaphsot = shippingDestinationEnv.CreateSnapshot())
				{
					Assert.DoesNotThrow(() => //if tree doesn't exist --> throws InvalidOperationException
					{
						var result = snaphsot.Read("TestTree", "ABC");
						Assert.Equal(1, result.Version);
						Assert.Equal("Foo", result.Reader.ToStringValue());
					});
				}

				transactionsToShip.TryDequeue(out tx);
				shippingDestinationEnv.Journal.Shipper.ApplyShippedLog(tx.PagesSnapshot);

				using (var snaphsot = shippingDestinationEnv.CreateSnapshot())
				{
					Assert.DoesNotThrow(() => //if tree doesn't exist --> throws InvalidOperationException
					{
						var result = snaphsot.Read("TestTree", "ABC");
						Assert.Equal(1, result.Version);
						Assert.Equal("Foo", result.Reader.ToStringValue());
					});

					Assert.DoesNotThrow(() => //if tree doesn't exist --> throws InvalidOperationException
					{
						var result = snaphsot.Read("TestTree2", "ABC");
						Assert.Equal(1, result.Version);
						Assert.Equal("Foo", result.Reader.ToStringValue());
					});
				}
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:60,代码来源:LogShipping.cs


示例16: PageSplitterShouldCalculateSeparatorKeyCorrectly2

        public void PageSplitterShouldCalculateSeparatorKeyCorrectly2()
        {
            var ids = ReadIds("data2.txt");

            StorageEnvironmentOptions storageEnvironmentOptions = StorageEnvironmentOptions.CreateMemoryOnly();
            storageEnvironmentOptions.MaxScratchBufferSize *=2;
            using (var env = new StorageEnvironment(storageEnvironmentOptions))
            {
                var rand = new Random();
                var testBuffer = new byte[69];
                rand.NextBytes(testBuffer);

                var trees = CreateTrees(env, 1, "tree");

                foreach (var id in ids)
                {
                    using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                    {
                        foreach (var treeName in trees)
                        {
                            var tree = tx.Environment.CreateTree(tx, treeName);
                            tree.Add(id, new MemoryStream(testBuffer));
                        }

                        tx.Commit();
                    }
                }

                ValidateRecords(env, trees, ids);
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:31,代码来源:PageSplitter.cs


示例17: DebugJournal

        public DebugJournal(string journalName, StorageEnvironment env, bool isRecordingByDefault = false)
        {
            _env = env;

            IsRecording = isRecordingByDefault;
            InitializeDebugJournal(journalName);
            _isDisposed = false;
        }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:8,代码来源:DebugJournal.cs


示例18: DefaultScratchLocation

 public void DefaultScratchLocation()
 {
     var options = (StorageEnvironmentOptions.DirectoryStorageEnvironmentOptions)StorageEnvironmentOptions.ForPath(path);
     using (var env = new StorageEnvironment(options))
     {
         var scratchFile = Path.Combine(path, "scratch.buffers");
         Assert.True(File.Exists(scratchFile));
     }
 }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:9,代码来源:Files.cs


示例19: FromFile

        public static DebugJournal FromFile(string journalName, StorageEnvironment env, bool onlyValueLength = false)
        {
            var newJournal = new DebugJournal(journalName, env)
                             {
                                 RecordOnlyValueLength = onlyValueLength
                             };

            return newJournal;
        }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:9,代码来源:DebugJournal.cs


示例20: CanBackupAndRestore

        public void CanBackupAndRestore()
        {
            RequireFileBasedPager();
			var random = new Random();
			var buffer = new byte[8192];
			random.NextBytes(buffer);

			using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
			{
				for (int i = 0; i < 500; i++)
				{
					tx.State.Root.Add("items/" + i, new MemoryStream(buffer));
				}

				tx.Commit();
			}

			Assert.True(Env.Journal.Files.Count > 1);

			Env.FlushLogToDataFile(); // force writing data to the data file
			 
			// add more data to journal files
			using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
			{
				for (int i = 500; i < 1000; i++)
				{
					tx.State.Root.Add("items/" + i, new MemoryStream(buffer));
				}

				tx.Commit();
			}

            Env.FlushLogToDataFile(); // force writing data to the data file - this won't sync data to disk because there was another sync withing last minute

			BackupMethods.Full.ToFile(Env, _backupFile);

			BackupMethods.Full.Restore(_backupFile, _recoveredStoragePath);

		    var options = StorageEnvironmentOptions.ForPath(_recoveredStoragePath);
		    options.MaxLogFileSize = Env.Options.MaxLogFileSize;

			using (var env = new StorageEnvironment(options))
			{
				using (var tx = env.NewTransaction(TransactionFlags.Read))
				{
					for (int i = 0; i < 1000; i++)
					{
						var readResult = tx.State.Root.Read("items/" + i);
						Assert.NotNull(readResult);
						var memoryStream = new MemoryStream();
						readResult.Reader.CopyTo(memoryStream);
						Assert.Equal(memoryStream.ToArray(), buffer);
					}
				}
			}
        }
开发者ID:VPashkov,项目名称:ravendb,代码行数:56,代码来源:Full.cs



注:本文中的StorageEnvironment类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# StorageEnvironmentOptions类代码示例发布时间:2022-05-24
下一篇:
C# StorageEntityContainerMapping类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap