Skip to content

Commit f9851d9

Browse files
committed
s/slave/replica in guestbook app
1 parent 04dec17 commit f9851d9

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

test/images/agnhost/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ Usage:
194194
Starts a HTTP server on the given `--http-port` (default: 80), serving various endpoints representing a
195195
guestbook app. The endpoints and their purpose are:
196196

197-
- `/register`: A guestbook slave will subscribe to a master, to its given `--slaveof` endpoint. The master
198-
will then push any updates it receives to its registered slaves through the `--backend-port` (default: 6379).
197+
- `/register`: A guestbook replica will subscribe to a master, to its given `--replicaof` endpoint. The master
198+
will then push any updates it receives to its registered replicas through the `--backend-port` (default: 6379).
199199
- `/get`: Returns `{"data": value}`, where the `value` is the stored value for the given `key` if non-empty,
200200
or the entire store.
201-
- `/set`: Will set the given key-value pair in its own store and propagate it to its slaves, if any.
201+
- `/set`: Will set the given key-value pair in its own store and propagate it to its replicas, if any.
202202
Will return `{"data": "Updated"}` to the caller on success.
203-
- `/guestbook`: Will proxy the request to `agnhost-master` if the given `cmd` is `set`, or `agnhost-slave`
203+
- `/guestbook`: Will proxy the request to `agnhost-master` if the given `cmd` is `set`, or `agnhost-replica`
204204
if the given `cmd` is `get`.
205205

206206
Usage:

test/images/agnhost/guestbook/guestbook.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ var CmdGuestbook = &cobra.Command{
3838
Short: "Creates a HTTP server with various endpoints representing a guestbook app",
3939
Long: `Starts a HTTP server on the given --http-port (default: 80), serving various endpoints representing a guestbook app. The endpoints and their purpose are:
4040
41-
- /register: A guestbook slave will subscribe to a master, to its given --slaveof endpoint. The master will then push any updates it receives to its registered slaves through the --backend-port.
41+
- /register: A guestbook replica will subscribe to a master, to its given --replicaof endpoint. The master will then push any updates it receives to its registered replicas through the --backend-port.
4242
- /get: Returns '{"data": value}', where the value is the stored value for the given key if non-empty, or the entire store.
43-
- /set: Will set the given key-value pair in its own store and propagate it to its slaves, if any. Will return '{"data": "Updated"}' to the caller on success.
44-
- /guestbook: Will proxy the request to agnhost-master if the given cmd is 'set', or agnhost-slave if the given cmd is 'get'.`,
43+
- /set: Will set the given key-value pair in its own store and propagate it to its replicas, if any. Will return '{"data": "Updated"}' to the caller on success.
44+
- /guestbook: Will proxy the request to agnhost-master if the given cmd is 'set', or agnhost-replica if the given cmd is 'get'.`,
4545
Args: cobra.MaximumNArgs(0),
4646
Run: main,
4747
}
4848

4949
var (
5050
httpPort string
5151
backendPort string
52-
slaveOf string
53-
slaves []string
52+
replicaOf string
53+
replicas []string
5454
store map[string]interface{}
5555
)
5656

@@ -62,12 +62,12 @@ const (
6262
func init() {
6363
CmdGuestbook.Flags().StringVar(&httpPort, "http-port", "80", "HTTP Listen Port")
6464
CmdGuestbook.Flags().StringVar(&backendPort, "backend-port", "6379", "Backend's HTTP Listen Port")
65-
CmdGuestbook.Flags().StringVar(&slaveOf, "slaveof", "", "The host's name to register to")
65+
CmdGuestbook.Flags().StringVar(&replicaOf, "replicaof", "", "The host's name to register to")
6666
store = make(map[string]interface{})
6767
}
6868

6969
func main(cmd *cobra.Command, args []string) {
70-
go registerNode(slaveOf, backendPort)
70+
go registerNode(replicaOf, backendPort)
7171
startHTTPServer(httpPort)
7272
}
7373

@@ -91,7 +91,7 @@ func registerNode(registerTo, port string) {
9191
log.Printf("Registering to master: %s/%s", hostPort, request)
9292
_, err = net.ResolveTCPAddr("tcp", hostPort)
9393
if err != nil {
94-
log.Printf("unable to resolve %s, --slaveof param and/or --backend-port param are invalid: %v. Retrying in %s.", hostPort, err, sleep)
94+
log.Printf("unable to resolve %s, --replicaof param and/or --backend-port param are invalid: %v. Retrying in %s.", hostPort, err, sleep)
9595
time.Sleep(sleep)
9696
continue
9797
}
@@ -129,8 +129,8 @@ func startHTTPServer(port string) {
129129
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
130130
}
131131

132-
// registerHandler will register the caller in this server's list of slaves.
133-
// /set requests will be propagated to slaves, if any.
132+
// registerHandler will register the caller in this server's list of replicas.
133+
// /set requests will be propagated to replicas, if any.
134134
func registerHandler(w http.ResponseWriter, r *http.Request) {
135135
values, err := url.Parse(r.URL.RequestURI())
136136
if err != nil {
@@ -141,7 +141,7 @@ func registerHandler(w http.ResponseWriter, r *http.Request) {
141141
ip := values.Query().Get("host")
142142
log.Printf("GET /register?host=%s", ip)
143143

144-
// send all the store to the slave as well.
144+
// send all the store to the replica as well.
145145
output := make(map[string]interface{})
146146
output["data"] = store
147147
bytes, err := json.Marshal(output)
@@ -150,7 +150,7 @@ func registerHandler(w http.ResponseWriter, r *http.Request) {
150150
return
151151
}
152152
fmt.Fprint(w, string(bytes))
153-
slaves = append(slaves, ip)
153+
replicas = append(replicas, ip)
154154
log.Printf("Node '%s' registered.", ip)
155155
}
156156

@@ -187,7 +187,7 @@ func getHandler(w http.ResponseWriter, r *http.Request) {
187187
}
188188

189189
// setHandler will set the given key-value pair in its own store and propagate
190-
// it to its slaves, if any. Will return '{"message": "Updated"}' to the caller on success.
190+
// it to its replicas, if any. Will return '{"message": "Updated"}' to the caller on success.
191191
func setHandler(w http.ResponseWriter, r *http.Request) {
192192
values, err := url.Parse(r.URL.RequestURI())
193193
if err != nil {
@@ -207,11 +207,11 @@ func setHandler(w http.ResponseWriter, r *http.Request) {
207207

208208
store[key] = value
209209
request := fmt.Sprintf("set?key=%s&value=%s", key, value)
210-
for _, slave := range slaves {
211-
hostPort := net.JoinHostPort(slave, backendPort)
210+
for _, replica := range replicas {
211+
hostPort := net.JoinHostPort(replica, backendPort)
212212
_, err = dialHTTP(request, hostPort)
213213
if err != nil {
214-
http.Error(w, fmt.Sprintf("encountered error while propagating to slave '%s': %v", slave, err), http.StatusExpectationFailed)
214+
http.Error(w, fmt.Sprintf("encountered error while propagating to replica '%s': %v", replica, err), http.StatusExpectationFailed)
215215
return
216216
}
217217
}
@@ -227,7 +227,7 @@ func setHandler(w http.ResponseWriter, r *http.Request) {
227227
}
228228

229229
// guestbookHandler will proxy the request to agnhost-master if the given cmd is
230-
// 'set' or agnhost-slave if the given cmd is 'get'.
230+
// 'set' or agnhost-replica if the given cmd is 'get'.
231231
func guestbookHandler(w http.ResponseWriter, r *http.Request) {
232232
values, err := url.Parse(r.URL.RequestURI())
233233
if err != nil {
@@ -252,7 +252,7 @@ func guestbookHandler(w http.ResponseWriter, r *http.Request) {
252252

253253
host := "agnhost-master"
254254
if cmd == "get" {
255-
host = "agnhost-slave"
255+
host = "agnhost-replica"
256256
}
257257

258258
hostPort := net.JoinHostPort(host, backendPort)

0 commit comments

Comments
 (0)