Skip to content

Add undocumented taskLockType to MSQ.#15168

Merged
cryptoe merged 6 commits into
apache:masterfrom
cryptoe:adding_configurable_lock_types
Oct 17, 2023
Merged

Add undocumented taskLockType to MSQ.#15168
cryptoe merged 6 commits into
apache:masterfrom
cryptoe:adding_configurable_lock_types

Conversation

@cryptoe

@cryptoe cryptoe commented Oct 16, 2023

Copy link
Copy Markdown
Contributor

With #14258 going in, we want these lock types to be used by MSQ. This pr adds an undocumented parameter taskLockType to MSQ so that we can start enabling this feature for users who are interested in testing the new lock types.

This context parameter should be removed once these new lock types are battle tested.

@github-actions github-actions Bot added Area - Batch Ingestion Area - Querying Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 labels Oct 16, 2023
@cryptoe cryptoe added this to the 28.0 milestone Oct 16, 2023

@LakshSingla LakshSingla left a comment

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.

} else if (taskLockType.equals(TaskLockType.SHARED)) {
return SegmentTransactionalInsertAction.appendAction(segments, null, null);
} else {
throw DruidException.defensive("Invalid lock type %s received for append action", taskLockType);

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.

nit: extrapolation

Suggested change
throw DruidException.defensive("Invalid lock type %s received for append action", taskLockType);
throw DruidException.defensive("Invalid lock type [%s] received for append action", taskLockType);

} else if (taskLockType.equals(TaskLockType.EXCLUSIVE)) {
return SegmentTransactionalInsertAction.overwriteAction(null, segmentsWithTombstones);
} else {
throw DruidException.defensive("Invalid lock type %s received for overwrite action", taskLockType);

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.

Suggested change
throw DruidException.defensive("Invalid lock type %s received for overwrite action", taskLockType);
throw DruidException.defensive("Invalid lock type [%s] received for overwrite action", taskLockType);

throw DruidException.forPersona(DruidException.Persona.USER)
.ofCategory(DruidException.Category.INVALID_INPUT)
.build(
"TaskLock must be of type %s or %s for a replace query. Found type %s set."

@LakshSingla LakshSingla Oct 16, 2023

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.

  1. Capitalization of REPLACE to be consistent with error messages across MSQ
  2. Reworded the second sentence so that it makes sense without extrapolation as well - https://github.com/apache/druid/blob/master/dev/style-conventions.md?plain=1#L51
Suggested change
"TaskLock must be of type %s or %s for a replace query. Found type %s set."
"TaskLock must be of type %s or %s for a REPLACE query. Invalid lock type [%s] found."

throw DruidException.forPersona(DruidException.Persona.USER)
.ofCategory(DruidException.Category.INVALID_INPUT)
.build(
"TaskLock must be of type %s or %s for an insert query. Found type %s set."

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.

Suggested change
"TaskLock must be of type %s or %s for an insert query. Found type %s set."
"TaskLock must be of type %s or %s for an INSERT query. Invalid lock type [%s] found."

for (TaskLockType taskLockType : new TaskLockType[]{TaskLockType.EXCLUSIVE, TaskLockType.REPLACE}) {
testLockTypes(
taskLockType,
"insert into foo1 select * from foo partitioned by day",

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.

nit: Better capitalization in the test cases.

Suggested change
"insert into foo1 select * from foo partitioned by day",
"INSERT INTO foo1 SELECT * FROM foo PARTITIONED BY DAY",

.putAll(DEFAULT_MSQ_CONTEXT)
.put(
Tasks.TASK_LOCK_TYPE,
TaskLockType.REPLACE.name().toLowerCase(Locale.ENGLISH)

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.

Suggested change
TaskLockType.REPLACE.name().toLowerCase(Locale.ENGLISH)
StringUtils.toLowerCase(TaskLockType.REPLACE.name())

} else if (taskLockType.equals(TaskLockType.SHARED)) {
return SegmentTransactionalInsertAction.appendAction(segments, null, null);
} else {
throw DruidException.defensive("Invalid lock type %s received for append action", taskLockType);

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.

Don't think we really need these exceptions (esp since the methods are private) here as we would reach these methods only after the validation is already done.

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 just like a more defensive approach here in case we break something above. I guess this check does not hurt functionality.

if (isReplaceQuery) {
return TaskLockType.EXCLUSIVE;
} else {
return TaskLockType.APPEND;

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.

Typo: I think this should be SHARED (as indicated in the javadoc of this method too)

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.

Good catch

@kfaraz kfaraz left a comment

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.

Apart from minor comments and existing style feedback from @LakshSingla , the changes look good to me.

Thanks a lot for the quick fix, @cryptoe !

@cryptoe

cryptoe commented Oct 17, 2023

Copy link
Copy Markdown
Contributor Author

@LakshSingla @kfaraz I have addressed the comments. PTAL soon since this is a druid 28.0 work item.

segmentSortOrder,
replaceTimeChunks
);
MultiStageQueryContext.validateAndGetTaskLockType(sqlQueryContext,

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.

The return value is not being utilized. Is this call made to validate the lock type?

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.

Yes

@AmatyaAvadhanula AmatyaAvadhanula left a comment

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.

LGTM! Thank you @cryptoe

@abhishekrb19 abhishekrb19 left a comment

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.

LGTM!

* {@link TaskLockType#SHARED} is used for insert queries.
* If the queryContext contains the taskLockType, then it is validated and returned.
*/
public static TaskLockType validateAndGetTaskLockType(QueryContext queryContext, boolean isReplaceQuery)

@abhishekrb19 abhishekrb19 Oct 17, 2023

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.

In my mind, !isReplaceQuery means an INSERT or SELECT query. I see it's invoked only in the context of ingestion, but would also be good to clarify that in the javadoc since this class is common to all queries.

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.

@abhishekrb19 I will fix this as part of a upcoming PR. I kind of assumed TaskLocks means something to do with ingestion but yes I can be more clear there.

@cryptoe
cryptoe merged commit 953ce79 into apache:master Oct 17, 2023
LakshSingla pushed a commit to LakshSingla/druid that referenced this pull request Oct 17, 2023
Patch adds an undocumented parameter taskLockType to MSQ so that we can start enabling this feature for users who are interested in testing the new lock types.
LakshSingla added a commit that referenced this pull request Oct 17, 2023
Patch adds an undocumented parameter taskLockType to MSQ so that we can start enabling this feature for users who are interested in testing the new lock types.

Co-authored-by: Karan Kumar <[email protected]>
CaseyPan pushed a commit to CaseyPan/druid that referenced this pull request Nov 17, 2023
Patch adds an undocumented parameter taskLockType to MSQ so that we can start enabling this feature for users who are interested in testing the new lock types.
riovic918data pushed a commit to riovic918data/druid that referenced this pull request Jun 12, 2026
Patch adds an undocumented parameter taskLockType to MSQ so that we can start enabling this feature for users who are interested in testing the new lock types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Batch Ingestion Area - Ingestion Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 Area - Querying

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants