libtsdb / libtsdb-go

Building blocks for Time Series Database (TSDB) in Go
MIT License
9 stars 2 forks source link

[db][akumuli] Write client #14

Closed at15 closed 6 years ago

at15 commented 6 years ago

Akumuli doesn't send anything back in response to your writes if everything is OK. But if anything goes wrong it will send error message to client. Client can read data from socket (but not obliged) asynchronously to receive error messages. Error messages are RESP-encoded and will start with '-'.

TODO

at15 commented 6 years ago

although we won't check response in current implementation ... some redis client in go could be a reference, after write, wait for replies from server (though I don't know if akumuli only return error when there is one or success message is also returned ...)

https://github.com/go-redis/redis/blob/master/redis.go#L134-L170

func (c *baseClient) defaultProcess(cmd Cmder) error {
    for attempt := 0; attempt <= c.opt.MaxRetries; attempt++ {
        if attempt > 0 {
            time.Sleep(c.retryBackoff(attempt))
        }
        cn, _, err := c.getConn()
        if err != nil {
            cmd.setErr(err)
            if internal.IsRetryableError(err, true) {
                continue
            }
            return err
        }
        cn.SetWriteTimeout(c.opt.WriteTimeout)
        if err := writeCmd(cn, cmd); err != nil {
            c.releaseConn(cn, err)
            cmd.setErr(err)
            if internal.IsRetryableError(err, true) {
                continue
            }
            return err
        }
        cn.SetReadTimeout(c.cmdTimeout(cmd))
        err = cmd.readReply(cn)
        c.releaseConn(cn, err)
        if err != nil && internal.IsRetryableError(err, cmd.readTimeout() == nil) {
            continue
        }
        return err
    }
    return cmd.Err()
}