public void CanOpenAfterCompaction() { var memoryPersistentSource = new MemoryPersistentSource(); var tableStorage = new TableStorage(memoryPersistentSource); tableStorage.Initialze(); tableStorage.BeginTransaction(); tableStorage.Documents.Put(new JObject { {"key", "1"}, {"etag", Guid.NewGuid().ToByteArray()}, {"modified", DateTime.UtcNow}, {"id", 1}, {"entityName", "test"} }, new byte[512] ); tableStorage.Documents.Put(new JObject { {"key", "2"}, {"etag", Guid.NewGuid().ToByteArray()}, {"modified", DateTime.UtcNow}, {"id", 1}, {"entityName", "test"} }, new byte[512] ); tableStorage.Commit(); tableStorage.BeginTransaction(); tableStorage.Documents.Remove(new JObject { { "key", "1" } }); tableStorage.Commit(); tableStorage.Compact(); var remoteManagedStorageState = memoryPersistentSource.CreateRemoteAppDomainState(); new TableStorage(new MemoryPersistentSource(remoteManagedStorageState.Log)).Initialze(); }
public bool Initialize(IUuidGenerator generator, OrderedPartCollection<AbstractDocumentCodec> documentCodecs) { DocumentCodecs = documentCodecs; uuidGenerator = generator; if (configuration.RunInMemory == false && Directory.Exists(configuration.DataDirectory) == false) Directory.CreateDirectory(configuration.DataDirectory); persistenceSource = configuration.RunInMemory ? (IPersistentSource)new MemoryPersistentSource() : new FileBasedPersistentSource(configuration.DataDirectory, "Raven", configuration.TransactionMode == TransactionMode.Safe); tableStroage = new TableStorage(persistenceSource); idleTimer = new Timer(MaybeOnIdle, null, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30)); tableStroage.Initialze(); if (persistenceSource.CreatedNew) { Id = Guid.NewGuid(); Batch(accessor => tableStroage.Details.Put("id", Id.ToByteArray())); } else { using(tableStroage.BeginTransaction()) { var readResult = tableStroage.Details.Read("id"); Id = new Guid(readResult.Data()); } } return persistenceSource.CreatedNew; }