Skip to content

Commit

Permalink
proxy: implement (re)store of proxy's state
Browse files Browse the repository at this point in the history
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 clearcontainers#4.

Signed-off-by: Dmitry Voytik <[email protected]>
  • Loading branch information
Dmitry Voytik committed Oct 11, 2017
1 parent 161a82a commit 97a65e3
Show file tree
Hide file tree
Showing 5 changed files with 754 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ LOCALSTATEDIR := /var

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

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

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

#
# Tests
Expand Down
28 changes: 20 additions & 8 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ func registerVM(data []byte, userData interface{}, response *handlerResponse) {

client.vm = vm

if err := storeVMState(vm, io.Tokens); err != nil {
logContID(vm.containerID).Errorf(
"couldn't store a VM state: %v", err)
}

if err := proxy.storeState(); err != nil {
proxyLog.Errorf("couldn't store proxy's state: %v", err)
}

if proxyKSM != nil {
proxyKSM.kick()
}
Expand Down Expand Up @@ -325,9 +334,10 @@ func unregisterVM(data []byte, userData interface{}, response *handlerResponse)

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

proxy.Lock()
delete(proxy.vms, vm.containerID)
proxy.Unlock()
if err := delVMAndState(proxy, vm); err != nil {
logContID(payload.ContainerID).Warnf("Error deleting state: %v",
err)
}

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

// flags
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel
if !proxy.restoreAllState() {
// flags
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel

// Open the proxy socket
if proxy.socketPath, err = getSocketPath(); err != nil {
return fmt.Errorf("couldn't get a rigth socket path: %v", err)
// Open the proxy socket
if proxy.socketPath, err = getSocketPath(); err != nil {
return fmt.Errorf("couldn't get a right socket path: %v", err)
}
}
fds := listenFds()

Expand Down
Loading

0 comments on commit 97a65e3

Please sign in to comment.