MCPcopy Create free account
hub / github.com/AdRoll/baker / ProcessRecords

Method ProcessRecords

input/kcl.go:306–350  ·  view source on GitHub ↗

ProcessRecords process data records. vmware kcl will invoke this method to deliver data records. Upon fail over, the new instance will get records with sequence number greater than checkpoint position for each partition key. 'input' provides the records to be processed as well as information and c

(input *interfaces.ProcessRecordsInput)

Source from the content-addressed store, hash-verified

304// 'input' provides the records to be processed as well as information and
305// capabilities related to them (eg checkpointing).
306func (p *recordProcessor) ProcessRecords(input *interfaces.ProcessRecordsInput) {
307 // Control read throughput to prevent throttling.
308 //
309 // Kinesis imposes limits on GetRecords, see
310 // https://docs.aws.amazon.com/streams/latest/dev/service-sizes-and-limits.html
311 //
312 // Each shard can support up to a maximum total data read rate of 2 MiB
313 // per second via GetRecords. If a call to GetRecords returns 10 MiB, the
314 // maximum size GetRecords is allowed to return, subsequent calls made
315 // within the next 5 seconds will meet a ProvisionedThroughputExceededException.
316 //
317 // Limiting the number of records per call would work but would increase
318 // the number of performed IO syscalls and will increase the risk to meet
319 // the limits imposed by AWS on API calls.
320 //
321 // The strategy we're using is to not limit MaxRecords but sleeping for 6s.
322 // Doing so, we're guaranteed to never exceed the per-shard read througput
323 // limit of 2MB/s, while being close to it on data peaks. This has the
324 // added advantage of reducing the number of IO syscalls.
325 time.Sleep(6 * time.Second)
326
327 // Skip if no records
328 if len(input.Records) == 0 {
329 log.Debug("No records to process")
330 return
331 }
332
333 // Send the records to Baker pipeline
334 var nlines int64
335 for _, v := range input.Records {
336 nlines += int64(bytes.Count(v.Data, []byte{'\n'}))
337 p.inch <- &baker.Data{Bytes: v.Data}
338 }
339
340 // Increment the total number of lines processed by the KCL worker.
341 // note: p.nlines is shared among all record processors
342 atomic.AddInt64(p.nlines, nlines)
343
344 // Checkpoint it after processing this batch
345 lastRecordSequenceNumber := input.Records[len(input.Records)-1].SequenceNumber
346 log.Debugf("Processed %d records: checkpoint=%s, msBehindLatest=%v", len(input.Records), aws.StringValue(lastRecordSequenceNumber), input.MillisBehindLatest)
347 if err := input.Checkpointer.Checkpoint(lastRecordSequenceNumber); err != nil {
348 log.Errorf("Error checkpointing at %s: %s", *lastRecordSequenceNumber, err)
349 }
350}
351
352// kclMetrics implements kcl metrics.MonitoringService.
353type kclDatadogMetrics struct {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected