Developing lightweight computation at the DSG edge

Commit 6f5349e2 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[monitor-assign] Improve deregistration workflow. Add verbosity


Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent bec044df
...@@ -49,6 +49,9 @@ var DEFAULTFILEMODE os.FileMode = 0755 ...@@ -49,6 +49,9 @@ var DEFAULTFILEMODE os.FileMode = 0755
//Default settings and descriptions //Default settings and descriptions
// monitorTimeout defines how long to wait before removing a crashed monitor from the database
var monitorTimeout int64 = 15
// idNum holds the monitor id, in numberic form // idNum holds the monitor id, in numberic form
var idNum int var idNum int
...@@ -88,9 +91,8 @@ func main() { ...@@ -88,9 +91,8 @@ func main() {
go func() { go func() {
for _ = range signalChan { for _ = range signalChan {
fmt.Println("\nReceived an interrupt, deregistering and quitting...") fmt.Println("\nReceived an interrupt, deregistering and quitting...")
// TODO: remove this monitor's ID from all nodes
// removeMonitorFromAllNodes() deregisterMonitorInAntidote(ID)
deregisterMonitorInAntidote()
cleanupDone <- true cleanupDone <- true
} }
}() }()
...@@ -248,15 +250,22 @@ func updateLocalAssignationList() { ...@@ -248,15 +250,22 @@ func updateLocalAssignationList() {
} }
func manageMonitorsList() { func manageMonitorsList() {
fmt.Println("")
fmt.Println("Managing the monitors list...") fmt.Println("Managing the monitors list...")
fmt.Println("I am monitor", ID)
// Move the current monitors list to a temporary variable
// var oldTimestamps []MonitorTimestamp
// oldTimestamps = globalTimestamps
// Fetch the current monitors list // Fetch the current monitors list
currentMonitors := goclidote.AntidoteReadItemsFromSetInBucket("guifi", "monitors") currentMonitors := goclidote.AntidoteReadItemsFromSetInBucket("guifi", "monitors")
fmt.Println(len(currentMonitors), "monitors registered in the database") fmt.Println(len(currentMonitors), "monitors registered in the database:")
var monitors = ""
for _, v := range currentMonitors {
if monitors == "" {
monitors = v
} else {
monitors = fmt.Sprintf("%s, %s", monitors, v)
}
}
fmt.Println(monitors)
// Create an array and store the timestamps fetched from the database // Create an array and store the timestamps fetched from the database
var currentTimestamps []MonitorTimestamp var currentTimestamps []MonitorTimestamp
...@@ -277,22 +286,24 @@ func manageMonitorsList() { ...@@ -277,22 +286,24 @@ func manageMonitorsList() {
var nextGlobalTimestamps []MonitorTimestamp var nextGlobalTimestamps []MonitorTimestamp
// Iterate the fetched timestamps list and process it // Iterate the fetched timestamps list and process it
for k, v := range currentTimestamps { for _, v := range currentTimestamps {
var knownMonitor = false var knownMonitor = false
// Look for the matching monitor // Iterate the local timestamps list
for l, w := range globalTimestamps { for _, w := range globalTimestamps {
fmt.Println("##################################")
fmt.Println(k, l, v, w) // Look for matching IDs in both lists
if v.id == w.id { if v.id == w.id {
knownMonitor = true knownMonitor = true
// Check if the timestamps are the same // Check if the timestamps are the same (i.e., the monitor has not
// reported itself to the database recently)
if v.timestamps.monitor == w.timestamps.monitor { if v.timestamps.monitor == w.timestamps.monitor {
// The monitor is not updating its info to the database, check local timestamps // The monitor is not updating its info to the database, check local timestamps
if v.timestamps.local-w.timestamps.local > 15 { if v.timestamps.local-w.timestamps.local > monitorTimeout {
// Deregister the monitor // Deregister the monitor
goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", v.id) fmt.Println("Deregistering crashed monitor", v.id)
deregisterMonitorInAntidote(v.id)
} else { } else {
nextGlobalTimestamps = append(nextGlobalTimestamps, w) nextGlobalTimestamps = append(nextGlobalTimestamps, w)
} }
...@@ -542,7 +553,7 @@ func startLocalAssignTimer() { ...@@ -542,7 +553,7 @@ func startLocalAssignTimer() {
localAssignTicker := time.NewTicker(time.Duration(reassignInterval) * time.Second) localAssignTicker := time.NewTicker(time.Duration(reassignInterval) * time.Second)
go func() { go func() {
for range localAssignTicker.C { for range localAssignTicker.C {
updateMonitorTimestampInAntidote() registerMonitorInAntidote()
manageMonitorsList() manageMonitorsList()
//reassignDevs() //reassignDevs()
} }
...@@ -560,19 +571,20 @@ func updateMonitorTimestampInAntidote() { ...@@ -560,19 +571,20 @@ func updateMonitorTimestampInAntidote() {
fmt.Println("Setting timestamp to", timestamp) fmt.Println("Setting timestamp to", timestamp)
} }
func deregisterMonitorInAntidote() { // Deregister a monitor from AntidoteDB (e.g., on exit, or on crash)
if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", ID) { func deregisterMonitorInAntidote(monitorID string) {
fmt.Println("Deregistration successful")
} else { // Try up to 3 times
fmt.Println("Deregistration unsuccessful") for i := 0; i < 3; i++ {
} if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", monitorID) {
if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", ID) { fmt.Println("Deregistration successful")
fmt.Println("Deregistration successful") break
} else { } else {
fmt.Println("Deregistration unsuccessful") fmt.Println("Deregistration unsuccessful")
}
} }
goclidote.AntidoteRemoveRegisterInBucket("guifi", IDts) goclidote.AntidoteRemoveRegisterInBucket("guifi", fmt.Sprintf("%s_ts", monitorID))
} }
func errCheck(e error, level int, message string) { func errCheck(e error, level int, message string) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment