Esempio n. 1
0
        internal static DatabaseLocationInfo GetServerNameForDatabaseInternal(IADDatabase database, NetworkCredential networkCredential, IFindAdObject <IADDatabaseAvailabilityGroup> dagLookup, IFindMiniServer findMiniServer, ActiveManagerClientPerfmonInstance perfCounters, bool throwOnErrors, bool isService)
        {
            Guid     guid                            = database.Guid;
            string   serverFqdn                      = null;
            string   lastMountedServerFqdn           = null;
            bool     isDatabaseHighlyAvailable       = false;
            DateTime mountedTime                     = DateTime.MinValue;
            DatabaseLocationInfoResult requestResult = DatabaseLocationInfoResult.Unknown;
            ServerVersion serverVersion              = null;

            if (ActiveManagerImplementation.TestHookHangGsfdForMilliseconds > 0)
            {
                ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <int>(0L, "TestHook is hanging GetServerNameForDatabaseInternal for {0} milliseconds", ActiveManagerImplementation.TestHookHangGsfdForMilliseconds);
                Thread.Sleep(ActiveManagerImplementation.TestHookHangGsfdForMilliseconds);
            }
            if (Interlocked.Increment(ref ActiveManagerImplementation.NumberOfConcurrentRPCthreads) <= 3000)
            {
                try
                {
                    if (!ActiveManagerImplementation.IsActiveManagerRpcSupported(database))
                    {
                        ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <string>(0L, "Database {0} doesn't support RPC's for ActiveManager", database.Name);
                    }
                    else
                    {
                        try
                        {
                            ActiveManagerImplementation.s_perfCounters.GetServerForDatabaseClientRpcCalls.Increment();
                            AmDbStatusInfo2 amDbStatusInfo = AmRpcClientHelper.RpcchGetServerForDatabase(database, networkCredential, dagLookup, findMiniServer, perfCounters, isService, out serverVersion);
                            isDatabaseHighlyAvailable = (amDbStatusInfo.IsHighlyAvailable != 0);
                            serverFqdn            = amDbStatusInfo.MasterServerFqdn;
                            lastMountedServerFqdn = amDbStatusInfo.LastMountedServerFqdn;
                            mountedTime           = amDbStatusInfo.MountedTime;
                            requestResult         = DatabaseLocationInfoResult.Success;
                        }
                        catch (AmDatabaseNeverMountedException innerException)
                        {
                            ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <string>(0L, "Database {0} was never mounted on any of the servers (defaulting to owner server)", string.Empty);
                            if (throwOnErrors)
                            {
                                throw new ServerForDatabaseNotFoundException(database.Name, guid.ToString(), innerException);
                            }
                        }
                        catch (AmServerException ex)
                        {
                            ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <string>(0L, "Encountered AM Server exception: {0} (defaulting to owner server)", ex.Message);
                            if (throwOnErrors)
                            {
                                throw new ServerForDatabaseNotFoundException(database.Name, guid.ToString(), ex);
                            }
                        }
                        catch (AmServerTransientException ex2)
                        {
                            ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <string>(0L, "Encountered AM Server exception: {0} (defaulting to owner server)", ex2.Message);
                            if (throwOnErrors)
                            {
                                throw new ServerForDatabaseNotFoundException(database.Name, guid.ToString(), ex2);
                            }
                        }
                    }
                    goto IL_1CF;
                }
                finally
                {
                    Interlocked.Decrement(ref ActiveManagerImplementation.NumberOfConcurrentRPCthreads);
                }
            }
            Interlocked.Decrement(ref ActiveManagerImplementation.NumberOfConcurrentRPCthreads);
            ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <int>(0L, "Maximum number ({0}) of concurrent RPC threads reached.", 3000);
            if (throwOnErrors)
            {
                throw new ServerForDatabaseNotFoundException(database.Name, guid.ToString(), new TooManyActiveManagerClientRPCsException(3000));
            }
IL_1CF:
            return(new DatabaseLocationInfo(serverFqdn, null, lastMountedServerFqdn, null, null, null, database.Name, false, database.Recovery, Guid.Empty, mountedTime, null, null, serverVersion, MailboxRelease.None, requestResult, isDatabaseHighlyAvailable));
        }