Exemplo n.º 1
0
        private List <StationOffsetPoint> GetMockPointsFromSiteModel(Guid projectUid, int countPointsRequired)
        {
            var    points    = new List <StationOffsetPoint>();
            double station   = 0;
            var    siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(projectUid);

            /* this piece of code reads data into memory, using the existence map */
            siteModel.ExistenceMap.ScanAllSetBitsAsSubGridAddresses(address =>
            {
                if (points.Count > countPointsRequired)
                {
                    return;
                }

                var subGrid = SubGridUtilities.LocateSubGridContaining
                                  (siteModel.PrimaryStorageProxy, siteModel.Grid, address.X, address.Y, siteModel.Grid.NumLevels, false, false);

                if (subGrid != null)
                {
                    subGrid.CalculateWorldOrigin(out var originX, out var originY);

                    ((IServerLeafSubGrid)subGrid).Directory.GlobalLatestCells.PassDataExistenceMap.ForEachSetBit(
                        (x, y) =>
                    {
                        points.Add(new StationOffsetPoint(station += 1, 0,
                                                          originY + y * siteModel.CellSize + siteModel.CellSize / 2,
                                                          originX + x * siteModel.CellSize + siteModel.CellSize / 2));
                        return(points.Count < countPointsRequired);
                    });
                }
            });

            return(points);
        }
Exemplo n.º 2
0
        public void NoLocalCachingAfterRequest()
        {
            var siteModel = DITAGFileAndSubGridRequestsFixture.BuildModel
                                (new [] { Path.Combine(TestHelper.CommonTestDataPath, "TestTAGFile.tag") }, out _);

            siteModel.SetStorageRepresentationToSupply(StorageMutability.Mutable);

            siteModel.Grid.CountLeafSubGridsInMemory().Should().Be(0);
            siteModel.Grid.CachingStrategy.Should().Be(ServerSubGridTreeCachingStrategy.CacheSubGridsInTree);

            siteModel.ExistenceMap.CountBits().Should().BeGreaterThan(0);

            // Request all sub grids and ensure they are present in cache
            siteModel.ExistenceMap.ScanAllSetBitsAsSubGridAddresses(address =>
            {
                var subGrid = SubGridUtilities.LocateSubGridContaining
                                  (siteModel.PrimaryStorageProxy, siteModel.Grid, address.X, address.Y, siteModel.Grid.NumLevels, false, false);

                subGrid.Should().NotBeNull();
            });

            siteModel.Grid.CountLeafSubGridsInMemory().Should().BeGreaterThan(0);

            DIContext.Obtain <ISiteModels>().DropSiteModel(siteModel.ID);

            siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(siteModel.ID);
            siteModel.SetStorageRepresentationToSupply(StorageMutability.Immutable);

            siteModel.Grid.CountLeafSubGridsInMemory().Should().Be(0);

            // Request all sub grids and ensure they are NOT present in cache
            siteModel.ExistenceMap.ScanAllSetBitsAsSubGridAddresses(address =>
            {
                var subGrid = SubGridUtilities.LocateSubGridContaining
                                  (siteModel.PrimaryStorageProxy, siteModel.Grid, address.X, address.Y, siteModel.Grid.NumLevels, false, false);

                subGrid.Should().NotBeNull();
                subGrid.Parent.Should().NotBeNull();
                subGrid.Owner.Should().Be(siteModel.Grid);
            });

            siteModel.Grid.CountLeafSubGridsInMemory().Should().Be(0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Locates a sub grid in within this site model. If the sub grid cannot be found it will be created.
        /// If requested from an immutable grid context, the result of this call should be considered as an immutable
        /// copy of the requested data that is valid for the duration the request holds a reference to it. Updates
        /// to sub grids in this data model from ingest processing and other operations performed in mutable contexts
        /// can occur while this request is in process, but will not affected the immutable copy initially requested.
        /// If requested from a mutable grid context the calling context is responsible for ensuring serialized write access
        /// to the data elements being requested.
        /// </summary>
        // ReSharper disable once MemberCanBePrivate.Global
        public IServerLeafSubGrid LocateOrCreateSubGrid(IServerSubGridTree grid, int cellX, int cellY)
        {
            var result = SubGridUtilities.LocateSubGridContaining(
                _storageProxySubGrids,
                grid,
                // DataStoreInstance.GridDataCache,
                cellX, cellY,
                grid.NumLevels,
                false, true) as IServerLeafSubGrid;

            // Ensure the cells and segment directory are initialized if this is a new sub grid
            if (result != null)
            {
                // By definition, any new sub grid we create here is dirty, even if we
                // ultimately do not add any cell passes to it. This is necessary to
                // encourage even otherwise empty sub grids to be persisted to disk if
                // they have been created, but never populated with cell passes.
                // The sub grid persistent layer may implement a rule that no empty
                // sub grids are saved to disk if this becomes an issue...
                result.SetDirty();

                result.AllocateLeafFullPassStacks();
                if (result.Directory.SegmentDirectory.Count == 0)
                {
                    result.Cells.SelectSegment(Consts.MIN_DATETIME_AS_UTC);
                }

                if (result.Cells == null)
                {
                    _log.LogCritical($"LocateSubGridContaining returned a sub grid {result.Moniker()} with no allocated cells");
                }
                else if (result.Directory.SegmentDirectory.Count == 0)
                {
                    _log.LogCritical($"LocateSubGridContaining returned a sub grid {result.Moniker()} with no segments in its directory");
                }
            }
            else
            {
                _log.LogCritical($"LocateSubGridContaining failed to return a sub grid (CellX/Y={cellX}/{cellY})");
            }

            return(result);
        }
Exemplo n.º 4
0
        private void CompareSiteModels(ISiteModel sm1, ISiteModel sm2,
                                       int expectedExistanceMapSubGridCount, int expectedCallPassCount, int expectedNonNullCelCount)
        {
            var bitCount1 = sm1.ExistenceMap.CountBits();
            var bitCount2 = sm2.ExistenceMap.CountBits();

            // Check both site models have the same number of sub grids in their existence maps
            bitCount1.Should().Be(bitCount2);
            bitCount1.Should().Be(expectedExistanceMapSubGridCount);

            // Check the content of the existence maps is identical
            var testMap = new SubGridTreeSubGridExistenceBitMask();

            testMap.SetOp_OR(sm1.ExistenceMap);
            testMap.SetOp_XOR(sm2.ExistenceMap);
            testMap.CountBits().Should().Be(0);

            // The expected distribution of cell pass counts
            long[] expectedCounts = { 93, 687, 68, 385, 57, 598, 65, 986, 52, 63, 0, 0, 0, 0, 0 };

            // Scan the leaves in each model and count cell passes
            int sm1Count     = 0;
            int sm1LeafCount = 0;

            long[] actualCounts1     = new long[15];
            int    segmentCount1     = 0;
            int    nonNullCellCount1 = 0;

            sm1.ExistenceMap.ScanAllSetBitsAsSubGridAddresses(address =>
            {
                sm1LeafCount++;
                var leaf     = SubGridUtilities.LocateSubGridContaining(sm1.PrimaryStorageProxy, sm1.Grid, address.X, address.Y, sm1.Grid.NumLevels, false, false) as IServerLeafSubGrid;
                var iterator = new SubGridSegmentIterator(leaf, sm1.PrimaryStorageProxy);
                while (iterator.MoveNext())
                {
                    segmentCount1++;
                    TRex.SubGridTrees.Core.Utilities.SubGridUtilities.SubGridDimensionalIterator((x, y) =>
                    {
                        var passCount = iterator.CurrentSubGridSegment.PassesData.PassCount(x, y);
                        sm1Count     += passCount;
                        if (passCount > 0)
                        {
                            nonNullCellCount1++;
                            actualCounts1[passCount - 1]++;
                        }
                    });
                }
            });

            int sm2Count     = 0;
            int sm2LeafCount = 0;

            long[] actualCounts2     = new long[15];
            int    segmentCount2     = 0;
            int    nonNullCellCount2 = 0;

            sm2.ExistenceMap.ScanAllSetBitsAsSubGridAddresses(address =>
            {
                sm2LeafCount++;
                var leaf     = SubGridUtilities.LocateSubGridContaining(sm2.PrimaryStorageProxy, sm2.Grid, address.X, address.Y, sm2.Grid.NumLevels, false, false) as IServerLeafSubGrid;
                var iterator = new SubGridSegmentIterator(leaf, sm2.PrimaryStorageProxy);
                while (iterator.MoveNext())
                {
                    segmentCount2++;
                    TRex.SubGridTrees.Core.Utilities.SubGridUtilities.SubGridDimensionalIterator((x, y) =>
                    {
                        var passCount = iterator.CurrentSubGridSegment.PassesData.PassCount(x, y);
                        sm2Count     += passCount;
                        if (passCount > 0)
                        {
                            nonNullCellCount2++;
                            actualCounts2[passCount - 1]++;
                        }
                    });
                }
            });

            segmentCount1.Should().Be(segmentCount2);
            segmentCount1.Should().Be(sm1LeafCount);

            sm1LeafCount.Should().Be(expectedExistanceMapSubGridCount);
            sm1Count.Should().Be(sm2Count);

            sm2LeafCount.Should().Be(expectedExistanceMapSubGridCount);
            sm1Count.Should().Be(expectedCallPassCount);

            actualCounts1.Should().BeEquivalentTo(actualCounts2);
            actualCounts1.Should().BeEquivalentTo(expectedCounts);

            nonNullCellCount1.Should().Be(nonNullCellCount2);
            nonNullCellCount1.Should().Be(expectedNonNullCelCount);
        }