Пример #1
0
// Read (as much as possible of) a chunk of binary log events starting the given startingCoordinates
func readBinlogEventsChunk(instanceKey *InstanceKey, startingCoordinates BinlogCoordinates) ([]BinlogEvent, error) {
	events := []BinlogEvent{}
	db, err := db.OpenTopology(instanceKey.Hostname, instanceKey.Port)
	if err != nil {
		return events, err
	}
	commandToken := math.TernaryString(startingCoordinates.Type == BinaryLog, "binlog", "relaylog")
	if startingCoordinates.LogFile == "" {
		return events, log.Errorf("readBinlogEventsChunk: empty binlog file name for %+v.", *instanceKey)
	}
	query := fmt.Sprintf("show %s events in '%s' FROM %d LIMIT %d", commandToken, startingCoordinates.LogFile, startingCoordinates.LogPos, config.Config.BinlogEventsChunkSize)
	err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
		binlogEvent := BinlogEvent{}
		binlogEvent.Coordinates.LogFile = m.GetString("Log_name")
		binlogEvent.Coordinates.LogPos = m.GetInt64("Pos")
		binlogEvent.Coordinates.Type = startingCoordinates.Type
		binlogEvent.NextEventPos = m.GetInt64("End_log_pos")
		binlogEvent.EventType = m.GetString("Event_type")
		binlogEvent.Info = m.GetString("Info")

		events = append(events, binlogEvent)
		return nil
	})
	return events, err
}
Пример #2
0
// QueryRowsMapOrchestrator
func QueryOrchestratorRowsMap(query string, on_row func(sqlutils.RowMap) error) error {
	if config.Config.DatabaselessMode__experimental {
		return nil
	}
	db, err := OpenOrchestrator()
	if err != nil {
		return err
	}

	return sqlutils.QueryRowsMap(db, query, on_row)
}
Пример #3
0
// QueryOrchestrator
func QueryOrchestrator(query string, argsArray []interface{}, on_row func(sqlutils.RowMap) error) error {
	if config.Config.DatabaselessMode__experimental {
		return nil
	}
	db, err := OpenOrchestrator()
	if err != nil {
		return err
	}

	return log.Criticale(sqlutils.QueryRowsMap(db, query, on_row, argsArray...))
}
Пример #4
0
// readInternalDeployments reads orchestrator db deployment statements that are known to have been executed
func readInternalDeployments() (baseDeployments []string, patchDeployments []string, err error) {
	if !config.Config.SmartOrchestratorDatabaseUpdate {
		return baseDeployments, patchDeployments, nil
	}
	query := fmt.Sprintf(`
		select 
			deployment_type, 
			sql_statement  
		from 
			_orchestrator_db_deployment
		order by
			deployment_id
		`)
	db, err := OpenOrchestrator()
	if err != nil {
		log.Fatalf("Cannot initiate orchestrator internal deployment: %+v", err)
	}

	err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
		deploymentType := m.GetString("deployment_type")
		sqlStatement := m.GetString("sql_statement")

		if deploymentType == "base" {
			baseDeployments = append(baseDeployments, sqlStatement)
		} else if deploymentType == "patch" {
			patchDeployments = append(patchDeployments, sqlStatement)
		} else {
			log.Fatalf("Unknown deployment type (%+v) encountered in _orchestrator_db_deployment", deploymentType)
		}

		return nil
	})
	if err != nil {
		log.Debugf("Deploying internal orchestrator tables to fix the above; this is a one time operation")
		// Table does not exist? Create it for first time
		for _, query := range internalDBDeploymentSQL {
			if _, err = execInternal(db, query); err != nil {
				log.Fatalf("Cannot initiate orchestrator internal deployment: %+v", err)
			}
		}
	}
	return baseDeployments, patchDeployments, nil
}