Exemple #1
0
        public async Task SetPriority(string name, IndexPriority priority)
        {
            await _indexLocker.WaitAsync();

            try
            {
                var index = GetIndex(name);
                if (index == null)
                {
                    IndexDoesNotExistException.ThrowFor(name);
                }

                var faultyInMemoryIndex = index as FaultyInMemoryIndex;
                if (faultyInMemoryIndex != null)
                {
                    faultyInMemoryIndex.SetPriority(priority); // this will throw proper exception
                    return;
                }

                var command = new SetIndexPriorityCommand(name, priority, _documentDatabase.Name);

                var(etag, _) = await _serverStore.SendToLeaderAsync(command);

                await _documentDatabase.RachisLogIndexNotifications.WaitForIndexNotification(etag);
            }
            finally
            {
                _indexLocker.Release();
            }
        }
        public SetIndexesPriorityOperation(string indexName, IndexPriority priority)
        {
            if (indexName == null)
            {
                throw new ArgumentNullException(nameof(indexName));
            }

            _parameters = new Parameters
            {
                IndexNames = new[] { indexName },
                Priority   = priority
            };
        }
Exemple #3
0
        public unsafe void WritePriority(IndexPriority priority)
        {
            TransactionOperationContext context;

            using (_contextPool.AllocateOperationContext(out context))
                using (var tx = context.OpenWriteTransaction())
                {
                    var   statsTree   = tx.InnerTransaction.ReadTree(IndexSchema.StatsTree);
                    var   priorityInt = (int)priority;
                    Slice prioritySlice;
                    using (Slice.External(context.Allocator, (byte *)&priorityInt, sizeof(int), out prioritySlice))
                        statsTree.Add(IndexSchema.PrioritySlice, prioritySlice);

                    tx.Commit();
                }
        }
Exemple #4
0
        public void WritePriority(IndexPriority priority)
        {
            using (_contextPool.AllocateOperationContext(out TransactionOperationContext context))
                using (var tx = context.OpenWriteTransaction())
                {
                    var oldPriority = _index.Definition.Priority;
                    try
                    {
                        _index.Definition.Priority = priority;
                        _index.Definition.Persist(context, _environment.Options);

                        tx.Commit();
                    }
                    catch (Exception)
                    {
                        _index.Definition.Priority = oldPriority;
                        throw;
                    }
                }
        }
Exemple #5
0
 public void SetIndexPriority(string name, IndexPriority priority)
 {
     AsyncHelpers.RunSync(() => asyncServerClient.SetIndexPriorityAsync(name, priority));
 }
 public FaultyAutoIndexDefinition(string name, HashSet <string> collections, IndexLockMode lockMode, IndexPriority priority, IndexState state, IndexField[] mapFields, AutoIndexDefinitionBaseServerSide definition)
     : base(name, collections, lockMode, priority, state, mapFields, definition.Version, definition.DeploymentMode, definition.ClusterState)
 {
     Definition = definition;
 }
Exemple #7
0
 public SetIndexPriorityCommand(string name, IndexPriority priority, string databaseName, string uniqueRequestId)
     : base(databaseName, uniqueRequestId)
 {
     IndexName = name;
     Priority  = priority;
 }
Exemple #8
0
 /// <summary>
 /// Tells the query planner how to select the best index:
 /// by filtering or by sorting. The defult is the filtering
 /// priority, which should be used when a minority of the
 /// records are supposed to be returned. Use sorting priority
 /// when you expect to query back most of the records in
 /// a specific order.
 /// This setting is ignored if you hint a specific index
 /// using 'HintIndex'.
 /// </summary>
 public Query <T> HintIndexPriority(IndexPriority priority)
 {
     this.IndexPriority = priority;
     return(this);
 }
Exemple #9
0
 public FaultyIndexDefinition(string name, HashSet <string> collections, IndexLockMode lockMode, IndexPriority priority,
                              IndexField[] mapFields, IndexDefinition definition)
     : base(name, collections, lockMode, priority, mapFields)
 {
     _definition = definition;
 }
Exemple #10
0
 public FaultyIndexDefinition(string name, IEnumerable <string> collections, IndexLockMode lockMode, IndexPriority priority, IndexState state, IndexField[] mapFields, IndexDefinition definition)
     : base(name, collections, lockMode, priority, state, mapFields, IndexVersion.CurrentVersion, definition.DeploymentMode, definition.ClusterState)
 {
     _definition = definition;
 }
 public FaultyIndexDefinition(string name, IEnumerable <string> collections, IndexLockMode lockMode, IndexPriority priority, IndexField[] mapFields, IndexDefinition definition)
     : base(name, collections, lockMode, priority, mapFields, IndexVersion.CurrentVersion)
 {
     _definition = definition;
 }
Exemple #12
0
 public static string SetIndexPriority(this string url, string index, IndexPriority priority)
 {
     return($"{url}/indexes/set-priority?name={index}&priority={priority}");
 }
Exemple #13
0
 public SetIndexPriorityCommand(string indexName, IndexPriority priority)
 {
     _indexName = indexName ?? throw new ArgumentNullException(nameof(indexName));
     _priority  = priority;
 }
Exemple #14
0
 public FaultyAutoIndexDefinition(string name, HashSet <string> collections, IndexLockMode lockMode, IndexPriority priority, IndexField[] mapFields, AutoIndexDefinitionBase definition)
     : base(name, collections, lockMode, priority, mapFields, definition.Version)
 {
     Definition = definition;
 }
 public override void SetPriority(IndexPriority priority)
 {
     throw new NotSupportedException($"Index {Name} is in-memory implementation of a faulty index", _e);
 }
Exemple #16
0
        /// <summary>
        /// Finds the best index by giving priority to "index filtering" over sorting.
        /// </summary>
        /// <returns></returns>
        private TableIndex <T> FindBestIndex(IndexPriority prio)
        {
            var indices      = Table.GetIndices();
            var orderBy      = Query.Sorting;
            var indexFilters = Query.IndexFilters;

            indices.Sort((i2, i1) => {
                int indexLevel = 0;
                Nullable <int> indexProperty1, indexProperty2;
                bool canBeFiltered1, canBeFiltered2;
                int sortingLevel1 = 0, sortingLevel2 = 0;
                bool sortingCanApply1, sortingCanApply2;

                /*
                 *  Search for the first decisive level
                 */
                do
                {
                    sortingCanApply1 = false;
                    sortingCanApply2 = false;

                    if (i1.PropertyIndices.Count > indexLevel)
                    {
                        // The level is still valid for index 1
                        indexProperty1 = i1.PropertyIndices[indexLevel];
                        canBeFiltered1 = indexFilters.ContainsKey((int)indexProperty1);

                        // Independently check if sorting is possible
                        if (orderBy.Count > sortingLevel1)
                        {
                            if (orderBy[sortingLevel1].Item1 == indexProperty1)
                            {
                                sortingCanApply1 = true;
                                // A sorting directive can only match if the previous
                                //  ones were matching too.
                                sortingLevel1++;
                            }
                        }
                    }
                    else
                    {
                        // Index 1 has run out
                        canBeFiltered1 = false;
                        indexProperty1 = null;
                    }

                    if (i2.PropertyIndices.Count > indexLevel)
                    {
                        // The level is still valid for index 2
                        indexProperty2 = i2.PropertyIndices[indexLevel];
                        canBeFiltered2 = indexFilters.ContainsKey((int)indexProperty2);

                        // Independently check if sorting is possible
                        if (orderBy.Count > sortingLevel2)
                        {
                            if (orderBy[sortingLevel2].Item1 == indexProperty2)
                            {
                                sortingCanApply2 = true;
                                // A sorting directive can only match if the previous
                                //  ones were matching too.
                                sortingLevel2++;
                            }
                        }
                    }
                    else
                    {
                        // Index 2 has run out
                        canBeFiltered2 = false;
                        indexProperty2 = null;
                    }

                    // Both indexes ran out
                    if (indexProperty1 == null && indexProperty2 == null)
                    {
                        break;
                    }

                    // They are the same => no winner on this level
                    if (indexProperty1 == indexProperty2)
                    {
                        indexLevel++;
                        continue;
                    }

                    if (prio == IndexPriority.Filtering)
                    {
                        /*
                         *  If only one of the properties is used in an
                         *  "index filtering" (or "Where") expression,
                         *  then its index wins.
                         */
                        if (canBeFiltered1 && !canBeFiltered2)
                        {
                            return(1);
                        }
                        if (canBeFiltered2 && !canBeFiltered1)
                        {
                            return(-1);
                        }

                        /*
                         *  If none or both of the fields in the current index level
                         *  are filtered by a "Where" statement, then check if
                         *  any of the sorting directives apply.
                         */
                        if (sortingCanApply1 && !sortingCanApply2)
                        {
                            return(1);
                        }
                        if (sortingCanApply2 && !sortingCanApply1)
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        /*
                         *  If only one of them is used on the current
                         *  sorting level, then it wins.
                         */
                        if (sortingCanApply1 && !sortingCanApply2)
                        {
                            return(1);
                        }
                        if (sortingCanApply2 && !sortingCanApply1)
                        {
                            return(-1);
                        }

                        /*
                         *  If none or both fields can be filtered,
                         *  then check is "index filtering" can
                         *  be applied.
                         */
                        if (canBeFiltered1 && !canBeFiltered2)
                        {
                            return(1);
                        }
                        if (canBeFiltered2 && !canBeFiltered1)
                        {
                            return(-1);
                        }
                    }

                    indexLevel++;
                } while(true);

                /*
                 *  If it's not possible to choose between the two,
                 *  then choose the one which precedes the other
                 *  in the list of index annotations at the
                 *  table definition. As it is expected that the
                 *  user ordered the indexes in a smart way.
                 *  (Rank 0 is the first)
                 */
                return(i2.Rank - i1.Rank);
            });

            return(indices.First());
        }
 public SetIndexPriorityCommand(string name, IndexPriority priority, string databaseName)
     : base(databaseName)
 {
     IndexName = name;
     Priority  = priority;
 }