示例#1
0
 private void CheckServerProtocolSignatures(RemoteStorage storage)
 {
     Task.Run(() =>
     {
         Log.WriteLine("Checking {0}-Server protocol signatures...", cluster_config.RunningMode);
         CheckProtocolSignatures_impl(storage, cluster_config.RunningMode, RunningMode.Server);
     });
 }
示例#2
0
        /// <inheritdoc/>
        public override bool Open(ClusterConfig config, bool nonblocking)
        {
            this.cluster_config = config;

            Log.WriteLines(config.OutputCurrentConfig());

            if (config.RunningMode == RunningMode.Embedded)
            {
                return(SetupEmbeddedMemoryCloud());
            }

            if (_InstanceList(config.RunningMode).Count == 0 && config.RunningMode != RunningMode.Client)
            {
                Log.WriteLine(LogLevel.Warning, "No distributed instances configured. Turning on local test mode.");
                TrinityConfig.LocalTest = true;
            }
            server_count    = cluster_config.Servers.Count;
            my_partition_id = _GetPartitionId(config);
            my_proxy_id     = _GetProxyId(config);

            m_storageTable = new IStorage[server_count];

            if (server_count == 0 && config.RunningMode != RunningMode.Proxy)
            {
                Log.WriteLine(LogLevel.Error, $"{nameof(MemoryCloud)}: Failed to open cloud storage: No servers found.");
                return(false);
            }

            for (int i = 0; i < server_count; i++)
            {
                if (cluster_config.RunningMode == RunningMode.Server &&
                    (cluster_config.Servers[i].Has(Global.MyIPAddresses, Global.MyIPEndPoint.Port) || cluster_config.Servers[i].HasLoopBackEndpoint(Global.MyIPEndPoint.Port))
                    )
                {
                    StorageTable[i] = Global.LocalStorage;
                }
                else
                {
                    StorageTable[i] = new RemoteStorage(cluster_config.Servers[i].Instances, TrinityConfig.ClientMaxConn, this, i, nonblocking);
                }
            }

            StaticGetPartitionByCellId = this.GetServerIdByCellIdDefault;

            if (!nonblocking)
            {
                int my_server_id = (cluster_config.RunningMode == RunningMode.Server) ? MyPartitionId : -1;
                var storage      = StorageTable.Where((_, idx) => idx != my_server_id).FirstOrDefault() as RemoteStorage;
                CheckServerProtocolSignatures(storage);
            }
            else
            {
                ServerConnected += (_, rs_ev) => CheckServerProtocolSignatures(rs_ev.RemoteStorage);
            }

            return(true);
        }
示例#3
0
        public bool Open(bool nonblocking)
        {
            bool server_found = false;

            StorageTable = new Storage[server_count];

            if (server_count == 0)
            {
                goto server_not_found;
            }

            for (int i = 0; i < server_count; i++)
            {
                if (cluster_config.RunningMode == RunningMode.Server &&
                    (cluster_config.Servers[i].Has(Global.MyIPAddresses, Global.MyIPEndPoint.Port) || cluster_config.Servers[i].HasLoopBackEndpoint(Global.MyIPEndPoint.Port))
                    )
                {
                    StorageTable[i] = Global.LocalStorage;
                    server_found    = true;
                }
                else
                {
                    StorageTable[i] = new RemoteStorage(cluster_config.Servers[i], TrinityConfig.ClientMaxConn, this, i, nonblocking);
                }
            }

            if (cluster_config.RunningMode == RunningMode.Server && !server_found)
            {
                goto server_not_found;
            }

            StaticGetServerIdByCellId = this.GetServerIdByCellIdDefault;

            if (!nonblocking)
            {
                CheckServerProtocolSignatures();
            }                                                      // TODO should also check in nonblocking setup when any remote storage is connected
            // else this.ServerConnected += (_, __) => {};

            return(true);

server_not_found:
            if (cluster_config.RunningMode == RunningMode.Server || cluster_config.RunningMode == RunningMode.Client)
            {
                Log.WriteLine(LogLevel.Warning, "Incorrect server configuration. Message passing via CloudStorage not possible.");
            }
            else if (cluster_config.RunningMode == RunningMode.Proxy)
            {
                Log.WriteLine(LogLevel.Warning, "No servers are found. Message passing to servers via CloudStorage not possible.");
            }
            return(false);
        }
示例#4
0
 /// <summary>
 /// Constructs an instance of ServerStatusEventArgs.
 /// </summary>
 /// <param name="rs">The RemoteStorage whose status is changed.</param>
 public RemoteStorageEventArgs(RemoteStorage rs)
 {
     this.RemoteStorage = rs;
 }
示例#5
0
        protected unsafe void CheckProtocolSignatures_impl(RemoteStorage storage, RunningMode from, RunningMode to)
        {
            if (storage == null)
            {
                return;
            }

            string my_schema_name;
            string my_schema_signature;
            string remote_schema_name;
            string remote_schema_signature;
            ICommunicationSchema my_schema;

            storage.GetCommunicationSchema(out remote_schema_name, out remote_schema_signature);

            if (from != to)// Asymmetrical checking, need to scan for matching local comm schema first.
            {
                var local_candidate_schemas = Global.ScanForTSLCommunicationSchema(to);

                /* If local or remote is default, we skip the verification. */

                if (local_candidate_schemas.Count() == 0)
                {
                    Log.WriteLine(LogLevel.Info, "{0}-{1}: Local instance has default communication capabilities.", from, to);
                    return;
                }

                if (remote_schema_name == DefaultCommunicationSchema.GetName() || remote_schema_signature == "{[][][]}")
                {
                    Log.WriteLine(LogLevel.Info, "{0}-{1}: Remote cluster has default communication capabilities.", from, to);
                    return;
                }

                /* Both local and remote are not default instances. */

                my_schema = local_candidate_schemas.FirstOrDefault(_ => _.Name == remote_schema_name);

                if (my_schema == null)
                {
                    Log.WriteLine(LogLevel.Fatal, "No candidate local communication schema signature matches the remote one.\r\n\tName: {0}\r\n\tSignature: {1}", remote_schema_name, remote_schema_signature);
                    Global.Exit(-1);
                }
            }
            else
            {
                my_schema = Global.CommunicationSchema;
            }

            my_schema_name      = my_schema.Name;
            my_schema_signature = CommunicationSchemaSerializer.SerializeProtocols(my_schema);

            if (my_schema_name != remote_schema_name)
            {
                Log.WriteLine(LogLevel.Error, "Local communication schema name not matching the remote one.\r\n\tLocal: {0}\r\n\tRemote: {1}", my_schema_name, remote_schema_name);
            }

            if (my_schema_signature != remote_schema_signature)
            {
                Log.WriteLine(LogLevel.Fatal, "Local communication schema signature not matching the remote one.\r\n\tLocal: {0}\r\n\tRemote: {1}", my_schema_signature, remote_schema_signature);
                throw new InvalidOperationException();
            }
        }
示例#6
0
        internal void ReportServerDisconnectedEvent(RemoteStorage rs)
        {
            RemoteStorageEventArgs e = new RemoteStorageEventArgs(rs);

            OnDisconnected(e);
        }
示例#7
0
        internal unsafe void ShutDownProxy(RemoteStorage proxy)
        {
            TrinityMessage msg = new TrinityMessage(TrinityMessageType.PRESERVED_ASYNC, (ushort)RequestType.Shutdown, 0);

            proxy.SendMessage(msg.Buffer, msg.Size);
        }