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

Persist merged entities only on the primary #6075

Merged
merged 15 commits into from
Feb 8, 2019
Merged

Conversation

vishalnayak
Copy link
Member

No description provided.

@chrishoffman chrishoffman added this to the 1.0.3 milestone Jan 24, 2019
// The entity and aliases will be loaded into memdb and persisted
// as a result of the merge so we are done here
return nil
}

if strutil.StrListContains(aliasFactors, i.sanitizeName(alias.Name)+alias.MountAccessor) {
i.logger.Warn(errDuplicateIdentityName.Error(), "alias_name", alias.Name, "mount_accessor", alias.MountAccessor, "entity_name", entity.Name, "action", "delete one of the duplicate aliases")
if !i.disableLowerCasedNames {
if !persist && !i.disableLowerCasedNames {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be an OR, not AND?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be an AND.

Copy link
Member

Choose a reason for hiding this comment

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

OK, so this will then cause memdb updates in this case, whereas before we would not do memdb updates and would simply return the error. Just making sure that's the correct behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for asking! The reason behind this change is just that disableLowerCasedNames error is captured only in the startup flow and no where else, and it only makes sense to get this error in that flow. But this function is not restricted to the login flow alone. So adding the guard of persist being set to false ensures that regular operations doesn't result in this error. This is not related to the core fix in this PR, and is something that I happened to notice.

@@ -332,7 +332,7 @@ func (i *IdentityStore) upsertEntityInTxn(ctx context.Context, txn *memdb.Txn, e
// Otherwise it's still tied to previousEntity and fall through
// into merging
fallthrough
default:
case persist && !i.core.ReplicationState().HasState(consts.ReplicationPerformanceSecondary):
Copy link
Member

Choose a reason for hiding this comment

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

Should this be checking for performance standby too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.


// At this point, identity store is operating case-sensitively.
// Persisting is allowed only on the primary.
if i.core.ReplicationState().HasState(consts.ReplicationPerformanceSecondary) || i.core.ReplicationState().HasState(consts.ReplicationPerformanceStandby) {
Copy link
Member

Choose a reason for hiding this comment

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

As I found out today, this won't do what you expect. Perf standby only appears in this call if you're going through a system view. You need to check c.perfStandby.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks a bunch! Fixed.

loadFunc := func(context.Context) error {
err := c.identityStore.loadEntities(ctx)
err = c.identityStore.loadEntities(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to leave as := I think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

ID: toEntity.ID,
Message: toEntityAsAny,
}
if persist && !(i.core.ReplicationState().HasState(consts.ReplicationPerformanceSecondary) || i.core.perfStandby) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit, can you pull the replication state check into a var at the top of the function rather than have it twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@vishalnayak vishalnayak merged commit 0ce70b8 into master Feb 8, 2019
@vishalnayak vishalnayak deleted the entity-loading branch February 8, 2019 21:32
@vishalnayak vishalnayak changed the title Merge entities during unseal only on the primary Persist merged entities only on the primary Feb 8, 2019
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.

None yet

5 participants