本文整理汇总了C#中KeyValueDB.CalcStats方法的典型用法代码示例。如果您正苦于以下问题:C# KeyValueDB.CalcStats方法的具体用法?C# KeyValueDB.CalcStats怎么用?C# KeyValueDB.CalcStats使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyValueDB
的用法示例。
在下文中一共展示了KeyValueDB.CalcStats方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddingContinueToNewFileAfterReopenWithCorruption
public void AddingContinueToNewFileAfterReopenWithCorruption()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, _key1);
tr.Commit();
}
}
fileCollection.SimulateCorruptionBySetSize(20 + 16);
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
Assert.Equal(0, tr.GetKeyValueCount());
tr.CreateOrUpdateKeyValue(Key2, Key2);
tr.Commit();
}
Console.WriteLine(db.CalcStats());
}
Assert.True(2 <= fileCollection.GetCount());
}
}
示例2: AddingContinueToSameFileAfterReopen
public void AddingContinueToSameFileAfterReopen()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, _key1);
tr.Commit();
}
}
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(Key2, Key2);
tr.Commit();
}
Console.WriteLine(db.CalcStats());
}
Assert.Equal(2u, fileCollection.GetCount()); // Log + Index
}
}
示例3: FastCleanUpOnStartRemovesUselessFiles
public void FastCleanUpOnStartRemovesUselessFiles()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (var db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, new byte[1024]);
tr.CreateOrUpdateKeyValue(Key2, new byte[1024]);
tr.Commit();
}
using (var tr = db.StartTransaction())
{
tr.EraseAll();
tr.Commit();
}
Assert.Equal(3u, fileCollection.GetCount()); // 3 Logs
}
using (var db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
{
Console.WriteLine(db.CalcStats());
Assert.Equal(2u, fileCollection.GetCount()); // 1 Log, 1 KeyIndex
}
}
}
示例4: Main
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Need to have just one parameter with directory of ObjectDB");
return;
}
var action = "dump";
if (args.Length > 1)
{
action = args[1].ToLowerInvariant();
}
switch (action)
{
case "dump":
{
using (var dfc = new OnDiskFileCollection(args[0]))
using (var kdb = new KeyValueDB(dfc))
using (var odb = new ObjectDB())
{
odb.Open(kdb, false);
using (var tr = odb.StartTransaction())
{
var visitor = new ToStringVisitor();
var iterator = new ODBIterator(tr, visitor);
iterator.Iterate();
var text = visitor.ToString();
Console.WriteLine(text);
}
}
break;
}
case "stat":
{
using (var dfc = new OnDiskFileCollection(args[0]))
using (var kdb = new KeyValueDB(dfc))
{
Console.WriteLine(kdb.CalcStats());
}
break;
}
case "compact":
{
using (var dfc = new OnDiskFileCollection(args[0]))
using (var kdb = new KeyValueDB(dfc, new SnappyCompressionStrategy(), 100 * 1024 * 1024, null))
{
Console.WriteLine("Starting first compaction");
while (kdb.Compact(new CancellationToken()))
{
Console.WriteLine(kdb.CalcStats());
Console.WriteLine("Another compaction needed");
}
Console.WriteLine(kdb.CalcStats());
}
break;
}
case "export":
{
using (var dfc = new OnDiskFileCollection(args[0]))
using (var kdb = new KeyValueDB(dfc))
using (var tr = kdb.StartReadOnlyTransaction())
using (var st = File.Create(Path.Combine(args[0], "export.dat")))
{
KeyValueDBExportImporter.Export(tr, st);
}
break;
}
default:
{
Console.WriteLine($"Unknown action: {action}");
break;
}
}
}
示例5: CompactionWaitsForFinishingOldTransactionsBeforeRemovingFiles
public void CompactionWaitsForFinishingOldTransactionsBeforeRemovingFiles()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (var db = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, new byte[1024]);
tr.CreateOrUpdateKeyValue(Key2, new byte[10]);
tr.Commit();
}
var longTr = db.StartTransaction();
using (var tr = db.StartTransaction())
{
tr.FindExactKey(_key1);
tr.EraseCurrent();
tr.Commit();
}
db.Compact();
Thread.Sleep(2000);
Console.WriteLine(db.CalcStats());
Assert.True(4 <= fileCollection.GetCount()); // 2 Logs, 1 Value, 1 KeyIndex, (optinal 1 Unknown (old KeyIndex))
longTr.Dispose();
Thread.Sleep(1000);
Assert.Equal(2u, fileCollection.GetCount()); // 1 Log, 1 KeyIndex
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key3, new byte[10]);
tr.Commit();
}
using (var db2 = new KeyValueDB(fileCollection, new NoCompressionStrategy(), 1024))
{
using (var tr = db2.StartTransaction())
{
Assert.True(tr.FindExactKey(_key3));
}
}
}
}
}
示例6: HugeTest
public void HugeTest()
{
const int keyCount = 100;
using (var fileCollection = CreateTestFileCollection())
{
_sw.Start();
using (IKeyValueDB db = CreateKeyValueDB(fileCollection, new NoCompressionStrategy()))
{
var key = new byte[100];
var value = new byte[100000000];
for (int i = 0; i < keyCount; i++)
{
using (var tr = db.StartTransaction())
{
key[0] = (byte)(i / 100);
key[1] = (byte)(i % 100);
value[100] = (byte)(i / 100);
value[200] = (byte)(i % 100);
tr.CreateOrUpdateKeyValue(key, value);
tr.Commit();
}
}
}
_sw.Stop();
Console.WriteLine("Time to create 10GB DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds);
_sw.Restart();
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
_sw.Stop();
Console.WriteLine("Time to open 10GB DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds);
_sw.Restart();
var key = new byte[100];
for (int i = 0; i < keyCount; i++)
{
using (var tr = db.StartTransaction())
{
key[0] = (byte)(i / 100);
key[1] = (byte)(i % 100);
tr.FindExactKey(key);
var value = tr.GetValueAsByteArray();
if (value[100] != (byte)(i / 100)) throw new InvalidDataException();
if (value[200] != (byte)(i % 100)) throw new InvalidDataException();
}
}
_sw.Stop();
Console.WriteLine("Time to read all values 10GB DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds);
Console.WriteLine(db.CalcStats());
}
_sw.Restart();
using (IKeyValueDB db = CreateKeyValueDB(fileCollection))
{
_sw.Stop();
Console.WriteLine("Time to open2 10GB DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds);
_sw.Restart();
var key = new byte[100];
for (int i = 0; i < keyCount; i++)
{
using (var tr = db.StartTransaction())
{
key[0] = (byte)(i / 100);
key[1] = (byte)(i % 100);
tr.FindExactKey(key);
var value = tr.GetValueAsByteArray();
if (value[100] != (byte)(i / 100)) throw new InvalidDataException();
if (value[200] != (byte)(i % 100)) throw new InvalidDataException();
}
}
_sw.Stop();
Console.WriteLine("Time to read2 all values 10GB DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds);
Console.WriteLine(db.CalcStats());
}
}
}