Exemple #1
0
        public void Update()
        {
            if (this.catalogReader == null)
            {
                return;
            }

            // since the cache is possibly shared by several store readers,
            // we need to lock before making changes
            lock (this.syncRoot)
            {
                if (this.catalogReader == null || !this.catalogReader.HasMoreData())
                {
                    return;
                }

                byte[] buffer                   = new byte[1024]; // will resize as needed
                var    newMetadata              = new List <Metadata>();
                var    newStreamDescriptors     = new Dictionary <string, PsiStreamMetadata>(this.streamDescriptors);
                var    newStreamDescriptorsById = new Dictionary <int, PsiStreamMetadata>(this.streamDescriptorsById);
                while (this.catalogReader.MoveNext())
                {
                    var count = this.catalogReader.ReadBlock(ref buffer);
                    var br    = new BufferReader(buffer, count);
                    var meta  = Metadata.Deserialize(br);
                    if (meta.Kind == MetadataKind.RuntimeInfo)
                    {
                        // we expect this to be first in the file (or completely missing in v0 files)
                        this.runtimeVersion = meta as RuntimeInfo;

                        // Need to review this with Mihai. The issue was that the RemoteExporter is not writing
                        // out the RuntimeInfo to the stream. This causes the RemoteImporter side of things to
                        // never see a RuntimeInfo metadata object and thus it assumes that the stream is using
                        // version 0.0 of serialization (i.e. non-data-contract version) which causes a mismatch
                        // in the serialization resulting in throw from TypeSchema.ValidateCompatibleWith. This
                        // change fixes the issue.
                        newMetadata.Add(meta);
                    }
                    else
                    {
                        newMetadata.Add(meta);
                        if (meta.Kind == MetadataKind.StreamMetadata)
                        {
                            var sm = meta as PsiStreamMetadata;
                            sm.PartitionName = this.name;
                            sm.PartitionPath = this.path;

                            // the same meta entry will appear multiple times (written on open and on close).
                            // The last one wins.
                            newStreamDescriptors[sm.Name]   = sm;
                            newStreamDescriptorsById[sm.Id] = sm;
                        }
                    }
                }

                // compute the time ranges
                this.activeTimeRange      = GetTimeRange(newStreamDescriptors.Values, meta => meta.ActiveLifetime);
                this.originatingTimeRange = GetTimeRange(newStreamDescriptors.Values, meta => meta.OriginatingLifetime);

                // clean up if the catalog is closed and we really reached the end
                if (!this.catalogReader.IsMoreDataExpected() && !this.catalogReader.HasMoreData())
                {
                    this.catalogReader.Dispose();
                    this.catalogReader = null;
                }

                // swap the caches
                this.streamDescriptors     = newStreamDescriptors;
                this.streamDescriptorsById = newStreamDescriptorsById;

                // let the registered delegates know about the change
                if (newMetadata.Count > 0 && this.entriesAdded != null)
                {
                    this.entriesAdded(newMetadata, this.runtimeVersion);
                }
            }
        }
Exemple #2
0
 public void Dispose()
 {
     this.fileReader?.Dispose();
     this.fileReader = null;
 }
Exemple #3
0
 public PageIndexCache(string name, string path)
 {
     this.indexReader = new InfiniteFileReader(path, PsiStoreCommon.GetIndexFileName(name));
 }