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
dvoytik committed Oct 9, 2017
1 parent 05e19de commit 9673679
Show file tree
Hide file tree
Showing 5 changed files with 745 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
27 changes: 19 additions & 8 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,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 @@ -323,9 +332,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 @@ -617,12 +627,13 @@ func (proxy *proxy) init() error {
var l net.Listener
var err error

// flags
proxy.enableVMConsole = logrus.GetLevel() == logrus.DebugLevel
if !proxy.restoreState() {
// 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)
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 9673679

Please sign in to comment.