/// <inheritdoc/>
 public void TruncateNamespace(string nsName)
 {
     using (var nsNameRx = nsName.GetHandle())
         Assert.ThrowIfError(() =>
                             ReindexerBinding.reindexer_truncate_namespace(Rx, nsNameRx, _ctxInfo)
                             );
 }
        public void ParallelModifyItemPacked()
        {
            var nsName = "ParallelTestNs";

            AssertError(ReindexerBinding.reindexer_open_namespace(_rx, nsName.GetHandle(),
                                                                  new StorageOpts {
                options = StorageOpt.kStorageOptCreateIfMissing | StorageOpt.kStorageOptEnabled
            },
                                                                  _ctxInfo));

            var indexDefJson = JsonSerializer.ToJsonString(
                new Index
            {
                Name      = "Id",
                IsPk      = true,
                FieldType = FieldType.Int64,
                IndexType = IndexType.Hash,
                JsonPaths = new List <string> {
                    "Id"
                }
            }, Utf8Json.Resolvers.StandardResolver.ExcludeNull);

            AssertError(ReindexerBinding.reindexer_add_index(_rx, nsName.GetHandle(), indexDefJson.GetHandle(), _ctxInfo));

            using (var ser1 = new CJsonWriter())
            {
                ser1.PutVString(nsName);
                ser1.PutVarCUInt((int)DataFormat.FormatJson);
                ser1.PutVarCUInt((int)ItemModifyMode.Upsert);
                ser1.PutVarCUInt(0);
                ser1.PutVarCUInt(0);

                reindexer_buffer.PinBufferFor(ser1.CurrentBuffer, args =>
                {
                    Parallel.For(0, 30000, i =>
                    {
                        var dataHandle = reindexer_buffer.From(Encoding.UTF8.GetBytes($"{{\"Id\":{i}, \"Guid\":\"{Guid.NewGuid()}\"}}"));
                        var rsp        = ReindexerBinding.reindexer_modify_item_packed(_rx, args, dataHandle.Buffer, _ctxInfo);
                        try
                        {
                            if (rsp.err_code != 0)
                            {
                                Assert.AreEqual(null, (string)rsp.@out);
                            }

                            Assert.AreNotEqual(UIntPtr.Zero, [email protected]_ptr);

                            var reader         = new CJsonReader(rsp.@out);
                            var rawQueryParams = reader.ReadRawQueryParams();

                            Assert.AreEqual(1, rawQueryParams.count);

                            reader.ReadRawItemParams();
                        }
                        finally
                        {
                            dataHandle.Dispose();
                            [email protected]();
                        }
                    });
                });
            }

            Thread.Sleep(6000);
#pragma warning disable S1215 // "GC.Collect" should not be called
            GC.Collect();
            GC.WaitForPendingFinalizers();
#pragma warning restore S1215 // "GC.Collect" should not be called
            AssertError(ReindexerBinding.reindexer_truncate_namespace(_rx, nsName.GetHandle(), _ctxInfo));
        }