public new void DeleteDocumentInTransaction(
     TransactionInformation transactionInformation,
     string key,
     Etag etag,
     Etag committedEtag,
     SequentialUuidGenerator uuidGenerator)
 {
     throw new InvalidOperationException("DTC is not supported by " + storageName + " storage.");
 }
 public new Etag AddDocumentInTransaction(
     string key,
     Etag etag,
     RavenJObject data,
     RavenJObject metadata,
     TransactionInformation transactionInformation,
     Etag committedEtag,
     SequentialUuidGenerator uuidGenerator)
 {
     throw new InvalidOperationException("DTC is not supported by " + storageName + " storage.");
 }
 public void DeleteDocumentInTransaction(
     TransactionInformation transactionInformation,
     string key,
     Etag etag,
     Etag committedEtag,
     SequentialUuidGenerator uuidGenerator)
 {
     AddToTransactionState(key, etag, transactionInformation, committedEtag, new DocumentInTransactionData
     {
         Delete       = true,
         Key          = key,
         LastModified = SystemTime.UtcNow
     });
 }
        public static bool TryToCreateTransactionalStorage(InMemoryRavenConfiguration ravenConfiguration,
                                                           bool hasCompression, EncryptionConfiguration encryption, out ITransactionalStorage storage)
        {
            storage = null;
            if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, Voron.Impl.Constants.DatabaseFilename)))
            {
                storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.VoronTypeName, () => { }, () => { });
            }
            else if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, "Data")))
            {
                storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.EsentTypeName, () => { }, () => { });
            }

            if (storage == null)
            {
                return(false);
            }

            var orderedPartCollection = new OrderedPartCollection <AbstractDocumentCodec>();

            if (encryption != null)
            {
                var documentEncryption = new DocumentEncryption();
                documentEncryption.SetSettings(new EncryptionSettings(encryption.EncryptionKey, encryption.SymmetricAlgorithmType,
                                                                      encryption.EncryptIndexes, encryption.PreferedEncryptionKeyBitsSize));
                orderedPartCollection.Add(documentEncryption);
            }
            if (hasCompression)
            {
                orderedPartCollection.Add(new DocumentCompression());
            }

            uuidGenerator = new SequentialUuidGenerator();
            storage.Initialize(uuidGenerator, orderedPartCollection);

            /*
             * Added configuration steps
             */
            storage.Batch(actions =>
            {
                var nextIdentityValue  = actions.General.GetNextIdentityValue("Raven/Etag");
                uuidGenerator.EtagBase = nextIdentityValue;
            });

            return(true);
        }
 public Etag AddDocumentInTransaction(
     string key,
     Etag etag,
     RavenJObject data,
     RavenJObject metadata,
     TransactionInformation transactionInformation,
     Etag committedEtag,
     SequentialUuidGenerator uuidGenerator)
 {
     metadata.EnsureCannotBeChangeAndEnableSnapshotting();
     data.EnsureCannotBeChangeAndEnableSnapshotting();
     return(AddToTransactionState(key, etag,
                                  transactionInformation,
                                  committedEtag,
                                  new DocumentInTransactionData
     {
         Metadata = metadata,
         Data = data,
         Delete = false,
         Key = key,
         LastModified = SystemTime.UtcNow,
         Etag = uuidGenerator.CreateSequentialUuid(UuidType.DocumentTransactions)
     }));
 }
Beispiel #6
0
        public DocumentDatabase(InMemoryRavenConfiguration configuration, TransportState transportState = null)
        {
            DocumentLock        = new PutSerialLock();
            Name                = configuration.DatabaseName;
            Configuration       = configuration;
            this.transportState = transportState ?? new TransportState();
            ExtensionsState     = new AtomicDictionary <object>();

            using (LogManager.OpenMappedContext("database", Name ?? Constants.SystemDatabase))
            {
                Log.Debug("Start loading the following database: {0}", Name ?? Constants.SystemDatabase);

                initializer = new DocumentDatabaseInitializer(this, configuration);

                initializer.InitializeEncryption();
                initializer.ValidateLicense();

                initializer.SubscribeToDomainUnloadOrProcessExit();
                initializer.ExecuteAlterConfiguration();
                initializer.SatisfyImportsOnce();

                backgroundTaskScheduler = configuration.CustomTaskScheduler ?? TaskScheduler.Default;


                recentTouches = new SizeLimitedConcurrentDictionary <string, TouchedDocumentInfo>(configuration.MaxRecentTouchesToRemember, StringComparer.OrdinalIgnoreCase);

                configuration.Container.SatisfyImportsOnce(this);

                workContext = new WorkContext
                {
                    Database            = this,
                    DatabaseName        = Name,
                    IndexUpdateTriggers = IndexUpdateTriggers,
                    ReadTriggers        = ReadTriggers,
                    TaskScheduler       = backgroundTaskScheduler,
                    Configuration       = configuration,
                    IndexReaderWarmers  = IndexReaderWarmers
                };

                try
                {
                    uuidGenerator = new SequentialUuidGenerator();
                    initializer.InitializeTransactionalStorage(uuidGenerator);
                    lastCollectionEtags = new LastCollectionEtags(TransactionalStorage, WorkContext);
                }
                catch (Exception)
                {
                    if (TransactionalStorage != null)
                    {
                        TransactionalStorage.Dispose();
                    }
                    throw;
                }

                try
                {
                    TransactionalStorage.Batch(actions => uuidGenerator.EtagBase = actions.General.GetNextIdentityValue("Raven/Etag"));

                    // Index codecs must be initialized before we try to read an index
                    InitializeIndexCodecTriggers();
                    initializer.InitializeIndexStorage();

                    Attachments   = new AttachmentActions(this, recentTouches, uuidGenerator, Log);
                    Documents     = new DocumentActions(this, recentTouches, uuidGenerator, Log);
                    Indexes       = new IndexActions(this, recentTouches, uuidGenerator, Log);
                    Maintenance   = new MaintenanceActions(this, recentTouches, uuidGenerator, Log);
                    Notifications = new NotificationActions(this, recentTouches, uuidGenerator, Log);
                    Patches       = new PatchActions(this, recentTouches, uuidGenerator, Log);
                    Queries       = new QueryActions(this, recentTouches, uuidGenerator, Log);
                    Tasks         = new TaskActions(this, recentTouches, uuidGenerator, Log);
                    Transformers  = new TransformerActions(this, recentTouches, uuidGenerator, Log);

                    inFlightTransactionalState = TransactionalStorage.GetInFlightTransactionalState(Documents.Put, Documents.Delete);

                    CompleteWorkContextSetup();

                    prefetcher       = new Prefetcher(workContext);
                    indexingExecuter = new IndexingExecuter(workContext, prefetcher);

                    RaiseIndexingWiringComplete();

                    InitializeTriggersExceptIndexCodecs();
                    SecondStageInitialization();
                    ExecuteStartupTasks();
                    lastCollectionEtags.Initialize();

                    Log.Debug("Finish loading the following database: {0}", configuration.DatabaseName ?? Constants.SystemDatabase);
                }
                catch (Exception)
                {
                    Dispose();
                    throw;
                }
            }
        }