当前位置: 首页>>代码示例>>C#>>正文


C# WriteBatch.Delete方法代码示例

本文整理汇总了C#中WriteBatch.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# WriteBatch.Delete方法的具体用法?C# WriteBatch.Delete怎么用?C# WriteBatch.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WriteBatch的用法示例。


在下文中一共展示了WriteBatch.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestIteratorWithSnapshot

        public void TestIteratorWithSnapshot()
        {
            using (var db = new DB(new Options { CreateIfMissing = true }, "test2.db"))
            {
                using (var batch = new WriteBatch())
                {
                    for (int i = 0; i < 100; i++)
                    {
                        batch.Put(Slice.FromString($"key::{i,20:D20}"), Slice.FromString($"{i,32}"));
                    }

                    db.Write(new WriteOptions { Sync = true }, batch);
                }

                using (var snapshot = db.GetSnapshot())
                using (var batch = new WriteBatch())
                using (var itr = db.NewIterator(new ReadOptions { Snapshot = snapshot }))
                {
                    itr.Seek(Slice.FromString("key::"));
                    Assert.IsTrue(itr.Valid());
                    int entriesDeleted = 0;
                    while (itr.Valid())
                    {
                        batch.Delete(itr.Key());
                        itr.Next();
                        entriesDeleted++;
                    }

                    db.Write(new WriteOptions(), batch);
                    Assert.AreEqual(100, entriesDeleted);
                }
            }
        }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:33,代码来源:BasicTests.cs

示例2: BatchConcurrencyExceptionShouldBeThrownWhenVersionMismatch

        public void BatchConcurrencyExceptionShouldBeThrownWhenVersionMismatch()
        {
            var batch1 = new WriteBatch();
            batch1.Add("key/1", StreamFor("123"), Constants.RootTreeName, 0);

            Env.Writer.Write(batch1);

            var batch2 = new WriteBatch();
            batch2.Add("key/1", StreamFor("123"), Constants.RootTreeName, 2);

            var e = Assert.Throws<AggregateException>(() => Env.Writer.Write(batch2)).InnerException;
            Assert.Equal("Cannot add 'key/1' to 'Root' tree. Version mismatch. Expected: 2. Actual: 1.", e.Message);

            var batch3 = new WriteBatch();
            batch3.Delete("key/1", Constants.RootTreeName, 2);

            e = Assert.Throws<AggregateException>(() => Env.Writer.Write(batch3)).InnerException;
            Assert.Equal("Cannot delete 'key/1' to 'Root' tree. Version mismatch. Expected: 2. Actual: 1.", e.Message);
        }
开发者ID:mattwarren,项目名称:LinqToMemory,代码行数:19,代码来源:Concurrency.cs

示例3: BatchConcurrencyExceptionShouldNotBeThrown2

        public void BatchConcurrencyExceptionShouldNotBeThrown2()
        {
            var batch1 = new WriteBatch();
            batch1.Add("key/1", StreamFor("123"), Constants.RootTreeName, 0);

            Env.Writer.Write(batch1);

            using (var snapshot = Env.CreateSnapshot())
            {
                var version = snapshot.ReadVersion(Constants.RootTreeName, "key/1", batch1);
                Assert.Equal(1, version);

                batch1 = new WriteBatch();
                batch1.Delete("key/1", Constants.RootTreeName);
                version = snapshot.ReadVersion(Constants.RootTreeName, "key/1", batch1);
                batch1.Add("key/1", StreamFor("123"), Constants.RootTreeName, version);

                Env.Writer.Write(batch1);
            }
        }
开发者ID:mattwarren,项目名称:LinqToMemory,代码行数:20,代码来源:Concurrency.cs

示例4: RebalancerIssue

		public void RebalancerIssue()
		{
			const int DocumentCount = 750;

			var rand = new Random();
			var testBuffer = new byte[757];
			rand.NextBytes(testBuffer);


			using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
			{
				Env.CreateTree(tx, "tree1");
				tx.Commit();
			}

			var batch = new WriteBatch();
			for (var i = 0; i < DocumentCount; i++)
			{
				batch.Add("Foo" + i, new MemoryStream(testBuffer), "tree1");
			}

			Env.Writer.Write(batch);

			batch = new WriteBatch();
			for (var i = 0; i < DocumentCount; i++)
			{
				if (i >= 180)
					continue;

				batch.Delete("Foo" + i, "tree1");
			}

			Env.Writer.Write(batch);

			using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
			{
			    var t1 = tx.Environment.State.GetTree(tx,"tree1");
				t1.Delete("Foo180"); // rebalancer fails to move 1st node from one branch to another
			}
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:40,代码来源:Deletes.cs

示例5: SplittersAndRebalancersShouldNotChangeNodeVersion

		public void SplittersAndRebalancersShouldNotChangeNodeVersion()
		{
			const int DocumentCount = 100000;

			var rand = new Random();
			var testBuffer = new byte[123];
			rand.NextBytes(testBuffer);

			Tree t1 = null;

			using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
			{
				t1 = Env.CreateTree(tx, "tree1");
				tx.Commit();
			}

			var batch = new WriteBatch();
			for (var i = 0; i < DocumentCount; i++)
			{
				batch.Add("Foo" + i, new MemoryStream(testBuffer), "tree1");
			}

			Env.Writer.Write(batch);

			batch = new WriteBatch();
			using (var snapshot = Env.CreateSnapshot())
			{
				for (var i = 0; i < DocumentCount; i++)
				{
					var result = snapshot.Read("tree1", "Foo" + 1, null);
					batch.Delete("Foo" + i, "tree1", result.Version);
				}
			}

			Env.Writer.Write(batch);
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:36,代码来源:Versioning.cs

示例6: DoDelete

		private Task<BenchmarkResult> DoDelete(BenchmarkParameters parameters, bool seq)
		{
			var random = new Random();
			var result = new BenchmarkResult(parameters);

			var tasks = new List<Task>(parameters.Num);

			for (var i = 0; i < parameters.Num; i += parameters.EntriesPerBatch)
			{
				var batch = new WriteBatch();
				for (var j = 0; j < parameters.EntriesPerBatch; j++)
				{
					var k = seq ? i + j : random.Next() % options.Num;
					var key = string.Format("{0:0000000000000000}", k);
					batch.Delete(key);
					result.FinishOperation();
				}

				tasks.Add(storage.Writer.WriteAsync(batch));
			}

			return Task.WhenAll(tasks).ContinueWith(t => result);
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:23,代码来源:Benchmark.cs

示例7: Delete

		public virtual void Delete(WriteBatch writeBatch, Slice key, ushort? expectedVersion = null)
		{
			writeBatch.Delete(key, TableName, expectedVersion);
		}
开发者ID:randacc,项目名称:ravendb,代码行数:4,代码来源:TableBase.cs

示例8: BatchDelete

		public void BatchDelete()
		{
			var batch1 = new WriteBatch();
            batch1.Add("key/1", StreamFor("123"), Constants.RootTreeName);

			Env.Writer.Write(batch1);

			using (var tx = Env.NewTransaction(TransactionFlags.Read))
			{
				Assert.Equal(1, tx.State.Root.ReadVersion("key/1"));
			}

			var batch2 = new WriteBatch();
            batch2.Delete("key/1", Constants.RootTreeName);

			Env.Writer.Write(batch2);

			using (var tx = Env.NewTransaction(TransactionFlags.Read))
			{
				Assert.Equal(0, tx.State.Root.ReadVersion("key/1"));
			}
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:22,代码来源:Concurrency.cs

示例9: CanWriteStructsByUsingWriteBatchAndReadFromSnapshot

		public void CanWriteStructsByUsingWriteBatchAndReadFromSnapshot()
		{
			var statsSchema = new StructureSchema<IndexingStatsFields>()
				.Add<int>(IndexingStatsFields.Attempts)
				.Add<int>(IndexingStatsFields.Errors)
				.Add<int>(IndexingStatsFields.Successes)
				.Add<string>(IndexingStatsFields.Message);

			var operationSchema = new StructureSchema<IndexingStatsFields>()
				.Add<int>(IndexingStatsFields.Attempts)
				.Add<int>(IndexingStatsFields.Successes)
				.Add<string>(IndexingStatsFields.Message);

			using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
			{
				Env.CreateTree(tx, "stats");
				Env.CreateTree(tx, "operations");

				tx.Commit();
			}
			var batch = new WriteBatch();

			batch.AddStruct("stats/1",
				new Structure<IndexingStatsFields>(statsSchema)
				.Set(IndexingStatsFields.Attempts, 5)
				.Set(IndexingStatsFields.Errors, -1)
				.Set(IndexingStatsFields.Successes, 4)
				.Set(IndexingStatsFields.Message, "hello world"),
				"stats");

			batch.AddStruct("operations/1",
				new Structure<IndexingStatsFields>(operationSchema)
				.Set(IndexingStatsFields.Attempts, 10)
				.Set(IndexingStatsFields.Successes, 10)
				.Set(IndexingStatsFields.Message, "hello world"),
				"operations");

			using (var snapshot = Env.CreateSnapshot())
			{
				var stats = snapshot.ReadStruct("stats", "stats/1", statsSchema, batch).Reader;

				Assert.Equal(5, stats.ReadInt(IndexingStatsFields.Attempts));
				Assert.Equal(-1, stats.ReadInt(IndexingStatsFields.Errors));
				Assert.Equal(4, stats.ReadInt(IndexingStatsFields.Successes));
				Assert.Equal("hello world", stats.ReadString(IndexingStatsFields.Message));
			}

			Env.Writer.Write(batch);

			using (var snapshot = Env.CreateSnapshot())
			{
				var operation = snapshot.ReadStruct("operations", "operations/1", operationSchema).Reader;

				Assert.Equal(10, operation.ReadInt(IndexingStatsFields.Attempts));
				Assert.Equal(10, operation.ReadInt(IndexingStatsFields.Successes));
				Assert.Equal("hello world", operation.ReadString(IndexingStatsFields.Message));
			}

			batch.Delete("stats/1", "stats");

			using (var snapshot = Env.CreateSnapshot())
			{
				var stats = snapshot.ReadStruct("stats", "stats/1", statsSchema, batch);

				Assert.Null(stats);
			}
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:67,代码来源:RavenDB_3114_WorkingWithStructs.cs

示例10: WhenLastBatchOperationVersionIsNullThenVersionComesFromStorage

        public void WhenLastBatchOperationVersionIsNullThenVersionComesFromStorage()
        {
            using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
            {
                Env.CreateTree(tx, "tree");
                tx.Environment.CreateTree(tx,"tree").Add("foo1", StreamFor("foo1"));

                tx.Commit();
            }

            using (var writeBatch = new WriteBatch())
            using (var snapshot = Env.CreateSnapshot())
            {
                writeBatch.Delete("foo1", "tree");

                var foo1Version = snapshot.ReadVersion("tree", "foo1", writeBatch);
                var foo1VersionThatShouldBe1 = snapshot.ReadVersion("tree", "foo1");

                Assert.Equal(1, foo1Version);
                Assert.Equal(1, foo1VersionThatShouldBe1);

                writeBatch.Add("foo1", StreamFor("123"), "tree");

                foo1Version = snapshot.ReadVersion("tree", "foo1", writeBatch);
                foo1VersionThatShouldBe1 = snapshot.ReadVersion("tree", "foo1");

                Assert.Equal(1, foo1Version);
                Assert.Equal(1, foo1VersionThatShouldBe1);
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:30,代码来源:Batches.cs

示例11: Read_Items_From_Both_WriteBatch_And_Snapshot_Deleted_Key_Returns_Null

        public void Read_Items_From_Both_WriteBatch_And_Snapshot_Deleted_Key_Returns_Null()
        {
            using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
            {
                Env.CreateTree(tx, "tree");
                tx.Environment.CreateTree(tx,"tree").Add("foo1", StreamFor("foo1"));

                tx.Commit();
            }

            using (var writeBatch = new WriteBatch())
            using (var snapshot = Env.CreateSnapshot())
            {
                writeBatch.Delete("foo1", "tree");

                var foo1ReadResult = snapshot.Read("tree", "foo1", writeBatch);
                var foo1ReadResultWithoutWriteBatch = snapshot.Read("tree", "foo1");

                Assert.Null(foo1ReadResult);
                Assert.NotNull(foo1ReadResultWithoutWriteBatch);

                Assert.Equal(foo1ReadResultWithoutWriteBatch.Reader.ToStringValue(), "foo1");
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:24,代码来源:Batches.cs

示例12: Delete

 public virtual void Delete(WriteBatch writeBatch, Slice key, ushort? expectedVersion = null, bool shouldIgnoreConcurrencyExceptions = false)
 {
     writeBatch.Delete(key, TableName, expectedVersion, shouldIgnoreConcurrencyExceptions);
 }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:4,代码来源:TableBase.cs

示例13: 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);
//.........这里部分代码省略.........
开发者ID:cocytus,项目名称:ravendb,代码行数:101,代码来源:DebugJournalTest.cs

示例14: TestWriteBatch

        public void TestWriteBatch()
        {
            var path = CleanTestDB();

            using (var db = new DB(path, new Options { CreateIfMissing = true }))
            {
                db.Put("NA", "Na");

                using (var batch = new WriteBatch())
                {
                    batch.Delete("NA")
                         .Put("Tampa", "Green")
                         .Put("London", "red")
                         .Put("New York", "blue");
                    db.Write(batch);
                }

                var expected = new[] { "London", "New York", "Tampa" };
                var actual = from kv in db as IEnumerable<KeyValuePair<string, string>>
                             select kv.Key;

                CollectionAssert.AreEqual(expected, actual.ToArray());
            }
        }
开发者ID:ren85,项目名称:leveldb.net,代码行数:24,代码来源:ReactiveTests.cs

示例15: Replay

        public void Replay()
        {
            var wasDebugRecording = _env.IsDebugRecording;
            _env.IsDebugRecording = false;

            using (var writeBatch = new WriteBatch())
            {
                ActivityEntry entry;
                while (WriteQueue.TryDequeue(out entry))
                {
                    switch (entry.ActionType)
                    {
                        case DebugActionType.Add:
                            writeBatch.Add(entry.Key, entry.ValueStream, entry.TreeName);
                            break;
                        case DebugActionType.Delete:
                            writeBatch.Delete(entry.Key, entry.TreeName);
                            break;
                        case DebugActionType.MultiAdd:
                            writeBatch.MultiAdd(entry.Key, new Slice(Encoding.UTF8.GetBytes(entry.Value.ToString())), entry.TreeName);
                            break;
                        case DebugActionType.MultiDelete:
                            writeBatch.MultiDelete(entry.Key, new Slice(Encoding.UTF8.GetBytes(entry.Value.ToString())), entry.TreeName);
                            break;
                        case DebugActionType.CreateTree:
                            using (var tx = _env.NewTransaction(TransactionFlags.ReadWrite))
                            {
                                _env.CreateTree(tx, entry.TreeName);
                                tx.Commit();
                            }
                            break;
                        default: //precaution against newly added action types
                            throw new InvalidOperationException("unsupported tree action type");
                    }
                }

                _env.Writer.Write(writeBatch);
            }

            _env.IsDebugRecording = wasDebugRecording; //restore the state as it was
        }
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:41,代码来源:DebugJournal.cs


注:本文中的WriteBatch.Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。