Exemplo n.º 1
0
        public object ExecuteEmbedded(IDatabaseCommands commands)
        {
            if (string.IsNullOrEmpty(transformer) == false)
            {
                return(commands.Get(new[] { key }, null, transformer));
            }

            return(commands.Get(key));
        }
Exemplo n.º 2
0
        protected void WaitForRestore(IDatabaseCommands databaseCommands)
        {
            var done = SpinWait.SpinUntil(() =>
            {
                // We expect to get the doc from the <system> database
                var doc = databaseCommands.Get(RestoreStatus.RavenRestoreStatusDocumentKey);

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

                var status = doc.DataAsJson["restoreStatus"].Values().Select(token => token.ToString()).ToList();

                var restoreFinishMessages = new[]
                {
                    "The new database was created",
                    "Esent Restore: Restore Complete",
                    "Restore ended but could not create the datebase document, in order to access the data create a database with the appropriate name",
                };
                return(restoreFinishMessages.Any(status.Last().Contains));
            }, TimeSpan.FromMinutes(5));

            Assert.True(done);
        }
Exemplo n.º 3
0
        ///<summary>
        /// Ensures that the database exists, creating it if needed
        ///</summary>
        /// <remarks>
        /// This operation happens _outside_ of any transaction
        /// </remarks>
        public static void EnsureDatabaseExists(this IDatabaseCommands self, string name, bool ignoreFailures = false)
        {
            self = self.ForDefaultDatabase();
            var doc   = MultiDatabase.CreateDatabaseDocument(name);
            var docId = "Raven/Databases/" + name;

            using (new TransactionScope(TransactionScopeOption.Suppress))
            {
                try
                {
                    if (self.Get(docId) != null)
                    {
                        return;
                    }

                    self.Put(docId, null, doc, new RavenJObject());
                }
                catch (Exception)
                {
                    if (ignoreFailures == false)
                    {
                        throw;
                    }
                }
            }
        }
Exemplo n.º 4
0
        ///<summary>
        /// Ensures that the database exists, creating it if needed
        ///</summary>
        /// <remarks>
        /// This operation happens _outside_ of any transaction
        /// </remarks>
        public static void EnsureDatabaseExists(this IDatabaseCommands self, string name, bool ignoreFailures = false)
        {
            self = self.ForDefaultDatabase();
            AssertValidName(name);
            var doc = RavenJObject.FromObject(new DatabaseDocument
            {
                Settings =
                {
                    { "Raven/DataDir", Path.Combine("~", Path.Combine("Tenants", name)) }
                }
            });

            doc.Remove("Id");
            var docId = "Raven/Databases/" + name;

            using (new TransactionScope(TransactionScopeOption.Suppress))
            {
                try
                {
                    if (self.Get(docId) != null)
                    {
                        return;
                    }

                    self.Put(docId, null, doc, new RavenJObject());
                }
                catch (Exception)
                {
                    if (ignoreFailures == false)
                    {
                        throw;
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static void WaitForDocument(IDatabaseCommands databaseCommands, string id)
        {
            var done = SpinWait.SpinUntil(() =>
            {
                var doc = databaseCommands.Get(id);
                return(doc != null);
            }, TimeSpan.FromMinutes(1));

            Assert.True(done);
        }
Exemplo n.º 6
0
        protected void WaitForDocument(IDatabaseCommands databaseCommands, string id)
        {
            var done = SpinWait.SpinUntil(() =>
            {
                // We expect to get the doc from the <system> database
                var doc = databaseCommands.Get(id);
                return(doc != null);
            }, TimeSpan.FromMinutes(5));

            Assert.True(done);
        }
Exemplo n.º 7
0
 static WindowsAuthDocument GetWindowsAuthDocument(IDatabaseCommands systemCommands)
 {
     var existing = systemCommands.Get("Raven/Authorization/WindowsSettings");
     if (existing == null)
     {
         return new WindowsAuthDocument();
     }
     return existing
         .DataAsJson
         .JsonDeserialization<WindowsAuthDocument>();
 }
        static WindowsAuthDocument GetWindowsAuthDocument(IDatabaseCommands systemCommands)
        {
            var existing = systemCommands.Get("Raven/Authorization/WindowsSettings");

            if (existing == null)
            {
                return(new WindowsAuthDocument());
            }
            return(existing
                   .DataAsJson
                   .JsonDeserialization <WindowsAuthDocument>());
        }
        internal static void AfterExecute(IDatabaseCommands databaseCommands, string indexName, ScriptedIndexResults scripts)
        {
            var documentId = GetScriptedIndexResultsDocumentId(indexName);
            scripts.Id = documentId;

            var oldDocument = databaseCommands.Get(documentId);
            var newDocument = RavenJObject.FromObject(scripts);
            if (oldDocument != null && RavenJToken.DeepEquals(oldDocument.DataAsJson, newDocument))
                return;

            databaseCommands.Put(documentId, null, newDocument, null);
            databaseCommands.ResetIndex(indexName);
        }
Exemplo n.º 10
0
        protected virtual void WaitForDocument(IDatabaseCommands databaseCommands, string id)
        {
            var done = SpinWait.SpinUntil(() =>
            {
                // We expect to get the doc from the <system> database
                var doc = databaseCommands.Get(id);
                return(doc != null);
            }, TimeSpan.FromMinutes(5));

            if (!done)
            {
                throw new Exception("WaitForDocument failed");
            }
        }
Exemplo n.º 11
0
        public void WaitForDelete(IDatabaseCommands commands, string key, TimeSpan?timeout = null)
        {
            var done = SpinWait.SpinUntil(() =>
            {
                // We expect to get the doc from the <system> database
                var doc = commands.Get(key);
                return(doc == null);
            }, timeout ?? TimeSpan.FromMinutes(5));

            if (!done)
            {
                throw new Exception("WaitForDelete failed");
            }
        }
Exemplo n.º 12
0
        internal static void AfterExecute(IDatabaseCommands databaseCommands, string indexName, ScriptedIndexResults scripts)
        {
            var documentId = GetScriptedIndexResultsDocumentId(indexName);

            scripts.Id = documentId;

            var oldDocument = databaseCommands.Get(documentId);
            var newDocument = RavenJObject.FromObject(scripts);

            if (oldDocument != null && RavenJToken.DeepEquals(oldDocument.DataAsJson, newDocument))
            {
                return;
            }

            databaseCommands.Put(documentId, null, newDocument, null);
            databaseCommands.ResetIndex(indexName);
        }
Exemplo n.º 13
0
        ///<summary>
        /// Ensures that the database exists, creating it if needed
        ///</summary>
        /// <remarks>
        /// This operation happens _outside_ of any transaction
        /// </remarks>
        public static void EnsureDatabaseExists(this IDatabaseCommands self, string name)
        {
            AssertValidName(name);
            var doc = RavenJObject.FromObject(new DatabaseDocument
            {
                Settings =
                {
                    { "Raven/DataDir", Path.Combine("~", Path.Combine("Tenants", name)) }
                }
            });
            var docId = "Raven/Databases/" + name;

            if (self.Get(docId) != null)
            {
                return;
            }
            using (new TransactionScope(TransactionScopeOption.Suppress))
                self.Put(docId, null, doc, new RavenJObject());
        }
Exemplo n.º 14
0
		public object ExecuteEmbedded(IDatabaseCommands commands)
		{
			var includePaths = this.includes != null ? this.includes.Select(x => x.Key).ToArray() : null;
			return commands.Get(ids, includePaths);
		}
Exemplo n.º 15
0
 private JsonDocument GetDocument()
 {
     return(databaseCommands.Get(RavenKeyGeneratorsHilo + tag));
 }
Exemplo n.º 16
0
 public Task <JsonDocument> GetAsync(string key)
 {
     return(new CompletedTask <JsonDocument>(databaseCommands.Get(key)));
 }
 public object ExecuteEmbedded(IDatabaseCommands commands)
 {
     return(commands.Get(ids, null, transformer));
 }
Exemplo n.º 18
0
        protected virtual void WaitForDocument(IDatabaseCommands databaseCommands, string id)
        {
            var done = SpinWait.SpinUntil(() =>
            {
                // We expect to get the doc from the <system> database
                var doc = databaseCommands.Get(id);
                return doc != null;
            }, TimeSpan.FromMinutes(5));

            if (!done) throw new Exception("WaitForDocument failed");
        }
Exemplo n.º 19
0
		private RangeValue GetNextRange(IDatabaseCommands databaseCommands)
		{
#if !NETFX_CORE
			using (new TransactionScope(TransactionScopeOption.Suppress))
			{
#endif
				ModifyCapacityIfRequired();
				while (true)
				{
					try
					{
						var minNextMax = Range.Max;
						JsonDocument document;

						try
						{
							document = GetDocument(databaseCommands);
						}
						catch (ConflictException e)
						{
							// resolving the conflict by selecting the highest number
							var highestMax = e.ConflictedVersionIds
								.Select(conflictedVersionId => GetMaxFromDocument(databaseCommands.Get(conflictedVersionId), minNextMax))
								.Max();

							PutDocument(databaseCommands, new JsonDocument
							{
								Etag = e.Etag,
								Metadata = new RavenJObject(),
								DataAsJson = RavenJObject.FromObject(new { Max = highestMax }),
								Key = HiLoDocumentKey
							});

							continue;
						}

						long min, max;
						if (document == null)
						{
							min = minNextMax + 1;
							max = minNextMax + capacity;
							document = new JsonDocument
							{
								Etag = Etag.Empty,
								// sending empty etag means - ensure the that the document does NOT exists
								Metadata = new RavenJObject(),
								DataAsJson = RavenJObject.FromObject(new { Max = max }),
								Key = HiLoDocumentKey
							};
						}
						else
						{
							var oldMax = GetMaxFromDocument(document, minNextMax);
							min = oldMax + 1;
							max = oldMax + capacity;

							document.DataAsJson["Max"] = max;
						}
						PutDocument(databaseCommands, document);

						return new RangeValue(min, max);
					}
					catch (ConcurrencyException)
					{
						// expected, we need to retry
					}
				}
#if !NETFX_CORE
			}
#endif
		}
Exemplo n.º 20
0
		private JsonDocument GetDocument(IDatabaseCommands databaseCommands)
		{
			var documents = databaseCommands.Get(new[] { HiLoDocumentKey, RavenKeyServerPrefix }, new string[0]);
			return HandleGetDocumentResult(documents);
		}
Exemplo n.º 21
0
 public object ExecuteEmbedded(IDatabaseCommands commands)
 {
     return(commands.Get(key));
 }
Exemplo n.º 22
0
		protected void WaitForRestore(IDatabaseCommands databaseCommands)
		{
			var done = SpinWait.SpinUntil(() =>
			{
				// We expect to get the doc from the <system> database
				var doc = databaseCommands.Get(RestoreStatus.RavenRestoreStatusDocumentKey);

				if (doc == null)
					return false;

				var status = doc.DataAsJson["restoreStatus"].Values().Select(token => token.ToString()).ToList();

				var restoreFinishMessages = new[]
				{
					"The new database was created",
					"Esent Restore: Restore Complete", 
					"Restore ended but could not create the datebase document, in order to access the data create a database with the appropriate name",
				};
				return restoreFinishMessages.Any(status.Last().Contains);
			}, TimeSpan.FromMinutes(5));

			Assert.True(done);
		}
Exemplo n.º 23
0
        public object ExecuteEmbedded(IDatabaseCommands commands)
        {
            var includePaths = includes != null?includes.Select(x => x.Key).ToArray() : null;

            return(commands.Get(ids, includePaths, transformer));
        }
Exemplo n.º 24
0
		protected void WaitForDocument(IDatabaseCommands databaseCommands, string id)
		{
			var done = SpinWait.SpinUntil(() =>
			{
				// We expect to get the doc from the <system> database
				var doc = databaseCommands.Get(id);
				return doc != null;
			}, TimeSpan.FromMinutes(5));

			Assert.True(done);
		}
Exemplo n.º 25
0
        private JsonDocument GetDocument(IDatabaseCommands databaseCommands)
        {
            var documents = databaseCommands.Get(new[] { HiLoDocumentKey, RavenKeyServerPrefix }, new string[0]);

            return(HandleGetDocumentResult(documents));
        }
Exemplo n.º 26
0
        private RangeValue GetNextRange(IDatabaseCommands databaseCommands)
        {
#if !NETFX_CORE
            using (new TransactionScope(TransactionScopeOption.Suppress))
                using (RavenTransactionAccessor.SupressExplicitRavenTransaction())
                    using (databaseCommands.ForceReadFromMaster())
                    {
#endif
            ModifyCapacityIfRequired();
            while (true)
            {
                try
                {
                    var          minNextMax = Range.Max;
                    JsonDocument document;

                    try
                    {
                        document = GetDocument(databaseCommands);
                    }
                    catch (ConflictException e)
                    {
                        // resolving the conflict by selecting the highest number
                        var highestMax = e.ConflictedVersionIds
                                         .Select(conflictedVersionId => GetMaxFromDocument(databaseCommands.Get(conflictedVersionId), minNextMax))
                                         .Max();

                        PutDocument(databaseCommands, new JsonDocument
                        {
                            Etag       = e.Etag,
                            Metadata   = new RavenJObject(),
                            DataAsJson = RavenJObject.FromObject(new { Max = highestMax }),
                            Key        = HiLoDocumentKey
                        });

                        continue;
                    }

                    long min, max;
                    if (document == null)
                    {
                        min      = minNextMax + 1;
                        max      = minNextMax + capacity;
                        document = new JsonDocument
                        {
                            Etag = Etag.Empty,
                            // sending empty etag means - ensure the that the document does NOT exists
                            Metadata   = new RavenJObject(),
                            DataAsJson = RavenJObject.FromObject(new { Max = max }),
                            Key        = HiLoDocumentKey
                        };
                    }
                    else
                    {
                        var oldMax = GetMaxFromDocument(document, minNextMax);
                        min = oldMax + 1;
                        max = oldMax + capacity;

                        document.DataAsJson["Max"] = max;
                    }
                    PutDocument(databaseCommands, document);

                    return(new RangeValue(min, max));
                }
                catch (ConcurrencyException)
                {
                    // expected, we need to retry
                }
            }
#if !NETFX_CORE
        }
#endif
        }
Exemplo n.º 27
0
        private Range GetNextRange()
        {
            using (new TransactionScope(TransactionScopeOption.Suppress))
            {
                IncreaseCapacityIfRequired();
                while (true)
                {
                    try
                    {
                        var          minNextMax = range.Max;
                        JsonDocument document;

                        try
                        {
                            document = GetDocument();
                        }
                        catch (ConflictException e)
                        {
                            // resolving the conflict by selecting the highest number
                            var highestMax = e.ConflictedVersionIds
                                             .Select(conflictedVersionId => GetMaxFromDocument(databaseCommands.Get(conflictedVersionId), minNextMax))
                                             .Max();

                            PutDocument(new JsonDocument
                            {
                                Etag       = e.Etag,
                                Metadata   = new RavenJObject(),
                                DataAsJson = RavenJObject.FromObject(new { Max = highestMax }),
                                Key        = HiLoDocumentKey
                            });

                            continue;
                        }

                        long min, max;
                        if (document == null)
                        {
                            min      = minNextMax + 1;
                            max      = minNextMax + capacity;
                            document = new JsonDocument
                            {
                                Etag = Guid.Empty,
                                // sending empty guid means - ensure the that the document does NOT exists
                                Metadata   = new RavenJObject(),
                                DataAsJson = RavenJObject.FromObject(new { Max = max }),
                                Key        = HiLoDocumentKey
                            };
                        }
                        else
                        {
                            var oldMax = GetMaxFromDocument(document, minNextMax);
                            min = oldMax + 1;
                            max = oldMax + capacity;

                            document.DataAsJson["Max"] = max;
                        }
                        PutDocument(document);

                        return(new Range(min, max));
                    }
                    catch (ConcurrencyException)
                    {
                        // expected, we need to retry
                    }
                }
            }
        }
Exemplo n.º 28
0
 public object ExecuteEmbedded(IDatabaseCommands commands)
 {
     return(commands.Get(ids, includes));
 }