private static IDatabaseCommands SetupCommands(IDatabaseCommands databaseCommands, string database, ICredentials credentialsForSession, OpenSessionOptions options) { if (database != null) { databaseCommands = databaseCommands.ForDatabase(database); } if (credentialsForSession != null) { databaseCommands = databaseCommands.With(credentialsForSession); } if (options.ForceReadFromMaster) { databaseCommands.ForceReadFromMaster(); } return(databaseCommands); }
public void ForceReadFromMaster() { databaseCommands.ForceReadFromMaster(); }
private static IDatabaseCommands SetupCommands(IDatabaseCommands databaseCommands, string database, ICredentials credentialsForSession, OpenSessionOptions options) { if (database != null) databaseCommands = databaseCommands.ForDatabase(database); if (credentialsForSession != null) databaseCommands = databaseCommands.With(credentialsForSession); if (options.ForceReadFromMaster) databaseCommands.ForceReadFromMaster(); return databaseCommands; }
private RangeValue GetNextRange(IDatabaseCommands databaseCommands) { using (new TransactionScope(TransactionScopeOption.Suppress)) using (databaseCommands.ForceReadFromMaster()) { 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 = 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(databaseCommands, document); return(new RangeValue(min, max)); } catch (ConcurrencyException) { // expected, we need to retry } } } }
private RangeValue GetNextRange(IDatabaseCommands databaseCommands) { using (new TransactionScope(TransactionScopeOption.Suppress)) using (RavenTransactionAccessor.SupressExplicitRavenTransaction()) using (databaseCommands.ForceReadFromMaster()) { 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 } } } }
private RangeValue GetNextRange(IDatabaseCommands databaseCommands) { #if !DNXCORE50 using (new TransactionScope(TransactionScopeOption.Suppress)) using (RavenTransactionAccessor.SupressExplicitRavenTransaction()) #endif using (databaseCommands.ForceReadFromMaster()) using (databaseCommands.DisableAllCaching()) { // we need the latest value of the capacity var calculatedCapacity = Interlocked.Read(ref capacity); ModifyCapacityIfRequired(ref calculatedCapacity); 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, calculatedCapacity)) .Max(); PutDocument(databaseCommands, new JsonDocument { Etag = e.Etag, Metadata = new RavenJObject(), DataAsJson = RavenJObject.FromObject(new { Max = highestMax }), Key = HiLoDocumentKey }); continue; } IncreaseCapacityIfRequired(ref calculatedCapacity); long min, max; if (document == null) { min = minNextMax + 1; max = minNextMax + calculatedCapacity; 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, calculatedCapacity); min = oldMax + 1; max = oldMax + calculatedCapacity; document.DataAsJson["Max"] = max; } PutDocument(databaseCommands, document); return(new RangeValue(min, max)); } catch (ConcurrencyException) { // expected, we need to retry // we'll try to increase the capacity ModifyCapacityIfRequired(ref calculatedCapacity); } } } }