How to set up a priority for a query in MemSql - singlestore

Is there a way to set priorities for queries in Memsql? I know that for MySql there are High/ Low priority Options . Are they applicable for MemSql too?

There is no query priority setting in MemSQL currently. If you need to prioritize queries, you will have to do it client-side.

Related

Increase request timeout for CQL from NiFi

I am using QueryCassandra processor in NiFi to fetch data from Cassandra but my query is getting timedoutexception. I want to increase the request time out while running the CQL query from the processor. Is there a way to do that or I will have to write a custom processor?
Most probably you're getting an exception because you're performing query on non-partition key - in this case, the query is distributed to the all nodes, and requires to go through all available data, and this is very slow if you have big data set.
In Cassandra queries are fast only when you're performing them on (at least) partition key. If you need to search on non-partition column, then you need to re-model your tables to match your queries. I recommend to take DS220 course on DataStax Academy for better understanding how Cassandra works.
As #Alex ott said, it is not recommended to query on non partition key. If you still want to do so and increase the timeout for the query, just property Max Wait Time to whatever timeout you want.
EDIT:
tl;dr: Apache's timeout wrapper doesn't really let you use the timeout option.
Now that you mentioned that this is a DataStax exception and not java.util.concurrent.TimeoutException, I can tell you that I've looked into QueryCassandra processor's source code and it seems like Apache just wrapped the query function with a Future to achieve a timeout instead of using DataStax's built-in timeout option. This results in a default non-changeable timeout by the DataStax driver. It should be reported to Apache as a bug.

Why set Consistency to ALL before Truncate table

According to docs from datastax, it's good to use the cqlsh CONSISTENCY command to set the consistency level to ALL. I saw same recommendation from many other places. But why should we do that? Especially, in native protocol specification from apache-cassandra, it seems truncate query would ignore the consistency we set before.
The truncate command requires all nodes up and it will fail preemptively if anything is down regardless of consistency level. You are right that you don't need to do that.
Also CQL truncate no longer uses JMX at all (blurb at bottom), that was from thrift days before cql3 so it might be just old documentation that hasn't been updated.

how to set cassandra read and write consistency

I can not find the documentation for this. I know there is a consistency command in cqlsh, but there is no distinction between read and write consistency. How would I set different consistency levels for read and write?
Furthermore, there is a mention of a "default" consistency level. Where is that default set? and is it for read or write?
How would I set different consistency levels for read and write?
If you just want to change consistency level for your current session, use CONSISTENCY.
If you want to change the consistency level programamtically, use the cassandra driver for your client language.
Since the Consistency Level can be set per-statement, you can either set it on every statement, or use PreparedStatements. If you're using the Java driver, you can configure a global Consistency level for BOTH reads and writes (but not only reads and only writes).
Where is that default [consistency level] set? and is it for read or write?
If you want to set up a different consistency level for reads than writes, you'll have to do it on a per-statement basis. Use QueryOptions().setConsistencyLevel to set a global consistency level (for the Java driver). It is for BOTH reads and writes.
To set the consistency level for your current session, use the CONSISTENCY command
from the cassandra shell (CQLSH).
For example:
Set CONSISTENCY to force the majority of the nodes to respond:
CONSISTENCY QUORUM
To see your current consistency level, just run CONSISTENCY; from the shell:
ty#cqlsh> consistency;
Current consistency level is ONE.
For programming client applications, set the consistency level using an appropriate driver.
To set a per-insert consistency level using the Java driver, for example, call QueryBuilder.insertInto with setConsistencyLevel.
For example:
PreparedStatement pstmt = session.prepare(
"INSERT INTO product (sku, description) VALUES (?, ?)");
pstmt.setConsistencyLevel(ConsistencyLevel.QUORUM);
To set a global consistency level for reads AND writes using the Java driver, do something like:
QueryOptions qo = new QueryOptions().setConsistencyLevel(ConsistencyLevel.ALL);
Since the Java driver only executes CQL statements, which can be either reads or writes to Cassandra, it is not possible to globally configure the Consistency Level for only reads or only writes. To do so, since the Consistency Level can be set per-statement, you can either set it on every statement, or use PreparedStatements. More info in the Queries and Results document.
More resources on read/write consistency levels
How consistency level is configured
The different consistency levels are also explained here ^
Cassandra's Java Driver documentation
See the "Consistency levels" section in configuring consistency with the Java Driver
Other resources on consistency:
You may also want to look into your replica placement strategy and replication factor (which are other forms of consistency).
I included links below for good measure:
Background on data replication in Cassandra
How to update replica strategy and replication factor using CREATE KEYSPACE
How consistency affects performance
By default, the Consistency Level is ONE for all R/W Operations.
Setting CL is done on a per query (read or upsert) basis by adding the CONSISTENCY XXXX syntax on the query as seen here:
https://cassandra.apache.org/doc/latest/cql/dml.html#insert
and
https://cassandra.apache.org/doc/4.0/tools/cqlsh.html
The consistency level is not set anymore with a CQL USING clause. See CASSANDRA-4734 for an explanation.
Instead, with CQLSH, you should use the CONSISTENCY command: see here for details.
Note that the default consistency level changed in all DataStax drivers from ONE to LOCAL_ONE: see the python driver documentation for details - however, in spite of using the python driver behind the scenes, CQLSH still has a default consistency of ONE).
The consisenty level is no longer set using PreparedStatement. That API was changed. Now you have to use BatchStatementBuilder.
Here is sample code that works.
BatchStatementBuilder builder = BatchStatement.builder(DefaultBatchType.UNLOGGED);
builder.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);
PreparedStatement preparedStatement = session.prepare("INSERT INTO \"ScottKeySpace16\".\"Movie\" (title, year, plot) values (:k0, :k1, :k2)");
builder.addStatement(preparedStatement.boundStatementBuilder()
.setString("k0", "Movie44")
.setInt("k1", 2022)
.setString("k2", "This is a very funny movie")
.build());
BatchStatement batchStatement = builder.build();
session.execute(batchStatement);
Default consistency is set in cassandra.conf file . It is for read and write .
You can set consistency per query basis adding USING option in query .

How do I set the consistency level of an individual CQL query in CQL3?

In the earlier beta releases of CQL, there was a command I could use to set the read / write consistency of an individual CQL operation. It looked like this:
SELECT * FROM users WHERE state='TX' USING CONSISTENCY QUORUM;
I use CQL3 regularly and have a use-case where I need to be able to perform a read with a higher consistency level than the rest of our application.
I looked through the CQL3 reference and didn't find any mention of any CQL syntax that allows me to change the consistency settings on a per-query basis, unless I'm using cqlsh (not useful for application development.)
How am I supposed to tune the consistency on a per-request basis using CQL3?
First set the consistency by running command:
CONSISTENCY QUORUM;
and then then run you query:
SELECT * FROM users WHERE state='TX'
At any point you can check the consistency using:
CONSISTENCY;
Aaron, the Consistency Level is not needed to be set on the protocol level - for the reasons explained here: https://issues.apache.org/jira/browse/CASSANDRA-4734
The default consistency level for any query is "ONE". However, one can set the consistency level on query basis as below.
Based on the Replication factor, the location of the partition (nodes list) can be found as below.
nodetool getendpoints Keyspace-name table-name partition-key value
$ nodetool getendpoints stresstest status bill
10.134.38.15
10.134.38.24
10.134.38.26

The query processor could not start the necessary thread resources

I am getting this error in SQL Server especially when there are many records inserted at the same time:
The query processor could not start the necessary thread resources for parallel query execution
I tried Google search the problem to upgrade my SQL performance so that can avoid this error, and plenty of it suggests to set maxdrop on the query or the max degree of parallelism on SQL Server.
But how can I know how many the value of the maxdrop or max degree of parallelism I should set to?
And how do I check the maximum value of max degree of parallelism of my server can run?
If I change the max degree of parallelism of the server, means all the stored procedures will run following that setting, so will it affect other performance? Or do I just need to set the maxdrop on certain stored procedures?
Right click the server then click FACETS then choose/select SERVER PERFORMANCE

Resources