// DemoteMaster will gracefully demote a master mysql instance to read only.
// If the master is still alive, then we need to demote it gracefully
// make it read-only, flush the writes and get the position
2739
func (mysqld *Mysqld) DemoteMaster() (rp mysql.Position, err error) {
	cmds := []string{
		"FLUSH TABLES WITH READ LOCK",
		"UNLOCK TABLES",
	}
	if err = mysqld.ExecuteSuperQueryList(context.TODO(), cmds); err != nil {
		return rp, err
	}
	return mysqld.MasterPosition()
}
1136213
func (r *RedisStorer) Del(key string) error {
	return r.client.Del(key).Err()
}
1017924
func (a *Agent) DeregisterEventHandler(eh EventHandler) {
	a.eventHandlersLock.Lock()
	defer a.eventHandlersLock.Unlock()

	delete(a.eventHandlers, eh)
	a.eventHandlerList = nil
	for eh := range a.eventHandlers {
		a.eventHandlerList = append(a.eventHandlerList, eh)
	}
}
1123140
func (c CanceledError) ToStatus() (s keybase1.Status) {
	s.Code = SCCanceled
	s.Name = "CANCELED"
	s.Desc = c.M
	return
}
84481
func (r *ShardedTTL) DeleteShard(tenantID string) error {
	r.Lock()
	defer r.Unlock()

	_, ok := r.setAts[tenantID]
	if ok {
		for key := range r.setAts[tenantID] {
			r.delete(tenantID, key)
		}
	}
	return nil
}
1174303
func (pool *ReaderPool) dropAll(doSave bool) error {
	pool.Lock() // synchronized
	defer pool.Unlock()

	var priorE error
	for len(pool.readerMap) > 0 {
		for k, rld := range pool.readerMap {
			if doSave {
				ok, err := rld.writeLiveDocs(pool.owner.directory)
				if err != nil {
					return err
				}
				if ok {
					// Make sure we only write del docs and field updates for a live segment:
					assert(pool.infoIsLive(rld.info))
					// Must checkpoint because we just
					// created new _X_N.del and field updates files;
					// don't call IW.checkpoint because that also
					// increments SIS.version, which we do not want to
					// do here: it was done previously (after we
					// invoked BDS.applyDeletes), whereas here all we
					// did was move the state to disk:
					err = pool.owner.checkpointNoSIS()
					if err != nil {
						return err
					}
				}
			}

			// Important to remove as-we-go, not with .clear()
			// in the end, in case we hit an exception;
			// otherwise we could over-decref if close() is
			// called again:
			delete(pool.readerMap, k)

			// NOTE: it is allowed that these decRefs do not
			// actually close the SRs; this happens when a
			// near real-time reader is kept open after the
			// IndexWriter instance is closed:
			err := rld.dropReaders()
			if err != nil {
				if doSave {
					return err
				}
				if priorE == nil {
					priorE = err
				}
			}
		}
	}
	assert(len(pool.readerMap) == 0)
	return priorE
}
1373382
func (m *MemoryStorer) Del(key string) error {
	m.mut.Lock()
	delete(m.sessions, key)
	m.mut.Unlock()

	return nil
}
918513
func (m *MySQLStore) Cleanup(interval time.Duration) (chan<- struct{}, <-chan struct{}) {
	if interval <= 0 {
		interval = defaultInterval
	}

	quit, done := make(chan struct{}), make(chan struct{})
	go m.cleanup(interval, quit, done)
	return quit, done
}
1334856
func (e DiskMDCacheError) ToStatus() (s keybase1.Status) {
	s.Code = StatusCodeDiskMDCacheError
	s.Name = "DISK_MD_CACHE_ERROR"
	s.Desc = e.Msg
	return
}
1222786
func (c *Client) DeleteRecord(record Record) error {
	resource := fmt.Sprintf("%s/%d/%s/%d", "/dns/managed", record.SourceID, "records", record.ID)

	resp, err := c.sendRequest(http.MethodDelete, resource, nil)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	return nil
}
261187
func (m *MySQLStore) deleteExpired() error {
	var deleteStmt = "DELETE FROM " + m.table + " WHERE expires_on < NOW()"
	_, err := m.db.Exec(deleteStmt)
	return err
}
1301301
func DeleteDoneRecord(ctx sessionctx.Context, dr DelRangeTask) error {
	sql := fmt.Sprintf(deleteDoneRecordSQL, dr.JobID, dr.ElementID)
	_, err := ctx.(sqlexec.SQLExecutor).Execute(context.TODO(), sql)
	return errors.Trace(err)
}
625866
func (mysqld *Mysqld) SetMaster(ctx context.Context, masterHost string, masterPort int, slaveStopBefore bool, slaveStartAfter bool) error {
	params, err := dbconfigs.WithCredentials(mysqld.dbcfgs.Repl())
	if err != nil {
		return err
	}
	conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
	if err != nil {
		return err
	}
	defer conn.Recycle()

	cmds := []string{}
	if slaveStopBefore {
		cmds = append(cmds, conn.StopSlaveCommand())
	}
	smc := conn.SetMasterCommand(params, masterHost, masterPort, int(masterConnectRetry.Seconds()))
	cmds = append(cmds, smc)
	if slaveStartAfter {
		cmds = append(cmds, conn.StartSlaveCommand())
	}
	return mysqld.executeSuperQueryListConn(ctx, conn, cmds)
}
656721
func (s *RepositoriesService) DeleteReleaseAsset(ctx context.Context, owner, repo string, id int64) (*Response, error) {
	u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id)

	req, err := s.client.NewRequest("DELETE", u, nil)
	if err != nil {
		return nil, err
	}
	return s.client.Do(ctx, req, nil)
}
1321438
func (agent *ActionAgent) InitMaster(ctx context.Context) (string, error) {
	if err := agent.lock(ctx); err != nil {
		return "", err
	}
	defer agent.unlock()

	// Initializing as master implies undoing any previous "do not replicate".
	agent.setSlaveStopped(false)

	// we need to insert something in the binlogs, so we can get the
	// current position. Let's just use the mysqlctl.CreateReparentJournal commands.
	cmds := mysqlctl.CreateReparentJournal()
	if err := agent.MysqlDaemon.ExecuteSuperQueryList(ctx, cmds); err != nil {
		return "", err
	}

	// get the current replication position
	pos, err := agent.MysqlDaemon.MasterPosition()
	if err != nil {
		return "", err
	}

	// If using semi-sync, we need to enable it before going read-write.
	if err := agent.fixSemiSync(topodatapb.TabletType_MASTER); err != nil {
		return "", err
	}

	// Set the server read-write, from now on we can accept real
	// client writes. Note that if semi-sync replication is enabled,
	// we'll still need some slaves to be able to commit transactions.
	startTime := time.Now()
	if err := agent.MysqlDaemon.SetReadOnly(false); err != nil {
		return "", err
	}
	agent.setExternallyReparentedTime(startTime)

	// Change our type to master if not already
	if _, err := agent.TopoServer.UpdateTabletFields(ctx, agent.TabletAlias, func(tablet *topodatapb.Tablet) error {
		tablet.Type = topodatapb.TabletType_MASTER
		return nil
	}); err != nil {
		return "", err
	}

	// and refresh our state
	agent.initReplication = true
	if err := agent.refreshTablet(ctx, "InitMaster"); err != nil {
		return "", err
	}
	return mysql.EncodePosition(pos), nil
}
527970
func (mysqld *Mysqld) SlaveStatus() (mysql.SlaveStatus, error) {
	conn, err := getPoolReconnect(context.TODO(), mysqld.dbaPool)
	if err != nil {
		return mysql.SlaveStatus{}, err
	}
	defer conn.Recycle()

	return conn.ShowSlaveStatus()
}
1128573
func (client *Client) DeleteRunstatusMaintenance(ctx context.Context, maintenance RunstatusMaintenance) error {
	if maintenance.URL == "" {
		return fmt.Errorf("empty URL for %#v", maintenance)
	}

	_, err := client.runstatusRequest(ctx, maintenance.URL, nil, "DELETE")
	return err
}