Skip to content

Commit

Permalink
Dump the core in case of a partition removal
Browse files Browse the repository at this point in the history
  • Loading branch information
M. Mert Yildiran committed Nov 11, 2021
1 parent 12b4054 commit 0ec839c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,24 @@ func handleExit() {
os.Exit(7)
}

dumpCore(false)
dumpCore(false, false)

// 0: process exited normally
os.Exit(1)
}

// Dumps the core into a file named "basenine.gob"
func dumpCore(silent bool) {
func dumpCore(silent bool, dontLock bool) {
f, err := os.Create(coreDumpFilename)
check(err)
defer f.Close()
encoder := gob.NewEncoder(f)

// ConcurrentSlice has an embedded mutex. Therefore it cannot be dumped directly.
var csExport ConcurrentSliceExport
cs.Lock()
if !dontLock {
cs.Lock()
}
csExport.LastOffset = cs.lastOffset
csExport.PartitionRefs = cs.partitionRefs
csExport.Offsets = cs.offsets
Expand All @@ -269,7 +271,9 @@ func dumpCore(silent bool) {
}
csExport.PartitionIndex = cs.partitionIndex
csExport.PartitionSizeLimit = cs.partitionSizeLimit
cs.Unlock()
if !dontLock {
cs.Unlock()
}

err = encoder.Encode(csExport)
if err != nil {
Expand Down Expand Up @@ -339,7 +343,7 @@ func periodicPartitioner(ticker *time.Ticker) {

if *persistent {
// Dump the core periodically
dumpCore(true)
dumpCore(true, false)
}

var partitionSizeLimit int64
Expand Down Expand Up @@ -374,6 +378,11 @@ func periodicPartitioner(ticker *time.Ticker) {
}
os.Remove(discarded.Name())
cs.partitions[cs.partitionIndex-2] = nil

if *persistent {
// Dump the core in case of a partition removal
dumpCore(true, true)
}
}
cs.Unlock()
}
Expand Down

0 comments on commit 0ec839c

Please sign in to comment.