Skip to content

Commit 61d122e

Browse files
committed
add wait for AVAILABLE state after dbSystem update and before database update
1 parent 8c75636 commit 61d122e

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

oci/crud_helpers.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func FilterMissingResourceError(sync ResourceVoider, err *error) {
444444

445445
// In the Exadata case the service return the hostname provided by the service with a suffix
446446
func dbSystemHostnameDiffSuppress(key string, old string, new string, d *schema.ResourceData) bool {
447-
return EqualIgnoreCaseSuppressDiff(key, old, new, d) || newIsPrefixOfOldDiffSuppress(key, old, new, d)
447+
return EqualIgnoreCaseSuppressDiff(key, old, new, d) || NewIsPrefixOfOldDiffSuppress(key, old, new, d)
448448
}
449449

450450
func NewIsPrefixOfOldDiffSuppress(key string, old string, new string, d *schema.ResourceData) bool {
@@ -635,3 +635,24 @@ func convertResourceFieldsToDatasourceFields(resourceSchema *schema.Resource) *s
635635

636636
return resourceSchema
637637
}
638+
639+
func getRetryPolicyWithAdditionalretryCondition(timeout time.Duration, retryConditionFunction func(oci_common.OCIOperationResponse) bool, service string) *oci_common.RetryPolicy {
640+
startTime := time.Now()
641+
// wait for status of the database to not be UPDATING
642+
return &oci_common.RetryPolicy{
643+
ShouldRetryOperation: func(response oci_common.OCIOperationResponse) bool {
644+
if shouldRetry(response, false, service, startTime) {
645+
return true
646+
}
647+
if retryConditionFunction(response) {
648+
timeWaited := getElapsedRetryDuration(startTime)
649+
return timeWaited < timeout
650+
}
651+
return false
652+
},
653+
NextDuration: func(response oci_common.OCIOperationResponse) time.Duration {
654+
return getRetryBackoffDuration(response, false, service, startTime)
655+
},
656+
MaximumNumberAttempts: 0,
657+
}
658+
}

oci/database_db_system_resource.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,34 @@ func (s *DatabaseDbSystemResourceCrud) Update() error {
765765

766766
s.Res = &response.DbSystem
767767

768+
// Wait for dbSystem to not be in updating state after the update. UpdateDatabase returns 409 if the dbSystem is in Updating state
769+
// We cannot use the usual waitForState logic here because a Get() before the SetData() would interfere with the subsequent Database Update
770+
getDbSystemRequest := oci_database.GetDbSystemRequest{}
771+
772+
getDbSystemRequest.DbSystemId = s.Res.Id
773+
774+
dbSystemUpdating := func(response oci_common.OCIOperationResponse) bool {
775+
if getDbSystemResponse, ok := response.Response.(oci_database.GetDbSystemResponse); ok {
776+
if getDbSystemResponse.LifecycleState == oci_database.DbSystemLifecycleStateUpdating {
777+
return true
778+
}
779+
}
780+
return false
781+
}
782+
783+
getDbSystemRequest.RequestMetadata.RetryPolicy = getRetryPolicyWithAdditionalretryCondition(s.D.Timeout(schema.TimeoutUpdate), dbSystemUpdating, "database")
784+
getDbSystemResponse, err := s.Client.GetDbSystem(context.Background(), getDbSystemRequest)
785+
if err != nil {
786+
// Do SetData here in case the service returns updated values immediately on the Update request that don't need to wait for the waitForState
787+
err = s.SetData()
788+
if err != nil {
789+
log.Printf("[ERROR] error setting data after polling error on the dbSystem: %v", err)
790+
}
791+
return fmt.Errorf("[ERROR] unable to get dbSystem after the update: %v", err)
792+
}
793+
794+
s.Res = &getDbSystemResponse.DbSystem
795+
768796
err = s.SetData()
769797
if err != nil {
770798
return fmt.Errorf("[ERROR] error setting data after dbsystem update but before database update: %v", err)

0 commit comments

Comments
 (0)