Beispiel #1
0
        public Compact()
        {
            using (var store = new DocumentStore())
            {
                #region compact_3
                CompactSettings settings = new CompactSettings
                {
                    DatabaseName = "Northwind",
                    Documents    = true,
                    Indexes      = new[] { "Orders/Totals", "Orders/ByCompany" }
                };
                Operation operation = store.Maintenance.Server.Send(new CompactDatabaseOperation(settings));
                operation.WaitForCompletion();
                #endregion
            }
            using (var store = new DocumentStore())
            {
                #region compact_4
                // get all index names
                string[] indexNames = store.Maintenance.Send(new GetIndexNamesOperation(0, int.MaxValue));

                CompactSettings settings = new CompactSettings
                {
                    DatabaseName = "Northwind",
                    Documents    = true,
                    Indexes      = indexNames
                };
                // compact entire database: documents + all indexes
                Operation operation = store.Maintenance.Server.Send(new CompactDatabaseOperation(settings));
                operation.WaitForCompletion();
                #endregion
            }
        }
        public void CompactarBancoDeDados(string databaseName)
        {
            // Get all index names
            var indexNames = Maintenance.Send(new GetIndexNamesOperation(0, int.MaxValue));

            var settings = new CompactSettings
            {
                DatabaseName = databaseName,
                Documents    = true,
                Indexes      = indexNames
            };

            // Compact entire database: documents + all indexes
            var operation = Maintenance.Server.Send(new CompactDatabaseOperation(settings));

            operation.WaitForCompletion();
        }
Beispiel #3
0
        public void Should_Not_Throw_Nre_When_Compacting_Not_Existing_Index()
        {
            using (var documentStore = GetDocumentStore(new Options
            {
                RunInMemory = false
            }))
            {
                var settings = new CompactSettings
                {
                    DatabaseName = documentStore.Database,
                    Documents    = true,
                    Indexes      = new[] { "DoesNotExist" }
                };

                var operation = documentStore.Maintenance.Server.Send(new CompactDatabaseOperation(settings));
                operation.WaitForCompletion();
            }
        }
Beispiel #4
0
            public CompactDatabaseCommand(DocumentConventions conventions, JsonOperationContext context, CompactSettings compactSettings)
            {
                if (conventions == null)
                {
                    throw new ArgumentNullException(nameof(conventions));
                }
                if (compactSettings == null)
                {
                    throw new ArgumentNullException(nameof(compactSettings));
                }
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                _compactSettings = EntityToBlittable.ConvertCommandToBlittable(compactSettings, context);
            }
Beispiel #5
0
 public CompactDatabaseOperation(CompactSettings compactSettings)
 {
     _compactSettings = compactSettings ?? throw new ArgumentNullException(nameof(compactSettings));
 }
Beispiel #6
0
        public async Task CompressAllCollectionsAfterCompactDatabaseCalled()
        {
            var dbname = "CompressAllCollectionsDB";

            using var store = GetDocumentStore(new Options
            {
                ModifyDatabaseName = (name) => dbname,
                RunInMemory        = false
            });

            using (var session = store.OpenAsyncSession())
            {
                var arr = new string[100000];
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = "stv";
                }

                var arr2 = new string[100000];
                for (int i = 0; i < arr2.Length; i++)
                {
                    arr2[i] = "val";
                }

                var user = new User {
                    arr = arr
                };
                var company = new Company {
                    arr = arr2
                };

                await session.StoreAsync(user, "users/1");

                await session.StoreAsync(company, "companies/1");

                await session.SaveChangesAsync();
            }

            var  executor = store.GetRequestExecutor();
            long originalCompanySize, originalUserSize;

            using (var _ = executor.ContextPool.AllocateOperationContext(out var ctx))
            {
                var companySize = new DocCompression.GetDocumentSize("companies/1");
                await executor.ExecuteAsync(companySize, ctx);

                originalCompanySize = companySize.Result.AllocatedSize;

                var userSize = new DocCompression.GetDocumentSize("users/1");
                await executor.ExecuteAsync(userSize, ctx);

                originalUserSize = userSize.Result.AllocatedSize;
            }

            //turn on compression
            var record = store.Maintenance.Server.Send(new GetDatabaseRecordOperation(store.Database));

            record.DocumentsCompression = new DocumentsCompressionConfiguration(false, true);
            store.Maintenance.Server.Send(new UpdateDatabaseOperation(record, record.Etag));

            //run compact database
            CompactSettings settings = new CompactSettings
            {
                DatabaseName = dbname,
                Documents    = true
            };
            var operation = await store.Maintenance.Server.SendAsync(new CompactDatabaseOperation(settings));

            await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(5));

            long compressedUserSize, compressedCompanySize;

            using (var _ = executor.ContextPool.AllocateOperationContext(out var ctx))
            {
                var companySize = new DocCompression.GetDocumentSize("companies/1");
                await executor.ExecuteAsync(companySize, ctx);

                compressedCompanySize = companySize.Result.AllocatedSize;

                var userSize = new DocCompression.GetDocumentSize("users/1");
                await executor.ExecuteAsync(userSize, ctx);

                compressedUserSize = userSize.Result.AllocatedSize;
            }

            Assert.True(originalCompanySize * 0.25 > compressedCompanySize);
            Assert.True(originalUserSize * 0.25 > compressedUserSize);
        }
            public CompactDatabaseCommand(DocumentConventions conventions, JsonOperationContext context, CompactSettings compactSettings)
            {
                if (conventions == null)
                {
                    throw new ArgumentNullException(nameof(conventions));
                }
                if (compactSettings == null)
                {
                    throw new ArgumentNullException(nameof(compactSettings));
                }
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                _compactSettings = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(compactSettings, context);
            }