Beispiel #1
0
        public bool LoadLeafSubGrid(IStorageProxy storageProxy,
                                    SubGridCellAddress cellAddress,
                                    bool loadAllPasses, bool loadLatestPasses,
                                    IServerLeafSubGrid subGrid)
        {
            var fullFileName = string.Empty;
            var result       = false;

            try
            {
                // Loading contents into a dirty sub grid (which should happen only on the mutable nodes), or
                // when there is already content in the segment directory are strictly forbidden and break immutability
                // rules for sub grids
                if (subGrid.Dirty)
                {
                    throw new TRexSubGridIOException("Leaf sub grid directory loads may not be performed while the sub grid is dirty. The information should be taken from the cache instead.");
                }

                // Load the cells into it from its file
                // Briefly lock this sub grid just for the period required to read its contents
                lock (subGrid)
                {
                    // If more than thread wants this sub grid then they may concurrently attempt to load it.
                    // Make a check to see if this has happened and another thread has already loaded this sub grid directory.
                    // If so, just return success. Previously the commented out assert was enforced causing exceptions
                    // Debug.Assert(SubGrid.Directory?.SegmentDirectory?.Count == 0, "Loading a leaf sub grid directory when there are already segments present within it.");

                    // Check this thread is the winner of the lock to be able to load the contents
                    if (subGrid.Directory?.SegmentDirectory?.Count == 0)
                    {
                        // Ensure the appropriate storage is allocated
                        if (loadAllPasses)
                        {
                            subGrid.AllocateLeafFullPassStacks();
                        }

                        if (loadLatestPasses)
                        {
                            subGrid.AllocateLeafLatestPassGrid();
                        }

                        fullFileName = GetLeafSubGridFullFileName(cellAddress);

                        // Briefly lock this sub grid just for the period required to read its contents
                        result = subGrid.LoadDirectoryFromFile(storageProxy, fullFileName);
                    }
                    else
                    {
                        // A previous thread has already read the directory so there is nothing more to do, return a true result.
                        return(true);
                    }
                }
            }
            finally
            {
                if (result && RecordSubGridFileReadingToLog)
                {
                    _log.LogDebug($"Sub grid file {fullFileName} read from persistent store containing {subGrid.Directory.SegmentDirectory.Count} segments (Moniker: {subGrid.Moniker()}");
                }
            }

            return(result);
        }