mr

package
v0.0.0-...-6a77d36 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FinishWork

func FinishWork(args RpcArgs)

完成任务

func Worker

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

main/mrworker.go calls this function.

Types

type ByKey

type ByKey []KeyValue

定义键值对数组类型 for sorting by key.

func (ByKey) Len

func (a ByKey) Len() int

重写方法以使用排序函数 for sorting by key.

func (ByKey) Less

func (a ByKey) Less(i, j int) bool

func (ByKey) Swap

func (a ByKey) Swap(i, j int)

type Comparable

type Comparable interface {
	Equals(other Comparable) bool
}

限制队列中的元素类型,需实现equals方法

type ExampleArgs

type ExampleArgs struct {
	X int
}

type ExampleReply

type ExampleReply struct {
	Y int
}

type KeyValue

type KeyValue struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

Map functions return a slice of KeyValue.

func (KeyValue) MarshalJSON

func (p KeyValue) MarshalJSON() ([]byte, error)

实现 json.Marshaler 接口 ,使得可以将自定义类型变为JSON

type Master

type Master struct {
	NFinalmidFiles int //中间文件数量
	// contains filtered or unexported fields
}

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.

产生master的方法,全局只运行一次

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 *ExampleArgs, reply *ExampleReply) error

an example RPC handler.

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

func (*Master) RPC

func (m *Master) RPC(args *RpcArgs, reply *RpcReply) error

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

func (*Master) RPCFinish

func (m *Master) RPCFinish(args *RpcArgs, reply *RpcReply) error

接受任务完成的请求

type Queue

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

func (*Queue) Add

func (q *Queue) Add(item Comparable)

入队

func (*Queue) Delete

func (q *Queue) Delete(index int) error

删除某一下标的值

func (*Queue) FindIndex

func (q *Queue) FindIndex(item Comparable) int

查找某个元素的下标(对于自定义类型)

func (*Queue) IsEmpty

func (q *Queue) IsEmpty() bool

func (*Queue) Out

func (q *Queue) Out() (Comparable, error)

出队

func (*Queue) Size

func (q *Queue) Size() int

type QueueNorm

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

func (*QueueNorm) Add

func (q *QueueNorm) Add(item interface{})

入队

func (*QueueNorm) Delete

func (q *QueueNorm) Delete(index int) error

删除某一下标的值

func (*QueueNorm) FindIndexNormal

func (q *QueueNorm) FindIndexNormal(item interface{}) int

查找某个元素的下标(对于普通类型)

func (*QueueNorm) IsEmpty

func (q *QueueNorm) IsEmpty() bool

func (*QueueNorm) Out

func (q *QueueNorm) Out() (interface{}, error)

出队

func (*QueueNorm) Size

func (q *QueueNorm) Size() int

type RpcArgs

type RpcArgs struct {
	Num     int //worker编号
	WorkNum int //任务编号
}

Add your RPC definitions here. worker向master的RPC

type RpcReply

type RpcReply struct {
	Work Works //得到的任务信息
	Info int   //得到的消息信息
	Num  int   //worker编号
}

func GetWork

func GetWork() RpcReply

获取任务

type Works

type Works struct {
	Typee     int    //任务类型,0为map任务,1为reduce任务
	Filename  string //若为map人物需要指明文件名
	Num       int    //任务编号
	Status    int    //任务状态,0:未分配,1:已分配未完成,2:已完成
	NmidFiles int    //中间文件数量
	Info      string //传递的信息
	WorkerNum int    //给worker分配的编号
}

任务的信息

func (Works) Equals

func (work Works) Equals(other Comparable) bool

实现接口

Jump to

Keyboard shortcuts

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