use of org.apache.cassandra.transport.messages.ResultMessage in project cassandra by apache.
the class Coordinator method executeInternal.
private SimpleQueryResult executeInternal(String query, ConsistencyLevel consistencyLevelOrigin, Object[] boundValues) {
ClientState clientState = makeFakeClientState();
CQLStatement prepared = QueryProcessor.getStatement(query, clientState);
List<ByteBuffer> boundBBValues = new ArrayList<>();
ConsistencyLevel consistencyLevel = ConsistencyLevel.valueOf(consistencyLevelOrigin.name());
for (Object boundValue : boundValues) boundBBValues.add(ByteBufferUtil.objectToBytes(boundValue));
prepared.validate(QueryState.forInternalCalls().getClientState());
// Start capturing warnings on this thread. Note that this will implicitly clear out any previous
// warnings as it sets a new State instance on the ThreadLocal.
ClientWarn.instance.captureWarnings();
CoordinatorWarnings.init();
try {
ResultMessage res = prepared.execute(QueryState.forInternalCalls(), QueryOptions.create(toCassandraCL(consistencyLevel), boundBBValues, false, Integer.MAX_VALUE, null, null, ProtocolVersion.CURRENT, null), nanoTime());
// Collect warnings reported during the query.
CoordinatorWarnings.done();
if (res != null)
res.setWarnings(ClientWarn.instance.getWarnings());
return RowUtil.toQueryResult(res);
} catch (Exception | Error e) {
CoordinatorWarnings.done();
throw e;
} finally {
CoordinatorWarnings.reset();
ClientWarn.instance.resetWarnings();
}
}
use of org.apache.cassandra.transport.messages.ResultMessage in project cassandra by apache.
the class Instance method unsafeExecuteInternalWithResult.
public static SimpleQueryResult unsafeExecuteInternalWithResult(String query, Object... args) {
ClientWarn.instance.captureWarnings();
CoordinatorWarnings.init();
try {
QueryHandler.Prepared prepared = QueryProcessor.prepareInternal(query);
ResultMessage result = prepared.statement.executeLocally(QueryProcessor.internalQueryState(), QueryProcessor.makeInternalOptions(prepared.statement, args));
CoordinatorWarnings.done();
if (result != null)
result.setWarnings(ClientWarn.instance.getWarnings());
return RowUtil.toQueryResult(result);
} catch (Exception | Error e) {
CoordinatorWarnings.done();
throw e;
} finally {
CoordinatorWarnings.reset();
ClientWarn.instance.resetWarnings();
}
}
use of org.apache.cassandra.transport.messages.ResultMessage in project cassandra by apache.
the class Query method call.
public Object[][] call() {
ConsistencyLevel commitConsistency = toCassandraCL(commitConsistencyOrigin);
ConsistencyLevel serialConsistency = serialConsistencyOrigin == null ? null : toCassandraCL(serialConsistencyOrigin);
ClientState clientState = Coordinator.makeFakeClientState();
CQLStatement prepared = QueryProcessor.getStatement(query, clientState);
List<ByteBuffer> boundBBValues = new ArrayList<>();
for (Object boundValue : boundValues) boundBBValues.add(ByteBufferUtil.objectToBytes(boundValue));
prepared.validate(QueryState.forInternalCalls().getClientState());
// Start capturing warnings on this thread. Note that this will implicitly clear out any previous
// warnings as it sets a new State instance on the ThreadLocal.
ClientWarn.instance.captureWarnings();
ResultMessage res = prepared.execute(QueryState.forInternalCalls(), QueryOptions.create(commitConsistency, boundBBValues, false, Integer.MAX_VALUE, null, serialConsistency, ProtocolVersion.V4, null, timestamp, FBUtilities.nowInSeconds()), nanoTime());
// Collect warnings reported during the query.
if (res != null)
res.setWarnings(ClientWarn.instance.getWarnings());
return RowUtil.toQueryResult(res).toObjectArrays();
}
use of org.apache.cassandra.transport.messages.ResultMessage in project cassandra by apache.
the class AlterSchemaStatement method execute.
public ResultMessage execute(QueryState state, boolean locally) {
if (SchemaConstants.isLocalSystemKeyspace(keyspaceName))
throw ire("System keyspace '%s' is not user-modifiable", keyspaceName);
KeyspaceMetadata keyspace = Schema.instance.getKeyspaceMetadata(keyspaceName);
if (null != keyspace && keyspace.isVirtual())
throw ire("Virtual keyspace '%s' is not user-modifiable", keyspaceName);
validateKeyspaceName();
KeyspacesDiff diff = MigrationManager.announce(this, locally);
clientWarnings(diff).forEach(ClientWarn.instance::warn);
if (diff.isEmpty())
return new ResultMessage.Void();
/*
* When a schema alteration results in a new db object being created, we grant permissions on the new
* object to the user performing the request if:
* - the user is not anonymous
* - the configured IAuthorizer supports granting of permissions (not all do, AllowAllAuthorizer doesn't and
* custom external implementations may not)
*/
AuthenticatedUser user = state.getClientState().getUser();
if (null != user && !user.isAnonymous())
createdResources(diff).forEach(r -> grantPermissionsOnResource(r, user));
return new ResultMessage.SchemaChange(schemaChangeEvent(diff));
}
use of org.apache.cassandra.transport.messages.ResultMessage in project cassandra by apache.
the class DescribeStatement method executeLocally.
@Override
public ResultMessage executeLocally(QueryState state, QueryOptions options) {
Keyspaces keyspaces = Schema.instance.snapshot();
UUID schemaVersion = Schema.instance.getVersion();
keyspaces = Keyspaces.builder().add(keyspaces).add(VirtualKeyspaceRegistry.instance.virtualKeyspacesMetadata()).build();
PagingState pagingState = options.getPagingState();
// The paging implemented here uses some arbitray row number as the partition-key for paging,
// which is used to skip/limit the result from the Java Stream. This works good enough for
// reasonably sized schemas. Even a 'DESCRIBE SCHEMA' for an abnormally schema with 10000 tables
// completes within a few seconds. This seems good enough for now. Once Cassandra actually supports
// more than a few hundred tables, the implementation here should be reconsidered.
//
// Paging is only supported on row-level.
//
// The "partition key" in the paging-state contains a serialized object:
// (short) version, currently 0x0001
// (long) row offset
// (vint bytes) serialized schema hash (currently the result of Keyspaces.hashCode())
//
long offset = getOffset(pagingState, schemaVersion);
int pageSize = options.getPageSize();
Stream<? extends T> stream = describe(state.getClientState(), keyspaces);
if (offset > 0L)
stream = stream.skip(offset);
if (pageSize > 0)
stream = stream.limit(pageSize);
List<List<ByteBuffer>> rows = stream.map(e -> toRow(e, includeInternalDetails)).collect(Collectors.toList());
ResultSet.ResultMetadata resultMetadata = new ResultSet.ResultMetadata(metadata(state.getClientState()));
ResultSet result = new ResultSet(resultMetadata, rows);
if (pageSize > 0 && rows.size() == pageSize) {
result.metadata.setHasMorePages(getPagingState(offset + pageSize, schemaVersion));
}
return new ResultMessage.Rows(result);
}
Aggregations