Skip to content

Commit

Permalink
Sync from server repo (b39ac5d304f)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Sep 8, 2023
1 parent aa31924 commit 97ca903
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
18 changes: 14 additions & 4 deletions vclusterops/nma_download_file_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ type downloadFileRequestData struct {
Parameters map[string]string `json:"parameters,omitempty"`
}

// ClusterLeaseNotExpiredFailure is returned when an attempt is made to use a
// communal storage before the lease for it has expired.
type ClusterLeaseNotExpiredError struct {
Expiration string
}

func (e *ClusterLeaseNotExpiredError) Error() string {
return fmt.Sprintf("revive database cannot continue because the communal storage location might still be in use."+
" The cluster lease will expire at %s(UTC)."+
" Please ensure that the other cluster has stopped and try revive_db after the cluster lease expiration",
e.Expiration)
}

func makeNMADownloadFileOp(newNodes []string, sourceFilePath, destinationFilePath, catalogPath string,
communalStorageParameters map[string]string, vdb *VCoordinationDatabase, displayOnly, ignoreClusterLease bool) (NMADownloadFileOp, error) {
op := NMADownloadFileOp{}
Expand Down Expand Up @@ -251,10 +264,7 @@ func (op *NMADownloadFileOp) clusterLeaseCheck(clusterLeaseExpiration string) er

// current time < expire time, it means that the cluster lease is not expired
if utcNow.Before(utcExpiration) {
return fmt.Errorf("revive database cannot continue because the communal storage location might still be in use."+
" The cluster lease will expire at %s(UTC)."+
" Please ensure that the other cluster has stopped and try revive_db after the cluster lease expiration",
clusterLeaseExpiration)
return &ClusterLeaseNotExpiredError{Expiration: clusterLeaseExpiration}
}

vlog.LogPrintInfoln("Cluster lease check has passed. We proceed to revive the database")
Expand Down
45 changes: 45 additions & 0 deletions vclusterops/nma_download_file_op_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
(c) Copyright [2023] Open Text.
Licensed under the Apache License, Version 2.0 (the "License");
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vclusterops

import (
"errors"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestClusteLeaseExpiryError(t *testing.T) {
op := NMADownloadFileOp{
ignoreClusterLease: false,
}

// Failure case when lease hasn't expired
fakeLeaseTime := time.Now().UTC().Add(time.Minute * time.Duration(5))
err := op.clusterLeaseCheck(fakeLeaseTime.Format(expirationStringLayout))
assert.Error(t, err)
// Ensure we get a specific error type back
clusterLeaseErr := &ClusterLeaseNotExpiredError{}
ok := errors.As(err, &clusterLeaseErr)
assert.True(t, ok)
assert.Contains(t, err.Error(), "The cluster lease will expire at")

// Success case
fakeLeaseTime = time.Now().UTC().Add(-time.Minute * time.Duration(5))
err = op.clusterLeaseCheck(fakeLeaseTime.Format(expirationStringLayout))
assert.NoError(t, err)
}

0 comments on commit 97ca903

Please sign in to comment.