示例#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));
 }
示例#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));
 }
示例#3
0
            private void WriteExpiration(ExpirationConfiguration expiration)
            {
                if (expiration == null)
                {
                    _writer.WriteNull();
                    return;
                }

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

            await ExpirationHelper.SetupExpiration(store, Server.ServerStore, config);
        }
示例#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();
     }
 }
示例#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();
     }
 }
示例#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);
        }
示例#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();
            }
        }
示例#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();
            }
        }
示例#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();
            }
        }
示例#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();
            }
示例#12
0
        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);
        }
示例#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);
                        }
                }
            }
        }
示例#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;
 }
示例#16
0
 public EditExpirationCommand(ExpirationConfiguration configuration, string databaseName) : base(databaseName)
 {
     Configuration = configuration;
 }
示例#17
0
 public ConfigureExpirationCommand(ExpirationConfiguration configuration, string databaseName)
 {
     _configuration = configuration;
     _databaseName  = databaseName;
 }