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

Commit e7ebeda

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 32cad21 commit e7ebeda

File tree

5 files changed

+843
-10
lines changed

5 files changed

+843
-10
lines changed

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)/run/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: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ func registerVM(data []byte, userData interface{}, response *handlerResponse) {
255255

256256
client.vm = vm
257257

258+
if err := storeVMState(vm); err != nil {
259+
logContID(vm.containerID).Errorf(
260+
"couldn't store a VM state: %v", err)
261+
}
262+
263+
if err := storeProxyState(proxy); err != nil {
264+
proxyLog.Errorf("couldn't store proxy's state: %v", err)
265+
}
266+
258267
if proxyKSM != nil {
259268
proxyKSM.kick()
260269
}
@@ -300,6 +309,15 @@ func attachVM(data []byte, userData interface{}, response *handlerResponse) {
300309
client.log.Infof("AttachVM(containerId=%s)", payload.ContainerID)
301310

302311
client.vm = vm
312+
313+
if err := storeVMState(vm); err != nil {
314+
logContID(vm.containerID).Errorf(
315+
"couldn't store a VM state: %v", err)
316+
}
317+
318+
if err := storeProxyState(proxy); err != nil {
319+
proxyLog.Errorf("couldn't store proxy's state: %v", err)
320+
}
303321
}
304322

305323
// "UnregisterVM"
@@ -330,9 +348,10 @@ func unregisterVM(data []byte, userData interface{}, response *handlerResponse)
330348

331349
client.log.Info("UnregisterVM()")
332350

333-
proxy.Lock()
334-
delete(proxy.vms, vm.containerID)
335-
proxy.Unlock()
351+
if err := delVMAndState(proxy, vm); err != nil {
352+
logContID(payload.ContainerID).Warnf("Error deleting state: %v",
353+
err)
354+
}
336355

337356
client.vm = nil
338357
}
@@ -627,12 +646,19 @@ func (proxy *proxy) init() error {
627646
// Force a coredump + full stacktrace on internal error
628647
debug.SetTraceback("crash")
629648

630-
// flags
631-
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel
649+
stateIsRestored, err := restoreAllState(proxy)
650+
if err != nil {
651+
proxyLog.Errorf("Restoring failed: %v", err)
652+
}
653+
654+
if !stateIsRestored {
655+
// flags
656+
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel
632657

633-
// Open the proxy socket
634-
if proxy.socketPath, err = getSocketPath(); err != nil {
635-
return fmt.Errorf("couldn't get a rigth socket path: %v", err)
658+
// Open the proxy socket
659+
if proxy.socketPath, err = getSocketPath(); err != nil {
660+
return fmt.Errorf("couldn't get a right socket path: %v", err)
661+
}
636662
}
637663
fds := listenFds()
638664

0 commit comments

Comments
 (0)