Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Worker ¶
main/mrworker.go calls this function.
这段代码实现了一个 MapReduce 模型中的 Worker 节点。Worker 通过向 Coordinator 发送请求,获取需要处理的任务。 任务分为 MapTask、ReduceTask 和 WaitTask 三种类型,Worker 根据任务类型进行不同的处理。 如果任务类型为 MapTask,则打开对应的文件并读取文件内容,调用用户提供的 Map 函数进行处理,并根据 Reduce 数量将处理结果按照键值分组。 将分组后的结果写入对应的文件中,并告知 Coordinator 任务已完成。如果任务类型为 ReduceTask,则读取所有 Map 任务输出的文件, 将键值相同的记录聚合起来,然后调用用户提供的 Reduce 函数进行处理,将处理结果写入对应的输出文件中,并告知 Coordinator 任务已完成。 如果任务类型为 WaitTask,则 Worker 休眠一秒钟后重新发送请求。如果任务类型无法识别,则输出错误信息并退出程序。
Types ¶
type AcTaskArgs ¶
type AcTaskArgs struct { }
type AcTaskReply ¶
type Coordinator ¶
type Coordinator struct {
// contains filtered or unexported fields
}
func MakeCoordinator ¶
func MakeCoordinator(files []string, nReduce int) *Coordinator
创建协调器。 main/mrcoordinator.go 调用此函数 nReduce 是要使用的 reduce 任务数
func (*Coordinator) AcquireTask ¶
func (c *Coordinator) AcquireTask(args *AcTaskArgs, reply *AcTaskReply) error
worker call this function to get task to do
func (*Coordinator) Done ¶
func (c *Coordinator) Done() bool
main/mrcoordinator.go 周期性调用 Done() 函数,以了解整个作业是否已完成
func (*Coordinator) Example ¶
func (c *Coordinator) Example(args *ExampleArgs, reply *ExampleReply) error
在此编写代码--用于工作进程调用的 RPC 处理程序。 这是一个示例 RPC 处理程序,RPC 参数和回复类型在 rpc.go 中定义。
func (*Coordinator) TaskDone ¶
func (c *Coordinator) TaskDone(args *DoneTaskArgs, reply *DoneTaskReply) error
worker call this function to finish task
type DoneTaskArgs ¶
type DoneTaskReply ¶
type DoneTaskReply struct { }
type ExampleArgs ¶
type ExampleArgs struct {
X int
}
type ExampleReply ¶
type ExampleReply struct {
Y int
}