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

Commit 9673679

Browse files
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 <voytikd@gmail.com>
1 parent 05e19de commit 9673679

5 files changed

Lines changed: 745 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: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ func registerVM(data []byte, userData interface{}, response *handlerResponse) {
248248

249249
client.vm = vm
250250

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

324333
client.log.Info("UnregisterVM()")
325334

326-
proxy.Lock()
327-
delete(proxy.vms, vm.containerID)
328-
proxy.Unlock()
335+
if err := delVMAndState(proxy, vm); err != nil {
336+
logContID(payload.ContainerID).Warnf("Error deleting state: %v",
337+
err)
338+
}
329339

330340
client.vm = nil
331341
}
@@ -617,12 +627,13 @@ func (proxy *proxy) init() error {
617627
var l net.Listener
618628
var err error
619629

620-
// flags
621-
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel
630+
if !proxy.restoreState() {
631+
// flags
632+
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel
622633

623-
// Open the proxy socket
624-
if proxy.socketPath, err = getSocketPath(); err != nil {
625-
return fmt.Errorf("couldn't get a rigth socket path: %v", err)
634+
if proxy.socketPath, err = getSocketPath(); err != nil {
635+
return fmt.Errorf("couldn't get a right socket path: %v", err)
636+
}
626637
}
627638
fds := listenFds()
628639

0 commit comments

Comments
 (0)