Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Snapshot/Restore APIs #723

Merged
merged 22 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7160344
internal/server: proto CreateSnapshot
mitchellh Oct 26, 2020
b6043ea
internal/server: CreateSnapshot API
mitchellh Oct 26, 2020
746dc96
internal/server/state: snapshot/restore
mitchellh Oct 27, 2020
9c5755f
go.mod
mitchellh Oct 27, 2020
44a768f
internal/server/state: test snapshot/restore
mitchellh Oct 27, 2020
f712deb
internal/server/state: validate restore file consistency
mitchellh Oct 27, 2020
12879a1
internal/server/state: validate that restore only happens once
mitchellh Oct 27, 2020
8278715
internal/server/state: snapshot/restore should use db-agnostic format
mitchellh Oct 28, 2020
a48b5c2
internal/server/proto: trailers for snapshot
mitchellh Oct 28, 2020
70eb22a
internal/server: calculate checksum and add as a trailer
mitchellh Oct 28, 2020
2a46f05
internal/server/state: validate checksum on restore
mitchellh Oct 28, 2020
c94ce71
internal/server: do not forget to close gzip reader
mitchellh Oct 28, 2020
15a91eb
internal/server/state: during snapshot restore, txn should be smaller
mitchellh Oct 28, 2020
a656b84
internal/server/proto: restore
mitchellh Oct 28, 2020
5d0529e
internal/server: RestoreSnapshot impl, no tests yet
mitchellh Oct 28, 2020
e91f090
internal/server: snapshot/restore unit test
mitchellh Oct 29, 2020
12080cc
internal/server: option on restore to exit the server
mitchellh Oct 29, 2020
8473514
internal/server: typo
mitchellh Oct 30, 2020
4f7d457
internal/server: rename final bolt chunk to final not trailer
mitchellh Oct 30, 2020
49a5986
Update internal/server/singleprocess/state/snapshot.go
mitchellh Nov 2, 2020
5917ecb
Update internal/server/singleprocess/state/snapshot.go
mitchellh Nov 2, 2020
a95bfde
Update internal/server/singleprocess/state/snapshot.go
mitchellh Nov 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/go-ozzo/ozzo-validation/v4 v4.2.1
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator v9.31.0+incompatible
github.com/gofrs/flock v0.8.0
github.com/golang/protobuf v1.4.2
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/gorilla/handlers v1.4.2
Expand Down Expand Up @@ -67,6 +68,7 @@ require (
github.com/mitchellh/pointerstructure v1.0.0
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/mr-tron/base58 v1.2.0
github.com/natefinch/atomic v0.0.0-20200526193002-18c0533a5b09
github.com/netlify/open-api v0.15.0
github.com/oklog/run v1.1.0
github.com/oklog/ulid v1.3.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/V
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/gocql/gocql v0.0.0-20190301043612-f6df8288f9b4/go.mod h1:4Fw1eo5iaEhDUs8XyuhSVCVy52Jq3L+/3GJgYkwc+/0=
github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY=
github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
Expand Down Expand Up @@ -978,6 +980,8 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+
github.com/myitcv/gobin v0.0.14/go.mod h1:GvHEiYCWroKI2KrMT+xQkHC3FC551wigVWeR4Sgg5P4=
github.com/nakagami/firebirdsql v0.0.0-20190310045651-3c02a58cfed8/go.mod h1:86wM1zFnC6/uDBfZGNwB65O+pR2OFi5q/YQaEUid1qA=
github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8=
github.com/natefinch/atomic v0.0.0-20200526193002-18c0533a5b09 h1:DXR0VtCesBD2ss3toN9OEeXszpQmW9dc3SvUbUfiBC0=
github.com/natefinch/atomic v0.0.0-20200526193002-18c0533a5b09/go.mod h1:1rLVY/DWf3U6vSZgH16S7pymfrhK2lcUlXjgGglw/lY=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/neo4j-drivers/gobolt v1.7.4/go.mod h1:O9AUbip4Dgre+CD3p40dnMD4a4r52QBIfblg5k7CTbE=
github.com/neo4j/neo4j-go-driver v1.7.4/go.mod h1:aPO0vVr+WnhEJne+FgFjfsjzAnssPFLucHgGZ76Zb/U=
Expand Down
130 changes: 130 additions & 0 deletions internal/pkg/protowriter/protowriter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Protocol Buffers for Go with Gadgets
//
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
// http://github.com/gogo/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package protowriter

import (
"encoding/binary"
"errors"
"io"

"github.com/golang/protobuf/proto"
)

var (
errSmallBuffer = errors.New("Buffer Too Small")
errLargeValue = errors.New("Value is Larger than 64 bits")
)

func NewDelimitedWriter(w io.Writer) WriteCloser {
return &varintWriter{w, make([]byte, binary.MaxVarintLen64), nil}
}

type varintWriter struct {
w io.Writer
lenBuf []byte
buffer []byte
}

func (this *varintWriter) WriteMsg(msg proto.Message) (err error) {
data, err := proto.Marshal(msg)
if err != nil {
return err
}
length := uint64(len(data))
n := binary.PutUvarint(this.lenBuf, length)
_, err = this.w.Write(this.lenBuf[:n])
if err != nil {
return err
}
_, err = this.w.Write(data)
return err
}

func (this *varintWriter) Close() error {
if closer, ok := this.w.(io.Closer); ok {
return closer.Close()
}
return nil
}

func NewDelimitedReader(r ByteReader, maxSize int) ReadCloser {
return &varintReader{r, nil, maxSize}
}

type varintReader struct {
r ByteReader
buf []byte
maxSize int
}

func (this *varintReader) ReadMsg(msg proto.Message) error {
length64, err := binary.ReadUvarint(this.r)
if err != nil {
return err
}
length := int(length64)
if length < 0 || length > this.maxSize {
return io.ErrShortBuffer
}
if len(this.buf) < length {
this.buf = make([]byte, length)
}
buf := this.buf[:length]
if _, err := io.ReadFull(this.r, buf); err != nil {
return err
}
return proto.Unmarshal(buf, msg)
}

func (this *varintReader) Close() error {
return nil
}

type Writer interface {
WriteMsg(proto.Message) error
}

type WriteCloser interface {
Writer
io.Closer
}

type Reader interface {
ReadMsg(msg proto.Message) error
}

type ReadCloser interface {
Reader
io.Closer
}

type ByteReader interface {
io.ByteReader
io.Reader
}
15 changes: 15 additions & 0 deletions internal/server/gen/mocks/is_create_snapshot_response__event.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions internal/server/gen/mocks/is_create_snapshot_response__type.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions internal/server/gen/mocks/is_restore_snapshot_request__event.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions internal/server/gen/mocks/is_snapshot__trailer__checksum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 137 additions & 0 deletions internal/server/gen/mocks/waypoint__create_snapshot_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading