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

Token store deleted parent #4193

Merged
merged 12 commits into from
Mar 27, 2018
Merged

Token store deleted parent #4193

merged 12 commits into from
Mar 27, 2018

Conversation

calvn
Copy link
Contributor

@calvn calvn commented Mar 24, 2018

Addresses the following:

  • Revoke-orphan and tidy now removes the parent prefix entry if the token entry doesn't exist
  • Revoke-orphan and tidy now converts/marks all child tokens as orphan tokens as it's cleaning up the parent prefix entry.

@calvn calvn added this to the 0.10 milestone Mar 24, 2018
@calvn calvn requested review from jefferai and vishalnayak March 24, 2018 00:07
lock.Unlock()
continue
}
// Otherwise, if the entry doesn't exist, or if the parent doesn't exit go
Copy link
Member

Choose a reason for hiding this comment

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

s/exit/exist

continue
}
// Otherwise, if the entry doesn't exist, or if the parent doesn't exit go
// on with the delete onthe secondary index
Copy link
Member

Choose a reason for hiding this comment

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

s/onthe/on the

}
}
// Add current children deleted count to the total count
deletedCountParentList += deletedChildrenCount
// If we deleted all the children, then add that to our deleted parent entries count
Copy link
Member

Choose a reason for hiding this comment

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

Should the parent prefix be cleaned out here if exists == nil? Since ClearView above operates at revocation time but in this situation we won't be revoking the parent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consul will remove the prefix entry if the "directory" is empty so I didn't have an explicit delete in here, but I guess we can't guarantee that this is the behavior for other storage backends so I might be good to explicitly call a delete (though I'd do it inside if originalChildrenCount == deletedChildrenCount {...} which ensures that we delete the prefix iff all child/secondary indexes are removed).

Copy link
Member

Choose a reason for hiding this comment

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

👍

// N.B.: This is a no-op for the consul storage backend since the delete doesn't support
// recursive deletes, and delete on a path is a no-op.
if exists == nil {
err := ts.view.Delete(ctx, parentPrefix+parent)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jefferai @vishalnayak I added the explicit delete in here to ensure that the parent prefix gets deleted if there are no children as per previous discussion in here.

In the case for Consul, it should automatically remove this (and even if it didn't, this would result in a no-op since the underlying ConsulBackend.Delete would have to call DeleteTree to handle tree deletions and deletes on a non-existing key is simply treated as a success). However, other storage backend implementations might error on this since the delete method is usually done against an entry, and not a path/tree (thinking that this might be an issue for Cassandra's delete, for instance). This would result in the tidy operation being treated as a failure, so I wonder if we should a) not do this at all or b) treat this as warning instead of an error.

Copy link
Member

Choose a reason for hiding this comment

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

@calvn Apologies -- I think this needs to come back out. You're right that we don't know what storage implementations will do, but I believe the expected behavior is that they clean up their own empty prefixes. I remember making this change with file for instance, so if a storage backend isn't doing this then it's for the backend to fix. It was right the first way :-/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries, I'll revert! Glad this discussion happened; I learn something new every day :)

jefferai
jefferai previously approved these changes Mar 26, 2018
@@ -1169,6 +1169,33 @@ func (ts *TokenStore) revokeSalted(ctx context.Context, saltedId string) (ret er
}
}

// Mark all children token as orphan by removing
// their parent index, and clear the parent entry
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add to this comment explaining that marking orphan is correct since revokeTree will ensure that any are deleted anyways if it is not an explicit call to orphan the child tokens.

if err != nil {
return fmt.Errorf("failed to get child token: %v", err)
}
lock := locksutil.LockForKey(ts.tokenLocks, entry.ID)
Copy link
Member

Choose a reason for hiding this comment

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

If this lock happens to be the same lock that is being used outside of this loop, acquiring this will deadlock. No?

Copy link
Member

Choose a reason for hiding this comment

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

Never mind.

Copy link
Member

@vishalnayak vishalnayak left a comment

Choose a reason for hiding this comment

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

LGTM!

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