Lab 0: Intro to Go

Deadline: 1/26 23:59:59 EST

Introduction

In this lab you'll get familiar with basic distributed programming and lab environments. The goal is to implement a simple RPC program so the worker process can talk to the coordinator.

Lab 0 will not be graded. However, this lab is mandatory as a prerequisite for future labs and should be implemented before you start Lab 1. This lab also includes student info registration step and provides a useful preview of the course’s lab series if you are deciding to enroll this course or not :)

Getting started

You need to setup Go to do the labs.

We will use Github Classroom to manage all the lab submissions. Use the Github Classroom invitation link on Canvas Course HomePage to register and create your own git repo golabs-[Your Github ID].

Fetch the initial lab software with git (a version control system). We assume you are already familiar with git, but it is fine if you just started. To learn more about git, look at the Pro Git book or the git user's manual.

$ git clone git@github.com:uva-cs4740/golabs-[Your Github ID].git golabs
$ cd golabs
$ ls
src

Important: register your student information by creating a new file student_info under the root directory and adding a new commit:

$ echo "[Your Name]\n[UVA_computing_id]\n" > student_info
$ git add student_info
$ git commit -m "first commit"

For example:

$ echo "Chang Lou\ncqx3bu\n" > student_info

To work on a specific lab (e.g., lab0), you should create a new branch and commit all your updates to this branch.

$ git checkout -b lab0

Your Job

Your job in this lab is to implement the basic communication between two programs, the coordinator and the worker. There will be just one coordinator process, and one or more worker processes executing in parallel. In a real system the workers would run on a bunch of different machines, but for this lab you'll run them all on a single machine. The workers will talk to the coordinator via RPC.

Specifically, in Lab 0 you just need to implement a simple StringReverse feature: the worker submits a string (e.g., ABCDE) to the coordinator, and the coordinator should print the reversed string to the screen (e.g., EDCBA). In Lab 1 you will build a full MapReduce application on top of such simple structures.

Hints: you may find the CallExample function in src/mr/worker.go useful.

We have given you a little code to start you off. The "main" routines for the coordinator and worker are in main/mrcoordinator.go and main/mrworker.go; don't change these files. You should put your implementation in mr/coordinator.go, mr/worker.go, and mr/rpc.go.

How to run

Here's how to play with your codes. In Lab 0 we don't involve the word-count plugin but the application depends on it. So we need to make sure it is freshly built:

$ cd src/main
$ go build -buildmode=plugin ../mrapps/wc.go

In the main directory, run the coordinator.

$ go run mrcoordinator.go pg-*.txt

The pg-*.txt arguments to mrcoordinator.go are some input files in Lab 1. For now you can ignore.

In one or more other windows, run some workers:

$ go run mrworker.go wc.so

If you haven't made any changes, the workers will exit without printing anything. After you've finished the task, the output should look like the example below. (You can print both lines in Worker output, or separately in Coordinator and Worker output.)

Worker: ABCDE
Coordinator: EDCBA

Q & A

  • Q: Can I use Windows for the projects? What is the alternative?

  • A: We strongly suggest you using Linux or Mac instead. Using Windows for this lab series brings many extra challenges. You can setup virtual machines with tools such as VirtualBox.

  • Q: How many lines of codes are needed for Lab 0?

  • A: This lab requires very few lines of changes (<10 LOC). It targets to get you familiar with the development environment and ready for the next lab. Most "Your code here" you see in the files are for Lab 1.

  • Q: I ran into a weird Go bug: the function/variables I defined are sometimes not visible to others

  • A: Possibly you made a common mistake for Go beginners. The names in Go have semantic effect: the visibility of a name outside a package is determined by whether its first character is upper case. Try replacing your "reverseString" to "ReverseString".

  • Q: How to solve errors from the Go RPC package that look like

    2019/12/16 13:27:09 rpc.Register: method "Done" has 1 input parameters; needs exactly three
    
  • A: Ignore these messages; registering the coordinator as an RPC server checks if all its methods are suitable for RPCs (have 3 inputs); we know that Done is not called via RPC.

Submission

The submission process is simple. All you need to do is to push your commits in local lab0 branch to Github.

$ git push -u origin lab0

For future labs, our grading scripts will automatically take a snapshot of your lab branch at the submission deadline (unless you use the late tokens, in this case your codes will be graded later). Make sure you check in all commits to the correct branch and do not submit new commits that may break the compilation.