The starter code for Module 3: Surfstore

Surfstore

This is the starter code for Module 3: Surfstore. Before you get started, make sure you understand the following 2 things about Go. (These will also be covered in class and in discussions)

  1. Interfaces: They are named collections of method signatures. Here are some good resources to understand interfaces in Go: a. https://gobyexample.com/interfaces b. https://jordanorelli.com/post/32665860244/how-to-use-interfaces-in-go

  2. RPC: You should know how to write RPC servers and clients in Go. The online documentation of the rpc package is a good resource.

Data Types

Recall from the module write-up the following things:

  1. The SurfStore service is composed of two services: BlockStore and MetadataStore
  2. A file in SurfStore is broken into an ordered sequence of one or more blocks which are stored in the BlockStore.
  3. The MetadataStore maintains the mapping of filenames to hashes of these blocks (and versions) in a map.

The starter code defines the following types for your usage in SurfstoreInterfaces.go:

type Block struct {
	BlockData []byte
	BlockSize int
}

type FileMetaData struct {
	Filename      string
	Version       int
	BlockHashList []string
}

Surfstore Interface

SurfstoreInterfaces.go also contains interfaces for the BlockStore and the MetadataStore:

type MetaStoreInterface interface {
	// Retrieves the server's FileInfoMap
	GetFileInfoMap(_ignore *bool, serverFileInfoMap *map[string]FileMetaData) error
	
	// Update a file's fileinfo entry
	UpdateFile(fileMetaData *FileMetaData, latestVersion *int) (err error)
}

type BlockStoreInterface interface {

	// Get a block based on its hash
	GetBlock(blockHash string, block *Block) error

	// Put a block
	PutBlock(block Block, succ *bool) error

	// Check if certain blocks are alredy present on the server
	HasBlocks(blockHashesIn []string, blockHashesOut *[]string) error
}

The Surfstore interface then glues these two together and is also present in SurfstoreInterfaces.go.

type Surfstore interface {
	MetaStoreInterface
	BlockStoreInterface
}

Server

BlockStore.go provides a skeleton implementation of the BlockStoreInterface and MetaStore.go provides a skeleton implementation of the MetaStoreInterface You must implement the methods in these 2 files which have panic("todo") as their body.

SurfstoreServer.go should then put everything together to provide a complete implementation of the Surfstore interface. You must implement the methods in this file which have panic("todo") as their body. (Hint: You have already implemented these for the BlockStore and the Metastore, you just need to call them appropriately. )

SurfstoreServer.go also has a method ServeSurfstoreServer which you must implement. It should register the Server instance passed to it and start listening for connections from clients.

Client

SurfstoreRPCClient.go provides the rpc client stub for the surfstore rpc server. You must implement the methods in this file which have panic("todo") as their body. (Hint: one of them has been implemented for you)

SurfstoreClientUtils.go also has the following method which you need to implement for the sync logic of clients:

/*
Implement the logic for a client syncing with the server here.
*/
func ClientSync(client RPCClient) {
	panic("todo")
}

Setup

You will need to setup your runtime environment variables so that you can build your code and also use the executables that will be generated.

  1. If you are using a Mac, open ~/.bash_profile or if you are using a unix/linux machine, open ~/.bashrc. Then add the following:
export GOPATH=<path to starter code>
export PATH=$PATH:$GOPATH/bin
  1. Run source ~/.bash_profile or source ~/.bashrc

Usage

  1. Only after you have implemented all the methods and completed the Setup steps, run the build.sh script provided with the starter code. This should create 2 executables in the bin folder inside your starter code directory.
> ./build.sh
> ls bin
SurfstoreClientExec SurfstoreServerExec
  1. Run your server using the script provided in the starter code.
./run-server.sh
  1. From a new terminal (or a new node), run the client using the script provided in the starter code (if using a new node, build using step 1 first). Use a base directory with some files in it.
> mkdir dataA
> cp ~/pic.jpg dataA/ 
> ./run-client.sh server_addr:port dataA 4096

This would sync pic.jpg to the server hosted on server_addr:port, using dataA as the base directory, with a block size of 4096 bytes.

  1. From another terminal (or a new node), run the client to sync with the server. (if using a new node, build using step 1 first)
> ls dataB/
> ./run-client.sh server_addr:port dataB 4096
> ls dataB/
pic.jpg index.txt

We observe that pic.jpg has been synced to this client.

Similar Resources

OpenAPI Client and Server Code Generator

This package contains a set of utilities for generating Go boilerplate code for services based on OpenAPI 3.0 API definitions

Dec 2, 2022

Source code related to an on-site demonstration (for Ardan Labs) of packaging Go applications with Nix

Ardan Labs Nix Demo High-Level Overview We bumbled the scheduling of an earlier presentation about git worktree that a few co-workers attended. In eff

Oct 12, 2022

Just a quick demo of how you can use automatically generated protobuffer and gRPC code from buf.build

buf.build demo The purpose of this repository is to demonstrate how to use the services offered by buf.build for hosting protobuffer definitions and a

Jan 4, 2022

Gecho-starter - A starter/boilerplate for Golang Echo API

gecho-starter gecho-starter is a boilerplate for writing services in Golang quic

Jul 24, 2022

PHP functions implementation to Golang. This package is for the Go beginners who have developed PHP code before. You can use PHP like functions in your app, module etc. when you add this module to your project.

PHP Functions for Golang - phpfuncs PHP functions implementation to Golang. This package is for the Go beginners who have developed PHP code before. Y

Dec 30, 2022

Starter code for writing web services in Go

Ultimate Service Copyright 2018, 2019, 2020, 2021, Ardan Labs [email protected] Ultimate Service 2.0 Video If you are watching the Ultimate Service v

Dec 30, 2022

Template/Starter code for Go application with Gin, System Tray, Gorm, Air, Swagger, JWT

gin-systray-starter Starter code for Go application with Gin, System Tray, Gorm, Air, Swagger, JWT systray, https://github.com/getlantern/systray gin,

Sep 16, 2022

UCSD CSE 124 Fall 2021 Project 3 Starter Code

Surfstore This is the starter code for Module 3: Surfstore. Before you get started, make sure you understand the following 2 things about Go. (These w

May 15, 2022

Example hello-world service uses go-fx-grpc-starter boilerplate code

About Example hello-world service uses https://github.com/srlk/go-fx-grpc-starter boilerplate code. Implementation A hello world grpc service is creat

Nov 14, 2021

A starter repo for VS Code, Gitpod, etc for Go.

go-starter After using this template: Replace github.com/mattwelke/go-starter in go.mod after using this template. Replace go-starter in .gitignore wi

Nov 26, 2021

Opinionated Go starter with gin for REST API, logrus for logging, viper for config with added graceful shutdown

go-gin-starter An opinionated starter for Go Backend projects using: gin-gonic/gin as the REST framework logrus for logging viper for configs Docker f

Dec 2, 2022

An idiomatic Go REST API starter kit (boilerplate) following the SOLID principles and Clean Architecture

Go RESTful API Starter Kit (Boilerplate) This starter kit is designed to get you up and running with a project structure optimized for developing REST

Jan 3, 2023

Moldy CLI the best project starter and manager of the world

Moldy CLI the best project starter and manager of the world

You don't know how to start your project ... you want to help other people know your tool or language. Use Moldy! the best helper to start your project

Oct 17, 2022

Moldy CLI the best project starter and manager of the world

Moldy CLI the best project starter and manager of the world

Moldy The best project starter of the world πŸ€” What is Moldy ? Hey I present Moldy this beautiful tool that will solve your life in creating, managing

Oct 17, 2022

starter pack for building backend with go and fiber, with jwt auth

go-fiber-api-template starter pack for building backend with go and fiber, with jwt auth authentication there are few steps for authentication steps:

Oct 12, 2021

Starter files for the News application built with Go

Starter files for the News application built with Go

News Demo starter files Starter files for the News application built with Go. Tutorial: https://freshman.tech/web-development-with-go/ Here's what the

Oct 16, 2021

An opinionated Microservice starter in Go

Go Microservice Starter An opinionated Microservice starter in Go Usage Checkout the code. TLDR; Start the service: docker build -t go-microservice-st

Oct 25, 2021

Kyoto starter project

Kyoto starter project

kyoto starter Quick Start project setup What's included kyoto kyoto uikit tailwindcss How to use Clone project with git clone https://github.com/yurii

Apr 10, 2022

A simple Go, GraphQL, and PostgreSQL starter template

Simple Go/GraphQL/PostgreSQL template Purpose Have a good starting point for any project that needs a graphql, go, and postgres backend. It's a very l

Jan 8, 2022
Starter code for writing web services in Go

Ultimate Service Copyright 2018, 2019, 2020, 2021, Ardan Labs [email protected] Ultimate Service 2.0 Video If you are watching the Ultimate Service v

Dec 30, 2022
A starter repo for VS Code, Gitpod, etc for Go.

go-starter After using this template: Replace github.com/mattwelke/go-starter in go.mod after using this template. Replace go-starter in .gitignore wi

Nov 26, 2021
An opinionated Microservice starter in Go

Go Microservice Starter An opinionated Microservice starter in Go Usage Checkout the code. TLDR; Start the service: docker build -t go-microservice-st

Oct 25, 2021
Kyoto starter project
Kyoto starter project

kyoto starter Quick Start project setup What's included kyoto kyoto uikit tailwindcss How to use Clone project with git clone https://github.com/yurii

Apr 10, 2022
Astro Starter Kit: Docs Site

Astro Starter Kit: Docs Site npm init astro -- --template docs Features βœ… Full Markdown support βœ… Responsive mobile-friendly design βœ… Sidebar navigat

Apr 10, 2022
GCP Cloud Functions ready to Go starter with hot reload πŸ”₯

GCP Cloud Functions - Go Starter Features: funcFramework already set up - ready for local development and testing. Hot Reload ready-to-go thanks to th

Dec 16, 2021
Hackpack-go: A starter pack for hacking in go

hackpack-go This repository is a starter pack for hacking in go Slides https://d

Apr 14, 2022
UPBit Auto Trading with OpenAPI Golang Module

Go-Bit! UPBit Auto Trading System with OpenAPI 이 λ ˆν¬μ§€ν† λ¦¬λŠ” upbitλ₯Ό μœ„ν•œ μžλ™λ§€λ§€ ν”„λ‘œκ·Έλž¨μ„ κ°œλ°œν•˜κΈ° μœ„ν•΄ μ œκ³΅ν•˜λŠ” go moduleμž…λ‹ˆλ‹€. Features κ΅¬ν˜„ μž‘μ—… 진행상황 Sample Code Template shiel

Jun 27, 2022
This project implements p11-kit RPC server protocol, allowing Go programs to act as a PKCS #11 module without the need for cgo

PKCS #11 modules in Go without cgo This project implements p11-kit RPC server protocol, allowing Go programs to act as a PKCS #11 module without the n

Nov 30, 2022
A code generator that turns plain old Go services into RPC-enabled (micro)services with robust HTTP APIs.

Frodo is a code generator and runtime library that helps you write RPC-enabled (micro) services and APIs.

Dec 16, 2022