本文整理汇总了C#中StorageEnvironment.CreateTree方法的典型用法代码示例。如果您正苦于以下问题:C# StorageEnvironment.CreateTree方法的具体用法?C# StorageEnvironment.CreateTree怎么用?C# StorageEnvironment.CreateTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StorageEnvironment
的用法示例。
在下文中一共展示了StorageEnvironment.CreateTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
}
}
}
}
示例2: 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\"));
}
}
}
示例3: 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));
}
}
示例4: 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));
}
}
示例5: Can_make_multiple_min_inc_backups_and_then_restore
public void Can_make_multiple_min_inc_backups_and_then_restore()
{
const int UserCount = 5000;
_tempDir = Guid.NewGuid().ToString();
var storageEnvironmentOptions = StorageEnvironmentOptions.ForPath(_tempDir);
storageEnvironmentOptions.IncrementalBackupEnabled = true;
using (var envToSnapshot = new StorageEnvironment(storageEnvironmentOptions))
{
int index = 0;
for (int xi = 0; xi < 5; xi++)
{
for (int yi = 0; yi < 2; yi++)
{
using (var tx = envToSnapshot.NewTransaction(TransactionFlags.ReadWrite))
{
var tree = envToSnapshot.CreateTree(tx, "test");
for (int i = 0; i < UserCount / 10; i++)
{
tree.Add("users/" + index, "john doe/" + index);
index++;
}
tx.Commit();
}
}
var snapshotWriter = new MinimalIncrementalBackup();
snapshotWriter.ToFile(envToSnapshot, Path.Combine(_tempDir, xi + ".snapshot"));
}
}
var incremental = new IncrementalBackup();
var restoredOptions = StorageEnvironmentOptions.ForPath(Path.Combine(_tempDir, "restored"));
incremental.Restore(restoredOptions, Enumerable.Range(0, 5).Select(i => Path.Combine(_tempDir, i + ".snapshot")));
using (var snapshotRestoreEnv = new StorageEnvironment(restoredOptions))
{
using (var tx = snapshotRestoreEnv.NewTransaction(TransactionFlags.Read))
{
var tree = tx.ReadTree("test");
Assert.NotNull(tree);
for (int i = 0; i < UserCount; i++)
{
var readResult = tree.Read("users/" + i);
Assert.NotNull(readResult);
Assert.Equal("john doe/" + i, readResult.Reader.ToStringValue());
}
}
}
}
示例6: ShouldBeAbleToWriteValuesGreaterThanLogAndRecoverThem
public void ShouldBeAbleToWriteValuesGreaterThanLogAndRecoverThem()
{
DeleteDirectory("test2.data");
var random = new Random(1234);
var buffer = new byte[1024 * 512];
random.NextBytes(buffer);
var options = StorageEnvironmentOptions.ForPath("test2.data");
options.MaxLogFileSize = 10 * AbstractPager.PageSize;
using (var env = new StorageEnvironment(options))
{
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
env.CreateTree(tx, "tree");
tx.Commit();
}
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
tx.Environment.State.GetTree(tx,"tree").Add("key1", new MemoryStream(buffer));
tx.Commit();
}
}
options = StorageEnvironmentOptions.ForPath("test2.data");
options.MaxLogFileSize = 10 * AbstractPager.PageSize;
using (var env = new StorageEnvironment(options))
{
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
env.CreateTree(tx, "tree");
tx.Commit();
}
using (var tx = env.NewTransaction(TransactionFlags.Read))
{
var read = tx.Environment.State.GetTree(tx,"tree").Read("key1");
Assert.NotNull(read);
{
Assert.Equal(buffer.Length, read.Reader.Length);
int used;
Assert.Equal(buffer, read.Reader.ReadBytes(read.Reader.Length, out used).Take(used).ToArray());
}
}
}
DeleteDirectory("test2.data");
}
示例7: StorageRecoveryShouldWorkWhenThereSingleTransactionToRecoverFromLog
public void StorageRecoveryShouldWorkWhenThereSingleTransactionToRecoverFromLog()
{
var path = "test2.data";
DeleteDirectory(path);
using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(path)))
{
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
var tree = env.CreateTree(tx, "tree");
for (var i = 0; i < 100; i++)
{
tree.Add("key" + i, new MemoryStream());
}
tx.Commit();
}
}
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.Read))
{
var tree = tx.Environment.State.GetTree(tx,"tree");
for (var i = 0; i < 100; i++)
{
Assert.NotNull(tree.Read("key" + i));
}
}
}
DeleteDirectory(path);
}
示例8: MultiAdds_And_MultiDeletes_After_Causing_PageSplit_DoNot_Fail
public void MultiAdds_And_MultiDeletes_After_Causing_PageSplit_DoNot_Fail(int size)
{
using (var Env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
{
var inputData = new List<byte[]>();
for (int i = 0; i < size; i++)
{
inputData.Add(Encoding.UTF8.GetBytes(RandomString(1024)));
}
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
Env.CreateTree(tx, "foo");
tx.Commit();
}
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
var tree = tx.Environment.State.GetTree(tx,"foo");
foreach (var buffer in inputData)
{
Assert.DoesNotThrow(() => tree.MultiAdd(tx, "ChildTreeKey", new Slice(buffer)));
}
tx.Commit();
}
using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
{
var tree = tx.Environment.State.GetTree(tx,"foo");
for (int i = 0; i < inputData.Count; i++)
{
var buffer = inputData[i];
Assert.DoesNotThrow(() => tree.MultiDelete(tx, "ChildTreeKey", new Slice(buffer)));
}
tx.Commit();
}
}
}
示例9: DataIsKeptAfterRestartForSubTrees
public void DataIsKeptAfterRestartForSubTrees()
{
using (var pureMemoryPager = StorageEnvironmentOptions.CreateMemoryOnly())
{
pureMemoryPager.OwnsPagers = false;
using (var env = new StorageEnvironment(pureMemoryPager))
{
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
env.CreateTree(tx, "test");
tx.Commit();
}
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
var tree = tx.Environment.CreateTree(tx,"test");
tree.Add("test", Stream.Null);
tx.Commit();
Assert.NotNull(tree.Read("test"));
}
}
using (var env = new StorageEnvironment(pureMemoryPager))
{
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
var tree = env.CreateTree(tx, "test");
tx.Commit();
}
using (var tx = env.NewTransaction(TransactionFlags.Read))
{
var tree = tx.Environment.CreateTree(tx,"test");
Assert.NotNull(tree.Read("test"));
tx.Commit();
}
}
}
}
示例10: ShouldCorrectlyLoadAfterRestartIfIncrementalBackupWasDone
public void ShouldCorrectlyLoadAfterRestartIfIncrementalBackupWasDone()
{
var bytes = new byte[1024];
new Random().NextBytes(bytes);
using (var env = new StorageEnvironment(ModifyOptions(StorageEnvironmentOptions.ForPath("Data"))))
{
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
env.CreateTree(tx, "items");
tx.Commit();
}
for (int j = 0; j < 100; j++)
{
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
var tree = tx.ReadTree("items");
for (int i = 0; i < 100; i++)
{
tree.Add("items/" + i, bytes);
}
tx.Commit();
}
}
BackupMethods.Incremental.ToFile(env, IncrementalBackupTestUtils.IncrementalBackupFile(0));
}
// restart
using (var env = new StorageEnvironment(ModifyOptions(StorageEnvironmentOptions.ForPath("Data"))))
{
}
}
示例11: CannotCompactStorageIfIncrementalBackupEnabled
public void CannotCompactStorageIfIncrementalBackupEnabled()
{
var envOptions = StorageEnvironmentOptions.ForPath(CompactionTestsData);
envOptions.IncrementalBackupEnabled = true;
using (var env = new StorageEnvironment(envOptions))
{
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
var tree = env.CreateTree(tx, "records");
tree.Add("record/1", new byte[9]);
tree.Add("record/2", new byte[9]);
tx.Commit();
}
}
var srcOptions = StorageEnvironmentOptions.ForPath(CompactionTestsData);
srcOptions.IncrementalBackupEnabled = true;
var invalidOperationException = Assert.Throws<InvalidOperationException>(() => StorageCompaction.Execute(srcOptions, (StorageEnvironmentOptions.DirectoryStorageEnvironmentOptions)StorageEnvironmentOptions.ForPath(CompactedData)));
Assert.Equal(StorageCompaction.CannotCompactBecauseOfIncrementalBackup, invalidOperationException.Message);
}
示例12: StorageRecoveryShouldWorkForSplitTransactions
public void StorageRecoveryShouldWorkForSplitTransactions()
{
var random = new Random(1234);
var buffer = new byte[4096];
random.NextBytes(buffer);
var path = "test2.data";
var count = 1000;
DeleteDirectory(path);
var options = StorageEnvironmentOptions.ForPath(path);
options.MaxLogFileSize = 10 * AbstractPager.PageSize;
using (var env = new StorageEnvironment(options))
{
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
env.CreateTree(tx, "atree");
env.CreateTree(tx, "btree");
tx.Commit();
}
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
var aTree = tx.Environment.State.GetTree(tx,"atree");
var bTree = tx.Environment.State.GetTree(tx,"btree");
for (var i = 0; i < count; i++)
{
aTree.Add("a" + i, new MemoryStream(buffer));
bTree.MultiAdd("a", "a" + i);
}
tx.Commit();
}
}
var expectedString = Encoding.UTF8.GetString(buffer);
options = StorageEnvironmentOptions.ForPath(path);
options.MaxLogFileSize = 10 * AbstractPager.PageSize;
using (var env = new StorageEnvironment(options))
{
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
env.CreateTree(tx, "atree");
env.CreateTree(tx, "btree");
tx.Commit();
}
using (var tx = env.NewTransaction(TransactionFlags.Read))
{
var aTree = tx.Environment.State.GetTree(tx,"atree");
var bTree = tx.Environment.State.GetTree(tx,"btree");
for (var i = 0; i < count; i++)
{
var read = aTree.Read("a" + i);
Assert.NotNull(read);
Assert.Equal(expectedString, read.Reader.ToStringValue());
}
using (var iterator = bTree.MultiRead("a"))
{
Assert.True(iterator.Seek(Slice.BeforeAllKeys));
var keys = new HashSet<string>();
do
{
keys.Add(iterator.CurrentKey.ToString());
}
while (iterator.MoveNext());
Assert.Equal(count, keys.Count);
}
}
}
DeleteDirectory(path);
}
示例13: CreateTrees
private IList<string> CreateTrees(StorageEnvironment env, int number, string prefix)
{
var results = new List<string>();
using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
{
for (var i = 0; i < number; i++)
{
results.Add(env.CreateTree(tx, prefix + i).Name);
}
tx.Commit();
}
return results;
}
示例14: 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);
//.........这里部分代码省略.........
示例15: 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");
}
}
}