Skip to content

Fix is_realtime column behavior in sys.segments table - #8154

Merged
dclim merged 8 commits into
apache:masterfrom
surekhasaharan:is_realtime_fix
Aug 1, 2019
Merged

dclim merged 8 commits into
apache:masterfrom
surekhasaharan:is_realtime_fix

Conversation

@surekhasaharan

@surekhasaharan surekhasaharan commented Jul 24, 2019 •

Copy link
Copy Markdown

Fixes #8142

Description

Update the isRealtime flag when a segment is dropped by a realtime task.
In DruidSchema added a check in removeServerSegment() when none of the replicas is a realtime server type, mark isRealtime=0.
Added unit test.
This is marked incompatible because the semantics of the is_realtime flag for a segment is changed, earlier a segment would be marked realtime, if any realtime task was serving the segment. It's now changed to that a segment would be marked realtime, if only realtime task is serving the segment and if a historical starts serving the segment, it's realtime flag is 0 or false.


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths.

final DruidServerMetadata realtimeServer = servers.stream()
.filter(metadata -> metadata.getType().equals(ServerType.REALTIME))
.findAny()
.orElse(null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since findAny() returns an Optional, you could use Optional.isPresent() below instead of using orElse() to convert to null. Another option is to use anyMatch() instead of findAny().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ah, sure, i used Optional.isPresent()

.map(AvailableSegmentMetadata::getSegment)
.collect(Collectors.toList());
Assert.assertEquals(segments.size(), 3);
Assert.assertEquals(segments.size(), 4);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If 4 is the expected value, it should be the first argument. (Similar comment for other occurrences below).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed here and other places.

.filter(segment -> segment.getDataSource().equals("foo3"))
.findFirst()
.orElse(null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you want to assert existingSegment is not null? (similar comment for other occurrences below)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yup

.orElse(null);

final AvailableSegmentMetadata metadata = segmentsMetadata.get(existingSegment.getId());
Assert.assertEquals(metadata.isRealtime(), 1L);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make 1L the first argument as it's the expected value.

.findAny();

// if there is no realtime server in the replicas, isRealtime flag should be unset
long isRealtime = realtimeServer.isPresent() ? 1 : 0;

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.

Apologies for missing this original discussion, but is this the most useful thing for the is_realtime flag to mean, where it reports true if any of the servers serving a segment is a realtime task?

It might be more useful for is_realtime to report true if it is only available on realtime tasks, and false if any server serving the segment is a historical, since that is how the broker will behave at query time (#4764). I think this would probably involve doing this as part of addSegment instead of removeSegment.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You have a point, i think i sort of agree, it'll make is_realtime more intuitive for users. The docs for is_realtime here say this flag is 1 if this segment is being served on any type of realtime tasks, that'll need to change. Yeah, with the changed semantics of is_realtime, the flag will be unset when addSegment is called a second time via a historical. May be it should be updated in removeSegment as well, but the check will be if there is any historical server in the replicas, unset this flag.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This change will make it incompatible with previous behavior, which I hope is okay, unless someone is relying on that behavior of is_realtime.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It might be more useful for is_realtime to report true if it is only available on realtime tasks, and false if any server serving the segment is a historical

That sounds good to me

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the idea I had in the previous conversation was motivated by is_realtime being false meaning that the segment has completely flushed out of the realtime system. I thought it'd be useful for finding segments where handoff is lingering for some reason.

If we change it to what you are proposing, @clintropolis, then it'd be somewhat harder to find segments where handoff is lingering (but still possible by joining segments and servers). But it'd be easier to find segments where handoff has progressed far enough that a historical has loaded the segment.

Six of one, half dozen of the other.

I am okay with either approach, so long as it's clearly documented what the behavior should be. I don't think the fact that the change would be theoretically incompatible is a big deal, since the column is buggy enough that it doesn't work anyway right now.

@clintropolis clintropolis left a comment

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.

lgtm thanks! 👍 after CI

@dclim

dclim commented Aug 1, 2019

Copy link
Copy Markdown
Contributor

👍

@dclim
dclim merged commit f0ecdfe into apache:master Aug 1, 2019
@surekhasaharan
surekhasaharan deleted the is_realtime_fix branch August 1, 2019 06:09
@clintropolis clintropolis added this to the 0.16.0 milestone Aug 8, 2019
riovic918data pushed a commit to riovic918data/druid that referenced this pull request Jun 12, 2026
* Fix is_realtime flag

* make variable final

* minor changes

* Modify is_realtime behavior based on review comment

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sys.segment's is_realtime flag once set, is never unset

6 participants