Пример #1
0
        public void InitializeFromDump(string path)
        {
            path = DumpHelper.NormalizeDumpPath(path);

            var schemaPath = Path.Combine(path, "schema.json");

            var json = File.ReadAllText(schemaPath);

            var schema = SerializationHelper.DeserializeJson <Schema>(json);

            foreach (var typeDescription in schema.TypeDescriptions)
            {
                // register the type on the server

                var shard = 0;
                foreach (var client in CacheClients)
                {
                    var request = new RegisterTypeRequest(typeDescription, shard, CacheClients.Count);

                    var response = client.Channel.SendRequest(request);

                    if (response is ExceptionResponse exResponse)
                    {
                        throw new CacheException("Error while registering a type on the server", exResponse.Message,
                                                 exResponse.CallStack);
                    }

                    shard++;
                }

                FeedMany(DumpHelper.ObjectsInDump(path, typeDescription), true);
            }

            // reinitialize the sequences. As the shard count has probably changed reinitialize all the sequences in each shard
            // starting with the maximum value

            var maxValues = new Dictionary <string, int>();

            var files = Directory.EnumerateFiles(path, "sequence_*.json");

            foreach (var file in files)
            {
                var sequenceJson = File.ReadAllText(file);
                var seq          = SerializationHelper.DeserializeJson <Dictionary <string, int> >(sequenceJson);
                foreach (var pair in seq)
                {
                    var keyFound = maxValues.ContainsKey(pair.Key);
                    if (keyFound && maxValues[pair.Key] < pair.Value || !keyFound)
                    {
                        maxValues[pair.Key] = pair.Value;
                    }
                }
            }

            // resync sequences on the server

            ResyncUniqueIds(maxValues);
        }
Пример #2
0
        internal void LoadFromDump(string path, int shardIndex)
        {
            foreach (var cachedObject in DumpHelper.ObjectsInDump(path, CollectionSchema, shardIndex))
            {
                InternalAddNew(cachedObject);

                // only in debug, only if this simulation was activated (for tests only)
                Dbg.SimulateException(100, shardIndex);
            }
        }
Пример #3
0
        public void InitializeFromDump(string path)
        {
            path = DumpHelper.NormalizeDumpPath(path);

            var schemaPath = Path.Combine(path, "schema.json");

            var json = File.ReadAllText(schemaPath);

            var schema = SerializationHelper.DeserializeJson <Schema>(json);

            foreach (var collections in schema.CollectionsDescriptions)
            {
                // register the type on the server
                var shard = 0;
                foreach (var client in CacheClients)
                {
                    client.DeclareCollection(collections.Key, collections.Value, shard);

                    shard++;
                }

                FeedMany(collections.Key, DumpHelper.ObjectsInDump(path, collections.Value), true);
            }

            // reinitialize the sequences. As the shard count has probably changed reinitialize all the sequences in each shard
            // starting with the maximum value

            var maxValues = new Dictionary <string, int>();

            var files = Directory.EnumerateFiles(path, "sequence_*.json");

            foreach (var file in files)
            {
                var sequenceJson = File.ReadAllText(file);
                var seq          = SerializationHelper.DeserializeJson <Dictionary <string, int> >(sequenceJson);
                foreach (var pair in seq)
                {
                    var keyFound = maxValues.ContainsKey(pair.Key);
                    if (keyFound && maxValues[pair.Key] < pair.Value || !keyFound)
                    {
                        maxValues[pair.Key] = pair.Value;
                    }
                }
            }

            // resync sequences on the server

            ResyncUniqueIds(maxValues);
        }