microsoft / microsoft/sqlmanagementobjects

JobServer constructor shouldn't run a SQL query

Aperta
#31 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

enhancement
Lingua principale
C#
Stelle
143
Fork
28
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

the JobServer class requires initializing its parent's Databases collection to construct itself:

 internal JobServer(Server parentsrv, ObjectKeyBase key, SqlSmoState state) : 
            base(key, state)
        {
            // even though we called with the parent collection of the column, we will 
            // place the JobServer under the right collection
            singletonParent = parentsrv as Server;
            
            // WATCH OUT! we are setting the m_server value here, because JobServer does
            // not live in a collection, but directly under the Database
            SetServerObject( parentsrv.GetServerObject());
            m_comparer = parentsrv.Databases["msdb"].StringComparer;
            jobCategories = null;
            alertCategories = null;
            operatorCategories = null;
            alertSystem = null;
            alerts = null;
            operators = null;
            targetServers = null;
            targetServerGroups = null;
            jobs = null;
            sharedSchedules = null;
        }
  1. It shouldn't be making a SQL query of any kind in the constructor anyway
  2. Populating the databases collection is hugely expensive
  3. SqlSmoObject has a way to delay load StringComparer already that doesn't populate the collection, this object may just need a little refactoring of that method to support specifying msdb as the database to use for the query.

I found this by accident while trying to write a test for something else.
This code blows up because Databases["msdb"] doesn't exist:

var smoFilter = "[contains(@Name, 'SmoBaseline')]";
db.Parent.Databases.ClearAndInitialize($"[@Name='{Urn.EscapeString(db.Name)}']", Enumerable.Empty<string>());
db.Parent.Logins.ClearAndInitialize(smoFilter, Enumerable.Empty<string>());
db.Parent.LinkedServers.ClearAndInitialize(smoFilter, Enumerable.Empty<string>());
if (db.Parent.IsSupportedObject<JobServer>())
{
    db.Parent.JobServer.Jobs.ClearAndInitialize(smoFilter, Enumerable.Empty<string>());
}

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Iniziare dal costruttore di JobServer mostrato nell’issue e analizzare come parentsrv.Databases["msdb"] ottiene StringComparer. Confrontare questo comportamento con il caricamento ritardato già esistente di StringComparer in SqlSmoObject, quindi usare lo scenario di test ClearAndInitialize fornito per verificare che la costruzione di JobServer non popoli Databases e non fallisca quando msdb è assente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, sql
Ambito
databases
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.