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

fix: add a warning message on startup if the server name is default #14613

Merged
merged 2 commits into from
Oct 27, 2022

Conversation

nic-chen
Copy link
Contributor

@nic-chen nic-chen commented Oct 23, 2022

fix #13757

@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2022

Codecov Report

Merging #14613 (191fb30) into main (e5790d2) will decrease coverage by 0.32%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main   #14613      +/-   ##
==========================================
- Coverage   75.76%   75.44%   -0.33%     
==========================================
  Files         457      457              
  Lines       37267    37269       +2     
==========================================
- Hits        28235    28117     -118     
- Misses       7284     7385     +101     
- Partials     1748     1767      +19     
Flag Coverage Δ
all 75.44% <100.00%> (-0.33%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
server/embed/config.go 74.35% <100.00%> (+0.13%) ⬆️
server/proxy/grpcproxy/register.go 69.76% <0.00%> (-9.31%) ⬇️
server/storage/mvcc/watchable_store.go 84.42% <0.00%> (-9.06%) ⬇️
client/pkg/v3/testutil/leak.go 62.83% <0.00%> (-7.08%) ⬇️
client/v3/namespace/watch.go 87.87% <0.00%> (-6.07%) ⬇️
server/lease/lease.go 94.87% <0.00%> (-5.13%) ⬇️
raft/rafttest/node.go 95.00% <0.00%> (-5.00%) ⬇️
client/v3/concurrency/session.go 88.63% <0.00%> (-4.55%) ⬇️
server/storage/mvcc/kvstore_compaction.go 95.65% <0.00%> (-4.35%) ⬇️
client/v3/leasing/cache.go 87.77% <0.00%> (-3.89%) ⬇️
... and 23 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

for idx := range urls {
m := NewMember(name, urls[idx:idx+1], token, nil)
if _, ok := c.members[m.ID]; ok {
return nil, fmt.Errorf("member exists with identical ID %v", m)
Copy link
Member

Choose a reason for hiding this comment

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

You might be heading in the wrong direction. Usually each member has different peerURL(s), they must have different memberID. FYI.

func computeMemberId(peerURLs types.URLs, clusterName string, now *time.Time) types.ID {
peerURLstrs := peerURLs.StringSlice()
sort.Strings(peerURLstrs)
joinedPeerUrls := strings.Join(peerURLstrs, "")
b := []byte(joinedPeerUrls)
b = append(b, []byte(clusterName)...)
if now != nil {
b = append(b, []byte(fmt.Sprintf("%d", now.Unix()))...)
}
hash := sha1.Sum(b)
return types.ID(binary.BigEndian.Uint64(hash[:8]))
}

For simplicity, we can just add a warning message on startup if --name isn't provided a value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you very much for the reminder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated. Please take a look again.
Instead of actually checking if --name is empty, I'm checking if it's default.

Signed-off-by: nic-chen <chenjunxu6@gmail.com>
@nic-chen nic-chen marked this pull request as ready for review October 26, 2022 15:35
@nic-chen nic-chen changed the title fix: the issue about duplicate cluster names caused member count is unequal error when initializing a cluster fix: add a warning message on startup if the server name is default Oct 26, 2022
@@ -90,6 +90,10 @@ func startEtcdOrProxyV2(args []string) {
lg.Info("failed to detect default host", zap.Error(dhErr))
}

if cfg.ec.Name == embed.DefaultName {
lg.Warn("the server is using default name, which might cause error that failed the startup.")
}
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to add the check into (*Config) Validate(), so that we have all configuration checker in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!
I tried to find such a place, but failed.
So I put it here according to the content in the log 'data-dir' was empty; using default...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

server/etcdmain/etcd.go Outdated Show resolved Hide resolved
Signed-off-by: nic-chen <chenjunxu6@gmail.com>
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

LGTM

Thank you @nic-chen

@ahrtr ahrtr merged commit 1e12426 into etcd-io:main Oct 27, 2022
// because each member can have multiple client or peer URLs.
// Please refer to https://github.com/etcd-io/etcd/issues/13757
if cfg.Name == DefaultName {
cfg.logger.Warn("the server is using default name, which might cause error that failed the startup.")
Copy link
Member

Choose a reason for hiding this comment

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

I was planning to add a comment for this, but somehow forgot to do it:(

Please change it to something like below,

return fmt.Errorf("it isn't recommended to use %q name, please set a value for --name. Note that etcd might run into issue when multiple members have the same default name", DefaultName)

Copy link
Member

Choose a reason for hiding this comment

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

Please ignore my previous comment. We can't return an error, because etcd may fail to get started. Let's just update the message,

cfg.logger.Warn("it isn't recommended to use %q name, please set a value for --name. Note that etcd might run into issue when multiple members have the same default name", DefaultName)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will update it later today or tomorrow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will update it later today or tomorrow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated. #14642
please take a look at your convenience. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Duplicate names in ETCD_INITIAL_CLUSTER not handled correctly
3 participants