コード例 #1
0
ファイル: RavenDB_1600.cs プロジェクト: 925coder/ravendb
		public void ShouldNotSetAutoIndexesToAbandonedPriorityAfterDatabaseRecovery()
		{
			using (var db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false
			}))
			{
				db.SpinBackgroundWorkers();
				db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());

				db.Put("users/1", null, RavenJObject.Parse("{'Name':'Arek'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
				db.Put("users/2", null, RavenJObject.Parse("{'Name':'David'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

				var results = db.ExecuteDynamicQuery("Users", new IndexQuery()
				{
					PageSize = 128,
					Start = 0,
					Cutoff = SystemTime.UtcNow,
					Query = "Name:Arek"
				}, CancellationToken.None);

				WaitForIndexing(db);

				var autoIdexes = db.Statistics.Indexes.Where(x => x.Name.StartsWith("Auto")).ToList();

				Assert.True(autoIdexes.Count > 0);

				autoIdexes.ForEach(x => db.TransactionalStorage.Batch(accessor => accessor.Indexing.SetIndexPriority(x.Name, IndexingPriority.Idle)));
				
				db.StartBackup(BackupDir, false, new DatabaseDocument());
				WaitForBackup(db, true);
			}
			IOExtensions.DeleteDirectory(DataDir);

			DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => { }, defrag: true);

			using (var db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
			}))
			{
				db.SpinBackgroundWorkers();
				db.RunIdleOperations();

				var autoIndexes = db.Statistics.Indexes.Where(x => x.Name.StartsWith("Auto")).ToList();

				Assert.True(autoIndexes.Count > 0);

				foreach (var indexStats in autoIndexes)
				{
					Assert.NotEqual(indexStats.Priority, IndexingPriority.Abandoned);
				}
			}
		}
コード例 #2
0
        public void ShouldNotSetAutoIndexesToAbandonedPriorityAfterDatabaseRecovery()
        {
            using (var db = new DocumentDatabase(new RavenConfiguration
            {
                DataDirectory = DataDir,
                RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false
            }))
            {
                db.SpinBackgroundWorkers();
                db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());

                db.Put("users/1", null, RavenJObject.Parse("{'Name':'Arek'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
                db.Put("users/2", null, RavenJObject.Parse("{'Name':'David'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

                var results = db.ExecuteDynamicQuery("Users", new IndexQuery()
                {
                    PageSize = 128,
                    Start    = 0,
                    Cutoff   = SystemTime.UtcNow,
                    Query    = "Name:Arek"
                }, CancellationToken.None);

                WaitForIndexing(db);

                var autoIdexes = db.Statistics.Indexes.Where(x => x.Name.StartsWith("Auto")).ToList();

                Assert.True(autoIdexes.Count > 0);

                autoIdexes.ForEach(x => db.TransactionalStorage.Batch(accessor => accessor.Indexing.SetIndexPriority(x.Name, IndexingPriority.Idle)));

                db.StartBackup(BackupDir, false, new DatabaseDocument());
                WaitForBackup(db, true);
            }
            IOExtensions.DeleteDirectory(DataDir);

            DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => { }, defrag: true);

            using (var db = new DocumentDatabase(new RavenConfiguration
            {
                DataDirectory = DataDir,
                RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
            }))
            {
                db.SpinBackgroundWorkers();
                db.RunIdleOperations();

                var autoIndexes = db.Statistics.Indexes.Where(x => x.Name.StartsWith("Auto")).ToList();

                Assert.True(autoIndexes.Count > 0);

                foreach (var indexStats in autoIndexes)
                {
                    Assert.NotEqual(indexStats.Priority, IndexingPriority.Abandoned);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Queries the specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="query">The query.</param>
        /// <param name="includes">The includes are ignored for this implementation.</param>
        /// <param name="metadataOnly">Load just the document metadata</param>
        /// <param name="indexEntriesOnly">Include index entries</param>
        public QueryResult Query(string index, IndexQuery query, string[] includes, bool metadataOnly = false, bool indexEntriesOnly = false)
        {
            query.PageSize = Math.Min(query.PageSize, database.Configuration.MaxPageSize);
            CurrentOperationContext.Headers.Value = OperationsHeaders;

            // metadataOnly is not supported for embedded

            // indexEntriesOnly is not supported for embedded

            QueryResultWithIncludes queryResult;

            if (index.StartsWith("dynamic/", StringComparison.InvariantCultureIgnoreCase) || index.Equals("dynamic", StringComparison.InvariantCultureIgnoreCase))
            {
                string entityName = null;
                if (index.StartsWith("dynamic/"))
                {
                    entityName = index.Substring("dynamic/".Length);
                }
                queryResult = database.ExecuteDynamicQuery(entityName, query.Clone());
            }
            else
            {
                queryResult = database.Query(index, query.Clone());
            }
            EnsureLocalDate(queryResult.Results);

            var loadedIds = new HashSet <string>(
                queryResult.Results
                .Where(x => x["@metadata"] != null)
                .Select(x => x["@metadata"].Value <string>("@id"))
                .Where(x => x != null)
                );

            if (includes != null)
            {
                var includeCmd = new AddIncludesCommand(database, TransactionInformation,
                                                        (etag, doc) => queryResult.Includes.Add(doc), includes, loadedIds);

                foreach (var result in queryResult.Results)
                {
                    includeCmd.Execute(result);
                }

                includeCmd.AlsoInclude(queryResult.IdsToInclude);

                EnsureLocalDate(queryResult.Includes);
            }

            return(queryResult);
        }
コード例 #4
0
        /// <summary>
        /// Queries the specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="query">The query.</param>
        /// <param name="includes">The includes are ignored for this implementation.</param>
        public QueryResult Query(string index, IndexQuery query, string[] includes)
        {
            query.PageSize = Math.Min(query.PageSize, database.Configuration.MaxPageSize);
            CurrentOperationContext.Headers.Value = OperationsHeaders;

            if (index.StartsWith("dynamic", StringComparison.InvariantCultureIgnoreCase))
            {
                string entityName = null;
                if (index.StartsWith("dynamic/"))
                {
                    entityName = index.Substring("dynamic/".Length);
                }
                return(database.ExecuteDynamicQuery(entityName, query));
            }
            return(database.Query(index, query));
        }