Ejemplo n.º 1
0
func RedisDo(commandName string, args ...interface{}) (interface{}, error) {

	var redisConn redis.Conn
	var err error

	for i := 0; i < redisRetryCount; i++ {
		if redisConn, err = redis.Dial("tcp", redisAddress); err != nil {
			fog.Warn("redis.Dial: %s", err)
			time.Sleep(5 * time.Second)
			continue
		}

		result, err := redisConn.Do(commandName, args...)
		redisConn.Close()
		if err != nil {
			fog.Warn("RedisDo: %s", err)
			time.Sleep(1 * time.Second)
			continue
		}

		return result, nil
	}

	return nil, fmt.Errorf("RedisDo: failed after %d retries %s",
		redisRetryCount, err)
}
Ejemplo n.º 2
0
func (a availability) AvailableHosts(hostNames []string, destPort string) (
	[]string, error) {

	var availHosts []string
	for _, hostName := range hostNames {
		var address string
		var err error

		if address, err = a.HostResolver.Lookup(hostName); err != nil {
			fog.Warn("Host %s not available: %s", hostName, err)
			continue
		}

		addressKey := fmt.Sprintf("%s:%s", address, destPort)

		availJSON, err := redis.Bytes(tools.RedisDo("HGET",
			a.RedisWebMonitorHash, addressKey))
		if err != nil {
			fog.Warn("Host %s not available: '%s %s %s' %s", hostName,
				"HGET", a.RedisWebMonitorHash, addressKey, err)
			continue
		}

		hostAvail, err := parseAvailJSON(availJSON)
		if err != nil {
			fog.Warn("Host %s not available: unable to parse JSON %q %s",
				hostName, availJSON, err)
			continue
		}

		if hostAvail.Reachable {
			availHosts = append(availHosts, hostName)
		} else {
			fog.Warn("host %s listed as unreachable %f", hostName,
				hostAvail.TimestampFloat)
		}
	}

	if len(availHosts) == 0 {
		fog.Warn("unable to find available hosts, using all")
		return hostNames, nil
	}

	// to start with, just make all hosts available
	return availHosts, nil
}
Ejemplo n.º 3
0
// main entry point for data writer
func main() {
	var err error
	var writerSocket *zmq4.Socket
	var eventSubSocket *zmq4.Socket

	fog.Info("program starts")

	if writerSocket, err = createWriterSocket(); err != nil {
		fog.Critical("createWriterSocket %s", err)
	}
	defer writerSocket.Close()

	fog.Info("binding writer socket to %s", dataWriterAddress)
	if err = writerSocket.Bind(dataWriterAddress); err != nil {
		fog.Critical("Bind(%s) %s", dataWriterAddress, err)
	}

	if eventSubSocket, err = createEventSubSocket(); err != nil {
		fog.Critical("createEventSubSocket %s", err)
	}
	defer eventSubSocket.Close()

	fog.Info("connecting event sub socket to %s", eventAggregatorPubAddress)
	if err = eventSubSocket.Connect(eventAggregatorPubAddress); err != nil {
		fog.Critical("Connect(%s) %s", eventAggregatorPubAddress, err)
	}

	messageChan := NewMessageHandler()

	reactor := zmq4.NewReactor()
	reactor.AddChannel(tools.NewSignalWatcher(), 1, tools.SigtermHandler)
	reactor.AddSocket(writerSocket, zmq4.POLLIN,
		NewWriterSocketHandler(writerSocket, messageChan))
	reactor.AddSocket(eventSubSocket, zmq4.POLLIN,
		NewEventSubSocketHandler(eventSubSocket))

	fog.Debug("starting reactor.Run")
	reactor.SetVerbose(true)
	err = reactor.Run(reactorPollingInterval)
	if err == tools.SigtermError {
		fog.Info("program terminates normally due to SIGTERM")
	} else if errno, ok := err.(syscall.Errno); ok {
		// we can get 'interrupted system call' if we get SIGTERM while
		// a socket is waiting on a read. That's not too bad.
		if errno == syscall.EINTR {
			fog.Warn("reactor.Run returns '%s' assuming SIGTERM", errno)
		} else {
			fog.Error("reactor.Run returns %T '%s'", errno, errno)
		}
	} else {
		fog.Error("reactor.Run returns %T %s", err, err)
	}
}
Ejemplo n.º 4
0
// FinishSegment finishes storing the segment
func handleWaitSyncForFinishSegment(state *writerState, request requestWaitSyncForFinishSegment) {

	finishRequest := requestFinishSegment{
		UserRequestID: request.UserRequestID,
		Segment:       request.Segment,
		File:          request.File,
		MetaData:      request.MetaData,
		resultChan:    request.resultChan}

	// We now want to wait until the value file is synced to disk, but
	// only if the current value file is the last one we wrote to
	if request.ValueFileID != state.ValueFile.ID() {
		fog.Warn("%s not waiting for value file sync (%d)", request.UserRequestID,
			request.ValueFileID)
		state.WriterChan <- finishRequest
		return
	}

	state.WaitSyncRequests = append(state.WaitSyncRequests, finishRequest)
}
Ejemplo n.º 5
0
// Warn prepends literal 'WARNING' to log message
func (l logData) Warn(text string, args ...interface{}) {
	fog.Warn(l.prefix()+text, args...)
}