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
//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
var idNum int
......@@ -88,9 +91,8 @@ func main() {
go func() {
for _ = range signalChan {
fmt.Println("\nReceived an interrupt, deregistering and quitting...")
// TODO: remove this monitor's ID from all nodes
// removeMonitorFromAllNodes()
deregisterMonitorInAntidote()
deregisterMonitorInAntidote(ID)
cleanupDone <- true
}
}()
......@@ -248,15 +250,22 @@ func updateLocalAssignationList() {
}
func manageMonitorsList() {
fmt.Println("")
fmt.Println("Managing the monitors list...")
// Move the current monitors list to a temporary variable
// var oldTimestamps []MonitorTimestamp
// oldTimestamps = globalTimestamps
fmt.Println("I am monitor", ID)
// Fetch the current monitors list
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
var currentTimestamps []MonitorTimestamp
......@@ -277,22 +286,24 @@ func manageMonitorsList() {
var nextGlobalTimestamps []MonitorTimestamp
// Iterate the fetched timestamps list and process it
for k, v := range currentTimestamps {
for _, v := range currentTimestamps {
var knownMonitor = false
// Look for the matching monitor
for l, w := range globalTimestamps {
fmt.Println("##################################")
fmt.Println(k, l, v, w)
// Iterate the local timestamps list
for _, w := range globalTimestamps {
// Look for matching IDs in both lists
if v.id == w.id {
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 {
// 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
goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", v.id)
fmt.Println("Deregistering crashed monitor", v.id)
deregisterMonitorInAntidote(v.id)
} else {
nextGlobalTimestamps = append(nextGlobalTimestamps, w)
}
......@@ -542,7 +553,7 @@ func startLocalAssignTimer() {
localAssignTicker := time.NewTicker(time.Duration(reassignInterval) * time.Second)
go func() {
for range localAssignTicker.C {
updateMonitorTimestampInAntidote()
registerMonitorInAntidote()
manageMonitorsList()
//reassignDevs()
}
......@@ -560,19 +571,20 @@ func updateMonitorTimestampInAntidote() {
fmt.Println("Setting timestamp to", timestamp)
}
func deregisterMonitorInAntidote() {
if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", ID) {
// Deregister a monitor from AntidoteDB (e.g., on exit, or on crash)
func deregisterMonitorInAntidote(monitorID string) {
// Try up to 3 times
for i := 0; i < 3; i++ {
if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", monitorID) {
fmt.Println("Deregistration successful")
break
} else {
fmt.Println("Deregistration unsuccessful")
}
if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", ID) {
fmt.Println("Deregistration successful")
} else {
fmt.Println("Deregistration unsuccessful")
}
goclidote.AntidoteRemoveRegisterInBucket("guifi", IDts)
goclidote.AntidoteRemoveRegisterInBucket("guifi", fmt.Sprintf("%s_ts", monitorID))
}
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