예제 #1
0
//This sends the error to the client.
func sendError(sendReply proto.SendBinlogResponse, reqIdentifier string, inputErr error, blpPos *proto.BinlogPosition) {
	var err error
	streamBuf := new(proto.BinlogResponse)
	streamBuf.Error = inputErr.Error()
	if blpPos != nil {
		streamBuf.Position = *blpPos
	}
	buf := []*proto.BinlogResponse{streamBuf}
	err = blsSendStream(sendReply, buf)
	if err != nil {
		log.Errorf("Error in communicating message %v with the client: %v", inputErr, err)
	}
}
예제 #2
0
//This builds BinlogResponse for each transaction.
func (blp *Bls) buildTxnResponse() (txnResponseList []*proto.BinlogResponse, dmlCount int64) {
	var line []byte
	var keyspaceIdStr string
	var keyspaceId key.KeyspaceId

	dmlBuffer := make([]string, 0, 10)

	for _, event := range blp.txnLineBuffer {
		line = event.LogLine
		if bytes.HasPrefix(line, BINLOG_BEGIN) {
			streamBuf := new(proto.BinlogResponse)
			streamBuf.Position = event.BinlogPosition
			streamBuf.Data.SqlType = proto.BEGIN
			txnResponseList = append(txnResponseList, streamBuf)
			continue
		}
		if bytes.HasPrefix(line, BINLOG_COMMIT) {
			commitEvent := blsCreateCommitEvent(event)
			txnResponseList = append(txnResponseList, commitEvent)
			continue
		}
		sqlType := proto.GetSqlType(event.firstKw)
		if sqlType == proto.DML {
			keyspaceIdStr, keyspaceId = parseKeyspaceId(line)
			if keyspaceIdStr == "" {
				continue
			}
			if !blp.keyRange.Contains(keyspaceId) {
				dmlBuffer = dmlBuffer[:0]
				continue
			}
			dmlCount += 1
			dmlBuffer = append(dmlBuffer, string(line))
			dmlEvent := blp.createDmlEvent(event, keyspaceIdStr)
			dmlEvent.Data.Sql = make([]string, len(dmlBuffer))
			dmlLines := copy(dmlEvent.Data.Sql, dmlBuffer)
			if dmlLines < len(dmlBuffer) {
				log.Warningf("The entire dml buffer was not properly copied")
			}
			txnResponseList = append(txnResponseList, dmlEvent)
			dmlBuffer = dmlBuffer[:0]
		} else {
			//add as prefixes to the DML from last DML.
			//start a new dml buffer and keep adding to it.
			dmlBuffer = append(dmlBuffer, string(line))
		}
	}
	return txnResponseList, dmlCount
}