handle shutdown requested message

Message type shutdownRequested doesn't have reason, which causes
checkpoint on termination not work.
This commit is to ask KCL daemon to checkpoint on shutdownRequested.
This commit is contained in:
Tony Wang 2018-10-14 18:28:58 +08:00
parent c86a5da722
commit e7b75a20ac
No known key found for this signature in database
GPG key ID: 624D973D837983DF
2 changed files with 13 additions and 1 deletions

View file

@ -51,6 +51,12 @@ func (srp *sampleRecordProcessor) ProcessRecords(records []kcl.Record) error {
return nil
}
func (srp *sampleRecordProcessor) ShutdownRequested() error {
fmt.Fprintf(os.Stderr, "Got shutdown requested, attempt to checkpoint.\n")
srp.checkpointer.Shutdown()
return nil
}
func (srp *sampleRecordProcessor) Shutdown(reason string) error {
if reason == "TERMINATE" {
fmt.Fprintf(os.Stderr, "Was told to terminate, will attempt to checkpoint.\n")

View file

@ -12,6 +12,7 @@ import (
type RecordProcessor interface {
Initialize(shardID string, checkpointer Checkpointer) error
ProcessRecords(records []Record) error
ShutdownRequested() error
// Shutdown this call should block until it's safe to shutdown the process
Shutdown(reason string) error
}
@ -237,7 +238,12 @@ func (kclp *KCLProcess) handleLine(line string) (string, error) {
kclp.ioHandler.writeError("Received shutdown action...")
// Shutdown should block until it's safe to shutdown the process
if action.Action == "shutdownRequested" {
err = kclp.recordProcessor.ShutdownRequested()
} else {
err = kclp.recordProcessor.Shutdown(action.Reason)
}
if err != nil { // Log error and continue shutting down
kclp.ioHandler.writeError(fmt.Sprintf("ERR shutdown: %+#v", err))
}