当前位置: 首页>>代码示例>>C#>>正文


C# StorageEnvironment.CreateSnapshot方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: FillBatchReadBatchOneTransaction

		private static void FillBatchReadBatchOneTransaction(Stopwatch sw, int iterations)
		{
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(Path)))
			{
				sw.Start();
				using (var tx = env.NewTransaction(TransactionFlags.Read))
				{
					var ms = new byte[100];

					var batch = new WriteBatch();
					for (int i = 0; i < iterations; i++)
					{
						var key = i.ToString("0000000000000000");
						batch.Add(key, new MemoryStream(), null);
					}

					using (var snapshot = env.CreateSnapshot())
					{
						for (int i = 0; i < iterations; i++)
						{
							var key = i.ToString("0000000000000000");

							var read = snapshot.Read(null, key, batch).Reader;
							{
								while (read.Read(ms, 0, ms.Length) != 0)
								{
								}
							}
						}
					}

					tx.Commit();
				}
				sw.Stop();
			}
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:36,代码来源:Program.cs

示例6: Main

		public static void Main()
		{
			
			var basePath = @"C:\Work\ravendb-3.0\Raven.Voron\Voron.Tryout\bin\Debug\v4";

			var win = new Win32MemoryMapPager(Path.Combine(basePath, "v2", "Raven.voron"));
			var lin = new Win32MemoryMapPager(Path.Combine(basePath, "v2l", "Raven.voron"));

			var winPage = (PageHeader*)win.AcquirePagePointer(0);
			var linPage = (PageHeader*)lin.AcquirePagePointer(0);

			return;
			var path = "v4";
			if (Directory.Exists(path))
				Directory.Delete(path, true);
			Console.WriteLine(Process.GetCurrentProcess().Id);
			using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(path)))
			{
				var batch = new WriteBatch();
				batch.Add("[email protected]", "Oren Eini", "Names");
				env.Writer.Write(batch);

				using (var snp = env.CreateSnapshot())
				{
					var reader = snp.Read("Names", "[email protected]");
					if (reader == null)
					{
						Console.WriteLine("Couldn't find it");
					}
					else
					{
						Console.WriteLine(reader.Reader.ToStringValue());
					}
				}
			}

			using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(path)))
			{
				//				using (var snp = env.CreateSnapshot()) 
				//				{
				//					var reader = snp.Read ("Names", "[email protected]");
				//					if (reader == null) 
				//					{
				//						Console.WriteLine ("Couldn't find it");
				//					} 
				//					else 
				//					{
				//						Console.WriteLine (reader.Reader.ToStringValue());
				//					}
				//				}
			}


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

				using (var snp = env.CreateSnapshot())
				{
					var reader = snp.Read("Names", "[email protected]");
					if (reader == null)
					{
						Console.WriteLine("Couldn't find it");
					}
					else
					{
						Console.WriteLine(reader.Reader.ToStringValue());
					}
				}
			}
			Console.WriteLine("Done");
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:71,代码来源:Program.cs

示例7: Record_debug_journal_and_replay_it_with_manual_flushing

        public void Record_debug_journal_and_replay_it_with_manual_flushing()
        {
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                env.DebugJournal = new DebugJournal(debugJouralName, env, true);
                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    env.CreateTree(tx, "test-tree");
                    tx.Commit();
                }

                using (var writeBatch = new WriteBatch())
                {
                    var valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("{ \"title\": \"foo\",\"name\":\"bar\"}"));
                    writeBatch.Add("foo", valueBuffer, "test-tree");
                    env.Writer.Write(writeBatch);
                }

                using (env.Options.AllowManualFlushing())
                {
                    env.FlushLogToDataFile();
                }

                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                using (env.Options.AllowManualFlushing())
                {
                    env.FlushLogToDataFile(tx);
                    tx.Commit();
                }
            }

            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                env.DebugJournal = DebugJournal.FromFile(debugJouralName, env);
                env.DebugJournal.Replay();

                using (var snapshot = env.CreateSnapshot())
                {
                    Assert.Equal("{ \"title\": \"foo\",\"name\":\"bar\"}", snapshot.Read("test-tree", "foo").Reader.ToStringValue());
                }
            }

        }
开发者ID:cocytus,项目名称:ravendb,代码行数:43,代码来源:DebugJournalTest.cs

示例8: Record_debug_journal_and_replay_it

		public void Record_debug_journal_and_replay_it()
		{
			using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
			{
				env.DebugJournal = new DebugJournal(debugJouralName, env, true);
				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					env.CreateTree(tx, "test-tree");
					tx.Commit();
				}

				using (var writeBatch = new WriteBatch())
				{
					var valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("{ \"title\": \"foo\",\"name\":\"bar\"}"));
					writeBatch.Add("foo", valueBuffer, "test-tree");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2!"));
					writeBatch.Add("bar", valueBuffer, "test-tree");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2 3!"));
					writeBatch.Add("foo-bar", valueBuffer, "test-tree");

					writeBatch.MultiAdd("multi-foo", "AA", "test-tree");
					env.Writer.Write(writeBatch);
				}

                using (var writeBatch = new WriteBatch())
                {
                    writeBatch.Increment("incr-key", 5, "test-tree");
                    env.Writer.Write(writeBatch);
                }

                using (var tx = env.NewTransaction(TransactionFlags.Read))
                {
                    Assert.Equal(5, tx.ReadTree("test-tree").Read("incr-key").Reader.ReadLittleEndianInt64());

                    using (var writeBatch = new WriteBatch())
                    {
                        writeBatch.Increment("incr-key", 5, "test-tree");
                        env.Writer.Write(writeBatch);
                    }

                    Assert.Equal(5, tx.ReadTree("test-tree").Read("incr-key").Reader.ReadLittleEndianInt64());
                }

			    using (var tx = env.NewTransaction(TransactionFlags.Read))
			    {
                    Assert.Equal(10, tx.ReadTree("test-tree").Read("incr-key").Reader.ReadLittleEndianInt64());
			    }

			    using (var writeBatch = new WriteBatch())
				{
					writeBatch.MultiAdd("multi-foo", "BB", "test-tree");
					writeBatch.MultiAdd("multi-foo", "CC", "test-tree");

					writeBatch.Delete("foo-bar", "test-tree");
					env.Writer.Write(writeBatch);
				}

				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					env.CreateTree(tx, "test-tree2");
					tx.Commit();
				}

				using (var writeBatch = new WriteBatch())
				{
					var valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1!"));
					writeBatch.Add("foo", valueBuffer, "test-tree2");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2!"));
					writeBatch.Add("bar", valueBuffer, "test-tree2");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2 3!"));
					writeBatch.Add("foo-bar", valueBuffer, "test-tree2");
					env.Writer.Write(writeBatch);
				}
			}

			using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
			{
				env.DebugJournal = DebugJournal.FromFile(debugJouralName, env);
				env.DebugJournal.Replay();

				using (var snapshot = env.CreateSnapshot())
				{
					Assert.Equal("{ \"title\": \"foo\",\"name\":\"bar\"}", snapshot.Read("test-tree", "foo").Reader.ToStringValue());
				    Assert.Equal("testing testing 1 2!", snapshot.Read("test-tree", "bar").Reader.ToStringValue());

				    Assert.Equal("testing testing 1!", snapshot.Read("test-tree2", "foo").Reader.ToStringValue());
				    Assert.Equal("testing testing 1 2!", snapshot.Read("test-tree2", "bar").Reader.ToStringValue());
				    Assert.Equal("testing testing 1 2 3!", snapshot.Read("test-tree2", "foo-bar").Reader.ToStringValue());

                    Assert.Equal(10, snapshot.Read("test-tree", "incr-key").Reader.ReadLittleEndianInt64());

					Assert.Equal(0,snapshot.ReadVersion("test-tree","foo-bar"));

					using (var iter = snapshot.MultiRead("test-tree","multi-foo"))
					{
						iter.Seek(Slice.BeforeAllKeys);
//.........这里部分代码省略.........
开发者ID:cocytus,项目名称:ravendb,代码行数:101,代码来源:DebugJournalTest.cs

示例9: StorageEnvironment_should_be_able_to_accept_transactionsToShip_with_new_trees_no_flushing

		public void StorageEnvironment_should_be_able_to_accept_transactionsToShip_with_new_trees_no_flushing()
		{
			var transactionsToShip = new ConcurrentBag<TransactionToShip>();

			using (var shippingSourceEnv = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
			{
				shippingSourceEnv.Journal.OnTransactionCommit += tx =>
				{
					tx.CreatePagesSnapshot();
					transactionsToShip.Add(tx);
				};

				using (var tx = shippingSourceEnv.NewTransaction(TransactionFlags.ReadWrite))
				{
					shippingSourceEnv.CreateTree(tx, "TestTree");
					tx.Commit();
				}
			}

			var storageEnvironmentOptions = StorageEnvironmentOptions.CreateMemoryOnly();
			storageEnvironmentOptions.ManualFlushing = true;
			using (var shippingDestinationEnv = new StorageEnvironment(storageEnvironmentOptions))
			{
				foreach (var tx in transactionsToShip)
					shippingDestinationEnv.Journal.Shipper.ApplyShippedLog(tx.PagesSnapshot);

				using (var snapshot = shippingDestinationEnv.CreateSnapshot())
				{
					snapshot.Read("TestTree", "Foo");
				}
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:32,代码来源:LogShipping.cs

示例10: StorageEnvironment_should_be_able_to_accept_transactionsToShip_with_LOTS_of_transactions

		public void StorageEnvironment_should_be_able_to_accept_transactionsToShip_with_LOTS_of_transactions()
		{
			var transactionsToShip = new List<TransactionToShip>();
			using (var shippingSourceEnv = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
			{
				shippingSourceEnv.Journal.OnTransactionCommit += tx =>
				{
					tx.CreatePagesSnapshot();
					transactionsToShip.Add(tx);
				};

				using (var tx = shippingSourceEnv.NewTransaction(TransactionFlags.ReadWrite))
				{
					shippingSourceEnv.CreateTree(tx, "TestTree");
					shippingSourceEnv.CreateTree(tx, "TestTree2");
					tx.Commit();
				}

				WriteLotsOfTestDataForTree("TestTree", shippingSourceEnv);
				WriteLotsOfTestDataForTree("TestTree2", shippingSourceEnv);
			}


			var storageEnvironmentOptions = StorageEnvironmentOptions.CreateMemoryOnly();
			storageEnvironmentOptions.ManualFlushing = true;
			using (var shippingDestinationEnv = new StorageEnvironment(storageEnvironmentOptions))
			{
				foreach (var tx in transactionsToShip)
					shippingDestinationEnv.Journal.Shipper.ApplyShippedLog(tx.PagesSnapshot);

				shippingDestinationEnv.FlushLogToDataFile();

				using (var snapshot = shippingDestinationEnv.CreateSnapshot())
				{
					ValidateLotsOfTestDataForTree(snapshot, "TestTree");
					ValidateLotsOfTestDataForTree(snapshot, "TestTree2");
				}
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:39,代码来源:LogShipping.cs

示例11: StorageEnvironment_should_be_able_to_accept_transactionsToShip

		public void StorageEnvironment_should_be_able_to_accept_transactionsToShip()
		{
			var transactionsToShip = new List<TransactionToShip>();
			Env.Journal.OnTransactionCommit += tx =>
			{
				tx.CreatePagesSnapshot();
				transactionsToShip.Add(tx);
			};

			WriteTestDataToEnv();
			using (var shippingDestinationEnv = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
			{
				foreach (var tx in transactionsToShip)
					shippingDestinationEnv.Journal.Shipper.ApplyShippedLog(tx.PagesSnapshot);
				using (var snapshot = shippingDestinationEnv.CreateSnapshot())
				{
					var fooReadResult = snapshot.Read("TestTree", "foo");
					Assert.NotNull(fooReadResult);

					var fooValue = Encoding.UTF8.GetString(fooReadResult.Reader.AsStream().ReadData());
					Assert.Equal("bar", fooValue);

					var barReadResult = snapshot.Read("TestTree", "bar");
					Assert.NotNull(barReadResult);

					var barValue = Encoding.UTF8.GetString(barReadResult.Reader.AsStream().ReadData());
					Assert.Equal("foo", barValue);
				}
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:30,代码来源:LogShipping.cs


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