func (b *PopulatedMessageStream) populate(rvMsg *message.Message) { curLoc, lrl, waits := b.waitForLogToCatchUp(rvMsg) rvMsg.PopulateWait = waits rvMsg.PopulateLag = lrl - curLoc if rvMsg.Type == message.InsertMessage || rvMsg.Type == message.UpdateMessage || rvMsg.Type == message.DeleteMessage { rvMsg.DatabaseName = b.SchemaReader.GetDatabaseName(rvMsg.DatabaseID) rvMsg.Namespace, rvMsg.Relation = b.SchemaReader.GetNamespaceAndTable(rvMsg.DatabaseID, rvMsg.RelationID) } if rvMsg.Type == message.InsertMessage || rvMsg.Type == message.UpdateMessage { vs, err := b.SchemaReader.GetFieldValues(rvMsg.DatabaseID, rvMsg.RelationID, rvMsg.Block, rvMsg.Offset) if err != nil { rvMsg.PopulationError = fmt.Sprintf("%v - (%v, %v, %v)", err.Error(), curLoc, lrl, waits) } else if vs == nil { rvMsg.PopulationError = fmt.Sprintf("Message skipped for no fields.") } else { for f, v := range vs { if !b.Filters.FilterColumn(rvMsg.RelFullName(), f.Column) { rvMsg.AppendField(f.Column, f.String(), v) } } } } }
func createMessage(entry *wal.Entry) *message.Message { msg := new(message.Message) msg.ParseTime = time.Unix(0, entry.ParseTime).UTC() msg.TimelineID = entry.TimelineID msg.LogID = entry.ReadFrom.LogID() msg.RecordOffset = entry.ReadFrom.RecordOffset() msg.Key = createKey(entry) msg.Prev = createPrev(entry) msg.TransactionID = entry.TransactionID msg.TablespaceID = entry.TablespaceID msg.DatabaseID = entry.DatabaseID msg.RelationID = entry.RelationID msg.Fields = make([]message.Field, 0) switch entry.Type { case wal.MultiInsert: fallthrough case wal.Insert: msg.Type = message.InsertMessage msg.Block = entry.ToBlock msg.Offset = entry.ToOffset case wal.Update: msg.Type = message.UpdateMessage msg.Block = entry.ToBlock msg.Offset = entry.ToOffset msg.PrevTupleID = message.NewTupleID(entry.FromBlock, entry.FromOffset) case wal.Delete: msg.Type = message.DeleteMessage msg.Block = entry.FromBlock msg.Offset = entry.FromOffset case wal.Commit: msg.Type = message.CommitMessage default: msg.Type = message.UnknownMessage } msg.TupleID = message.NewTupleID(msg.Block, msg.Offset) return msg }