Ejemplo n.º 1
0
        /// <summary>
        ///     Creates the associated <see cref="DataStore" /> for new cacheable type
        /// </summary>
        /// <param name="request"></param>
        /// <param name="client"></param>
        private void RegisterType(RegisterTypeRequest request, IClient client)
        {
            try
            {
                var typeDescription = request.CollectionSchema;

                var collectionName = typeDescription.CollectionName;

                var dataStore = DataStores.TryGetValue(collectionName);


                if (ShardCount == 0) // not initialized
                {
                    ShardIndex = request.ShardIndex;
                    ShardCount = request.ShardsInCluster;
                }
                else // check it didn't change
                {
                    if (ShardIndex != request.ShardIndex || ShardCount != request.ShardsInCluster)
                    {
                        throw new NotSupportedException(
                                  $"Cluster configuration changed. This node was shard {ShardIndex} / {ShardCount} and now is {request.ShardIndex} / {request.ShardsInCluster}");
                    }
                }

                if (dataStore != null) //type already registered
                {
                    //if the type description changed reindex
                    if (!typeDescription.Equals(dataStore.CollectionSchema))
                    {
                        var newDataStore = DataStore.Reindex(dataStore, typeDescription);

                        DataStores[collectionName] = newDataStore;

                        _serviceContainer.SchemaPersistence.SaveSchema(GenerateSchema());
                    }
                }
                else // new type, store it in the type dictionary and initialize its DataStore
                {
                    var newDataStore =
                        new DataStore(typeDescription, new NullEvictionPolicy(), _serviceContainer.NodeConfig.FullTextConfig);


                    DataStores.Add(collectionName, newDataStore);

                    _serviceContainer.SchemaPersistence.SaveSchema(GenerateSchema());
                }

                client?.SendResponse(new NullResponse());
            }
            catch (Exception e)
            {
                client?.SendResponse(new ExceptionResponse(e));
            }
        }
Ejemplo n.º 2
0
        private void InternalProcessRegisterType(RegisterTypeRequest request)
        {
            var typeDescription = request.TypeDescription;

            if (ShardCount == 0) // not initialized
            {
                ShardIndex = request.ShardIndex;
                ShardCount = request.ShardsInCluster;
            }
            else // check it didn't change
            {
                if (ShardIndex != request.ShardIndex || ShardCount != request.ShardsInCluster)
                {
                    throw new NotSupportedException(
                              $"Cluster configuration changed. This node was shard {ShardIndex} / {ShardCount} and now is {request.ShardIndex} / {request.ShardsInCluster}");
                }
            }

            if (_knownTypes.ContainsKey(typeDescription.FullTypeName)) //type already registered
            {
                //check that the type description is the same
                if (!typeDescription.Equals(_knownTypes[typeDescription.FullTypeName]))
                {
                    var message =
                        $"The type {typeDescription.FullTypeName} is already registered but the type description is different";
                    throw new NotSupportedException(message);
                }
            }
            else // new type, store it in the type dictionary and initialize its DataStore
            {
                _knownTypes.Add(typeDescription.FullTypeName, typeDescription);

                PersistenceEngine?.UpdateSchema(GenerateSchema());


                var cfg = Config.ConfigByType.ContainsKey(typeDescription.FullTypeName)
                    ? Config.ConfigByType[typeDescription.FullTypeName]
                    : new ServerDatastoreConfig();

                var evictionPolicy = EvictionPolicyFactory.CreateEvictionPolicy(cfg.Eviction);

                var newDataStore =
                    new DataStore(typeDescription, evictionPolicy);


                Dbg.CheckThat(Profiler != null);

                newDataStore.Profiler = Profiler;
                DataStores.Add(typeDescription.FullTypeName, newDataStore);
            }
        }