Ejemplo n.º 1
0
        private void LocalStorage_StorageBeforeLoad()
        {
            Log.WriteLine("BeforeLoad");
            Serialization.Deserialize <List <VersionRecorder> >(PathHelper.VersionRecorders)
            .WhenNotDefault(_ => CompositeStorage.VersionRecorders = _);

            Serialization.Deserialize <Dictionary <string, int> >(PathHelper.CellTypeIDs)
            .WhenNotDefault(_ => CompositeStorage.CellTypeIDs = _);

            Serialization.Deserialize <List <int> >(PathHelper.IDIntervals)
            .WhenNotDefault(_ => CompositeStorage.IDIntervals = _);

            if (CompositeStorage.VersionRecorders != default(List <VersionRecorder>))
            {
                var asm = CompositeStorage.VersionRecorders
                          .Select(each => $"{each.Namespace}.dll"
                                  .By(PathHelper.DLL)
                                  .By(Assembly.LoadFrom))
                          .ToList();

                CompositeStorage.StorageSchema
                    = asm.Select(_ => AssemblyUtility.GetAllClassInstances <IStorageSchema>(assembly: _).First()).ToList();

                CompositeStorage.GenericCellOperations
                    = asm.Select(_ => AssemblyUtility.GetAllClassInstances <IGenericCellOperations>(assembly: _).First()).ToList();
            }
        }
Ejemplo n.º 2
0
        public void LoadsDynamically()
        {
            BlobStorageConfig.Instance.ConnectionString =
                "DefaultEndpointsProtocol=https;AccountName=redtest;AccountKey=cJF7OVo5NluWtotOAE5ZA362UlXKvHPEE7khssSzamQfs8b3KMvL8CTMskD4Fa491AuLbVA0NffuCwiJj6crDA==;EndpointSuffix=core.windows.net";
            BlobStorageConfig.Instance.ContainerName = "TestContainer";
            var azure_store = AssemblyUtility.GetAllClassInstances <IPersistentStorage>().First();

            Assert.AreEqual(typeof(BlobStoragePersistentStorage), azure_store.GetType());
        }
Ejemplo n.º 3
0
        public void LoadsDynamically2()
        {
            BlobStorageConfig.Instance.ConnectionString =
                "not-a-connection-string";
            BlobStorageConfig.Instance.ContainerName = "TestContainer";
            var azure_store = AssemblyUtility.GetAllClassInstances <IPersistentStorage>().First();

            Assert.AreEqual(typeof(BlobStoragePersistentStorage), azure_store.GetType());
        }
Ejemplo n.º 4
0
        internal static IEnumerable <ICommunicationSchema> ScanForTSLCommunicationSchema(RunningMode schemaRunningMode)
        {
            Debug.Assert(schemaRunningMode == RunningMode.Server || schemaRunningMode == RunningMode.Proxy);

            var schema_interface_type   = typeof(ICommunicationSchema);
            var comm_instance_base_type = schemaRunningMode == RunningMode.Server ? typeof(TrinityServer) : typeof(TrinityProxy);
            var default_comm_schema     = typeof(DefaultCommunicationSchema);

            return(AssemblyUtility.GetAllClassInstances <ICommunicationSchema, CommunicationSchemaAttribute>(
                       _ => comm_instance_base_type.IsAssignableFrom(_) && _ != default_comm_schema,
                       _ => _.CommunicationSchemaType
                       .GetConstructor(new Type[] { })
                       .Invoke(new object[] { })
                       as ICommunicationSchema));
        }
Ejemplo n.º 5
0
        public void LoadsDynamically4()
        {
            BlobStorageConfig.Instance.ConnectionString = null;
            BlobStorageConfig.Instance.ContainerName    = "TestContainer";
            var azure_store = AssemblyUtility.GetAllClassInstances <IPersistentStorage>().First();

            Assert.AreEqual(typeof(BlobStoragePersistentStorage), azure_store.GetType());
            try
            {
                azure_store.CreateNewVersion().Wait();
            }
            catch (AggregateException aex)
            {
                throw aex.InnerException;
            }
        }
Ejemplo n.º 6
0
        private void _OnCommunicationInstanceStart()
        {
            m_module = Global.CommunicationInstance.GetCommunicationModule <TrinityFFIModule>();
            Log.WriteLine("Scanning for foreign runtime providers.");
            m_providers = AssemblyUtility.GetAllClassInstances <ILanguageRuntimeProvider>();
            foreach (var runtime_provider in m_providers)
            {
                try
                {
                    ProgramRunner runner = new ProgramRunner(runtime_provider, m_module);
                    Log.WriteLine("Discovered foreign runtime provider '{0}'.", runtime_provider.Name);
                    foreach (var format in runtime_provider.SupportedSuffix)
                    {
                        m_runners[format] = runner;
                        Log.WriteLine(LogLevel.Debug, "Use {0} to load *.{1}.", runtime_provider.Name, format);
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteLine(LogLevel.Error, "Failed to load foreign runtime provider '{0}':{1}", runtime_provider.Name, ex.ToString());
                }
            }

            Log.WriteLine("Scanning for FFI Programs.");

            string dir;

            string[] files;

            dir   = FFIConfig.Instance.ProgramDirectory;
            dir   = FileUtility.CompletePath(dir, create_nonexistent: true);
            files = Directory.GetFiles(dir);

            foreach (var file in files)
            {
                try
                {
                    var suffix = Path.GetExtension(file);
                    if (m_runners.TryGetValue(suffix, out var runner))
                    {
                        Log.WriteLine("Loading program {0} with {1}.", Path.GetFileName(file), runner.RuntimeName);
                        runner.LoadProgram(file);
                    }
                }
                catch { }
            }
        }
Ejemplo n.º 7
0
        public override bool Open(ClusterConfig config, bool nonblocking)
        {
            this.m_cluster_config = config;
            m_cancelSrc           = new CancellationTokenSource();
            m_nameservice         = AssemblyUtility.GetAllClassInstances <INameService>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using name service provided by '{m_nameservice.GetType().FullName}'");
            m_chunktable = AssemblyUtility.GetAllClassInstances <IChunkTable>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using chunk table provided by '{m_chunktable.GetType().FullName}'");
            m_taskqueue = AssemblyUtility.GetAllClassInstances <ITaskQueue>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using task queue provided by '{m_taskqueue.GetType().FullName}'");
            m_healthmanager = AssemblyUtility.GetAllClassInstances <IHealthManager>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using health manager provided by '{m_healthmanager.GetType().FullName}'");
            m_backupmgr = AssemblyUtility.GetAllClassInstances <IBackupManager>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using backup manager provided by '{m_backupmgr.GetType().FullName}'");
            m_persistent_storage = AssemblyUtility.GetAllClassInstances <IPersistentStorage>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using persistent storage provided by '{m_persistent_storage.GetType().FullName}'");

            m_nameservice.Start(m_cancelSrc.Token);
            m_taskqueue.Start(m_cancelSrc.Token);
            m_chunktable.Start(m_cancelSrc.Token);
            m_healthmanager.Start(m_cancelSrc.Token);
            m_backupmgr.Start(m_cancelSrc.Token);

            m_myid                 = GetInstanceId(InstanceGuid);
            m_storageTable         = new DynamicStorageTable(PartitionCount);
            m_storageTable[m_myid] = Global.LocalStorage;
            NickName               = GenerateNickName(InstanceGuid);

            int redundancy = DynamicClusterConfig.Instance.MinimumReplica;

            m_cloudidx    = new CloudIndex(m_cancelSrc.Token, m_nameservice, m_chunktable, this, NickName, PartitionTable);
            m_healthmon   = new HealthMonitor(m_cancelSrc.Token, m_nameservice, m_cloudidx, m_healthmanager, redundancy);
            m_partitioner = new Partitioner(m_cancelSrc.Token, m_cloudidx, m_nameservice, m_taskqueue, DynamicClusterConfig.Instance.ReplicationMode, redundancy);
            m_taskexec    = new Executor(m_cancelSrc.Token, m_nameservice, m_taskqueue);
            m_backupctl   = new BackupController(m_cancelSrc.Token, m_backupmgr, m_nameservice, m_persistent_storage, m_taskqueue);

            Log.WriteLine($"{nameof(DynamicMemoryCloud)}: Partition {MyPartitionId}: Instance '{NickName}' {InstanceGuid} opened.");
            Global.CommunicationInstance.Started += InitModule;

            return(true);
        }
Ejemplo n.º 8
0
        /// <returns>E_SUCCESS if all the tasks are successfully executed. E_FAILURE otherwise.</returns>
        private static TrinityErrorCode _ScanForStartupTasks()
        {
            Log.WriteLine(LogLevel.Info, "Scanning for startup tasks.");
            bool all_good = true;
            var  tasks    = AssemblyUtility.GetAllClassInstances <IStartupTask>();

            foreach (var task in tasks)
            {
                try
                {
                    task.Run();
                }
                catch (Exception ex)
                {
                    Log.WriteLine(LogLevel.Error, "An error occured while executing a startup task: {0}", ex.ToString());
                    all_good = false;
                }
            }

            return(all_good ? TrinityErrorCode.E_SUCCESS : TrinityErrorCode.E_FAILURE);
        }
 public static IEnumerable <ServiceReplicaListener> CreateServiceReplicaListeners(StatefulServiceContext context) =>
 AssemblyUtility.GetAllClassInstances <GraphEngineListenerBase>()
 .Select(l => l._Setup(context))
 .Select(l => new ServiceReplicaListener(ctx => l, l.ListenerName, l.ListenOnSecondaries));
Ejemplo n.º 10
0
 /// <summary>
 /// Gets all the configuration instances
 /// </summary>
 /// <returns></returns>
 internal static List <ConfigurationInstance> GetConfigurationInstances()
 {
     return(Enumerable.OfType <ConfigurationInstance>(AssemblyUtility.GetAllClassInstances <object>(CreateConfigurationInstance)).ToList());
 }
Ejemplo n.º 11
0
        private static IStorageSchema Load(StorageExtensionRecord ext, bool primary)
        {
            //  capture states
            var ctoffset = ext.CellTypeOffset;
            var ctmap    = new Dictionary <string, int>(s_CellTypeIDs);
            var gcops    = new List <IGenericCellOperations>(s_GenericCellOperations);
            var schemas  = new List <IStorageSchema>(s_StorageSchemas);
            var iditv    = new List <int>(s_IDIntervals);

            var pshadow = ShadowCopy(Path.Combine(PathHelper.StorageSlot(primary), ext.AssemblyName));
            var apath   = Path.Combine(pshadow, ext.AssemblyName + ".dll");
            var asm     = Assembly.LoadFrom(apath);

            Log.WriteLine(LogLevel.Debug, $"{nameof(CompositeStorage)}: assembly from {apath} is loaded.");

            new[] { "Current Storage Info:",
                    $"#Loaded extensions: {s_Extensions.Count}",
                    $"#IDIntervals: : {iditv.Count}",
                    $"#CellTypeIDs:{ctmap.Count}",
                    $"#StorageSchema:{schemas.Count}",
                    $"#GenericCellOperations:{gcops.Count}" }
            .Each(_ => Log.WriteLine(LogLevel.Debug, $"{nameof(CompositeStorage)}: {{0}}", _));

            var schema  = AssemblyUtility.GetAllClassInstances <IStorageSchema>(assembly: asm).FirstOrDefault();
            var cellOps = AssemblyUtility.GetAllClassInstances <IGenericCellOperations>(assembly: asm).FirstOrDefault();

            if (schema == null || cellOps == null)
            {
                throw new AsmLoadException("Not a TSL extension.");
            }

            var cellDescs = schema.CellDescriptors.ToList();

            schemas.Add(schema);
            gcops.Add(cellOps);

            int maxoffset = ctoffset;

            foreach (var cellDesc in cellDescs)
            {
                if (ctmap.TryGetValue(cellDesc.TypeName, out var existing_tid))
                {
                    Log.WriteLine(LogLevel.Info, $"{nameof(CompositeStorage)}: overriding type {cellDesc.TypeName}: TypeId {existing_tid}->{cellDesc.CellType}");
                }

                ctmap[cellDesc.TypeName] = cellDesc.CellType;
                if (cellDesc.CellType < ctoffset)
                {
                    throw new AsmLoadException("New cell type id conflicts existing type space");
                }
                maxoffset = Math.Max(maxoffset, cellDesc.CellType);
            }

            ctoffset += cellDescs.Count + 1; // extra typeid for undefined/reserved cell type
            if (ctoffset != maxoffset + 1)
            {
                throw new AsmLoadException("The whole type id space is not compact");
            }

            iditv.Add(ctoffset);
            if (!iditv.OrderBy(_ => _).SequenceEqual(iditv))
            {
                throw new AsmLoadException("intervals do not grow monotonically");
            }

            //  commit states
            lock (s_lock)
            {
                s_currentCellTypeOffset = ctoffset;
                s_CellTypeIDs           = ctmap;
                s_GenericCellOperations = gcops;
                s_StorageSchemas        = schemas;
                s_IDIntervals           = iditv;
                s_Extensions.Add(ext);

                Log.WriteLine(LogLevel.Info, $"{nameof(CompositeStorage)}: storage extension '{ext.RootNamespace}' loaded");

                return(schema);
            }
        }