Exemple #1
0
        public async Task Auto_index_should_produce_multiple_outputs(int numberOfUsers, string[] locations)
        {
            using (var database = CreateDocumentDatabase())
            {
                var index = AutoMapReduceIndex.CreateNew(new AutoMapReduceIndexDefinition("Users", new[]
                {
                    new AutoIndexField
                    {
                        Name        = "Count",
                        Aggregation = AggregationOperation.Count,
                        Storage     = FieldStorage.Yes
                    }
                }, new[]
                {
                    new AutoIndexField
                    {
                        Name    = "Location",
                        Storage = FieldStorage.Yes
                    },
                }), database);

                index._threadAllocations = NativeMemory.ThreadAllocations.Value;

                var mapReduceContext = new MapReduceIndexingContext();
                using (var contextPool = new TransactionContextPool(database.DocumentsStorage.Environment))
                {
                    var indexStorage = new IndexStorage(index, contextPool, database);

                    var reducer = new ReduceMapResultsOfAutoIndex(index, index.Definition, indexStorage,
                                                                  new MetricCounters(), mapReduceContext);

                    await ActualTest(numberOfUsers, locations, index, mapReduceContext, reducer, database);
                }
            }
        }
Exemple #2
0
        public async Task Static_index_should_produce_multiple_outputs(int numberOfUsers, string[] locations)
        {
            using (var database = CreateDocumentDatabase())
            {
                var index = MapReduceIndex.CreateNew(new IndexDefinition()
                {
                    Name   = "Users_ByCount_GroupByLocation",
                    Maps   = { "from user in docs.Users select new { user.Location, Count = 1 }" },
                    Reduce =
                        "from result in results group result by result.Location into g select new { Location = g.Key, Count = g.Sum(x => x.Count) }",
                    Type   = IndexType.MapReduce,
                    Fields =
                    {
                        { "Location", new IndexFieldOptions {
                              Storage = FieldStorage.Yes
                          } },
                        { "Count",    new IndexFieldOptions {
                              Storage = FieldStorage.Yes
                          } }
                    }
                }, database);

                index._threadAllocations = NativeMemory.ThreadAllocations.Value;

                var mapReduceContext = new MapReduceIndexingContext();
                using (var contextPool = new TransactionContextPool(database.DocumentsStorage.Environment))
                {
                    var indexStorage = new IndexStorage(index, contextPool, database);
                    var reducer      = new ReduceMapResultsOfStaticIndex(index, index._compiled.Reduce, index.Definition, indexStorage, new MetricCounters(), mapReduceContext);

                    await ActualTest(numberOfUsers, locations, index, mapReduceContext, reducer, database);
                }
            }
        }
Exemple #3
0
        public void DeleteIndex(string name)
        {
            name = IndexDefinitionStorage.FixupIndexName(name);
            IndexDefinitionStorage.RemoveIndex(name);
            IndexStorage.DeleteIndex(name);
            //we may run into a conflict when trying to delete if the index is currently
            //busy indexing documents, worst case scenario, we will have an orphaned index
            //row which will get cleaned up on next db restart.
            for (var i = 0; i < 10; i++)
            {
                try
                {
                    TransactionalStorage.Batch(action =>
                    {
                        action.Indexing.DeleteIndex(name);

                        workContext.ShouldNotifyAboutWork();
                    });
                    return;
                }
                catch (ConcurrencyException)
                {
                    Thread.Sleep(100);
                }
            }
        }
 private SynchronizingFileStream(ITransactionalStorage transactionalStorage, string fileName,
                                 StorageStreamAccess storageStreamAccess, RavenJObject metadata,
                                 IndexStorage indexStorage, StorageOperationsTask operations)
     : base(transactionalStorage, fileName, storageStreamAccess, metadata, indexStorage, operations)
 {
     md5Hasher = Encryptor.Current.CreateHash();
 }
Exemple #5
0
        protected StorageStream(ITransactionalStorage transactionalStorage, string fileName,
                                StorageStreamAccess storageStreamAccess,
                                RavenJObject metadata, IndexStorage indexStorage, StorageOperationsTask operations)
        {
            TransactionalStorage = transactionalStorage;
            StorageStreamAccess  = storageStreamAccess;
            Name = fileName;

            switch (storageStreamAccess)
            {
            case StorageStreamAccess.Read:
                TransactionalStorage.Batch(accessor => fileHeader = accessor.ReadFile(fileName));
                if (fileHeader.TotalSize == null)
                {
                    throw new FileNotFoundException("File is not uploaded yet");
                }
                Metadata = fileHeader.Metadata;
                Seek(0, SeekOrigin.Begin);
                break;

            case StorageStreamAccess.CreateAndWrite:
                TransactionalStorage.Batch(accessor =>
                {
                    operations.IndicateFileToDelete(fileName);
                    accessor.PutFile(fileName, null, metadata);
                    indexStorage.Index(fileName, metadata);
                });
                Metadata = metadata;
                break;

            default:
                throw new ArgumentOutOfRangeException("storageStreamAccess", storageStreamAccess, "Unknown value");
            }
        }
        public RavenFileSystem(InMemoryRavenConfiguration systemConfiguration, string name, TransportState recievedTransportState = null)
        {
            this.Name = name;
            this.systemConfiguration = systemConfiguration;

            storage      = CreateTransactionalStorage(systemConfiguration);
            search       = new IndexStorage(systemConfiguration.FileSystem.IndexStoragePath, systemConfiguration.Settings);
            sigGenerator = new SigGenerator();
            var replicationHiLo = new SynchronizationHiLo(storage);
            var sequenceActions = new SequenceActions(storage);

            transportState        = recievedTransportState ?? new TransportState();
            notificationPublisher = new NotificationPublisher(transportState);
            fileLockManager       = new FileLockManager();
            storage.Initialize();
            search.Initialize();
            var uuidGenerator = new UuidGenerator(sequenceActions);

            historian  = new Historian(storage, replicationHiLo, uuidGenerator);
            BufferPool = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
            conflictArtifactManager = new ConflictArtifactManager(storage, search);
            conflictDetector        = new ConflictDetector();
            conflictResolver        = new ConflictResolver(storage, new CompositionContainer(systemConfiguration.Catalog));
            synchronizationTask     = new SynchronizationTask(storage, sigGenerator, notificationPublisher, systemConfiguration);
            storageOperationsTask   = new StorageOperationsTask(storage, search, notificationPublisher);
            metricsCounters         = new MetricsCountersManager();

            AppDomain.CurrentDomain.ProcessExit  += ShouldDispose;
            AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
        }
Exemple #7
0
        public void Map_reduce_index_should_produce_multiple_output_docs_even_there_is_hash_collision(int numberOfUsers, string[] locations)
        {
            var outputToCollectionName = "Locations";

            using (var database = CreateDocumentDatabase())
                using (var index = MapReduceIndex.CreateNew <MapReduceIndex>(new IndexDefinition()
                {
                    Name = "Users_ByCount_GroupByLocation",
                    Maps = { "from user in docs.Users select new { user.Location, Count = 1 }" },
                    Reduce =
                        "from result in results group result by result.Location into g select new { Location = g.Key, Count = g.Sum(x => x.Count) }",
                    Type = IndexType.MapReduce,
                    Fields =
                    {
                        { "Location", new IndexFieldOptions {
                              Storage = FieldStorage.Yes
                          } },
                        { "Count",    new IndexFieldOptions {
                              Storage = FieldStorage.Yes
                          } }
                    },
                    OutputReduceToCollection = outputToCollectionName
                }, database))
                {
                    var mapReduceContext = new MapReduceIndexingContext();
                    using (var contextPool = new TransactionContextPool(database.DocumentsStorage.Environment))
                    {
                        var indexStorage = new IndexStorage(index, contextPool, database);
                        var reducer      = new ReduceMapResultsOfStaticIndex(index, index._compiled.Reduce, index.Definition, indexStorage, new MetricCounters(), mapReduceContext);

                        ActualTest(numberOfUsers, locations, index, mapReduceContext, reducer, database, outputToCollectionName);
                    }
                }
        }
Exemple #8
0
        public RavenFileSystem(InMemoryRavenConfiguration systemConfiguration, string name, TransportState receivedTransportState = null)
        {
            this.Name = name;
            this.systemConfiguration = systemConfiguration;
            this.transportState      = receivedTransportState ?? new TransportState();

            this.storage = CreateTransactionalStorage(systemConfiguration);

            this.sigGenerator    = new SigGenerator();
            this.fileLockManager = new FileLockManager();

            this.BufferPool       = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
            this.conflictDetector = new ConflictDetector();
            this.conflictResolver = new ConflictResolver(storage, new CompositionContainer(systemConfiguration.Catalog));

            this.notificationPublisher = new NotificationPublisher(transportState);
            this.synchronizationTask   = new SynchronizationTask(storage, sigGenerator, notificationPublisher, systemConfiguration);

            this.metricsCounters = new MetricsCountersManager();

            this.search = new IndexStorage(name, systemConfiguration);
            this.conflictArtifactManager = new ConflictArtifactManager(storage, search);
            this.storageOperationsTask   = new StorageOperationsTask(storage, search, notificationPublisher);

            AppDomain.CurrentDomain.ProcessExit  += ShouldDispose;
            AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
        }
        public void DeleteIndex(string name)
        {
            IndexDefinitionStorage.RemoveIndex(name);
            IndexStorage.DeleteIndex(name);
            //we may run into a conflict when trying to delete if the index is currently
            //busy indexing documents
            for (var i = 0; i < 10; i++)
            {
                try
                {
                    TransactionalStorage.Batch(action =>
                    {
                        action.DeleteIndex(name);

                        workContext.ShouldNotifyAboutWork();
                    });
                    return;
                }
                catch (EsentErrorException e)
                {
                    if (e.Error == JET_err.WriteConflict)
                    {
                        Thread.Sleep(100);
                        continue;
                    }
                    throw;
                }
            }
        }
        public QueryResult Query(string index, IndexQuery query)
        {
            var list  = new List <JObject>();
            var stale = false;

            TransactionalStorage.Batch(
                actions =>
            {
                stale = actions.DoesTasksExistsForIndex(index, query.Cutoff);
                var indexFailureInformation = actions.GetFailureRate(index)
                ;
                if (indexFailureInformation.IsInvalidIndex)
                {
                    throw new IndexDisabledException(indexFailureInformation);
                }
                var loadedIds  = new HashSet <string>();
                var collection = from queryResult in IndexStorage.Query(index, query)
                                 select RetrieveDocument(actions, queryResult, loadedIds)
                                 into doc
                                 let processedDoc = ExecuteReadTriggersOnRead(ProcessReadVetoes(doc, null, ReadOperation.Query), null, ReadOperation.Query)
                                                    where processedDoc != null
                                                    select processedDoc.ToJson();
                list.AddRange(collection);
            });
            return(new QueryResult
            {
                Results = list.ToArray(),
                IsStale = stale,
                TotalResults = query.TotalSize.Value
            });
        }
        public string PutIndex(string name, IndexDefinition definition)
        {
            switch (IndexDefinitionStorage.FindIndexCreationOptionsOptions(name, definition))
            {
            case IndexCreationOptions.Noop:
                return(name);

            case IndexCreationOptions.Update:
                // ensure that the code can compile
                new DynamicViewCompiler(name, definition).GenerateInstance();
                DeleteIndex(name);
                break;
            }
            IndexDefinitionStorage.AddIndex(name, definition);
            IndexStorage.CreateIndexImplementation(name, definition);
            TransactionalStorage.Batch(actions =>
            {
                actions.AddIndex(name);
                var firstAndLast = actions.FirstAndLastDocumentIds();
                if (firstAndLast.Item1 != 0 && firstAndLast.Item2 != 0)
                {
                    for (var i = firstAndLast.Item1; i <= firstAndLast.Item2; i += Configuration.IndexingBatchSize)
                    {
                        actions.AddTask(new IndexDocumentRangeTask
                        {
                            FromId = i,
                            ToId   = Math.Min(i + Configuration.IndexingBatchSize, firstAndLast.Item2),
                            Index  = name
                        });
                    }
                }
                workContext.ShouldNotifyAboutWork();
            });
            return(name);
        }
Exemple #12
0
        void btnGetResultForTrecEval_Click(object sender, EventArgs e)
        {
            // load index for search
            IndexStorage textCaptionIndexStorage = new IndexStorage(ConfigCommon.CAPTION_INDEX_STORAGE);

            textCaptionIndexStorage.OpenIndexStore();

            // read queries
            Dictionary <string, string> dicQueries = ReadTopicFile(ConfigEvaluation.topicFile);

            foreach (var item in dicQueries)
            {
                Console.WriteLine(string.Format("'{0}'", item.Value));
            }

            // search for each query
            FileStream fs = File.Create(ConfigEvaluation.resultsFile);

            fs.Close();
            StreamWriter sw = new StreamWriter(ConfigEvaluation.resultsFile);

            foreach (var query in dicQueries)
            {
                // example: 301	Q0	FR940202-2-00150	104	  2.129133	STANDARD
                List <float>  listScores;
                List <Object> listTextCaptions = Searching.SearchByQueryPlusScore(textCaptionIndexStorage, ConfigCommon.TOP_RANK, query.Value, SearchType.CAPTION, out listScores);
                if (listTextCaptions == null)
                {
                    sw.Write(query.Key + "\tQ0\tNULL\tNULL\tNULL\tNULL\n");
                    continue;
                }

                HashSet <string> hsDocRetrieval = new HashSet <string>();
                List <float>     listScoresNew  = new List <float>();
                for (int i = 0; i < listTextCaptions.Count; i++)
                {
                    string docRetrieval = GetDocRetrieval(((TextCaption)listTextCaptions[i]).FrameName);
                    if (!hsDocRetrieval.Contains(docRetrieval))
                    {
                        hsDocRetrieval.Add(docRetrieval);
                        listScoresNew.Add(listScores[i]);
                    }
                    if (hsDocRetrieval.Count == numNumberOfTopGet.Value)
                    {
                        break;
                    }
                }
                for (int i = 0; i < hsDocRetrieval.Count; i++)
                {
                    //string docRelevanced = GetDocRelevanced(((TextCaption)listTextCaptions[i]).FrameName);
                    string record = string.Format("{0}\tQ0\t{1}\t{2}\t{3}\tRUN_0", query.Key, hsDocRetrieval.ElementAt(i), (i + 1), listScoresNew[i]);
                    //Console.WriteLine(record);
                    sw.Write(record + "\n");
                }
                Console.WriteLine(query.Key);
            }
            sw.Close();
            Console.WriteLine("Finish");
        }
Exemple #13
0
 public IndexCommand(string snapshotName, List <string> projects, ILoggerFactory loggerFactory, ILogger logger, IndexStorage storage)
 {
     _logger        = logger;
     _storage       = storage;
     _snapshotName  = snapshotName;
     _projects      = projects;
     _loggerFactory = loggerFactory;
 }
Exemple #14
0
        public StorageOperationsTask(ITransactionalStorage storage, IndexStorage search, INotificationPublisher notificationPublisher)
        {
            this.storage = storage;
            this.search  = search;
            this.notificationPublisher = notificationPublisher;

            InitializeTimer();
        }
        public StorageOperationsTask(ITransactionalStorage storage, OrderedPartCollection <AbstractFileDeleteTrigger> deleteTriggers, IndexStorage search, INotificationPublisher notificationPublisher)
        {
            this.storage               = storage;
            this.deleteTriggers        = deleteTriggers;
            this.search                = search;
            this.notificationPublisher = notificationPublisher;

            InitializeTimer();
        }
 protected ReduceMapResultsBase(Index index, T indexDefinition, IndexStorage indexStorage, MetricCounters metrics, MapReduceIndexingContext mapReduceContext)
 {
     _index            = index;
     _indexDefinition  = indexDefinition;
     _indexStorage     = indexStorage;
     _metrics          = metrics;
     _mapReduceContext = mapReduceContext;
     _logger           = LoggingSource.Instance.GetLogger <ReduceMapResultsBase <T> >(indexStorage.DocumentDatabase.Name);
 }
Exemple #17
0
 protected MapItems(Index index, IndexStorage indexStorage, MapReduceIndexingContext mapReduceContext, IndexingConfiguration configuration)
 {
     _index            = index;
     _mapReduceContext = mapReduceContext;
     _configuration    = configuration;
     _indexStorage     = indexStorage;
     _logger           = LoggingSource.Instance
                         .GetLogger <MapDocuments>(indexStorage.DocumentDatabase.Name);
 }
Exemple #18
0
        public RavenFileSystem(InMemoryRavenConfiguration config, string name, TransportState receivedTransportState = null)
        {
            ExtensionsState = new AtomicDictionary <object>();

            Name          = name;
            ResourceName  = string.Concat(Constants.FileSystem.UrlPrefix, "/", name);
            configuration = config;

            try
            {
                ValidateStorage();

                configuration.Container.SatisfyImportsOnce(this);

                transportState = receivedTransportState ?? new TransportState();

                storage = CreateTransactionalStorage(configuration);

                sigGenerator    = new SigGenerator();
                fileLockManager = new FileLockManager();

                BufferPool       = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
                conflictDetector = new ConflictDetector();
                conflictResolver = new ConflictResolver(storage, new CompositionContainer(configuration.Catalog));

                notificationPublisher = new NotificationPublisher(transportState);
                synchronizationTask   = new SynchronizationTask(storage, sigGenerator, notificationPublisher, configuration);

                metricsCounters = new MetricsCountersManager();

                search = new IndexStorage(name, configuration);

                conflictArtifactManager = new ConflictArtifactManager(storage, search);

                TimerManager = new ResourceTimerManager();

                Tasks            = new TaskActions(this, Log);
                Files            = new FileActions(this, Log);
                Synchronizations = new SynchronizationActions(this, Log);

                AppDomain.CurrentDomain.ProcessExit  += ShouldDispose;
                AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
            }
            catch (Exception e)
            {
                Log.ErrorException(string.Format("Could not create file system '{0}'", Name ?? "unknown name"), e);
                try
                {
                    Dispose();
                }
                catch (Exception ex)
                {
                    Log.FatalException("Failed to dispose when already getting an error in file system ctor", ex);
                }
                throw;
            }
        }
Exemple #19
0
 public HandleReferences(Index index, Dictionary <string, HashSet <CollectionName> > referencedCollections, DocumentsStorage documentsStorage, IndexStorage indexStorage, IndexingConfiguration configuration)
 {
     _index = index;
     _referencedCollections = referencedCollections;
     _configuration         = configuration;
     _documentsStorage      = documentsStorage;
     _indexStorage          = indexStorage;
     _logger = LoggingSource.Instance
               .GetLogger <HandleReferences>(_indexStorage.DocumentDatabase.Name);
 }
Exemple #20
0
 public CleanupDocuments(Index index, DocumentsStorage documentsStorage, IndexStorage indexStorage,
                         IndexingConfiguration configuration, MapReduceIndexingContext mapReduceContext)
 {
     _index            = index;
     _configuration    = configuration;
     _mapReduceContext = mapReduceContext;
     _documentsStorage = documentsStorage;
     _indexStorage     = indexStorage;
     _logger           = LoggingSource.Instance
                         .GetLogger <CleanupDocuments>(indexStorage.DocumentDatabase.Name);
 }
Exemple #21
0
        public static StorageStream CreatingNewAndWritting(ITransactionalStorage transactionalStorage,
                                                           IndexStorage indexStorage, StorageOperationsTask operations,
                                                           string fileName, RavenJObject metadata)
        {
            if (indexStorage == null)
            {
                throw new ArgumentNullException("indexStorage", "indexStorage == null");
            }

            return(new StorageStream(transactionalStorage, fileName, StorageStreamAccess.CreateAndWrite, metadata, indexStorage, operations));
        }
Exemple #22
0
        void VideoBrowsingForm_Load(object sender, EventArgs e)
        {
            textSpotingIndexStorage = new IndexStorage(ConfigCommon.TEXTSPOTTING_INDEX_STORAGE);
            textSpotingIndexStorage.OpenIndexStore();

            textCaptionIndexStorage = new IndexStorage(ConfigCommon.CAPTION_INDEX_STORAGE);
            textCaptionIndexStorage.OpenIndexStore();

            mappingVideoName = FileManager.GetInstance().GetDictionaryVideoName(ConfigCommon.MAPPING_VIDEO_NAME_PATH);
            mappingFPS       = XMLParser.GetFPSDictionary(ConfigCommon.FPS_VIDEO_PATH);

            pctIndexingData = PCTIndexing.LoadImageIndexStrorageV2(ConfigCommon.PCT_INDEX_STORAGE);
        }
Exemple #23
0
        void btnTextSpotIndexing_Click(object sender, EventArgs e)
        {
            btnTextSpotIndexing.Enabled = false;
            List <TextSpot> textSpot     = FileManager.GetInstance().DeserializeJson(ConfigCommon.TEXT_PLOTTING_PATH);
            IndexStorage    indexStorage = new IndexStorage(ConfigCommon.TEXTSPOTTING_INDEX_STORAGE);

            indexStorage.OpenIndexStore();

            Indexing.IndexFromDatabaseStorage(indexStorage, textSpot);

            indexStorage.CloseIndexStorage();

            btnTextSpotIndexing.Enabled = true;
        }
Exemple #24
0
        public IndexProcessing()
        {
            InitializeComponent();
            btnTextCaptionIndexing.Click += btnTextCaptionIndexing_Click;
            btnTextSpotIndexing.Click    += btnTextSpotIndexing_Click;
            btnParseXML.Click            += btnParseXML_Click;
            btnParseJson.Click           += btnParseJson_Click;
            btnSearchCap.Click           += btnSearchCap_Click;

            textCaptionStorage = new IndexStorage(ConfigCommon.CAPTION_INDEX_STORAGE);
            textCaptionStorage.OpenIndexStore();

            textSpotIndexStorage = new IndexStorage(ConfigCommon.TEXTSPOTTING_INDEX_STORAGE);
            textSpotIndexStorage.OpenIndexStore();
        }
        public DocumentDatabase(RavenConfiguration configuration)
        {
            Configuration = configuration;

            configuration.Container.SatisfyImportsOnce(this);

            workContext = new WorkContext {
                IndexUpdateTriggers = IndexUpdateTriggers
            };

            TransactionalStorage = configuration.CreateTransactionalStorage(workContext.NotifyAboutWork);
            configuration.Container.SatisfyImportsOnce(TransactionalStorage);

            bool newDb;

            try
            {
                newDb = TransactionalStorage.Initialize();
            }
            catch (Exception)
            {
                TransactionalStorage.Dispose();
                throw;
            }

            IndexDefinitionStorage = new IndexDefinitionStorage(
                TransactionalStorage,
                configuration.DataDirectory,
                configuration.Container.GetExportedValues <AbstractViewGenerator>(),
                Extensions);
            IndexStorage = new IndexStorage(IndexDefinitionStorage, configuration);

            workContext.PerformanceCounters    = new PerformanceCounters("Instance @ " + configuration.Port);
            workContext.IndexStorage           = IndexStorage;
            workContext.TransactionaStorage    = TransactionalStorage;
            workContext.IndexDefinitionStorage = IndexDefinitionStorage;


            InitializeTriggers();
            ExecuteStartupTasks();

            if (!newDb)
            {
                return;
            }

            OnNewlyCreatedDatabase();
        }
        public void ResetIndex(string index)
        {
            var indexDefinition = IndexDefinitionStorage.GetIndexDefinition(index);

            if (indexDefinition == null)
            {
                throw new InvalidOperationException("There is no index named: " + index);
            }
            IndexStorage.DeleteIndex(index);
            IndexStorage.CreateIndexImplementation(index, indexDefinition);
            TransactionalStorage.Batch(actions =>
            {
                actions.Indexing.DeleteIndex(index);
                AddIndexAndEnqueueIndexingTasks(actions, index);
            });
        }
Exemple #27
0
        public RavenFileSystem(InMemoryRavenConfiguration systemConfiguration, TransportState transportState, string name)
        {
            this.Name = name;
            this.systemConfiguration = systemConfiguration;

            var storageType = systemConfiguration.DefaultFileSystemStorageTypeName;

            if (string.Equals(InMemoryRavenConfiguration.VoronTypeName, storageType, StringComparison.OrdinalIgnoreCase) == false)
            {
                if (Directory.Exists(systemConfiguration.FileSystemDataDirectory) &&
                    Directory.EnumerateFileSystemEntries(systemConfiguration.FileSystemDataDirectory).Any())
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "We do not allow to run on a storage engine other then Voron, while we are in the early pre-release phase of RavenDB 3.0. You are currently running on {0}",
                                  storageType));
                }

                Trace.WriteLine("Forcing filesystem to run on Voron - pre release behavior only, mind " + Path.GetFileName(Path.GetDirectoryName(systemConfiguration.FileSystemDataDirectory)));
                storageType = InMemoryRavenConfiguration.VoronTypeName;
            }

            storage      = CreateTransactionalStorage(storageType, systemConfiguration);
            search       = new IndexStorage(systemConfiguration.FileSystemIndexStoragePath, systemConfiguration.Settings);
            sigGenerator = new SigGenerator();
            var replicationHiLo = new SynchronizationHiLo(storage);
            var sequenceActions = new SequenceActions(storage);

            this.transportState   = transportState;
            notificationPublisher = new NotificationPublisher(transportState);
            fileLockManager       = new FileLockManager();
            storage.Initialize();
            search.Initialize();
            var uuidGenerator = new UuidGenerator(sequenceActions);

            historian  = new Historian(storage, replicationHiLo, uuidGenerator);
            BufferPool = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
            conflictArtifactManager = new ConflictArtifactManager(storage, search);
            conflictDetector        = new ConflictDetector();
            conflictResolver        = new ConflictResolver();
            synchronizationTask     = new SynchronizationTask(storage, sigGenerator, notificationPublisher, systemConfiguration);
            storageOperationsTask   = new StorageOperationsTask(storage, search, notificationPublisher);
            metricsCounters         = new MetricsCountersManager();

            AppDomain.CurrentDomain.ProcessExit  += ShouldDispose;
            AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
        }
        public string PutIndex(string name, IndexDefinition definition)
        {
            switch (IndexDefinitionStorage.FindIndexCreationOptionsOptions(name, definition))
            {
            case IndexCreationOptions.Noop:
                return(name);

            case IndexCreationOptions.Update:
                // ensure that the code can compile
                new DynamicViewCompiler(name, definition, Extensions).GenerateInstance();
                DeleteIndex(name);
                break;
            }
            IndexDefinitionStorage.AddIndex(name, definition);
            IndexStorage.CreateIndexImplementation(name, definition);
            TransactionalStorage.Batch(actions => AddIndexAndEnqueueIndexingTasks(actions, name));
            return(name);
        }
Exemple #29
0
        public void ResetIndex(string index)
        {
            index = IndexDefinitionStorage.FixupIndexName(index);
            var indexDefinition = IndexDefinitionStorage.GetIndexDefinition(index);

            if (indexDefinition == null)
            {
                throw new InvalidOperationException("There is no index named: " + index);
            }
            IndexStorage.DeleteIndex(index);
            IndexStorage.CreateIndexImplementation(indexDefinition);
            TransactionalStorage.Batch(actions =>
            {
                actions.Indexing.DeleteIndex(index);
                actions.Indexing.AddIndex(index, indexDefinition.IsMapReduce);
                workContext.ShouldNotifyAboutWork();
            });
        }
Exemple #30
0
        private void FillCollectionEtags(Transaction tx,
                                         Dictionary <string, IndexTransactionCache.CollectionEtags> map)
        {
            foreach (string collection in _index.Collections)
            {
                using (Slice.From(tx.LowLevelTransaction.Allocator, collection, out Slice collectionSlice))
                {
                    var etags = new IndexTransactionCache.CollectionEtags
                    {
                        LastIndexedEtag = IndexStorage.ReadLastEtag(tx,
                                                                    IndexStorage.IndexSchema.EtagsTree,
                                                                    collectionSlice
                                                                    ),
                        LastProcessedTombstoneEtag = IndexStorage.ReadLastEtag(tx,
                                                                               IndexStorage.IndexSchema.EtagsTombstoneTree,
                                                                               collectionSlice
                                                                               )
                    };

                    map[collection] = etags;
                }
            }

            var referencedCollections = _index.GetReferencedCollections();

            if (referencedCollections == null || referencedCollections.Count == 0)
            {
                return;
            }

            foreach (var(src, collections)  in referencedCollections)
            {
                var collectionEtags = map[src];
                collectionEtags.LastReferencedEtags ??= new Dictionary <string, IndexTransactionCache.ReferenceCollectionEtags>(StringComparer.OrdinalIgnoreCase);
                foreach (var collectionName in collections)
                {
                    collectionEtags.LastReferencedEtags[collectionName.Name] = new IndexTransactionCache.ReferenceCollectionEtags
                    {
                        LastEtag = IndexStorage.ReadLastProcessedReferenceEtag(tx, src, collectionName),
                        LastProcessedTombstoneEtag = IndexStorage.ReadLastProcessedReferenceTombstoneEtag(tx, src, collectionName),
                    };
                }
            }
        }
 private TestContext CreateTarget(MemoryBinaryStore store)
 {
     var configuration = new IndexConfiguration {
         EntityType = typeof (Car),
         Type = typeof (int),
         UniqueName = "Nationality"
     };
     var storage = new IndexStorage<int>(store, configuration);
     storage.Initialize();
     var index = new TableIndex<int>(storage, new ComparableIndexAlgorithm<int>());
     return new TestContext {Store = store, Index = index};
 }