Example #1
0
        /// <summary>
        /// Reads the instance.
        /// </summary>
        internal static IAffinityFunction Read(IBinaryRawReader reader)
        {
            AffinityFunctionBase fun;

            var typeCode = reader.ReadByte();

            switch (typeCode)
            {
            case TypeCodeNull:
                return(null);

            case TypeCodeFair:
                fun = new FairAffinityFunction();
                break;

            case TypeCodeRendezvous:
                fun = new RendezvousAffinityFunction();
                break;

            case TypeCodeUser:
                var f = reader.ReadObject <IAffinityFunction>();
                reader.ReadInt();     // skip partition count

                return(f);

            default:
                throw new InvalidOperationException("Invalid AffinityFunction type code: " + typeCode);
            }

            fun.Partitions       = reader.ReadInt();
            fun.ExcludeNeighbors = reader.ReadBoolean();

            return(fun);
        }
        /// <summary>
        /// Writes the backup filter.
        /// </summary>
        private static void WriteBackupFilter(IBinaryRawWriter writer, RendezvousAffinityFunction func)
        {
            if (func.AffinityBackupFilter == null)
            {
                writer.WriteInt(-1);
                return;
            }

            var filter = func.AffinityBackupFilter as ClusterNodeAttributeAffinityBackupFilter;

            if (filter == null)
            {
                throw new NotSupportedException(string.Format(
                                                    "Unsupported RendezvousAffinityFunction.AffinityBackupFilter: '{0}'. " +
                                                    "Only predefined implementations are supported: '{1}'",
                                                    func.AffinityBackupFilter.GetType().FullName,
                                                    typeof(ClusterNodeAttributeAffinityBackupFilter).Name));
            }

            IgniteArgumentCheck.NotNullOrEmpty(filter.AttributeNames,
                                               "ClusterNodeAttributeAffinityBackupFilter.AttributeNames");

            writer.WriteInt(filter.AttributeNames.Count);

            foreach (var attr in filter.AttributeNames)
            {
                writer.WriteString(attr);
            }
        }
        /// <summary>
        /// Reads the instance.
        /// </summary>
        internal static IAffinityFunction Read(IBinaryRawReader reader)
        {
            Debug.Assert(reader != null);

            var typeCode = reader.ReadByte();

            if (typeCode == TypeCodeNull)
            {
                return(null);
            }

            var partitions    = reader.ReadInt();
            var exclNeighbors = reader.ReadBoolean();
            var overrideFlags = (UserOverrides)reader.ReadByte();
            var userFunc      = reader.ReadObjectEx <IAffinityFunction>();

            if (userFunc != null)
            {
                Debug.Assert(overrideFlags != UserOverrides.None);

                var fair = userFunc as FairAffinityFunction;
                if (fair != null)
                {
                    fair.Partitions       = partitions;
                    fair.ExcludeNeighbors = exclNeighbors;
                }

                var rendezvous = userFunc as RendezvousAffinityFunction;
                if (rendezvous != null)
                {
                    rendezvous.Partitions       = partitions;
                    rendezvous.ExcludeNeighbors = exclNeighbors;
                }

                return(userFunc);
            }

            Debug.Assert(overrideFlags == UserOverrides.None);
            AffinityFunctionBase fun;

            switch (typeCode)
            {
            case TypeCodeFair:
                fun = new FairAffinityFunction();
                break;

            case TypeCodeRendezvous:
                fun = new RendezvousAffinityFunction();
                break;

            default:
                throw new InvalidOperationException("Invalid AffinityFunction type code: " + typeCode);
            }

            fun.Partitions       = partitions;
            fun.ExcludeNeighbors = exclNeighbors;

            return(fun);
        }
        public void GlobalSetup()
        {
            _ignite = Ignition.Start();

            // Reduce number of partitions to reduce overhead.
            // With real-world data sets this won't be needed.
            var affinityFunction = new RendezvousAffinityFunction
            {
                Partitions = 10
            };

            _cache = _ignite.CreateCache <int, Person>(new CacheConfiguration
            {
                Name             = "normalCache",
                AffinityFunction = affinityFunction
            });

            _cacheWithPlatformCache = _ignite.CreateCache <int, Person>(new CacheConfiguration
            {
                Name                       = "platformEnabledCache",
                AffinityFunction           = affinityFunction,
                PlatformCacheConfiguration = new PlatformCacheConfiguration
                {
                    KeyTypeName   = typeof(int).AssemblyQualifiedName,
                    ValueTypeName = typeof(Person).AssemblyQualifiedName
                }
            });

            var data = Enumerable.Range(1, 100000)
                       .Select(x => Person.CreateInstance <Person>(x, dataSize: 10))
                       .Select(p => new KeyValuePair <int, Person>(p.Id, p))
                       .ToArray();

            _cache.PutAll(data);
            _cacheWithPlatformCache.PutAll(data);
        }
Example #5
0
        /// <summary>
        /// Reads the instance.
        /// </summary>
        internal static IAffinityFunction Read(IBinaryRawReader reader)
        {
            AffinityFunctionBase fun;

            var typeCode = reader.ReadByte();
            switch (typeCode)
            {
                case TypeCodeNull:
                    return null;
                case TypeCodeFair:
                    fun = new FairAffinityFunction();
                    break;
                case TypeCodeRendezvous:
                    fun = new RendezvousAffinityFunction();
                    break;
                case TypeCodeUser:
                    var f = reader.ReadObject<IAffinityFunction>();
                    reader.ReadInt(); // skip partition count

                    return f;
                default:
                    throw new InvalidOperationException("Invalid AffinityFunction type code: " + typeCode);
            }

            fun.Partitions = reader.ReadInt();
            fun.ExcludeNeighbors = reader.ReadBoolean();

            return fun;
        }
        /// <summary>
        /// Reads the instance.
        /// </summary>
        internal static IAffinityFunction Read(IBinaryRawReader reader)
        {
            Debug.Assert(reader != null);

            var typeCode = reader.ReadByte();

            if (typeCode == TypeCodeNull)
                return null;

            var partitions = reader.ReadInt();
            var exclNeighbors = reader.ReadBoolean();
            var overrideFlags = (UserOverrides)reader.ReadByte();
            var userFunc = reader.ReadObjectEx<IAffinityFunction>();

            if (userFunc != null)
            {
                Debug.Assert(overrideFlags != UserOverrides.None);

                var fair = userFunc as FairAffinityFunction;
                if (fair != null)
                {
                    fair.Partitions = partitions;
                    fair.ExcludeNeighbors = exclNeighbors;
                }

                var rendezvous = userFunc as RendezvousAffinityFunction;
                if (rendezvous != null)
                {
                    rendezvous.Partitions = partitions;
                    rendezvous.ExcludeNeighbors = exclNeighbors;
                }

                return userFunc;
            }

            Debug.Assert(overrideFlags == UserOverrides.None);
            AffinityFunctionBase fun;

            switch (typeCode)
            {
                case TypeCodeFair:
                    fun = new FairAffinityFunction();
                    break;
                case TypeCodeRendezvous:
                    fun = new RendezvousAffinityFunction();
                    break;
                default:
                    throw new InvalidOperationException("Invalid AffinityFunction type code: " + typeCode);
            }

            fun.Partitions = partitions;
            fun.ExcludeNeighbors = exclNeighbors;

            return fun;
        }