Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 2 - Mateus Goncalves de Oliveira #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions mapreduce/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ type Master struct {

idleWorkerChan chan *RemoteWorker
failedWorkerChan chan *RemoteWorker

///////////////////////////////
// ADD EXTRA PROPERTIES HERE //
///////////////////////////////
// Fault Tolerance
}

type Operation struct {
Expand Down Expand Up @@ -77,9 +72,15 @@ func (master *Master) acceptMultipleConnections() {

// handleFailingWorkers will handle workers that fails during an operation.
func (master *Master) handleFailingWorkers() {
/////////////////////////
// YOUR CODE GOES HERE //
/////////////////////////
var (
failedWorker *RemoteWorker
)
for failedWorker = range master.failedWorkerChan {
master.workersMutex.Lock()
delete(master.workers, failedWorker.id)
master.workersMutex.Unlock()
log.Println("Removing worker with id ", failedWorker.id)
}
}

// Handle a single connection until it's done, then closes it.
Expand Down
16 changes: 6 additions & 10 deletions mapreduce/master_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
// Schedules map operations on remote workers. This will run until InputFilePathChan
// is closed. If there is no worker available, it'll block.
func (master *Master) schedule(task *Task, proc string, filePathChan chan string) int {
//////////////////////////////////
// YOU WANT TO MODIFY THIS CODE //
//////////////////////////////////

var (
wg sync.WaitGroup
filePath string
Expand All @@ -31,22 +27,18 @@ func (master *Master) schedule(task *Task, proc string, filePathChan chan string
wg.Add(1)
go master.runOperation(worker, operation, &wg)
}

wg.Wait()

log.Printf("%vx %v operations completed\n", counter, proc)
return counter
}

// runOperation start a single operation on a RemoteWorker and wait for it to return or fail.
func (master *Master) runOperation(remoteWorker *RemoteWorker, operation *Operation, wg *sync.WaitGroup) {
//////////////////////////////////
// YOU WANT TO MODIFY THIS CODE //
//////////////////////////////////

var (
err error
args *RunArgs

)

log.Printf("Running %v (ID: '%v' File: '%v' Worker: '%v')\n", operation.proc, operation.id, operation.filePath, remoteWorker.id)
Expand All @@ -56,8 +48,12 @@ func (master *Master) runOperation(remoteWorker *RemoteWorker, operation *Operat

if err != nil {
log.Printf("Operation %v '%v' Failed. Error: %v\n", operation.proc, operation.id, err)
wg.Done()
//Em caso de falha, mandamos o worker para o failedWorkerChan e procuramos um novo worker para realizar a op. nao feita
master.failedWorkerChan <- remoteWorker
remoteWorker = <-master.idleWorkerChan
wg.Add(1)
go master.runOperation(remoteWorker, operation, wg)
wg.Done()
} else {
wg.Done()
master.idleWorkerChan <- remoteWorker
Expand Down