Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit 11d2371

Browse files
author
Dmitry Voytik
committed
proxy: implement (re)store of proxy's state
Introduce the high availability feature of cc-proxy by implementing store/restore of proxy's state to/from disk. This feature depends on the ability of shim to reconnect to cc-proxy if connection is lost. Fixes #4. Signed-off-by: Dmitry Voytik <dmitry.voytik@huawei.com>
1 parent 161a82a commit 11d2371

5 files changed

Lines changed: 754 additions & 13 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ LOCALSTATEDIR := /var
1616

1717
SOURCES := $(shell find . 2>&1 | grep -E '.*\.(c|h|go)$$')
1818
PROXY_SOCKET := $(LOCALSTATEDIR)/run/clear-containers/proxy.sock
19+
STORE_STATE_DIR := $(LOCALSTATEDIR)/lib/clear-containers/proxy/
1920

2021
DESCRIBE := $(shell git describe 2> /dev/null || true)
2122
DESCRIBE_DIRTY := $(if $(shell git status --porcelain --untracked-files=no 2> /dev/null),${DESCRIBE}-dirty,${DESCRIBE})
@@ -53,7 +54,7 @@ all: cc-proxy $(UNIT_FILES)
5354

5455
cc-proxy: $(SOURCES) Makefile
5556
$(QUIET_GOBUILD)go build -i -o $@ -ldflags \
56-
"-X main.DefaultSocketPath=$(PROXY_SOCKET) -X main.Version=$(VERSION)"
57+
"-X main.DefaultSocketPath=$(PROXY_SOCKET) -X main.Version=$(VERSION) -X main.storeStateDir=$(STORE_STATE_DIR)"
5758

5859
#
5960
# Tests

proxy.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ func registerVM(data []byte, userData interface{}, response *handlerResponse) {
250250

251251
client.vm = vm
252252

253+
if err := storeVMState(vm, io.Tokens); err != nil {
254+
logContID(vm.containerID).Errorf(
255+
"couldn't store a VM state: %v", err)
256+
}
257+
258+
if err := proxy.storeState(); err != nil {
259+
proxyLog.Errorf("couldn't store proxy's state: %v", err)
260+
}
261+
253262
if proxyKSM != nil {
254263
proxyKSM.kick()
255264
}
@@ -325,9 +334,10 @@ func unregisterVM(data []byte, userData interface{}, response *handlerResponse)
325334

326335
client.log.Info("UnregisterVM()")
327336

328-
proxy.Lock()
329-
delete(proxy.vms, vm.containerID)
330-
proxy.Unlock()
337+
if err := delVMAndState(proxy, vm); err != nil {
338+
logContID(payload.ContainerID).Warnf("Error deleting state: %v",
339+
err)
340+
}
331341

332342
client.vm = nil
333343
}
@@ -622,12 +632,14 @@ func (proxy *proxy) init() error {
622632
// Force a coredump + full stacktrace on internal error
623633
debug.SetTraceback("crash")
624634

625-
// flags
626-
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel
635+
if !proxy.restoreAllState() {
636+
// flags
637+
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel
627638

628-
// Open the proxy socket
629-
if proxy.socketPath, err = getSocketPath(); err != nil {
630-
return fmt.Errorf("couldn't get a rigth socket path: %v", err)
639+
// Open the proxy socket
640+
if proxy.socketPath, err = getSocketPath(); err != nil {
641+
return fmt.Errorf("couldn't get a right socket path: %v", err)
642+
}
631643
}
632644
fds := listenFds()
633645

0 commit comments

Comments
 (0)