本文整理了Java中io.atomix.copycat.protocol.QueryRequest.query
方法的一些代码示例,展示了QueryRequest.query
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QueryRequest.query
方法的具体详情如下:
包路径:io.atomix.copycat.protocol.QueryRequest
类名称:QueryRequest
方法名:query
[英]Returns the query.
[中]返回查询。
代码示例来源:origin: org.onosproject/onlab-thirdparty
@Override
protected CompletableFuture<QueryResponse> query(QueryRequest request) {
context.checkThread();
logRequest(request);
// If the query was submitted with RYW or monotonic read consistency, attempt to apply the query to the local state machine.
if (request.query().consistency() == Query.ConsistencyLevel.CAUSAL
|| request.query().consistency() == Query.ConsistencyLevel.SEQUENTIAL) {
// If this server has not yet applied entries up to the client's session ID, forward the
// query to the leader. This ensures that a follower does not tell the client its session
// doesn't exist if the follower hasn't had a chance to see the session's registration entry.
if (context.getStateMachine().getLastApplied() < request.session()) {
LOGGER.debug("{} - State out of sync, forwarding query to leader");
return queryForward(request);
}
// If the commit index is not in the log then we've fallen too far behind the leader to perform a local query.
// Forward the request to the leader.
if (context.getLog().lastIndex() < context.getCommitIndex()) {
LOGGER.debug("{} - State out of sync, forwarding query to leader");
return queryForward(request);
}
return queryLocal(request);
} else {
return queryForward(request);
}
}
代码示例来源:origin: atomix/copycat
@Override
public CompletableFuture<QueryResponse> query(final QueryRequest request) {
Query query = request.query();
final long timestamp = System.currentTimeMillis();
context.checkThread();
logRequest(request);
QueryEntry entry = context.getLog().create(QueryEntry.class)
.setIndex(request.index())
.setTerm(context.getTerm())
.setTimestamp(timestamp)
.setSession(request.session())
.setSequence(request.sequence())
.setQuery(query);
return query(entry).thenApply(this::logResponse);
}
代码示例来源:origin: io.atomix.copycat/copycat-server
@Override
public CompletableFuture<QueryResponse> query(final QueryRequest request) {
Query query = request.query();
final long timestamp = System.currentTimeMillis();
context.checkThread();
logRequest(request);
QueryEntry entry = context.getLog().create(QueryEntry.class)
.setIndex(request.index())
.setTerm(context.getTerm())
.setTimestamp(timestamp)
.setSession(request.session())
.setSequence(request.sequence())
.setQuery(query);
return query(entry).thenApply(this::logResponse);
}
代码示例来源:origin: org.onosproject/onlab-thirdparty
@Override
@SuppressWarnings("unchecked")
protected void complete(QueryResponse response) {
// If the query consistency level is CAUSAL, we can simply complete queries in sequential order.
if (request.query().consistency() == Query.ConsistencyLevel.CAUSAL) {
sequence(() -> {
state.setResponseIndex(response.index());
future.complete((T) response.result());
});
}
// If the query consistency level is strong, the query must be executed sequentially. In order to ensure responses
// are received in a sequential manner, we compare the response index number with the highest index for which
// we've received a response and resubmit queries with output resulting from stale (prior) versions.
else {
if (response.index() > 0 && response.index() < state.getResponseIndex()) {
retry();
} else {
sequence(() -> {
state.setResponseIndex(response.index());
future.complete((T) response.result());
});
}
}
}
代码示例来源:origin: atomix/copycat
if (request.query().consistency() == Query.ConsistencyLevel.SEQUENTIAL) {
.setSession(request.session())
.setSequence(request.sequence())
.setQuery(request.query());
代码示例来源:origin: io.atomix.copycat/copycat-server
if (request.query().consistency() == Query.ConsistencyLevel.SEQUENTIAL) {
.setSession(request.session())
.setSequence(request.sequence())
.setQuery(request.query());
代码示例来源:origin: org.onosproject/onlab-thirdparty
@Override
protected CompletableFuture<QueryResponse> query(final QueryRequest request) {
Query query = request.query();
final long timestamp = System.currentTimeMillis();
context.checkThread();
logRequest(request);
QueryEntry entry = context.getLog().create(QueryEntry.class)
.setIndex(request.index())
.setTerm(context.getTerm())
.setTimestamp(timestamp)
.setSession(request.session())
.setSequence(request.sequence())
.setQuery(query);
Query.ConsistencyLevel consistency = query.consistency();
if (consistency == null)
return submitQueryLinearizable(entry);
switch (consistency) {
case CAUSAL:
case SEQUENTIAL:
return submitQueryLocal(entry);
case BOUNDED_LINEARIZABLE:
return submitQueryBoundedLinearizable(entry);
case LINEARIZABLE:
return submitQueryLinearizable(entry);
default:
throw new IllegalStateException("unknown consistency level");
}
}
代码示例来源:origin: org.onosproject/onlab-thirdparty
.setSession(request.session())
.setSequence(request.sequence())
.setQuery(request.query());
if (request.query().consistency() == Query.ConsistencyLevel.CAUSAL) {
index = context.getStateMachine().getLastApplied();
} else {
内容来源于网络,如有侵权,请联系作者删除!