Esempio n. 1
0
        public async Task <string?> GetAsync(string url, string path)
        {
            string decodedUrl  = StoreUrlEncoder.Decode(url);
            string decodedPath = StoreUrlEncoder.Decode(path);

            // TODO: User context for repository ID & login
            var store = _storeFactory.Create(decodedUrl);

            if (store == null)
            {
                _logger.LogWarning("No store match for get {0}", decodedUrl);
                throw new NotFoundException("Protocol not registered", decodedUrl);
            }
            return(await store.ReadStringFileAsync(decodedUrl, decodedPath));
        }
Esempio n. 2
0
        public async Task <Stream> Download(RecordFileModel file)
        {
            var store      = _storeFactory.Create(file.FileStoreSchema);
            var recordFile = _mapper.Map <RecordFile>(file);

            return(await store.Download(recordFile));
        }
Esempio n. 3
0
        private BloomStorageLevel[] CreateStorageLevels(IBloomConfig config)
        {
            void ValidateConfigValue()
            {
                if (config.IndexLevelBucketSizes.Length == 0)
                {
                    throw new ArgumentException($"Can not create bloom index when there are no {nameof(config.IndexLevelBucketSizes)} provided.", nameof(config.IndexLevelBucketSizes));
                }
            }

            List <int> InsertBaseLevelIfNeeded()
            {
                List <int> sizes = config.IndexLevelBucketSizes.ToList();

                if (sizes.FirstOrDefault() != 1)
                {
                    sizes.Insert(0, 1);
                }

                return(sizes);
            }

            void ValidateCurrentDbStructure(IList <int> sizes)
            {
                var levelsFromDb = _bloomInfoDb.Get(LevelsKey);

                if (levelsFromDb == null)
                {
                    _bloomInfoDb.Set(LevelsKey, Rlp.Encode(sizes.ToArray()).Bytes);
                }
                else
                {
                    var stream        = new RlpStream(levelsFromDb);
                    var dbBucketSizes = stream.DecodeArray(x => x.DecodeInt());

                    if (!dbBucketSizes.SequenceEqual(sizes))
                    {
                        throw new ArgumentException($"Can not load bloom db. {nameof(config.IndexLevelBucketSizes)} changed without rebuilding bloom db. Db structure is [{string.Join(",", dbBucketSizes)}]. Current config value is [{string.Join(",", sizes)}]. " +
                                                    $"If you want to rebuild {DbNames.Bloom} db, please delete db folder. If not, please change config value to reflect current db structure", nameof(config.IndexLevelBucketSizes));
                    }
                }
            }

            ValidateConfigValue();
            var configIndexLevelBucketSizes = InsertBaseLevelIfNeeded();

            ValidateCurrentDbStructure(configIndexLevelBucketSizes);

            var lastLevelSize = 1;

            return(configIndexLevelBucketSizes
                   .Select((size, i) =>
            {
                byte level = (byte)(configIndexLevelBucketSizes.Count - i - 1);
                var levelElementSize = lastLevelSize * size;
                lastLevelSize = levelElementSize;
                return new BloomStorageLevel(_fileStoreFactory.Create(level.ToString()), level, levelElementSize, size, _config.MigrationStatistics);
            })
                   .Reverse()
                   .ToArray());
        }