Esempio n. 1
0
 public IEnumerable <ChangeList.Change> EnumerateChanges(AbstractPersistedDataFactory factory)
 {
     foreach (var serializedChange in this.SerializedChanges)
     {
         yield return(Deserialize(serializedChange, factory));
     }
 }
Esempio n. 2
0
            /// <summary>
            /// Deserializes a <see cref="Change"/> from the given byte array.
            /// </summary>
            /// <param name="serializedChange">Byte array containing a serialized change</param>
            /// <param name="factory">The <see cref="AbstractPersistedDataFactory"/> that must be associated with the deserialized change list</param>
            /// <returns>A <see cref="ChangeList"/></returns>
            private static ChangeList.Change Deserialize(byte[] serializedChange, AbstractPersistedDataFactory factory)
            {
                MemoryStream memoryStream = new MemoryStream(serializedChange);

                try
                {
                    using (var binaryReader = new BinaryReader(memoryStream))
                    {
                        memoryStream = null;

                        ChangeList.ChangeType changeType = (ChangeList.ChangeType)binaryReader.ReadInt32();
                        PersistedData         data       = new PersistedData(0);
                        data.ReadFrom(binaryReader);

                        return(new ChangeList.Change(changeType, data));
                    }
                }
                finally
                {
                    if (memoryStream != null)
                    {
                        memoryStream.Dispose();
                    }
                }
            }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RingMasterService"/> class.
        /// </summary>
        /// <param name="context">Service context</param>
        /// <param name="ringMasterMetricsFactory">Metrics factory for MDM</param>
        /// <param name="persistenceMetricsFactory">Metrics factory for persistence</param>
        public RingMasterService(StatefulServiceContext context, IMetricsFactory ringMasterMetricsFactory, IMetricsFactory persistenceMetricsFactory)
            : base(context, PersistedDataFactory.CreateStateManager(context))
        {
            var path    = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var builder = new ConfigurationBuilder().SetBasePath(Path.GetDirectoryName(path)).AddJsonFile("appSettings.json");

            appSettings = builder.Build();

            RingMasterBackendCore.GetSettingFunction = GetSetting;
            string factoryName = $"{this.Context.ServiceTypeName}-{this.Context.ReplicaId}-{this.Context.NodeContext.NodeName}";

            this.zooKeeperServerInstrumentation  = new ZooKeeperServerInstrumentation(ringMasterMetricsFactory);
            this.ringMasterServerInstrumentation = new RingMasterServerInstrumentation(ringMasterMetricsFactory);

            var ringMasterInstrumentation  = new RingMasterBackendInstrumentation(ringMasterMetricsFactory);
            var persistenceInstrumentation = new ServiceFabricPersistenceInstrumentation(persistenceMetricsFactory);

            RingMasterBackendCoreInstrumentation.Instance = ringMasterInstrumentation;

            bool needFixStatDuringLoad    = bool.TryParse(GetSetting("WinFabPersistence.FixStatDuringLoad"), out needFixStatDuringLoad) && needFixStatDuringLoad;
            var  persistenceConfiguration = new PersistedDataFactory.Configuration
            {
                EnableActiveSecondary = true,
                FixStatDuringLoad     = needFixStatDuringLoad,
            };

            bool useInMemoryPersistence;

            if (bool.TryParse(GetSetting("InMemoryPersistence"), out useInMemoryPersistence) && useInMemoryPersistence)
            {
                this.factory = new InMemoryFactory();
            }
            else
            {
                this.factory = new PersistedDataFactory(
                    this.StateManager,
                    factoryName,
                    persistenceConfiguration,
                    persistenceInstrumentation,
                    this.cancellationSource.Token);
            }

            this.backend = new RingMasterBackendCore(this.factory);

            this.factory.SetBackend(this.backend);

            this.executor = this.backend;
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PersistedData"/> class.
 /// </summary>
 /// <param name="id">Unique Id</param>
 /// <param name="unused">Unused factory object, for backward compatibility</param>
 public PersistedData(ulong id, AbstractPersistedDataFactory unused)
 {
     this.Id   = id;
     this.stat = new MutableStat();
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangeList"/> class.
 /// </summary>
 /// <param name="id">Unique Id</param>
 /// <param name="factory">The <see cref="AbstractPersistedDataFactory"/> associated with this change list</param>
 public ChangeList(ulong id, AbstractPersistedDataFactory factory)
 {
     this.Id      = id;
     this.factory = factory;
 }