-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[CASSANDRA-21471][trunk] Expose immediately-executed tasks in the queries virtual table #4902
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.cassandra.concurrent; | ||
|
|
||
| public interface ImmediateTaskHolder | ||
| { | ||
| void setImmediateTask(Runnable currentTask); | ||
|
|
||
| class NoOp implements ImmediateTaskHolder | ||
| { | ||
|
|
||
| @Override | ||
| public void setImmediateTask(Runnable currentTask) | ||
| { | ||
| // nothing to do | ||
| } | ||
| } | ||
|
|
||
| NoOp NO_OP = new NoOp(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,6 +211,8 @@ public void maybeExecuteImmediately(Runnable task) | |
| } | ||
| else | ||
| { | ||
| ImmediateTaskHolder taskHolder = getNestedCurrentTaskHolder(); | ||
| taskHolder.setImmediateTask(task); | ||
| try | ||
| { | ||
| task.run(); | ||
|
|
@@ -222,10 +224,22 @@ public void maybeExecuteImmediately(Runnable task) | |
| // in this case in particular we are not processing the rest of the queue anyway, and so | ||
| // the work permit may go wasted if we don't immediately attempt to spawn another worker | ||
| maybeSchedule(); | ||
| // nesting with depth > 1 is not supported | ||
|
Contributor
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. Is there a cheap way to assert this is the case? |
||
| taskHolder.setImmediateTask(null); | ||
|
Contributor
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 we move this to the start of the |
||
| } | ||
| } | ||
| } | ||
|
|
||
| private static ImmediateTaskHolder getNestedCurrentTaskHolder() | ||
| { | ||
| Thread currentThread = Thread.currentThread(); | ||
| if (currentThread instanceof CassandraThread) | ||
| { | ||
| return ((CassandraThread) currentThread).getImmediateTaskHolder(); | ||
| } | ||
| return ImmediateTaskHolder.NO_OP; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute(Runnable run) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,7 +123,8 @@ void workerEnded(SEPWorker worker) | |
|
|
||
| public Stream<? extends DebuggableTaskRunner> workers() | ||
| { | ||
| return allWorkers.stream(); | ||
| return Stream.concat(allWorkers.stream(), | ||
| allWorkers.stream().map(SEPWorker::immediateRunner)); | ||
|
Contributor
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. From CC shallow review:
|
||
| } | ||
|
|
||
| void maybeStartSpinningWorker() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,13 +121,13 @@ private static void assertReadsAndWritesVisible() | |
| String task = row.get("task").toString(); | ||
|
|
||
| boolean localReaderThread = threadId.contains("Read") || threadId.contains("SharedPool-Worker"); | ||
| readVisible |= localReaderThread && task.contains("SELECT"); | ||
| readVisible |= localReaderThread && task.contains("SELECT") && !task.contains("QUERY"); | ||
|
Contributor
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. From CC shallow review:
|
||
| boolean coordReaderThread = threadId.contains("Native-Transport-Requests") || threadId.contains("SharedPool-Worker"); | ||
| coordinatorReadVisible |= coordReaderThread && task.contains("SELECT"); | ||
| coordinatorReadVisible |= coordReaderThread && task.contains("SELECT") && task.contains("QUERY"); | ||
| boolean localWriterThread = threadId.contains("Mutation") || threadId.contains("SharedPool-Worker"); | ||
| writeVisible |= localWriterThread && task.contains("Mutation"); | ||
| writeVisible |= localWriterThread && task.contains("Mutation") && !task.contains("QUERY"); | ||
| boolean coordWriterThread = threadId.contains("Native-Transport-Requests") || threadId.contains("SharedPool-Worker"); | ||
| coordinatorWriteVisible |= coordWriterThread && task.contains("INSERT"); | ||
| coordinatorWriteVisible |= coordWriterThread && task.contains("INSERT") && task.contains("QUERY"); | ||
| } | ||
|
|
||
| assertTrue(readVisible); | ||
|
|
@@ -169,9 +169,9 @@ private static void assertCasVisible() | |
| String task = row.get("task").toString(); | ||
|
|
||
| boolean localReaderThread = threadId.contains("Read") || threadId.contains("SharedPool-Worker"); | ||
| readVisible |= localReaderThread && task.contains("SELECT"); | ||
| readVisible |= localReaderThread && task.contains("SELECT") && !task.contains("QUERY"); | ||
| boolean coordUpdateThread = threadId.contains("Native-Transport-Requests") || threadId.contains("SharedPool-Worker"); | ||
| coordinatorUpdateVisible |= coordUpdateThread && task.contains("UPDATE"); | ||
| coordinatorUpdateVisible |= coordUpdateThread && task.contains("UPDATE") && task.contains("QUERY"); | ||
| } | ||
|
|
||
| assertTrue(readVisible); | ||
|
|
||
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.
nit: Can we just set
NO_OPdirectly in the constructors above (and make passingnullillegal) so we don't have to do this check?