public object ExecuteEmbedded(IDatabaseCommands commands) { if (string.IsNullOrEmpty(transformer) == false) { return(commands.Get(new[] { key }, null, transformer)); } return(commands.Get(key)); }
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); }
///<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; } } } }
///<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; } } } }
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); }
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); }
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); }
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"); } }
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"); } }
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); }
///<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()); }
public object ExecuteEmbedded(IDatabaseCommands commands) { var includePaths = this.includes != null ? this.includes.Select(x => x.Key).ToArray() : null; return commands.Get(ids, includePaths); }
private JsonDocument GetDocument() { return(databaseCommands.Get(RavenKeyGeneratorsHilo + tag)); }
public Task <JsonDocument> GetAsync(string key) { return(new CompletedTask <JsonDocument>(databaseCommands.Get(key))); }
public object ExecuteEmbedded(IDatabaseCommands commands) { return(commands.Get(ids, null, transformer)); }
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"); }
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 }
private JsonDocument GetDocument(IDatabaseCommands databaseCommands) { var documents = databaseCommands.Get(new[] { HiLoDocumentKey, RavenKeyServerPrefix }, new string[0]); return HandleGetDocumentResult(documents); }
public object ExecuteEmbedded(IDatabaseCommands commands) { return(commands.Get(key)); }
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); }
public object ExecuteEmbedded(IDatabaseCommands commands) { var includePaths = includes != null?includes.Select(x => x.Key).ToArray() : null; return(commands.Get(ids, includePaths, transformer)); }
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); }
private JsonDocument GetDocument(IDatabaseCommands databaseCommands) { var documents = databaseCommands.Get(new[] { HiLoDocumentKey, RavenKeyServerPrefix }, new string[0]); return(HandleGetDocumentResult(documents)); }
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 }
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 } } } }
public object ExecuteEmbedded(IDatabaseCommands commands) { return(commands.Get(ids, includes)); }