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 Nov 7, 2017
1 parent 32cad21 commit e7ebeda
Show file tree
Hide file tree
Showing 5 changed files with 843 additions and 10 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)/run/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
42 changes: 34 additions & 8 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ func registerVM(data []byte, userData interface{}, response *handlerResponse) {

client.vm = vm

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

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

if proxyKSM != nil {
proxyKSM.kick()
}
Expand Down Expand Up @@ -300,6 +309,15 @@ func attachVM(data []byte, userData interface{}, response *handlerResponse) {
client.log.Infof("AttachVM(containerId=%s)", payload.ContainerID)

client.vm = vm

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

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

// "UnregisterVM"
Expand Down Expand Up @@ -330,9 +348,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 @@ -627,12 +646,19 @@ func (proxy *proxy) init() error {
// Force a coredump + full stacktrace on internal error
debug.SetTraceback("crash")

// flags
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel
stateIsRestored, err := restoreAllState(proxy)
if err != nil {
proxyLog.Errorf("Restoring failed: %v", err)
}

if !stateIsRestored {
// 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 e7ebeda

Please sign in to comment.