Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 public void ForceReadFromMaster()
 {
     databaseCommands.ForceReadFromMaster();
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
        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
                        }
                    }
                }
        }
Exemplo n.º 5
0
		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
					}
				}
			}
		}
Exemplo n.º 6
0
        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);
                        }
                    }
                }
        }