Exemple #1
0
        /// <summary>
        /// Supports reading a named stream from the persistent store via the grid cache
        /// </summary>
        public FileSystemErrorStatus ReadStreamFromPersistentStore(Guid dataModelId, string streamName, FileSystemStreamType streamType, out MemoryStream stream)
        {
            stream = null;

            try
            {
                var cacheKey = ComputeNamedStreamCacheKey(dataModelId, streamName);

                //Log.LogInformation($"Getting key:{cacheKey}");

                try
                {
                    using var ms    = new MemoryStream(NonSpatialCache(streamType).Get(cacheKey).Bytes);
                    stream          = MemoryStreamCompression.Decompress(ms);
                    stream.Position = 0;
                }
                catch (KeyNotFoundException)
                {
                    return(FileSystemErrorStatus.GranuleDoesNotExist);
                }

                return(FileSystemErrorStatus.OK);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Exception occurred:");

                stream = null;
                return(FileSystemErrorStatus.UnknownErrorReadingFromFS);
            }
        }
Exemple #2
0
        public void CompressTest()
        {
            byte[] someBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };

            MemoryStream ms     = new MemoryStream(someBytes);
            MemoryStream result = MemoryStreamCompression.Decompress(MemoryStreamCompression.Compress(ms));

            Assert.True(result.ToArray().SequenceEqual(someBytes), "Bytes are not the same after compression/decompression cycle");
        }
Exemple #3
0
        /// <summary>
        /// Supports writing a named data stream to the persistent store via the grid cache.
        /// </summary>
        public FileSystemErrorStatus WriteStreamToPersistentStore(Guid dataModelId,
                                                                  string streamName,
                                                                  FileSystemStreamType streamType,
                                                                  MemoryStream mutableStream,
                                                                  object source)
        {
            try
            {
                var cacheKey = ComputeNamedStreamCacheKey(dataModelId, streamName);

                using (var compressedStream = MemoryStreamCompression.Compress(mutableStream))
                {
                    if (_log.IsTraceEnabled())
                    {
                        _log.LogInformation($"Putting key:{cacheKey} in {NonSpatialCache(streamType).Name}, size:{mutableStream.Length} -> {compressedStream.Length}, ratio:{(compressedStream.Length / (1.0 * mutableStream.Length)) * 100}%");
                    }
                    NonSpatialCache(streamType).Put(cacheKey, new SerialisedByteArrayWrapper(compressedStream.ToArray()));
                }

                try
                {
                    // Create the immutable stream from the source data
                    if (Mutability == StorageMutability.Mutable && ImmutableProxy != null)
                    {
                        if (!PerformNonSpatialImmutabilityConversion(mutableStream, ImmutableProxy.NonSpatialCache(streamType), cacheKey, streamType, source))
                        {
                            _log.LogError("Unable to project an immutable stream");
                            return(FileSystemErrorStatus.MutableToImmutableConversionError);
                        }
                    }
                }
                catch (Exception e)
                {
                    _log.LogError(e, $"Exception performing mutability conversion in {nameof(WriteStreamToPersistentStore)}");
                    return(FileSystemErrorStatus.MutableToImmutableConversionError);
                }

                return(FileSystemErrorStatus.OK);
            }
            catch (Exception e)
            {
                _log.LogError(e, $"Exception writing stream {streamName} to persistent store");
                return(FileSystemErrorStatus.UnknownErrorWritingToFS);
            }
        }
Exemple #4
0
        /// <summary>
        /// Supports writing a spatial data stream to the persistent store via the grid cache.
        /// </summary>
        public FileSystemErrorStatus WriteSpatialStreamToPersistentStore(Guid dataModelId,
                                                                         string streamName,
                                                                         int subGridX, int subGridY,
                                                                         long segmentStartDateTicks, long segmentEndDateTicks,
                                                                         long version,
                                                                         FileSystemStreamType streamType,
                                                                         MemoryStream mutableStream,
                                                                         object source)
        {
            try
            {
                var cacheKey = new SubGridSpatialAffinityKey(version, dataModelId, subGridX, subGridY, segmentStartDateTicks, segmentEndDateTicks);

                using (var compressedStream = MemoryStreamCompression.Compress(mutableStream))
                {
                    var spatialCache = SpatialCache(streamType);
                    if (_log.IsTraceEnabled())
                    {
                        _log.LogInformation($"Putting key:{cacheKey} in {spatialCache.Name}, size:{mutableStream.Length} -> {compressedStream.Length}, ratio:{(compressedStream.Length / (1.0 * mutableStream.Length)) * 100}%");
                    }
                    spatialCache.Put(cacheKey, new SerialisedByteArrayWrapper(compressedStream.ToArray()));
                }

                // Convert the stream to the immutable form and write it to the immutable storage proxy
                try
                {
                    if (Mutability == StorageMutability.Mutable && ImmutableProxy != null)
                    {
                        PerformSpatialImmutabilityConversion(mutableStream, ImmutableProxy.SpatialCache(streamType), cacheKey, streamType, source);
                    }
                }
                catch (Exception e)
                {
                    _log.LogError(e, $"Exception performing mutability conversion in {nameof(WriteSpatialStreamToPersistentStore)}");
                    return(FileSystemErrorStatus.MutableToImmutableConversionError);
                }

                return(FileSystemErrorStatus.OK);
            }
            catch (Exception e)
            {
                _log.LogError(e, $"Exception writing spatial stream {streamName} to persistent store");
                return(FileSystemErrorStatus.UnknownErrorWritingToFS);
            }
        }
Exemple #5
0
        /// <summary>
        /// Supports reading a stream of spatial data from the persistent store via the grid cache
        /// </summary>
        public FileSystemErrorStatus ReadSpatialStreamFromPersistentStore(Guid dataModelId,
                                                                          string streamName,
                                                                          int subGridX, int subGridY,
                                                                          long segmentStartDateTicks,
                                                                          long segmentEndDateTicks,
                                                                          long version,
                                                                          FileSystemStreamType streamType,
                                                                          out MemoryStream stream)
        {
            stream = null;

            try
            {
                var cacheKey = new SubGridSpatialAffinityKey(version, dataModelId, subGridX, subGridY, segmentStartDateTicks, segmentEndDateTicks);

                //Log.LogInformation($"Getting key:{streamName}");

                try
                {
                    using var ms    = new MemoryStream(SpatialCache(streamType).Get(cacheKey).Bytes);
                    stream          = MemoryStreamCompression.Decompress(ms);
                    stream.Position = 0;
                }
                catch (KeyNotFoundException)
                {
                    return(FileSystemErrorStatus.GranuleDoesNotExist);
                }

                return(FileSystemErrorStatus.OK);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Exception occurred:");

                stream = null;
                return(FileSystemErrorStatus.UnknownErrorReadingFromFS);
            }
        }
Exemple #6
0
 public void DeCompressTest()
 {
     Assert.Null(MemoryStreamCompression.Decompress(null));
 }
Exemple #7
0
 public void CompressTest_Null()
 {
     Assert.Null(MemoryStreamCompression.Compress(null));
 }