lint: add staticcheck as a separate step (#3569)
This commit is contained in:
parent
d5963d81d0
commit
1e64006e32
@ -70,11 +70,14 @@ RUN yes | sdkmanager \
|
||||
# Linters
|
||||
|
||||
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ${GOPATH}/bin v1.21.0
|
||||
|
||||
RUN go get github.com/ckaznocha/protoc-gen-lint
|
||||
RUN go get github.com/nilslice/protolock/cmd/protolock
|
||||
RUN go get github.com/josephspurrier/goversioninfo
|
||||
RUN go get github.com/loov/leakcheck
|
||||
|
||||
RUN GO111MODULE=on go get honnef.co/go/tools/cmd/staticcheck@2019.2.2
|
||||
|
||||
# Output formatters
|
||||
|
||||
RUN go get github.com/mfridman/tparse
|
||||
|
@ -46,6 +46,7 @@ pipeline {
|
||||
sh 'go run ./scripts/atomicalign.go ./...'
|
||||
sh 'go run ./scripts/check-errs.go ./...'
|
||||
sh 'bash ./scripts/check-dbx-version.sh'
|
||||
sh 'staticcheck ./...'
|
||||
sh 'golangci-lint -j=2 run'
|
||||
sh 'go run scripts/check-mod-tidy.go -mod .build/go.mod.orig'
|
||||
sh 'make check-satellite-config-lock'
|
||||
|
@ -23,8 +23,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
idents = testidentity.NewPregeneratedIdentities(storj.LatestIDVersion())
|
||||
t1 = Token{
|
||||
t1 = Token{
|
||||
UserID: "user@mail.test",
|
||||
Data: [tokenDataLength]byte{1, 2, 3},
|
||||
}
|
||||
@ -189,8 +188,7 @@ func TestNewClient(t *testing.T) {
|
||||
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
|
||||
ident, err := idents.NewIdentity()
|
||||
ident, err := testidentity.PregeneratedIdentity(0, storj.LatestIDVersion())
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, ident)
|
||||
|
||||
|
@ -43,7 +43,7 @@ func (scope *Scope) register(name string, val interface{}, pusher func(l *lua.St
|
||||
defer scope.mu.Unlock()
|
||||
|
||||
if _, exists := scope.registrations[name]; exists {
|
||||
return fmt.Errorf("Registration %#v already exists", name)
|
||||
return fmt.Errorf("registration %#v already exists", name)
|
||||
}
|
||||
|
||||
scope.registrations[name] = func(l *lua.State) error {
|
||||
|
@ -61,28 +61,26 @@ func (m *service) Execute(args []string, r <-chan svc.ChangeRequest, changes cha
|
||||
|
||||
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
|
||||
|
||||
for {
|
||||
select {
|
||||
case c := <-r:
|
||||
switch c.Cmd {
|
||||
case svc.Interrogate:
|
||||
log.Println("Interrogate request received.")
|
||||
changes <- c.CurrentStatus
|
||||
// Testing deadlock from https://code.google.com/p/winsvc/issues/detail?id=4
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
changes <- c.CurrentStatus
|
||||
case svc.Stop, svc.Shutdown:
|
||||
log.Println("Stop/Shutdown request received.")
|
||||
changes <- svc.Status{State: svc.StopPending}
|
||||
for c := range r {
|
||||
switch c.Cmd {
|
||||
case svc.Interrogate:
|
||||
log.Println("Interrogate request received.")
|
||||
changes <- c.CurrentStatus
|
||||
// Testing deadlock from https://code.google.com/p/winsvc/issues/detail?id=4
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
changes <- c.CurrentStatus
|
||||
case svc.Stop, svc.Shutdown:
|
||||
log.Println("Stop/Shutdown request received.")
|
||||
changes <- svc.Status{State: svc.StopPending}
|
||||
|
||||
cancel()
|
||||
// Sleep some time to give chance for goroutines finish cleanup after cancelling the context
|
||||
time.Sleep(3 * time.Second)
|
||||
// After returning the Windows Service is stopped and the process terminates
|
||||
return
|
||||
default:
|
||||
log.Println("Unexpected control request:", c)
|
||||
}
|
||||
cancel()
|
||||
// Sleep some time to give chance for goroutines finish cleanup after cancelling the context
|
||||
time.Sleep(3 * time.Second)
|
||||
// After returning the Windows Service is stopped and the process terminates
|
||||
return
|
||||
default:
|
||||
log.Println("Unexpected control request:", c)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -69,28 +69,26 @@ func (m *service) Execute(args []string, r <-chan svc.ChangeRequest, changes cha
|
||||
|
||||
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
|
||||
|
||||
for {
|
||||
select {
|
||||
case c := <-r:
|
||||
switch c.Cmd {
|
||||
case svc.Interrogate:
|
||||
zap.S().Info("Interrogate request received.")
|
||||
changes <- c.CurrentStatus
|
||||
// Testing deadlock from https://code.google.com/p/winsvc/issues/detail?id=4
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
changes <- c.CurrentStatus
|
||||
case svc.Stop, svc.Shutdown:
|
||||
zap.S().Info("Stop/Shutdown request received.")
|
||||
changes <- svc.Status{State: svc.StopPending}
|
||||
// Cancel the command's root context to cleanup resources
|
||||
_, cancel := process.Ctx(runCmd)
|
||||
cancel()
|
||||
_ = group.Wait() // process.Exec does not return an error
|
||||
// After returning the Windows Service is stopped and the process terminates
|
||||
return
|
||||
default:
|
||||
zap.S().Infof("Unexpected control request: %d\n", c)
|
||||
}
|
||||
for c := range r {
|
||||
switch c.Cmd {
|
||||
case svc.Interrogate:
|
||||
zap.S().Info("Interrogate request received.")
|
||||
changes <- c.CurrentStatus
|
||||
// Testing deadlock from https://code.google.com/p/winsvc/issues/detail?id=4
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
changes <- c.CurrentStatus
|
||||
case svc.Stop, svc.Shutdown:
|
||||
zap.S().Info("Stop/Shutdown request received.")
|
||||
changes <- svc.Status{State: svc.StopPending}
|
||||
// Cancel the command's root context to cleanup resources
|
||||
_, cancel := process.Ctx(runCmd)
|
||||
cancel()
|
||||
_ = group.Wait() // process.Exec does not return an error
|
||||
// After returning the Windows Service is stopped and the process terminates
|
||||
return
|
||||
default:
|
||||
zap.S().Infof("Unexpected control request: %d\n", c)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func init() {
|
||||
// catMain is the function executed when catCmd is called
|
||||
func catMain(cmd *cobra.Command, args []string) (err error) {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("No object specified for copy")
|
||||
return fmt.Errorf("no object specified for copy")
|
||||
}
|
||||
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
@ -34,7 +34,7 @@ func catMain(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
|
||||
if src.IsLocal() {
|
||||
return fmt.Errorf("No bucket specified, use format sj://bucket/")
|
||||
return fmt.Errorf("no bucket specified, use format sj://bucket/")
|
||||
}
|
||||
|
||||
dst, err := fpath.New("-")
|
||||
|
@ -57,7 +57,7 @@ func upload(ctx context.Context, src fpath.FPath, dst fpath.FPath, showProgress
|
||||
return err
|
||||
}
|
||||
if expiration.Before(time.Now()) {
|
||||
return fmt.Errorf("Invalid expiration date: (%s) has already passed", *expires)
|
||||
return fmt.Errorf("invalid expiration date: (%s) has already passed", *expires)
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,10 +270,10 @@ func copyObject(ctx context.Context, src fpath.FPath, dst fpath.FPath) (err erro
|
||||
// copyMain is the function executed when cpCmd is called.
|
||||
func copyMain(cmd *cobra.Command, args []string) (err error) {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("No object specified for copy")
|
||||
return fmt.Errorf("no object specified for copy")
|
||||
}
|
||||
if len(args) == 1 {
|
||||
return fmt.Errorf("No destination specified")
|
||||
return fmt.Errorf("no destination specified")
|
||||
}
|
||||
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
@ -290,7 +290,7 @@ func copyMain(cmd *cobra.Command, args []string) (err error) {
|
||||
|
||||
// if both local
|
||||
if src.IsLocal() && dst.IsLocal() {
|
||||
return errors.New("At least one of the source or the desination must be a Storj URL")
|
||||
return errors.New("at least one of the source or the desination must be a Storj URL")
|
||||
}
|
||||
|
||||
// if uploading
|
||||
|
@ -55,7 +55,7 @@ func list(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if src.IsLocal() {
|
||||
return fmt.Errorf("No bucket specified, use format sj://bucket/")
|
||||
return fmt.Errorf("no bucket specified, use format sj://bucket/")
|
||||
}
|
||||
|
||||
bucket, err := project.OpenBucket(ctx, src.Bucket(), scope.EncryptionAccess)
|
||||
|
@ -28,7 +28,7 @@ func makeBucket(cmd *cobra.Command, args []string) error {
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("No bucket specified for creation")
|
||||
return fmt.Errorf("no bucket specified for creation")
|
||||
}
|
||||
|
||||
dst, err := fpath.New(args[0])
|
||||
@ -37,11 +37,11 @@ func makeBucket(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if dst.IsLocal() {
|
||||
return fmt.Errorf("No bucket specified, use format sj://bucket/")
|
||||
return fmt.Errorf("no bucket specified, use format sj://bucket/")
|
||||
}
|
||||
|
||||
if dst.Path() != "" {
|
||||
return fmt.Errorf("Nested buckets not supported, use format sj://bucket/")
|
||||
return fmt.Errorf("nested buckets not supported, use format sj://bucket/")
|
||||
}
|
||||
|
||||
project, err := cfg.GetProject(ctx)
|
||||
|
@ -29,14 +29,14 @@ func metaGetMain(cmd *cobra.Command, args []string) (err error) {
|
||||
|
||||
switch len(args) {
|
||||
case 0:
|
||||
return fmt.Errorf("No object specified")
|
||||
return fmt.Errorf("no object specified")
|
||||
case 1:
|
||||
path = args[0]
|
||||
case 2:
|
||||
key = &args[0]
|
||||
path = args[1]
|
||||
default:
|
||||
return fmt.Errorf("Too many arguments")
|
||||
return fmt.Errorf("too many arguments")
|
||||
}
|
||||
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
@ -46,7 +46,7 @@ func metaGetMain(cmd *cobra.Command, args []string) (err error) {
|
||||
return err
|
||||
}
|
||||
if src.IsLocal() {
|
||||
return fmt.Errorf("The source destination must be a Storj URL")
|
||||
return fmt.Errorf("the source destination must be a Storj URL")
|
||||
}
|
||||
|
||||
project, bucket, err := cfg.GetProjectAndBucket(ctx, src.Bucket())
|
||||
@ -69,8 +69,8 @@ func metaGetMain(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
|
||||
value, ok := object.Meta.Metadata[keyNorm]
|
||||
if ok != true {
|
||||
return fmt.Errorf("Key does not exist")
|
||||
if !ok {
|
||||
return fmt.Errorf("key does not exist")
|
||||
}
|
||||
|
||||
str, err := json.Marshal(value)
|
||||
|
@ -23,7 +23,7 @@ func init() {
|
||||
// putMain is the function executed when putCmd is called
|
||||
func putMain(cmd *cobra.Command, args []string) (err error) {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("No object specified for copy")
|
||||
return fmt.Errorf("no object specified for copy")
|
||||
}
|
||||
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
@ -34,7 +34,7 @@ func putMain(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
|
||||
if dst.IsLocal() {
|
||||
return fmt.Errorf("No bucket specified, use format sj://bucket/")
|
||||
return fmt.Errorf("no bucket specified, use format sj://bucket/")
|
||||
}
|
||||
|
||||
src, err := fpath.New("-")
|
||||
|
@ -25,7 +25,7 @@ func deleteBucket(cmd *cobra.Command, args []string) error {
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("No bucket specified for deletion")
|
||||
return fmt.Errorf("no bucket specified for deletion")
|
||||
}
|
||||
|
||||
dst, err := fpath.New(args[0])
|
||||
@ -34,11 +34,11 @@ func deleteBucket(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if dst.IsLocal() {
|
||||
return fmt.Errorf("No bucket specified, use format sj://bucket/")
|
||||
return fmt.Errorf("no bucket specified, use format sj://bucket/")
|
||||
}
|
||||
|
||||
if dst.Path() != "" {
|
||||
return fmt.Errorf("Nested buckets not supported, use format sj://bucket/")
|
||||
return fmt.Errorf("nested buckets not supported, use format sj://bucket/")
|
||||
}
|
||||
|
||||
project, bucket, err := cfg.GetProjectAndBucket(ctx, dst.Bucket())
|
||||
@ -53,7 +53,7 @@ func deleteBucket(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if len(list.Items) > 0 {
|
||||
return fmt.Errorf("Bucket not empty: %s", dst.Bucket())
|
||||
return fmt.Errorf("bucket not empty: %s", dst.Bucket())
|
||||
}
|
||||
|
||||
err = project.DeleteBucket(ctx, dst.Bucket())
|
||||
|
@ -24,7 +24,7 @@ func deleteObject(cmd *cobra.Command, args []string) error {
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("No object specified for deletion")
|
||||
return fmt.Errorf("no object specified for deletion")
|
||||
}
|
||||
|
||||
dst, err := fpath.New(args[0])
|
||||
@ -33,7 +33,7 @@ func deleteObject(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if dst.IsLocal() {
|
||||
return fmt.Errorf("No bucket specified, use format sj://bucket/")
|
||||
return fmt.Errorf("no bucket specified, use format sj://bucket/")
|
||||
}
|
||||
|
||||
project, bucket, err := cfg.GetProjectAndBucket(ctx, dst.Bucket())
|
||||
|
@ -158,11 +158,11 @@ func closeProjectAndBucket(project *libuplink.Project, bucket *libuplink.Bucket)
|
||||
|
||||
func convertError(err error, path fpath.FPath) error {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
return fmt.Errorf("Bucket not found: %s", path.Bucket())
|
||||
return fmt.Errorf("bucket not found: %s", path.Bucket())
|
||||
}
|
||||
|
||||
if storj.ErrObjectNotFound.Has(err) {
|
||||
return fmt.Errorf("Object not found: %s", path.String())
|
||||
return fmt.Errorf("object not found: %s", path.String())
|
||||
}
|
||||
|
||||
return err
|
||||
|
@ -13,7 +13,7 @@ func SplitConnstr(s string) (string, string, error) {
|
||||
// consider https://github.com/xo/dburl if this ends up lacking
|
||||
parts := strings.SplitN(s, "://", 2)
|
||||
if len(parts) != 2 {
|
||||
return "", "", fmt.Errorf("Could not parse DB URL %s", s)
|
||||
return "", "", fmt.Errorf("could not parse DB URL %s", s)
|
||||
}
|
||||
if parts[0] == "postgres" {
|
||||
parts[1] = s // postgres wants full URLS for its DSN
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
func EditFile(fileToEdit string) error {
|
||||
editorPath := getEditorPath()
|
||||
if editorPath == "" {
|
||||
return fmt.Errorf("Unable to find suitable editor for file %s", fileToEdit)
|
||||
return fmt.Errorf("unable to find suitable editor for file %s", fileToEdit)
|
||||
}
|
||||
cmd := exec.Command(editorPath, fileToEdit)
|
||||
cmd.Stdout = os.Stdout
|
||||
|
@ -107,12 +107,12 @@ func IsWritable(filepath string) (bool, error) {
|
||||
}
|
||||
|
||||
if !info.IsDir() {
|
||||
return false, fmt.Errorf("Path %s is not a directory", filepath)
|
||||
return false, fmt.Errorf("path %s is not a directory", filepath)
|
||||
}
|
||||
|
||||
// Check if the user bit is enabled in file permission
|
||||
if info.Mode().Perm()&0200 == 0 {
|
||||
return false, fmt.Errorf("Write permission bit is not set on this file for user")
|
||||
return false, fmt.Errorf("write permission bit is not set on this file for user")
|
||||
}
|
||||
|
||||
// Test if user can create file
|
||||
@ -122,7 +122,7 @@ func IsWritable(filepath string) (bool, error) {
|
||||
testFile := path.Join(filepath, ".perm")
|
||||
file, err := os.Create(testFile) // For read access.
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Write permission bit is not set on this file for user")
|
||||
return false, fmt.Errorf("write permission bit is not set on this file for user")
|
||||
}
|
||||
|
||||
_ = file.Close()
|
||||
|
@ -82,10 +82,8 @@ func (ctx *Context) CompileWithLDFlagsX(pkg string, ldFlagsX map[string]string)
|
||||
ctx.test.Helper()
|
||||
|
||||
var ldFlags = "-s -w"
|
||||
if ldFlagsX != nil {
|
||||
for key, value := range ldFlagsX {
|
||||
ldFlags += (" -X " + key + "=" + value)
|
||||
}
|
||||
for key, value := range ldFlagsX {
|
||||
ldFlags += (" -X " + key + "=" + value)
|
||||
}
|
||||
|
||||
return ctx.Compile(pkg, "-ldflags", ldFlags)
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"storj.io/storj/internal/testcontext"
|
||||
"storj.io/storj/internal/testplanet"
|
||||
"storj.io/storj/lib/uplink"
|
||||
libuplink "storj.io/storj/lib/uplink"
|
||||
"storj.io/storj/pkg/storj"
|
||||
)
|
||||
|
||||
@ -70,8 +69,8 @@ func TestProjectListBuckets(t *testing.T) {
|
||||
// List with restrictions
|
||||
scope.APIKey, scope.EncryptionAccess, err =
|
||||
scope.EncryptionAccess.Restrict(scope.APIKey,
|
||||
libuplink.EncryptionRestriction{Bucket: "test0"},
|
||||
libuplink.EncryptionRestriction{Bucket: "test1"})
|
||||
uplink.EncryptionRestriction{Bucket: "test0"},
|
||||
uplink.EncryptionRestriction{Bucket: "test1"})
|
||||
require.NoError(t, err)
|
||||
|
||||
p, err = ul.OpenProject(ctx, scope.SatelliteAddr, scope.APIKey)
|
||||
|
@ -28,7 +28,7 @@ type memoryLiveAccounting struct {
|
||||
|
||||
func newMemoryLiveAccounting(log *zap.Logger) (*memoryLiveAccounting, error) {
|
||||
pmac := &memoryLiveAccounting{log: log}
|
||||
pmac.spaceDeltas = make(map[uuid.UUID]int64, 0)
|
||||
pmac.spaceDeltas = make(map[uuid.UUID]int64)
|
||||
return pmac, nil
|
||||
}
|
||||
|
||||
|
@ -441,22 +441,6 @@ func (server *Server) serveError(w http.ResponseWriter, status int) {
|
||||
}
|
||||
}
|
||||
|
||||
// serveJSONError writes JSON error to response output stream.
|
||||
func (server *Server) serveJSONError(w http.ResponseWriter, status int, err error) {
|
||||
w.WriteHeader(status)
|
||||
|
||||
var response struct {
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
response.Error = err.Error()
|
||||
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
server.log.Error("failed to write json error response", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
// grapqlHandler is graphql endpoint http handler function
|
||||
func (server *Server) grapqlHandler(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
@ -67,8 +67,7 @@ func TestUserEmailCase(t *testing.T) {
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
for _, testCase := range []struct {
|
||||
email string
|
||||
expected string
|
||||
email string
|
||||
}{
|
||||
{email: "prettyandsimple@example.com"},
|
||||
{email: "firstname.lastname@domain.com "},
|
||||
|
@ -159,22 +159,6 @@ func (endpoint *Endpoint) validateAuth(ctx context.Context, header *pb.RequestHe
|
||||
return keyInfo, nil
|
||||
}
|
||||
|
||||
func (endpoint *Endpoint) validateCreateSegment(ctx context.Context, req *pb.SegmentWriteRequestOld) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
err = endpoint.validateBucket(ctx, req.Bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = endpoint.validateRedundancy(ctx, req.Redundancy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (endpoint *Endpoint) validateCommitSegment(ctx context.Context, req *pb.SegmentCommitRequestOld) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
@ -304,8 +288,8 @@ func (endpoint *Endpoint) validatePointer(ctx context.Context, pointer *pb.Point
|
||||
return Error.New("segment size %v is out of range, maximum allowed is %v", pointer.SegmentSize, maxAllowed)
|
||||
}
|
||||
|
||||
pieceNums := make(map[int32]struct{}, 0)
|
||||
nodeIds := make(map[storj.NodeID]struct{}, 0)
|
||||
pieceNums := make(map[int32]struct{})
|
||||
nodeIds := make(map[storj.NodeID]struct{})
|
||||
for _, piece := range remote.RemotePieces {
|
||||
if piece.PieceNum >= int32(len(originalLimits)) {
|
||||
return Error.New("invalid piece number")
|
||||
|
@ -425,7 +425,6 @@ func testDistinctIPs(t *testing.T, ctx *testcontext.Context, planet *testplanet.
|
||||
service := satellite.Overlay.Service
|
||||
|
||||
tests := []struct {
|
||||
nodeCount int
|
||||
duplicateCount int
|
||||
requestCount int
|
||||
preferences overlay.NodeSelectionConfig
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
|
||||
//go:generate dbx.v1 schema -d postgres satellitedb.dbx .
|
||||
//go:generate dbx.v1 golang -d postgres satellitedb.dbx .
|
||||
//go:generate sed -i '1i //lint:file-ignore * generated file\n' satellitedb.dbx.go
|
||||
|
||||
func init() {
|
||||
// catch dbx errors
|
||||
|
@ -1,3 +1,5 @@
|
||||
//lint:file-ignore * generated file
|
||||
|
||||
// AUTOGENERATED BY gopkg.in/spacemonkeygo/dbx.v1
|
||||
// DO NOT EDIT.
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
//lint:file-ignore * generated file
|
||||
|
||||
// Code generated for package schema by go-bindata DO NOT EDIT. (@generated)
|
||||
// sources:
|
||||
// 2018092201_initial-tables.down.sql
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See LICENSE for copying information.
|
||||
|
||||
//go:generate go-bindata -o data.go -pkg schema -ignore ".*go" .
|
||||
//go:generate sed -i '1i //lint:file-ignore * generated file\n' data.go
|
||||
|
||||
package schema
|
||||
|
||||
|
@ -277,41 +277,6 @@ func (cursor *forward) Advance() (*storage.ListItem, bool) {
|
||||
return cursor.next()
|
||||
}
|
||||
|
||||
type backward struct{ cursor }
|
||||
|
||||
func (cursor *backward) PositionToFirst(prefix, first storage.Key) {
|
||||
if prefix.IsZero() {
|
||||
// there's no prefix
|
||||
if first.IsZero() {
|
||||
// and no first item, so start from the end
|
||||
cursor.positionLast()
|
||||
} else {
|
||||
// theres a first item, so try to position on that or one before that
|
||||
cursor.positionBackward(first)
|
||||
}
|
||||
} else {
|
||||
// there's a prefix
|
||||
if first.IsZero() || storage.AfterPrefix(prefix).Less(first) {
|
||||
// there's no first, or it's after our prefix
|
||||
// storage.AfterPrefix("axxx/") is the next item after prefixes
|
||||
// so we position to the item before
|
||||
cursor.positionBefore(storage.AfterPrefix(prefix))
|
||||
} else {
|
||||
// otherwise try to position on first or one before that
|
||||
cursor.positionBackward(first)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (cursor *backward) SkipPrefix(prefix storage.Key) (*storage.ListItem, bool) {
|
||||
cursor.positionBefore(prefix)
|
||||
return cursor.prev()
|
||||
}
|
||||
|
||||
func (cursor *backward) Advance() (*storage.ListItem, bool) {
|
||||
return cursor.prev()
|
||||
}
|
||||
|
||||
// cursor implements iterating over items with basic repositioning when the items change
|
||||
type cursor struct {
|
||||
store *Client
|
||||
@ -336,35 +301,6 @@ func (cursor *cursor) positionForward(key storage.Key) {
|
||||
cursor.lastKey = storage.CloneKey(key)
|
||||
}
|
||||
|
||||
// positionLast positions at the last item
|
||||
func (cursor *cursor) positionLast() {
|
||||
store := cursor.store
|
||||
cursor.version = store.version
|
||||
cursor.nextIndex = len(store.Items) - 1
|
||||
cursor.lastKey = storage.NextKey(store.Items[cursor.nextIndex].Key)
|
||||
}
|
||||
|
||||
// positionBefore positions before key
|
||||
func (cursor *cursor) positionBefore(key storage.Key) {
|
||||
store := cursor.store
|
||||
cursor.version = store.version
|
||||
cursor.nextIndex, _ = store.indexOf(key)
|
||||
cursor.nextIndex--
|
||||
cursor.lastKey = storage.CloneKey(key) // TODO: probably not the right
|
||||
}
|
||||
|
||||
// positionBackward positions at key or before key
|
||||
func (cursor *cursor) positionBackward(key storage.Key) {
|
||||
store := cursor.store
|
||||
cursor.version = store.version
|
||||
var ok bool
|
||||
cursor.nextIndex, ok = store.indexOf(key)
|
||||
if !ok {
|
||||
cursor.nextIndex--
|
||||
}
|
||||
cursor.lastKey = storage.CloneKey(key)
|
||||
}
|
||||
|
||||
func (cursor *cursor) next() (*storage.ListItem, bool) {
|
||||
store := cursor.store
|
||||
if cursor.done {
|
||||
@ -391,34 +327,6 @@ func (cursor *cursor) next() (*storage.ListItem, bool) {
|
||||
return item, true
|
||||
}
|
||||
|
||||
func (cursor *cursor) prev() (*storage.ListItem, bool) {
|
||||
store := cursor.store
|
||||
if cursor.done {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
if cursor.version != store.version {
|
||||
cursor.version = store.version
|
||||
var ok bool
|
||||
cursor.nextIndex, ok = store.indexOf(cursor.lastKey)
|
||||
if !ok {
|
||||
cursor.nextIndex--
|
||||
}
|
||||
}
|
||||
if cursor.nextIndex >= len(store.Items) {
|
||||
cursor.nextIndex = len(store.Items) - 1
|
||||
}
|
||||
if cursor.nextIndex < 0 {
|
||||
cursor.close()
|
||||
return nil, false
|
||||
}
|
||||
|
||||
item := &store.Items[cursor.nextIndex]
|
||||
cursor.lastKey = item.Key
|
||||
cursor.nextIndex--
|
||||
return item, true
|
||||
}
|
||||
|
||||
// CompareAndSwap atomically compares and swaps oldValue with newValue
|
||||
func (store *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldValue, newValue storage.Value) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
@ -82,7 +82,7 @@ func (worker *Worker) Run(ctx context.Context, done func()) (err error) {
|
||||
response, err := c.Recv()
|
||||
if errs.Is(err, io.EOF) {
|
||||
// Done
|
||||
break
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
// TODO what happened
|
||||
@ -91,7 +91,8 @@ func (worker *Worker) Run(ctx context.Context, done func()) (err error) {
|
||||
|
||||
switch msg := response.GetMessage().(type) {
|
||||
case *pb.SatelliteMessage_NotReady:
|
||||
break // wait until next worker execution
|
||||
return nil
|
||||
|
||||
case *pb.SatelliteMessage_TransferPiece:
|
||||
transferPieceMsg := msg.TransferPiece
|
||||
worker.limiter.Go(ctx, func() {
|
||||
@ -100,6 +101,7 @@ func (worker *Worker) Run(ctx context.Context, done func()) (err error) {
|
||||
worker.log.Error("failed to transfer piece.", zap.Stringer("Satellite ID", worker.satelliteID), zap.Error(errs.Wrap(err)))
|
||||
}
|
||||
})
|
||||
|
||||
case *pb.SatelliteMessage_DeletePiece:
|
||||
deletePieceMsg := msg.DeletePiece
|
||||
worker.limiter.Go(ctx, func() {
|
||||
@ -119,10 +121,8 @@ func (worker *Worker) Run(ctx context.Context, done func()) (err error) {
|
||||
zap.Stringer("reason", msg.ExitFailed.Reason))
|
||||
|
||||
err = worker.satelliteDB.CompleteGracefulExit(ctx, worker.satelliteID, time.Now(), satellites.ExitFailed, msg.ExitFailed.GetExitFailureSignature())
|
||||
if err != nil {
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
break
|
||||
return errs.Wrap(err)
|
||||
|
||||
case *pb.SatelliteMessage_ExitCompleted:
|
||||
worker.log.Info("graceful exit completed.", zap.Stringer("Satellite ID", worker.satelliteID))
|
||||
|
||||
@ -132,18 +132,13 @@ func (worker *Worker) Run(ctx context.Context, done func()) (err error) {
|
||||
}
|
||||
// delete all remaining pieces
|
||||
err = worker.deleteOnePieceOrAll(ctx, nil)
|
||||
if err != nil {
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
break
|
||||
return errs.Wrap(err)
|
||||
|
||||
default:
|
||||
// TODO handle err
|
||||
worker.log.Error("unknown graceful exit message.", zap.Stringer("Satellite ID", worker.satelliteID))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
|
||||
type gracefulExitStream interface {
|
||||
|
Loading…
Reference in New Issue
Block a user