本文整理汇总了C#中StorageEnvironment类的典型用法代码示例。如果您正苦于以下问题:C# StorageEnvironment类的具体用法?C# StorageEnvironment怎么用?C# StorageEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StorageEnvironment类属于命名空间,在下文中一共展示了StorageEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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);
}
}
}
示例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();
}
}
}
}
示例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);
}
}
示例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\"));
}
}
}
示例6: TableStorage
public TableStorage(StorageEnvironment environment, IBufferPool bufferPool)
{
this.bufferPool = bufferPool;
env = environment;
Initialize();
}
示例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());
}
}
}
}
示例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));
}
}
示例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();
}
}
}
}
示例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);
}
}
}
}
示例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());
}
}
}
}
}
示例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);
}
}
}
}
示例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));
}
}
示例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);
}
示例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());
});
}
}
}