---
# System prepended metadata

title: Map Reduce Lab Design Doc

---

# Map Reduce Lab Design Doc
- **`master.go`**
    ```go
    import "container/list"

    // What do mappers need? A filename
    // What do mappers output? A filename, and the location of each key?
    

    type JobStatus struct {
        WorkPackets map[uuid.UUID]*Element // Element contains WorkPacket
        Pending *list.List,
        InProgress *list.List,
    }

    func (j *JobStatus) Done() bool {
        return j.Pending.Len() + j.InProgress.Len() == 0
    }

    type Master struct {
        nReduce int,
        mapStatus JobStatus,
        reduceStatus JobStatus,
    }

    func (m *Master) GetWork(args *GetWorkArgs, reply *GetWorkReply) error
    
    func (m *Master) WorkDone(args *WorkDoneArgs, reply *WorkDoneReply) error
    ```


- **`rpc.go`**
    ```go
    type WorkType int
    const (
        MAP WorkType = iota,
        REDUCE,
    )

    type WorkPacket struct {
        TypeOfWork WorkType,
        InputFilenames []string,
        Id        uuid.UUID,
    }

    type GetWorkArgs struct {}

    //mr-X-Y, where X is the Map task number, and Y is the reduce task number.
    type GetWorkReply struct {
        Packet WorkPacket
    }
    
    type WorkDoneArgs struct {
        Id              uuid.UUID
        OutputFilenames []string
    }

    type WorkDoneReply struct {}
    ```
