public void TestSetConcurrent(int concurrency) { int j = 0; using (var db = new PlaneDB(new DirectoryInfo("testdb"), FileMode.CreateNew, planeDBOptions.UsingTableSpace(concurrency.ToString()))) { void Adder() { int i; while ((i = Interlocked.Increment(ref j)) < COUNT) { var k = Encoding.UTF8.GetBytes(i.ToString()); var v = Encoding.UTF8.GetBytes(i.ToString() + i + i + i + i); db[k] = v; } } var threads = Enumerable.Range(0, concurrency).Select(_ => new Thread(Adder)).ToArray(); foreach (var thread in threads) { thread.Start(); } foreach (var thread in threads) { thread.Join(); } } j = 0; using (var db = new PlaneDB(new DirectoryInfo("testdb"), FileMode.Open, planeDBOptions.UsingTableSpace(concurrency.ToString()))) { void Reader() { int i; while ((i = Interlocked.Increment(ref j)) < COUNT) { var k = Encoding.UTF8.GetBytes(i.ToString()); var v = Encoding.UTF8.GetString(db[k]); Assert.AreEqual(v, i.ToString() + i + i + i + i); } } var threads = Enumerable.Range(0, concurrency).Select(_ => new Thread(Reader)).ToArray(); foreach (var thread in threads) { thread.Start(); } foreach (var thread in threads) { thread.Join(); } } }
public override void Execute() { var popts = new PlaneDBOptions().DisableJournal().WithBlockCacheCapacity(2_048); if (!string.IsNullOrEmpty(Owner.Passphrase)) { popts = popts.EnableEncryption(Owner.Passphrase); } else if (Owner.Compressed) { popts = popts.EnableCompression(); } if (DB == null || DB.Length != 1) { throw new GetOptException("No database specified"); } var db = DB[0]; if (!string.IsNullOrEmpty(Owner.Tablespace)) { InfoOne(db, popts.UsingTableSpace(Owner.Tablespace)); } else if (AllTablespaces) { foreach (var tableSpace in Options.GetTableSpaces(db)) { InfoOne(db, popts.UsingTableSpace(tableSpace)); } } else { InfoOne(db, popts); } }
public override void Execute() { var popts = new PlaneDBOptions().DisableJournal(); if (!string.IsNullOrEmpty(Owner.Passphrase)) { popts = popts.EnableEncryption(Owner.Passphrase); } else if (Owner.Compressed) { popts = popts.EnableCompression(); } if (!string.IsNullOrEmpty(Owner.Tablespace)) { popts = popts.UsingTableSpace(Owner.Tablespace); } if (From == null) { throw new GetOptException("No from"); } if (To == null) { throw new GetOptException("No to"); } using var rocks = RocksDb.OpenReadOnly(new DbOptions(), From.FullName, false); using var plane = new PlaneDB(To, FileMode.OpenOrCreate, popts); plane.OnFlushMemoryTable += (_, __) => Console.WriteLine("Flushed memory table"); plane.OnMergedTables += (_, __) => Console.WriteLine("Merged tables"); plane.Clear(); var iter = rocks.NewIterator(); plane.MassInsert(() => CopyFromRocks(plane, iter)); Console.WriteLine($"{copyCount:N0} entries copied in total"); }