Esempio n. 1
0
        void StartNewPureValueFile()
        {
            _pureValueFile       = _fileCollection.AddFile("hpv");
            _pureValueFileWriter = _pureValueFile.GetAppenderWriter();
            var fileInfo = new FilePureValuesWithId(_subDBId, _fileCollection.NextGeneration(), _fileCollection.Guid);

            fileInfo.WriteHeader(_pureValueFileWriter);
            _pureValueFile.Flush();
            _fileCollection.SetInfo(_pureValueFile.Index, fileInfo);
        }
Esempio n. 2
0
        StorageValue StoreContent(ByteBuffer content)
        {
            var result = new StorageValue();

            result.Compressed    = false;
            result.ContentLength = (uint)content.Length;
            if (_pureValueFile == null)
            {
                StartNewPureValueFile();
            }
            result.FileId  = _pureValueFile.Index;
            result.FileOfs = (uint)_pureValueFileWriter.GetCurrentPosition();
            _pureValueFileWriter.WriteBlock(content);
            _pureValueFile.Flush();
            if (_pureValueFileWriter.GetCurrentPosition() >= _maxFileSize)
            {
                _pureValueFile.HardFlushTruncateSwitchToReadOnlyMode();
                StartNewPureValueFile();
            }
            return(result);
        }
Esempio n. 3
0
        public void Put(ByteBuffer key, ByteBuffer content)
        {
            if (key.Length != _keySize)
            {
                throw new ArgumentException("Key has wrong Length not equal to KeySize");
            }
            if (content.Length == 0)
            {
                throw new ArgumentException("Empty Content cannot be stored");
            }
            var        k = new ByteStructs.Key20(key);
            CacheValue cacheValue;

            if (_cache.TryGetValue(k, out cacheValue))
            {
                return;
            }
            cacheValue.AccessRate = 1;
again:
            var writer = _cacheValueWriter;

            while (writer == null || writer.GetCurrentPosition() + content.Length > _sizeLimitOfOneValueFile)
            {
                StartNewValueFile();
                writer = _cacheValueWriter;
            }
            lock (writer)
            {
                if (writer != _cacheValueWriter)
                {
                    goto again;
                }
                cacheValue.FileId  = _cacheValueFileId;
                cacheValue.FileOfs = (uint)_cacheValueWriter.GetCurrentPosition();
                _cacheValueWriter.WriteBlock(content);
                _cacheValueFile.Flush();
            }
            cacheValue.ContentLength = (uint)content.Length;
            _cache.TryAdd(k, cacheValue);
        }