-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 12 commits
147743b
b12a558
dee8f9c
162d093
da27715
3fb55b6
4df3d3e
df84739
5020513
5ac6370
f2d0e83
41a47c2
d862f84
4ac25c6
ce9d094
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,10 @@ var ( | |
errDuplicateIdentityName = errors.New("duplicate identity name") | ||
) | ||
|
||
func (c *Core) SetLoadCaseSensitiveIdentityStore(caseSensitive bool) { | ||
c.loadCaseSensitiveIdentityStore = caseSensitive | ||
} | ||
|
||
func (c *Core) loadIdentityStoreArtifacts(ctx context.Context) error { | ||
if c.identityStore == nil { | ||
c.logger.Warn("identity store is not setup, skipping loading") | ||
|
@@ -38,14 +42,16 @@ func (c *Core) loadIdentityStoreArtifacts(ctx context.Context) error { | |
return c.identityStore.loadGroups(ctx) | ||
} | ||
|
||
// Load everything when memdb is set to operate on lower cased names | ||
err := loadFunc(ctx) | ||
switch { | ||
case err == nil: | ||
// If it succeeds, all is well | ||
return nil | ||
case err != nil && !errwrap.Contains(err, errDuplicateIdentityName.Error()): | ||
return err | ||
if !c.loadCaseSensitiveIdentityStore { | ||
// Load everything when memdb is set to operate on lower cased names | ||
err := loadFunc(ctx) | ||
switch { | ||
case err == nil: | ||
// If it succeeds, all is well | ||
return nil | ||
case err != nil && !errwrap.Contains(err, errDuplicateIdentityName.Error()): | ||
return err | ||
} | ||
} | ||
|
||
c.identityStore.logger.Warn("enabling case sensitive identity names") | ||
|
@@ -56,8 +62,7 @@ func (c *Core) loadIdentityStoreArtifacts(ctx context.Context) error { | |
// Swap the memdb instance by the one which operates on case sensitive | ||
// names, hence obviating the need to unload anything that's already | ||
// loaded. | ||
err = c.identityStore.resetDB(ctx) | ||
if err != nil { | ||
if err := c.identityStore.resetDB(ctx); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -334,21 +339,23 @@ func (i *IdentityStore) upsertEntityInTxn(ctx context.Context, txn *memdb.Txn, e | |
fallthrough | ||
jefferai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default: | ||
i.logger.Warn("alias is already tied to a different entity; these entities are being merged", "alias_id", alias.ID, "other_entity_id", aliasByFactors.CanonicalID, "entity_aliases", entity.Aliases, "alias_by_factors", aliasByFactors) | ||
respErr, intErr := i.mergeEntity(ctx, txn, entity, []string{aliasByFactors.CanonicalID}, true, false, true) | ||
|
||
respErr, intErr := i.mergeEntity(ctx, txn, entity, []string{aliasByFactors.CanonicalID}, true, false, true, persist) | ||
switch { | ||
case respErr != nil: | ||
return respErr | ||
case intErr != nil: | ||
return intErr | ||
} | ||
|
||
jefferai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be an OR, not AND? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be an AND. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for asking! The reason behind this change is just that |
||
return errDuplicateIdentityName | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.