Beispiel #1
0
 private static async Task SetupExpiration(DocumentStore store)
 {
     var config = new ExpirationConfiguration
     {
         Disabled             = false,
         DeleteFrequencyInSec = 100,
     };
     await store.Maintenance.Server.SendAsync(new ConfigureExpirationOperation(config, store.Database));
 }
Beispiel #2
0
 private static async Task SetupExpiration(DocumentStore store)
 {
     var config = new ExpirationConfiguration
     {
         Active = true,
         DeleteFrequencyInSec = 100,
     };
     await store.Admin.Server.SendAsync(new ConfigureExpirationOperation(config, store.Database));
 }
Beispiel #3
0
            private void WriteExpiration(ExpirationConfiguration expiration)
            {
                if (expiration == null)
                {
                    _writer.WriteNull();
                    return;
                }

                _context.Write(_writer, expiration.ToJson());
            }
Beispiel #4
0
        private async Task SetupExpiration(DocumentStore store)
        {
            var config = new ExpirationConfiguration
            {
                Disabled             = false,
                DeleteFrequencyInSec = 100,
            };

            await ExpirationHelper.SetupExpiration(store, Server.ServerStore, config);
        }
Beispiel #5
0
 private static void SetupExpiration(IDocumentStore store)
 {
     using (var session = store.OpenSession())
     {
         var config = new ExpirationConfiguration
         {
             Active = true,
             DeleteFrequencyInSec = 100,
         };
         store.Admin.Server.Send(new ConfigureExpirationOperation(config, store.Database));
         session.SaveChanges();
     }
 }
Beispiel #6
0
 private static void SetupExpiration(IDocumentStore store)
 {
     using (var session = store.OpenSession())
     {
         var config = new ExpirationConfiguration
         {
             Disabled             = false,
             DeleteFrequencyInSec = 100,
         };
         store.Maintenance.Send(new ConfigureExpirationOperation(config));
         session.SaveChanges();
     }
 }
Beispiel #7
0
        private async Task <bool> DisableExpiration(IDocumentStore store)
        {
            var config = new ExpirationConfiguration
            {
                Disabled             = true,
                DeleteFrequencyInSec = 100,
            };

            await ExpirationHelper.SetupExpiration(store, Server.ServerStore, config);

            var database = await Databases.GetDocumentDatabaseInstanceFor(store);

            return(database.ExpiredDocumentsCleaner != null);
        }
Beispiel #8
0
        private static async Task SetupExpiration(DocumentStore store)
        {
            using (var session = store.OpenAsyncSession())
            {
                var config = new ExpirationConfiguration
                {
                    Active = true,
                    DeleteFrequencyInSec = 100,
                };
                await store.Admin.Server.SendAsync(new ConfigureExpirationOperation(config, store.Database));

                await session.SaveChangesAsync();
            }
        }
Beispiel #9
0
        private static async Task SetupExpiration(DocumentStore store)
        {
            using (var session = store.OpenAsyncSession())
            {
                var config = new ExpirationConfiguration
                {
                    Disabled             = false,
                    DeleteFrequencyInSec = 100,
                };
                await store.Maintenance.SendAsync(new ConfigureExpirationOperation(config));

                await session.SaveChangesAsync();
            }
        }
Beispiel #10
0
        private async Task SetupExpiration(DocumentStore store)
        {
            using (var session = store.OpenAsyncSession())
            {
                var config = new ExpirationConfiguration
                {
                    Disabled             = false,
                    DeleteFrequencyInSec = 100,
                };

                await ExpirationHelper.SetupExpiration(store, Server.ServerStore, config);

                await session.SaveChangesAsync();
            }
        }
Beispiel #11
0
            private void WriteExpiration(ExpirationConfiguration expiration)
            {
                if (expiration == null)
                {
                    _writer.WriteNull();
                    return;
                }

                _writer.WriteStartObject();

                _writer.WritePropertyName(nameof(expiration.Disabled));
                _writer.WriteBool(expiration.Disabled);

                if (expiration.DeleteFrequencyInSec.HasValue)
                {
                    _writer.WriteComma();
                    _writer.WritePropertyName(nameof(expiration.DeleteFrequencyInSec));
                    _writer.WriteString(expiration.DeleteFrequencyInSec.Value.ToString());
                }

                _writer.WriteEndObject();
            }
        public static async Task SetupExpiration(IDocumentStore store, Raven.Server.ServerWide.ServerStore serverStore, ExpirationConfiguration configuration)
        {
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }
            if (serverStore == null)
            {
                throw new ArgumentNullException(nameof(serverStore));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var result = await store.Maintenance.SendAsync(new ConfigureExpirationOperation(configuration));

            var documentDatabase = await serverStore.DatabasesLandlord.TryGetOrCreateResourceStore(store.Database);

            await documentDatabase.RachisLogIndexNotifications.WaitForIndexNotification(result.RaftCommandIndex.Value, serverStore.Engine.OperationTimeout);
        }
Beispiel #13
0
        public async Task CanDeleteAllExpiredDocsAfterRunningTheExpirationBundle()
        {
            using (var store = GetDocumentStore())
            {
                var config = new ExpirationConfiguration
                {
                    Disabled             = false,
                    DeleteFrequencyInSec = 1000
                };

                await ExpirationHelper.SetupExpiration(store, Server.ServerStore, config);

                var expiry = SystemTime.UtcNow.AddMinutes(-5);

                var deleteList = new List <string>();

                var batchSize = 10;
                var batches   = 5;
                for (var i = 0; i < batches; i++)
                {
                    using (var session = store.OpenAsyncSession())
                    {
                        for (var j = 0; j < batchSize; j++)
                        {
                            var item = new Item();
                            await session.StoreAsync(item);

                            deleteList.Add(item.Id);
                            var metadata = session.Advanced.GetMetadataFor(item);
                            metadata[Constants.Documents.Metadata.Expires] = expiry.ToString(DefaultFormat.DateTimeOffsetFormatsToWrite);
                        }

                        await session.SaveChangesAsync();
                    }
                }

                using (var session = store.OpenAsyncSession())
                {
                    foreach (var toDelete in deleteList)
                    {
                        session.Delete(toDelete);
                    }

                    await session.SaveChangesAsync();
                }

                string lastId;
                using (var session = store.OpenAsyncSession())
                {
                    var item = new Item();
                    await session.StoreAsync(item);

                    lastId = item.Id;
                    var metadata = session.Advanced.GetMetadataFor(item);
                    metadata[Constants.Documents.Metadata.Expires] = SystemTime.UtcNow.AddMinutes(-1).ToString(DefaultFormat.DateTimeOffsetFormatsToWrite);

                    await session.SaveChangesAsync();
                }

                var database = await Databases.GetDocumentDatabaseInstanceFor(store);

                ValidateTotalExpirationCount(batchSize);

                var expiredDocumentsCleaner = database.ExpiredDocumentsCleaner;
                await expiredDocumentsCleaner.CleanupExpiredDocs(batchSize);

                ValidateTotalExpirationCount(0);

                using (var session = store.OpenAsyncSession())
                {
                    var item = await session.LoadAsync <Item>(lastId);

                    Assert.Null(item);
                }

                void ValidateTotalExpirationCount(int expected)
                {
                    using (database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                        using (context.OpenReadTransaction())
                        {
                            var currentTime = database.Time.GetUtcNow();
                            var options     = new ExpirationStorage.ExpiredDocumentsOptions(context, currentTime, false, batchSize);

                            var expired    = database.DocumentsStorage.ExpirationStorage.GetExpiredDocuments(options, out _, CancellationToken.None);
                            var totalCount = 0;
                            if (expired != null)
                            {
                                foreach (var singleExpired in expired)
                                {
                                    totalCount += singleExpired.Value.Count;
                                }
                            }

                            Assert.Equal(expected, totalCount);
                        }
                }
            }
        }
Beispiel #14
0
 protected bool Equals(ExpirationConfiguration other)
 {
     return(Active == other.Active && DeleteFrequencyInSec == other.DeleteFrequencyInSec);
 }
 public EditExpirationCommand(ExpirationConfiguration configuration, string databaseName, string uniqueRequestId) : base(databaseName, uniqueRequestId)
 {
     Configuration = configuration;
 }
Beispiel #16
0
 public EditExpirationCommand(ExpirationConfiguration configuration, string databaseName) : base(databaseName)
 {
     Configuration = configuration;
 }
Beispiel #17
0
 public ConfigureExpirationCommand(ExpirationConfiguration configuration, string databaseName)
 {
     _configuration = configuration;
     _databaseName  = databaseName;
 }