public void Batch(Action<IStorageActionsAccessor> action) { var tableStorage = new TableStorage(persistentSource); tableStorage.Initialze(); var accessor = new StorageActionsAccessor(tableStorage, new DummyUuidGenerator(), new AbstractDocumentCodec[0]); action(accessor); }
public void Batch(Action<IStorageActionsAccessor> action) { var tableStorage = new TableStorage(persistentSource); tableStorage.Initialze(); var accessor = new StorageActionsAccessor(tableStorage); action(accessor); }
public DocumentsStorageActions(TableStorage storage, ITransactionStorageActions transactionStorageActions, IUuidGenerator generator, IEnumerable<AbstractDocumentCodec> documentCodecs) { this.storage = storage; this.transactionStorageActions = transactionStorageActions; this.generator = generator; this.documentCodecs = documentCodecs; }
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 static void AssertNotModifiedByAnotherTransaction(TableStorage storage, ITransactionStorageActions transactionStorageActions, string key, Table.ReadResult readResult, TransactionInformation transactionInformation) { if (readResult == null) return; var txIdAsBytes = readResult.Key.Value<byte[]>("txId"); if (txIdAsBytes == null) return; var txId = new Guid(txIdAsBytes); if (transactionInformation != null && transactionInformation.Id == txId) { return; } var existingTx = storage.Transactions.Read(new RavenJObject { { "txId", txId.ToByteArray() } }); if (existingTx == null)//probably a bug, ignoring this as not a real tx return; var timeout = existingTx.Key.Value<DateTime>("timeout"); if (SystemTime.UtcNow > timeout) { transactionStorageActions.RollbackTransaction(txId); return; } throw new ConcurrencyException("Document '" + key + "' is locked by transacton: " + txId); }
public void Batch(Action<IStorageActionsAccessor> action) { using (var tableStorage = new TableStorage(persistentSource)) { tableStorage.Initialze(); var accessor = new StorageActionsAccessor(tableStorage, new DummyUuidGenerator(), new OrderedPartCollection<AbstractDocumentCodec>()); action(accessor); } }
public StorageActionsAccessor(TableStorage storage, IUuidGenerator generator, OrderedPartCollection<AbstractDocumentCodec> documentCodecs, IDocumentCacher documentCacher) { General = new GeneralStorageActions(storage); Attachments = new AttachmentsStorageActions(storage, generator); Transactions = new TransactionStorageActions(storage, generator, documentCodecs); Documents = new DocumentsStorageActions(storage, Transactions, generator, documentCodecs, documentCacher); Indexing = new IndexingStorageActions(storage); MappedResults = new MappedResultsStorageAction(storage, generator); Queue = new QueueStorageActions(storage, generator); Tasks = new TasksStorageActions(storage, generator); Staleness = new StalenessStorageActions(storage); }
public StorageActionsAccessor(TableStorage storage, IUuidGenerator generator) { General = new GeneralStorageActions(storage); Attachments = new AttachmentsStorageActions(storage, generator); Transactions = new TransactionStorageActions(storage, generator); Documents = new DocumentsStorageActions(storage, Transactions, generator); Indexing = new IndexingStorageActions(storage); MappedResults = new MappedResultsStorageAction(storage, generator); Queue = new QueueStorageActions(storage, generator); Tasks = new TasksStorageActions(storage, generator); Staleness = new StalenessStorageActions(storage); }
public StorageActionsAccessor(TableStorage storage, IUuidGenerator generator, IEnumerable<AbstractDocumentCodec> documentCodecs) { this.documentCodecs = documentCodecs; General = new GeneralStorageActions(storage); Attachments = new AttachmentsStorageActions(storage, generator); Transactions = new TransactionStorageActions(storage, generator, documentCodecs); Documents = new DocumentsStorageActions(storage, Transactions, generator, documentCodecs); Indexing = new IndexingStorageActions(storage); MappedResults = new MappedResultsStorageAction(storage, generator); Queue = new QueueStorageActions(storage, generator); Tasks = new TasksStorageActions(storage, generator); Staleness = new StalenessStorageActions(storage); }
public DocumentsStorageActions(TableStorage storage, ITransactionStorageActions transactionStorageActions, IUuidGenerator generator) { this.storage = storage; this.transactionStorageActions = transactionStorageActions; this.generator = generator; }
public void Compact(InMemoryRavenConfiguration compactConfiguration) { using (var ps = new FileBasedPersistentSource(compactConfiguration.DataDirectory, "Raven", configuration.TransactionMode == TransactionMode.Safe)) using (var storage = new TableStorage(ps)) { storage.Compact(); } }
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; }
public QueueStorageActions(TableStorage storage, IUuidGenerator generator) { this.storage = storage; this.generator = generator; }
public bool Initialize() { 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); 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 { var readResult = tableStroage.Details.Read("id"); Id = new Guid(readResult.Data()); } return persistenceSource.CreatedNew; }
public GeneralStorageActions(TableStorage storage) { this.storage = storage; }
public MappedResultsStorageAction(TableStorage storage, IUuidGenerator generator, OrderedPartCollection<AbstractDocumentCodec> documentCodecs) { this.storage = storage; this.generator = generator; this.documentCodecs = documentCodecs; }
public DocumentsStorageActions(TableStorage storage, ITransactionStorageActions transactionStorageActions) { this.storage = storage; this.transactionStorageActions = transactionStorageActions; }
public TasksStorageActions(TableStorage storage) { this.storage = storage; }
public AttachmentsStorageActions(TableStorage storage, IUuidGenerator generator) { this.storage = storage; this.generator = generator; }
public TransactionStorageActions(TableStorage storage, IUuidGenerator generator, OrderedPartCollection<AbstractDocumentCodec> documentCodecs) { this.storage = storage; this.generator = generator; this.documentCodecs = documentCodecs; }
public QueueStorageActions(TableStorage storage) { this.storage = storage; }
public StalenessStorageActions(TableStorage storage) { this.storage = storage; }
public IndexingStorageActions(TableStorage storage) { this.storage = storage; }
public MappedResultsStorageAction(TableStorage storage, IUuidGenerator generator) { this.storage = storage; this.generator = generator; }
public void CanProperlyHandleDeletingThreeItemsBothFromPK_And_SecondaryIndexes() { var cmds = new[] { @"{""Cmd"":""Put"",""Key"":{""index"":""Raven/DocumentsByEntityName"",""id"":""AAAAAAAAAAEAAAAAAAAABQ=="",""time"":""\/Date(1290420997504)\/"",""type"":""Raven.Database.Tasks.RemoveFromIndexTask"",""mergeable"":true},""TableId"":9,""TxId"":""NiAAMOT72EC/We7rnZS/Fw==""}" , @"{""Cmd"":""Put"",""Key"":{""index"":""Raven/DocumentsByEntityName"",""id"":""AAAAAAAAAAEAAAAAAAAABg=="",""time"":""\/Date(1290420997509)\/"",""type"":""Raven.Database.Tasks.RemoveFromIndexTask"",""mergeable"":true},""TableId"":9,""TxId"":""NiAAMOT72EC/We7rnZS/Fw==""}" , @"{""Cmd"":""Put"",""Key"":{""index"":""Raven/DocumentsByEntityName"",""id"":""AAAAAAAAAAEAAAAAAAAABw=="",""time"":""\/Date(1290420997509)\/"",""type"":""Raven.Database.Tasks.RemoveFromIndexTask"",""mergeable"":true},""TableId"":9,""TxId"":""NiAAMOT72EC/We7rnZS/Fw==""}" , @"{""Cmd"":""Commit"",""TableId"":9,""TxId"":""NiAAMOT72EC/We7rnZS/Fw==""}", @"{""Cmd"":""Del"",""Key"":{""index"":""Raven/DocumentsByEntityName"",""id"":""AAAAAAAAAAEAAAAAAAAABg=="",""time"":""\/Date(1290420997509)\/"",""type"":""Raven.Database.Tasks.RemoveFromIndexTask"",""mergeable"":true},""TableId"":9,""TxId"":""wM3q3VA0XkWecl5WBr9Cfw==""}" , @"{""Cmd"":""Del"",""Key"":{""index"":""Raven/DocumentsByEntityName"",""id"":""AAAAAAAAAAEAAAAAAAAABw=="",""time"":""\/Date(1290420997509)\/"",""type"":""Raven.Database.Tasks.RemoveFromIndexTask"",""mergeable"":true},""TableId"":9,""TxId"":""wM3q3VA0XkWecl5WBr9Cfw==""}" , @"{""Cmd"":""Del"",""Key"":{""index"":""Raven/DocumentsByEntityName"",""id"":""AAAAAAAAAAEAAAAAAAAABQ=="",""time"":""\/Date(1290420997504)\/"",""type"":""Raven.Database.Tasks.RemoveFromIndexTask"",""mergeable"":true},""TableId"":9,""TxId"":""wM3q3VA0XkWecl5WBr9Cfw==""}" , @"{""Cmd"":""Commit"",""TableId"":9,""TxId"":""wM3q3VA0XkWecl5WBr9Cfw==""}", }; var tableStorage = new TableStorage(new MemoryPersistentSource()); foreach (var cmdText in cmds) { var command = RavenJObject.Parse(cmdText); var tblId = command.Value<int>("TableId"); var table = tableStorage.Tables[tblId]; var txId = new Guid(Convert.FromBase64String(command.Value<string>("TxId"))); var key = command["Key"] as RavenJObject; if (key != null) { foreach (var property in key.ToArray())// nothing in .NET supports iterating & modifying at the same time, no news here { if (property.Value.Type != JTokenType.String) continue; var value = property.Value.Value<string>(); if (value.EndsWith("==") == false) continue; key[property.Key] = Convert.FromBase64String(value); } } switch (command.Value<string>("Cmd")) { case "Put": table.Put(command["Key"], new byte[] { 1, 2, 3 }, txId); break; case "Del": table.Remove(command["Key"], txId); break; case "Commit": table.CompleteCommit(txId); break; } } Assert.Empty(tableStorage.Tasks); Assert.Null(tableStorage.Tasks["ByIndexAndTime"].LastOrDefault()); }
public TransactionStorageActions(TableStorage storage) { this.storage = storage; }