mr

package
v0.0.0-...-3e2643c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallExample

func CallExample()

example function to show how to make an RPC call to the master.

the RPC argument and reply types are defined in rpc.go.

func Worker

func Worker(mapf func(string, string) []KeyValue, reducef func(string, []string) string)

main/mrworker.go calls this function.

Types

type ExampleReply

type ExampleReply struct {
	Y int
}

type ExampleReq

type ExampleReq struct {
	X int
}

type FinishTaskReply

type FinishTaskReply struct {
}

type FinishTaskReq

type FinishTaskReq struct {
	WorkerID   int
	TaskID     int
	TaskType   TaskType
	TaskStatus TaskStatus
}

type GetTaskReply

type GetTaskReply struct {
	Task *Task
}

type GetTaskReq

type GetTaskReq struct {
	WorkerID int
}

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

Map functions return a slice of KeyValue.

type Master

type Master struct {
	// contains filtered or unexported fields
}

必须所有的map操作做完后才能进行reduce

func MakeMaster

func MakeMaster(files []string, nReduce int) *Master

create a Master. main/mrmaster.go calls this function. nReduce is the number of reduce tasks to use.

func (*Master) Done

func (m *Master) Done() bool

main/mrmaster.go calls Done() periodically to find out if the entire job has finished.

func (*Master) Example

func (m *Master) Example(args *ExampleReq, reply *ExampleReply) error

an example RPC handler.

the RPC argument and reply types are defined in rpc.go.

func (*Master) FinishTask

func (m *Master) FinishTask(req *FinishTaskReq, reply *FinishTaskReply) error

func (*Master) GetTask

func (m *Master) GetTask(req *GetTaskReq, reply *GetTaskReply) error

func (*Master) RegisterWorker

func (m *Master) RegisterWorker(req *RegisterReq, reply *RegisterReply) error

Your code here -- RPC handlers for the worker to call.

type RegisterReply

type RegisterReply struct {
	WorkerID int
}

type RegisterReq

type RegisterReq struct {
}

Add your RPC definitions here.

type Task

type Task struct {
	WorkerID   int
	TaskID     int
	TaskType   TaskType
	TaskStatus TaskStatus
	FileName   string
	NMaps      int
	NReduce    int
	Alive      bool
}

!!!go中涉及到RPC调用时,变量一律开头字母大写,要不然无法传输!!!

type TaskStatus

type TaskStatus int
const (
	//go中默认初始化是0
	TaskInit     TaskStatus = 0
	TaskReady    TaskStatus = 1
	TaskRunning  TaskStatus = 2
	TaskFinished TaskStatus = 3
	TaskError    TaskStatus = 4
)

type TaskType

type TaskType int
const (
	TaskMap    TaskType = 0
	TaskReduce TaskType = 1
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL