Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBG-3768 Update only metadata during import #6782

Merged
merged 5 commits into from
Apr 22, 2024
Merged

CBG-3768 Update only metadata during import #6782

merged 5 commits into from
Apr 22, 2024

Conversation

adamcfraser
Copy link
Collaborator

@adamcfraser adamcfraser commented Apr 16, 2024

During document import, perform an xattr-only update of the document.

CBG-3768

Dependencies (if applicable)

Integration Tests

During document import, perform an xattr-only update of the document.
@adamcfraser adamcfraser changed the title CBG-3768 Update metadata only during import CBG-3768 Update only metadata during import Apr 16, 2024
Copy link
Collaborator

@torcolvin torcolvin left a comment

Choose a reason for hiding this comment

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

I'll wait for an update as to why TestXattrOnDemandImportPreservesExpiry is failing.

base.SkipImportTestsIfNotEnabled(t)

rtConfig := rest.RestTesterConfig{
SyncFn: `function(doc, oldDoc) { channel(doc.channels) }`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume you are defining a syncfn because it will undergo js sync function and not skip? I'm not sure if that's needed for this test, I'd document why this is.

Autoimport should be enabled by default as far as I can tell by the RestTesterso you could use the default config.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, this was just copy/paste of the setup code from another test. I agree it can be simplified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It turns out autoimport is only enabled by default for EE, so still need the explicit setting here for the time being.

mobileBody := make(map[string]interface{})
mobileBody["channels"] = "ABC"
_, err := dataStore.Add(mobileKey, 0, mobileBody)
assert.NoError(t, err, "Error writing SDK doc")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert.NoError(t, err, "Error writing SDK doc")
require.NoError(t, err, "Error writing SDK doc")

@@ -1899,7 +1899,8 @@ type updateAndReturnDocCallback func(*Document) (resultDoc *Document, resultAtta
// 1. Receive the updated document body in the response
// 2. Specify the existing document body/xattr/cas, to avoid initial retrieval of the doc in cases that the current contents are already known (e.g. import).
// On cas failure, the document will still be reloaded from the bucket as usual.
func (db *DatabaseCollectionWithUser) updateAndReturnDoc(ctx context.Context, docid string, allowImport bool, expiry *uint32, opts *sgbucket.MutateInOptions, existingDoc *sgbucket.BucketDocument, callback updateAndReturnDocCallback) (doc *Document, newRevID string, err error) {
// 3. If isImport=true, document body will not be updated - only metadata xattr(s)
func (db *DatabaseCollectionWithUser) updateAndReturnDoc(ctx context.Context, docid string, allowImport bool, expiry *uint32, opts *sgbucket.MutateInOptions, existingDoc *sgbucket.BucketDocument, isImport bool, callback updateAndReturnDocCallback) (doc *Document, newRevID string, err error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Take or leave this comment as maybe out of scope.

I noticed that allowImport and isImport are both args to this function and I dug deeper in the code to figure out why because these variables seem very similar and it was not clear why they would both need to be set and are different. As far as I can tell, allowImport could be removed because

err = validateExistingDoc(doc, allowImport, docExists)
could say:

err = validateExistingDoc(doc, col.UseXattrs(), docExists)

and this would avoid the need to pass in allowImport at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're correct that today allowImport is equivalent to "is shared bucket access enabled", which could be checked by UseXattrs(). I don't think that's related to this PR, though, and is different than 'isImport', which mean 'is the current operation being performed an import'

Copy link
Collaborator

Choose a reason for hiding this comment

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

Understood, I was commenting on the fact that these have very similar argument names and it was a bit confusing to me.

It is different than this PR, only related in that I look at the function signature and saw two bool arguments with import in the name and wondered how they were different.

@adamcfraser adamcfraser assigned torcolvin and unassigned adamcfraser Apr 18, 2024
@torcolvin torcolvin merged commit c091603 into main Apr 22, 2024
30 checks passed
@torcolvin torcolvin deleted the CBG-3768 branch April 22, 2024 19:56
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.

2 participants