Skip to content

Fix a bug in DruidCluster.getAllServers()#4500

Merged
gianm merged 2 commits intoapache:masterfrom
jihoonson:fix-get-all-servers
Jul 5, 2017
Merged

Fix a bug in DruidCluster.getAllServers()#4500
gianm merged 2 commits intoapache:masterfrom
jihoonson:fix-get-all-servers

Conversation

@jihoonson
Copy link
Copy Markdown
Contributor

@jihoonson jihoonson commented Jul 4, 2017

realtimes is accidentally changed after calling getAllServers(), but must not.


This change is Reviewable

return historicals.values().stream()
.flatMap(Collection::stream)
.collect(() -> realtimes, Set::add, Set::addAll);
final List<ServerHolder> allServers = historicals.values().stream()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested more old-style to avoid list reallocation:

int historicalServers = historicals.values().stream().mapToInt(Collection::size).sum();
int allServers = historicalServers + realtimes.size();
List<ServerHolder> result = new ArrayList<>(allServers);
historicals.values().forEach(tierServers -> result.addAll(tierServers));
result.addAll(realtimes);
return result;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or could use ImmutableList.builder

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I like the former one because DruidCluster is effectively used as immutable once all cluster nodes are added.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@jihoonson could it be turned into a proper immutable then, to avoid bugs? Also getAllServers() could be cached.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, I think it would be ok. Actually DruidCluster is a snapshot of the ServerInventoryView. DruidCoordinator builds a new DruidCluster at each run and this snapshot is used by subsequent DruidCoordinatorHelpers in the same run.

@leventov leventov added this to the 0.10.1 milestone Jul 4, 2017
Copy link
Copy Markdown
Contributor

@gianm gianm left a comment

Choose a reason for hiding this comment

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

LGTM

@gianm gianm merged commit a6d648a into apache:master Jul 5, 2017
gianm pushed a commit to gianm/druid that referenced this pull request Jul 5, 2017
* Fix a bug in getAllServers

* Change to old style
leventov pushed a commit that referenced this pull request Jul 5, 2017
* Fix a bug in getAllServers

* Change to old style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants