Skip to content

Conversation

@berndverst
Copy link
Member

@berndverst berndverst commented Sep 20, 2021

Description

Progress towards #950 : Adds conformance tests for Azure Table Storage Pass.

Fixes incorrect ETag Deletion behavior.

  • Code compiles correctly
  • Created/updated tests

@berndverst berndverst marked this pull request as ready for review September 20, 2021 22:55
@berndverst berndverst requested review from a team as code owners September 20, 2021 22:55
Copy link
Contributor

@CodeMonkeyLeet CodeMonkeyLeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for adding this and fixing up the component!

@berndverst
Copy link
Member Author

@CodeMonkeyLeet thanks for the review. Take another look when you got a chance.

Comment on lines 199 to 218
err := entity.Insert(storage.FullMetadata, nil)
if err != nil {
if isNotFoundError(err) {
// When entity is not found (set state first time) create it
entity.OdataEtag = ""
if etag == "" {
if req.Options.Concurrency == state.FirstWrite {
return state.NewETagError(state.ETagMismatch, err)
}

return entity.Insert(storage.FullMetadata, nil)
return entity.Update(true, nil)
}
err := entity.Update(false, nil)
if err != nil {
if isNotFoundError(err) {
return state.NewETagError(state.ETagMismatch, err)
}
}

return err
}

return err
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic LGTM, good job working it out. I would suggest heavily commenting it because the why it works took me a while to unravel that from the structure of the code and the quirks of the conformance test expectations.

I would also suggest explicitly checking for why Insert fails and handling expected cases with Update only.

err := entity.Insert(storage.FullMetadata, nil)
if err != nil {
	// If Insert failed because item already exists, try to Update instead per Upsert semantics
	if isEntityAlreadyExistsError(err) {
		// Always Update using the etag when provided even if Concurrency != FirstWrite.
		// This behavior is enforced by test state.go:440 today, where we treat the presence of etag as trumping Concurrency.
		// In the future, we should error if an etag is provided when not using FirstWrite (see #2739)
		if etag != "" {
			uerr := entity.Update(false, nil)
			if uerr != nil {
				if isNotFoundError(uerr) {
					return state.NewETagError(state.ETagMismatch, uerr)
				}
				return uerr
			}
		} else if req.Options.Concurrency == state.FirstWrite {
			// Otherwise, if FirstWrite was set, but no etag was provided for an Update operation
			// explicitly flag it as an error. This is enforced by test state.go:541.
			// entity.Update itself does not flag the test case as a mismatch as it does not distinguish
			// between nil and "" etags, the initial etag will always be "", which would match on update.
			return state.NewETagError(state.ETagMismatch, errors.New("update with Concurrency.FirstWrite without ETag"))
		} else {
			// Finally, last write semantics without ETag should always perform a force update.
			return entity.Update(true, nil)
		}
	} else {
		// Any other unexpected error on Insert is propagated to the caller
		return err
	}
}

return nil

where

func isEntityAlreadyExistsError(err error) bool {
	azureError, ok := err.(storage.AzureStorageServiceError)

	return ok && azureError.Code == "EntityAlreadyExists"
}

Copy link
Contributor

@CodeMonkeyLeet CodeMonkeyLeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@codecov
Copy link

codecov bot commented Sep 22, 2021

Codecov Report

Merging #1159 (905cbc0) into master (8f0cc88) will increase coverage by 0.06%.
The diff coverage is 41.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1159      +/-   ##
==========================================
+ Coverage   33.70%   33.77%   +0.06%     
==========================================
  Files         138      138              
  Lines       11635    11686      +51     
==========================================
+ Hits         3922     3947      +25     
- Misses       7308     7329      +21     
- Partials      405      410       +5     
Impacted Files Coverage Δ
authentication/azure/auth.go 56.09% <ø> (ø)
bindings/alicloud/dingtalk/webhook/webhook.go 52.68% <ø> (ø)
bindings/alicloud/nacos/nacos.go 35.23% <ø> (ø)
bindings/alicloud/oss/oss.go 11.11% <ø> (ø)
bindings/alicloud/rocketmq/rocketmq.go 0.00% <ø> (ø)
bindings/alicloud/rocketmq/settings.go 22.22% <ø> (ø)
bindings/apns/apns.go 88.00% <ø> (ø)
bindings/apns/authorization_builder.go 78.26% <ø> (ø)
bindings/aws/dynamodb/dynamodb.go 10.52% <ø> (ø)
bindings/aws/kinesis/kinesis.go 2.61% <ø> (ø)
... and 103 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 988fed0...905cbc0. Read the comment docs.

Copy link
Member

@daixiang0 daixiang0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@daixiang0 daixiang0 merged commit dafa457 into dapr:master Sep 23, 2021
@berndverst berndverst deleted the tablestorage branch September 23, 2021 17:33
amimimor pushed a commit to amimimor/components-contrib that referenced this pull request Dec 9, 2021
Conformance Tests for Azure Table Storage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants