本文整理汇总了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\"));
}
}
}
示例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);
}
}
}
}
示例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());
});
}
}
}
示例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);
}
}
}
}
示例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();
}
}
示例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");
}
示例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());
}
}
}
示例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);
//.........这里部分代码省略.........
示例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");
}
}
}
示例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");
}
}
}
示例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);
}
}
}