Create an index that allows to tag entities by their entity name
Inheritance: Raven.Client.Indexes.AbstractIndexCreationTask
Ejemplo n.º 1
0
		private void DeleteIndex(string deleteItems)
		{
			var ravenDocumentsByEntityNameIndexName = new RavenDocumentsByEntityName().IndexName;
			var tasks = (from indexListItem in model.IndexesOfPriority(deleteItems)
			             select indexListItem.Name
			             into indexName
			             where indexName != ravenDocumentsByEntityNameIndexName
			             select new {Task = DatabaseCommands.DeleteIndexAsync(indexName), Name = indexName}).ToArray();
			
			Task.Factory.ContinueWhenAll(tasks.Select(x=>x.Task).ToArray(), taskslist =>
			{
				foreach (var task in taskslist)
				{
					var indexName = tasks.First(x => x.Task == task).Name;
					if (task.IsFaulted)
					{
						ApplicationModel.Current.AddErrorNotification(task.Exception, "index " + indexName + " could not be deleted");
					}
					else
					{
						ApplicationModel.Current.AddInfoNotification("Index " + indexName + " successfully deleted");
						var deletedItem = model.GroupedIndexes.OfType<IndexItem>().FirstOrDefault(item => item.Name == indexName);
						model.GroupedIndexes.Remove(deletedItem);
					}
				}

				UrlUtil.Navigate("/indexes");
			});
		}
        public void Can_update_a_set_of_documents_based_on_an_index()
        {
            using (var store = NewDocumentStore())
            {
                var index = new RavenDocumentsByEntityName();
                index.Execute(store);

                using (var session = store.OpenSession())
                {
                    Helper.GetExamples(100).ForEach(session.Store);
                    session.SaveChanges();
                }

                WaitForIndexing(store);

                // now let's update some documents!
                store.DatabaseCommands.UpdateByIndex(index.IndexName, new IndexQuery(),
                    new[] {
                        new PatchRequest
                        {
                            Type = PatchCommandType.Add,
                            Name = "Tags",
                            Value = "magic"
                        }
                    }, allowStale:true).WaitForCompletion();

                using (var session = store.OpenSession())
                {
                    session.Query<Example, RavenDocumentsByEntityName>()
                        .FirstOrDefault()
                        .Tags
                        .Should().Contain("magic");
                }
            }
        }
Ejemplo n.º 3
0
        public void AddingMultipleSideBySideIndexesShouldSetValidPriority()
        {
            using (var store = NewDocumentStore())
            {
                var definition = new RavenDocumentsByEntityName().CreateIndexDefinition();

                var indexesToAdd = new List<IndexToAdd>();
                indexesToAdd.Add(new IndexToAdd
                {
                    Name = "Index1",
                    Definition = definition,
                    Priority = IndexingPriority.Error
                });

                indexesToAdd.Add(new IndexToAdd
                {
                    Name = "Index2",
                    Definition = definition,
                    Priority = IndexingPriority.Idle
                });

                store.DatabaseCommands.Admin.StopIndexing();
                store.DatabaseCommands.PutSideBySideIndexes(indexesToAdd.ToArray());

                var i1 = store.DocumentDatabase.IndexStorage.GetIndexInstance("Index1");
                var i2 = store.DocumentDatabase.IndexStorage.GetIndexInstance("Index2");

                Assert.Equal(IndexingPriority.Error, i1.Priority);
                Assert.Equal(IndexingPriority.Idle, i2.Priority);
            }
        }
        public void Can_delete_a_set_of_documents_based_on_a_index()
        {
            using (var store = NewDocumentStore())
            {
                var index = new RavenDocumentsByEntityName();
                index.Execute(store);

                using (var session = store.OpenSession())
                {
                    Helper.GetExamples(100).ForEach(session.Store);
                    session.SaveChanges();
                }

                WaitForIndexing(store);

                // now let's delete some documents!
                store.DatabaseCommands.DeleteByIndex(index.IndexName, new IndexQuery())
                    .WaitForCompletion();

                using (var session = store.OpenSession())
                {
                    session.Query<Example, RavenDocumentsByEntityName>()
                        .Customize(x => x.WaitForNonStaleResultsAsOfNow())
                        .Count()
                        .Should().Be(0);
                }
            }
        }
Ejemplo n.º 5
0
		public void CanResetIndexInMuninStorage()
		{
			using (var store = NewDocumentStore("munin", false))
			{
				var ravenDocumentsByEntityName = new RavenDocumentsByEntityName();
				ravenDocumentsByEntityName.Execute(store);
				store.DocumentDatabase.ResetIndex(ravenDocumentsByEntityName.IndexName);
			}
		}
Ejemplo n.º 6
0
		public void CanResetIndex()
		{
			using (var store = NewDocumentStore())
			{
				var ravenDocumentsByEntityName = new RavenDocumentsByEntityName();
				ravenDocumentsByEntityName.Execute(store);
				store.SystemDatabase.Indexes.ResetIndex(ravenDocumentsByEntityName.IndexName);
			}
		}
Ejemplo n.º 7
0
        public async Task StreamQueryShouldHandleFailover()
        {
            var index = new RavenDocumentsByEntityName();

            using (var store1 = CreateStore(configureStore: store => store.Conventions.FailoverBehavior = FailoverBehavior.AllowReadsFromSecondaries))
            using (var store2 = CreateStore())
            {
                TellFirstInstanceToReplicateToSecondInstance();

                var replicationInformerForDatabase = store1.GetReplicationInformerForDatabase(store1.DefaultDatabase);
				replicationInformerForDatabase.ClearReplicationInformationLocalCache((ServerClient)store1.DatabaseCommands);
				replicationInformerForDatabase.RefreshReplicationInformation((ServerClient)store1.DatabaseCommands);

                var people = InitializeData(store1);
                var lastPersonId = people.Last().Id;

                WaitForIndexing(store1);
                WaitForReplication(store2, lastPersonId);
                WaitForIndexing(store2);

                var count = 0;
                QueryHeaderInformation queryHeaderInfo;
                var enumerator = store1.DatabaseCommands.StreamQuery(index.IndexName, new IndexQuery(), out queryHeaderInfo);
                while (enumerator.MoveNext())
                {
                    count++;
                }

                Assert.Equal(10, count);

                count = 0;
                enumerator = store2.DatabaseCommands.StreamQuery(index.IndexName, new IndexQuery(), out queryHeaderInfo);
                while (enumerator.MoveNext())
                {
                    count++;
                }

                Assert.Equal(10, count);

                StopDatabase(0);

                count = 0;

                var failed = false;

                replicationInformerForDatabase.FailoverStatusChanged += (sender, args) => failed = true;
                enumerator = store1.DatabaseCommands.StreamQuery(index.IndexName, new IndexQuery(), out queryHeaderInfo);
                while (enumerator.MoveNext())
                {
                    count++;
                }

                Assert.Equal(10, count);
                Assert.True(failed);
            }
        }
Ejemplo n.º 8
0
		private void DeleteIndex(string deleteItems)
		{
			var ravenDocumentsByEntityNameIndexName = new RavenDocumentsByEntityName().IndexName;
			var indexes = (from indexListItem in model.IndexesOfPriority(deleteItems)
				where indexListItem.Name != ravenDocumentsByEntityNameIndexName
				select indexListItem.Name);
				
			
			DeleteIndexes(indexes);
		}
Ejemplo n.º 9
0
        public void Reset_index_in_database_with_replication_should_not_corrupt_etag_indice()
        {
            var sb = new StringBuilder();
            for (int i = 0; i < 1000; i++)
                sb.Append(Guid.NewGuid());
            var aLongString = sb.ToString();

            using (var store = NewDocumentStore())
            {
                var ravenDocumentsByEntityName = new RavenDocumentsByEntityName();
                ravenDocumentsByEntityName.Execute(store);

                using (var operation = store.BulkInsert(options: new BulkInsertOptions
                {
                    BatchSize = 1
                }))
                {

                    for (int i = 0; i < 10; i++)
                        operation.Store(new {Foo = aLongString}, "Foo/" + i);
                }
                WaitForIndexing(store);

                    using (var session = store.OpenSession())
                    {
                        var count = session.Query<dynamic>().Count();
                        Assert.Equal(10, count);
                    }

                    store.SystemDatabase.Indexes.ResetIndex(ravenDocumentsByEntityName.IndexName);

                    WaitForIndexing(store);

                    using (var session = store.OpenSession())
                    {
                        var count = session.Query<dynamic>().Count();
                        var errors = store.DatabaseCommands.GetStatistics().Errors;
                        Assert.Empty(errors);
                        Assert.Equal(10, count);
                    }
                

            }
        }
Ejemplo n.º 10
0
		public override void Execute(object parameter)
		{
			var group = model.SelectedGroup;
			if (group != null)
			{
				var ravenDocumentsByEntityNameIndexName = new RavenDocumentsByEntityName().IndexName;
				AskUser.ConfirmationAsync("Confirm Delete",
					string.Format("Are you sure that you want to delete all indexes in the group {0}?", group.GroupName))
					.ContinueWhenTrue(() => DeleteIndexes(group.Items.Select(item => item.Name).Where(indexName => indexName != ravenDocumentsByEntityNameIndexName)));
			}
			else
			{

				var deleteItems = parameter as string;
				AskUser.ConfirmationAsync("Confirm Delete",
					string.Format("Are you sure that you want to delete all " + deleteItems + " indexes?"))
					.ContinueWhenTrue(() => DeleteIndex(deleteItems));
			}
		}
Ejemplo n.º 11
0
		private static void MemoryTest()
		{
			//IOExtensions.DeleteDirectory("Data");
			using (var documentStore = new EmbeddableDocumentStore())
			{
				documentStore.Configuration.DataDirectory = "Data";
				documentStore.Configuration.DefaultStorageTypeName = "esent";
				documentStore.Configuration.Settings["Raven/Esent/CacheSizeMax"] = "512";
				documentStore.Configuration.Settings["Raven/Esent/MaxVerPages"] = "10";
				documentStore.Configuration.Settings["Raven/MemoryCacheLimitPercentage"] = "10";
				documentStore.Initialize();
				var index = new RavenDocumentsByEntityName();
				index.Execute(documentStore);
				var sw = Stopwatch.StartNew();

				var data = new String('x', 20480);
				var list = new List<decimal>(Enumerable.Range(0, 10000).Select(x => (decimal)x));

				// Insert some setup data
				using (var session = documentStore.OpenSession())
				{
					var testFoo = new Foo
									  {
										  Data = data,
										  List = list,
										  Counter = 0
									  };
					var bytes = RavenJObject.FromObject(testFoo).ToBytes();
					//json = RavenJObject.FromObject(testFoo).ToString();                    
					Console.WriteLine("Doc as BinaryJson is {0} bytes ({1:0.00}K or {2:0.00} MB)",
									  bytes.Length, bytes.Length / 1024.0, bytes.Length / 1024.0 / 1024.0);
					session.Store(testFoo);
					session.SaveChanges();

					//var highestId = session.Query<Foo>()
					//                    .Customize(x => x.WaitForNonStaleResults())
					//                    .OrderByDescending(x => x.Id)                                        
					//                    .FirstOrDefault();
					//Console.WriteLine("Highest Id: " + highestId.Id);
				}

				using (var textLog = new StreamWriter("log.txt"))
				using (var csvlog = new StreamWriter("log.csv"))
				{
					csvlog.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, {6}",
									 "Elapsed", "Counter", "Private Mem (MB)", "Total .NET Mem (MB)",
									 "Doc store size (MB)", "Insert Time (ms)", "Query Time (ms)");
					var counter = 0;
					while (!Console.KeyAvailable)
					{
						var foo = new Foo
									  {
										  Data = data,
										  List = list,
										  Counter = ++counter
									  };

						// Insert
						Stopwatch insertTimer = Stopwatch.StartNew();
						using (DocumentCacher.SkipSettingDocumentsInDocumentCache())
						{
							using (var session = documentStore.OpenSession())
							{
								session.Store(foo);
								session.SaveChanges();
							}
						}
						insertTimer.Stop();

						// Query
						Stopwatch queryTimer = Stopwatch.StartNew();
						int subQueryCount = 0;
						//using (DocumentCacher.SkipSettingDocumentsInDocumentCache())
						{
							using (var session = documentStore.OpenSession())
							{
								try
								{
									var counter1 = counter;
									RavenQueryStatistics stats;
									do
									{
										var subQueryTime = Stopwatch.StartNew();
										var firstOrDefault = session.Query<Foo>()
											//.Customize(x => x.WaitForNonStaleResults())
											.Statistics(out stats)
											.Where(x => x.Counter == counter1)
											.FirstOrDefault();
										subQueryTime.Stop();
										//Console.WriteLine("Sub-query took {0:0.00} ms", queryTime.ElapsedMilliseconds);
										Debug.Assert(firstOrDefault != null);
										Debug.Assert(firstOrDefault.Counter == counter1);
										Thread.Sleep(100);
										subQueryCount++;
									} while (stats.IsStale);
								}
								catch (TimeoutException tEx)
								{
									Console.WriteLine(tEx.Message);
								}
							}
						}
						queryTimer.Stop();

						// Update
						//using (var session = documentStore.OpenSession())
						//{
						//    foo.Data = new String('y', 2048);
						//    session.Store(foo);
						//    session.SaveChanges();
						//}

						double docStoreSize =
							documentStore.DocumentDatabase.TransactionalStorage.GetDatabaseSizeInBytes();
						docStoreSize = docStoreSize / 1024.0 / 1024.0;

						var gcTimer = Stopwatch.StartNew();
						var gcSize = GC.GetTotalMemory(true) / 1024.0 / 1024.0;
						gcTimer.Stop();

						var statsTimer = Stopwatch.StartNew();
						var memoryStats =
							String.Format("{0} {1} {2} private {3:0.00} MB, .NET managed {4:0.00} MB, store {5:0.00} MB",
										  DateTime.Now.ToLongTimeString(), sw.ElapsedMilliseconds, counter,
										  Process.GetCurrentProcess().PrivateMemorySize64 / 1024.0 / 1024.0,
										  gcSize, docStoreSize);
						var docDbStats = documentStore.DocumentDatabase.Statistics;
						var timingStats = String.Format("        {0}, insert took {1} ms, query {2} ms ({3} sub-queries), gc {4} ms",
														counter, insertTimer.ElapsedMilliseconds,
														queryTimer.ElapsedMilliseconds,
														subQueryCount,
														gcTimer.ElapsedMilliseconds);
						Console.WriteLine(memoryStats);
						Console.WriteLine(timingStats);
						textLog.WriteLine(memoryStats);
						textLog.WriteLine(timingStats);
						textLog.Flush();
						csvlog.WriteLine("{0}, {1}, {2:0.00}, {3:0.00}, {4:0.00}, {5:0.00}, {6:0.00}, {7}",
										 sw.Elapsed, counter,
										 Process.GetCurrentProcess().PrivateMemorySize64 / 1024.0 / 1024.0,
										 GC.GetTotalMemory(false) / 1024.0 / 1024.0,
										 docStoreSize,
										 insertTimer.ElapsedMilliseconds,
										 queryTimer.ElapsedMilliseconds,
										 subQueryCount);
						csvlog.Flush();
						statsTimer.Stop();
						Console.WriteLine("Took {0} ms to collect and log stats", statsTimer.ElapsedMilliseconds);
					}
				}
			}
		}
Ejemplo n.º 12
0
 public void SilverlightWasRequested(DocumentDatabase database)
 {
     var ravenDocumentsByEntityName = new RavenDocumentsByEntityName {};
     database.Indexes.PutIndex(Constants.DocumentsByEntityNameIndex,
         ravenDocumentsByEntityName.CreateIndexDefinition());
 }