cascade-kinesis-client will be used as a submodule of other projects, so it should not have "src/vmware.com/cascade-kinesis-client" in its path. To build this project locally, please manually create the parent folders. Change-Id: I8844e6a0e32aae65b28496915d8507e9fb1058c6
63 lines
2 KiB
Go
63 lines
2 KiB
Go
package worker
|
|
|
|
import (
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
kcl "vmware.com/cascade-kinesis-client/clientlibrary/interfaces"
|
|
)
|
|
|
|
type (
|
|
|
|
/* Objects of this class are prepared to checkpoint at a specific sequence number. They use an
|
|
* IRecordProcessorCheckpointer to do the actual checkpointing, so their checkpoint is subject to the same 'didn't go
|
|
* backwards' validation as a normal checkpoint.
|
|
*/
|
|
PreparedCheckpointer struct {
|
|
pendingCheckpointSequenceNumber *kcl.ExtendedSequenceNumber
|
|
checkpointer kcl.IRecordProcessorCheckpointer
|
|
}
|
|
|
|
/**
|
|
* This class is used to enable RecordProcessors to checkpoint their progress.
|
|
* The Amazon Kinesis Client Library will instantiate an object and provide a reference to the application
|
|
* RecordProcessor instance. Amazon Kinesis Client Library will create one instance per shard assignment.
|
|
*/
|
|
RecordProcessorCheckpointer struct {
|
|
shard *shardStatus
|
|
checkpoint Checkpointer
|
|
}
|
|
)
|
|
|
|
func NewRecordProcessorCheckpoint(shard *shardStatus, checkpoint Checkpointer) kcl.IRecordProcessorCheckpointer {
|
|
return &RecordProcessorCheckpointer{
|
|
shard: shard,
|
|
checkpoint: checkpoint,
|
|
}
|
|
}
|
|
|
|
func (pc *PreparedCheckpointer) GetPendingCheckpoint() *kcl.ExtendedSequenceNumber {
|
|
return pc.pendingCheckpointSequenceNumber
|
|
}
|
|
|
|
func (pc *PreparedCheckpointer) Checkpoint() error {
|
|
return pc.checkpointer.Checkpoint(pc.pendingCheckpointSequenceNumber.SequenceNumber)
|
|
}
|
|
|
|
func (rc *RecordProcessorCheckpointer) Checkpoint(sequenceNumber *string) error {
|
|
rc.shard.mux.Lock()
|
|
|
|
// checkpoint the last sequence of a closed shard
|
|
if rc.shard.EndingSequenceNumber == aws.StringValue(sequenceNumber) {
|
|
rc.shard.Checkpoint = SHARD_END
|
|
} else {
|
|
rc.shard.Checkpoint = aws.StringValue(sequenceNumber)
|
|
}
|
|
|
|
rc.shard.mux.Unlock()
|
|
return rc.checkpoint.CheckpointSequence(rc.shard)
|
|
}
|
|
|
|
func (rc *RecordProcessorCheckpointer) PrepareCheckpoint(sequenceNumber *string) (kcl.IPreparedCheckpointer, error) {
|
|
return &PreparedCheckpointer{}, nil
|
|
|
|
}
|