You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2021/11/19 16:50:42 UTC
[iotdb] branch master updated: [IOTDB-2036] RestApiServiceImpl accesses to BasicServiceProvider (#4434)
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new d9d8733 [IOTDB-2036] RestApiServiceImpl accesses to BasicServiceProvider (#4434)
d9d8733 is described below
commit d9d8733f17878cd07e4510a7f9b3af92049863c3
Author: Xieqijun <44...@users.noreply.github.com>
AuthorDate: Sat Nov 20 00:49:59 2021 +0800
[IOTDB-2036] RestApiServiceImpl accesses to BasicServiceProvider (#4434)
---
.../iotdb/cluster/server/ClusterTSServiceImpl.java | 2 +-
.../org/apache/iotdb/db/conf/IoTDBConstant.java | 2 +
.../db/rest/handler/AuthorizationHandler.java | 20 +++++---
.../iotdb/db/rest/impl/RestApiServiceImpl.java | 59 ++++++++++++----------
.../db/service/basic/BasicServiceProvider.java | 8 +--
5 files changed, 51 insertions(+), 40 deletions(-)
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/server/ClusterTSServiceImpl.java b/cluster/src/main/java/org/apache/iotdb/cluster/server/ClusterTSServiceImpl.java
index ada94cf..57aa401 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/server/ClusterTSServiceImpl.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/server/ClusterTSServiceImpl.java
@@ -89,7 +89,7 @@ public class ClusterTSServiceImpl extends TSServiceImpl {
* @return a RemoteQueryContext using queryId
*/
@Override
- protected QueryContext genQueryContext(
+ public QueryContext genQueryContext(
long queryId, boolean debug, long startTime, String statement, long timeout) {
RemoteQueryContext context =
new RemoteQueryContext(queryId, debug, startTime, statement, timeout);
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
index 362a3ee..afc6f94 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
@@ -159,6 +159,8 @@ public class IoTDBConstant {
// thrift
public static final int LEFT_SIZE_IN_REQUEST = 4 * 1024 * 1024;
+ public static final int DEFAULT_FETCH_SIZE = 5000;
+ public static final int DEFAULT_CONNECTION_TIMEOUT_MS = 0;
// change tsFile name
public static final int FILE_NAME_SUFFIX_INDEX = 0;
diff --git a/server/src/main/java/org/apache/iotdb/db/rest/handler/AuthorizationHandler.java b/server/src/main/java/org/apache/iotdb/db/rest/handler/AuthorizationHandler.java
index 4404a0b..2ab54b8 100644
--- a/server/src/main/java/org/apache/iotdb/db/rest/handler/AuthorizationHandler.java
+++ b/server/src/main/java/org/apache/iotdb/db/rest/handler/AuthorizationHandler.java
@@ -18,25 +18,29 @@
package org.apache.iotdb.db.rest.handler;
import org.apache.iotdb.db.auth.AuthException;
-import org.apache.iotdb.db.auth.AuthorityChecker;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
import org.apache.iotdb.db.rest.model.ExecutionStatus;
+import org.apache.iotdb.db.service.basic.BasicServiceProvider;
import org.apache.iotdb.rpc.TSStatusCode;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
public class AuthorizationHandler {
- private AuthorizationHandler() {}
+ private final BasicServiceProvider basicServiceProvider;
- public static Response checkAuthority(
- SecurityContext securityContext, PhysicalPlan physicalPlan) {
+ public AuthorizationHandler(BasicServiceProvider basicServiceProvider)
+ throws QueryProcessException {
+ this.basicServiceProvider = basicServiceProvider;
+ }
+
+ public Response checkAuthority(SecurityContext securityContext, PhysicalPlan physicalPlan) {
try {
- if (!AuthorityChecker.check(
- securityContext.getUserPrincipal().getName(),
+ if (!this.basicServiceProvider.checkAuthorization(
physicalPlan.getAuthPaths(),
- physicalPlan.getOperatorType(),
- null)) {
+ physicalPlan,
+ securityContext.getUserPrincipal().getName())) {
return Response.ok()
.entity(
new ExecutionStatus()
diff --git a/server/src/main/java/org/apache/iotdb/db/rest/impl/RestApiServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/rest/impl/RestApiServiceImpl.java
index c5c5582..16a1a30 100644
--- a/server/src/main/java/org/apache/iotdb/db/rest/impl/RestApiServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/rest/impl/RestApiServiceImpl.java
@@ -17,18 +17,14 @@
package org.apache.iotdb.db.rest.impl;
-import org.apache.iotdb.db.conf.IoTDBDescriptor;
-import org.apache.iotdb.db.exception.StorageEngineException;
-import org.apache.iotdb.db.exception.metadata.StorageGroupNotSetException;
+import org.apache.iotdb.db.conf.IoTDBConstant;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.qp.Planner;
-import org.apache.iotdb.db.qp.executor.IPlanExecutor;
-import org.apache.iotdb.db.qp.executor.PlanExecutor;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
import org.apache.iotdb.db.qp.physical.crud.InsertTabletPlan;
import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
-import org.apache.iotdb.db.qp.physical.sys.FlushPlan;
-import org.apache.iotdb.db.qp.physical.sys.SetSystemModePlan;
+import org.apache.iotdb.db.query.context.QueryContext;
+import org.apache.iotdb.db.query.control.QueryResourceManager;
import org.apache.iotdb.db.rest.RestApiService;
import org.apache.iotdb.db.rest.handler.AuthorizationHandler;
import org.apache.iotdb.db.rest.handler.ExceptionHandler;
@@ -38,31 +34,40 @@ import org.apache.iotdb.db.rest.handler.RequestValidationHandler;
import org.apache.iotdb.db.rest.model.ExecutionStatus;
import org.apache.iotdb.db.rest.model.InsertTabletRequest;
import org.apache.iotdb.db.rest.model.SQL;
+import org.apache.iotdb.db.service.basic.BasicServiceProvider;
import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
public class RestApiServiceImpl extends RestApiService {
- protected final IPlanExecutor executor = new PlanExecutor(); // todo cluster
protected final Planner planner = new Planner();
+ // TODO cluster
+ public final BasicServiceProvider basicServiceProvider = new BasicServiceProvider();
+ private final AuthorizationHandler authorizationHandler;
+
public RestApiServiceImpl() throws QueryProcessException {}
+ {
+ this.authorizationHandler = new AuthorizationHandler(basicServiceProvider);
+ }
+
@Override
public Response executeNonQueryStatement(SQL sql, SecurityContext securityContext) {
try {
RequestValidationHandler.validateSQL(sql);
PhysicalPlan physicalPlan = planner.parseSQLToPhysicalPlan(sql.getSql());
- Response response = AuthorizationHandler.checkAuthority(securityContext, physicalPlan);
+ Response response = authorizationHandler.checkAuthority(securityContext, physicalPlan);
if (response != null) {
return response;
}
return Response.ok()
.entity(
- executor.processNonQuery(physicalPlan)
+ basicServiceProvider.executeNonQuery(physicalPlan)
? new ExecutionStatus()
.code(TSStatusCode.SUCCESS_STATUS.getStatusCode())
.message(TSStatusCode.SUCCESS_STATUS.name())
@@ -90,13 +95,24 @@ public class RestApiServiceImpl extends RestApiService {
.build();
}
- Response response = AuthorizationHandler.checkAuthority(securityContext, physicalPlan);
+ Response response = authorizationHandler.checkAuthority(securityContext, physicalPlan);
if (response != null) {
return response;
}
- return QueryDataSetHandler.fillDateSet(
- QueryDataSetHandler.constructQueryDataSet(executor, physicalPlan),
- (QueryPlan) physicalPlan);
+ final long queryId = QueryResourceManager.getInstance().assignQueryId(true);
+ QueryContext queryContext =
+ basicServiceProvider.genQueryContext(
+ queryId,
+ physicalPlan.isDebug(),
+ System.currentTimeMillis(),
+ sql.getSql(),
+ IoTDBConstant.DEFAULT_CONNECTION_TIMEOUT_MS);
+ QueryDataSet queryDataSet =
+ basicServiceProvider.createQueryDataSet(
+ queryContext, physicalPlan, IoTDBConstant.DEFAULT_FETCH_SIZE);
+ response = QueryDataSetHandler.fillDateSet(queryDataSet, (QueryPlan) physicalPlan);
+ BasicServiceProvider.sessionManager.releaseSessionResource(queryId);
+ return response;
} catch (Exception e) {
return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
}
@@ -111,14 +127,14 @@ public class RestApiServiceImpl extends RestApiService {
InsertTabletPlan insertTabletPlan =
PhysicalPlanConstructionHandler.constructInsertTabletPlan(insertTabletRequest);
- Response response = AuthorizationHandler.checkAuthority(securityContext, insertTabletPlan);
+ Response response = authorizationHandler.checkAuthority(securityContext, insertTabletPlan);
if (response != null) {
return response;
}
return Response.ok()
.entity(
- executeNonQuery(insertTabletPlan)
+ basicServiceProvider.executeNonQuery(insertTabletPlan)
? new ExecutionStatus()
.code(TSStatusCode.SUCCESS_STATUS.getStatusCode())
.message(TSStatusCode.SUCCESS_STATUS.name())
@@ -130,15 +146,4 @@ public class RestApiServiceImpl extends RestApiService {
return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
}
}
-
- private boolean executeNonQuery(PhysicalPlan plan)
- throws QueryProcessException, StorageGroupNotSetException, StorageEngineException {
- if (!(plan instanceof SetSystemModePlan)
- && !(plan instanceof FlushPlan)
- && IoTDBDescriptor.getInstance().getConfig().isReadOnly()) {
- throw new QueryProcessException(
- "Current system mode is read-only, does not support non-query operation");
- }
- return executor.processNonQuery(plan);
- }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/service/basic/BasicServiceProvider.java b/server/src/main/java/org/apache/iotdb/db/service/basic/BasicServiceProvider.java
index 518a9b2..693e99e 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/basic/BasicServiceProvider.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/basic/BasicServiceProvider.java
@@ -102,7 +102,7 @@ public class BasicServiceProvider {
return isLoggedIn;
}
- protected boolean checkAuthorization(
+ public boolean checkAuthorization(
List<? extends PartialPath> paths, PhysicalPlan plan, String username) throws AuthException {
String targetUser = null;
if (plan instanceof AuthorPlan) {
@@ -228,13 +228,13 @@ public class BasicServiceProvider {
}
}
- protected QueryContext genQueryContext(
+ public QueryContext genQueryContext(
long queryId, boolean debug, long startTime, String statement, long timeout) {
return new QueryContext(queryId, debug, startTime, statement, timeout);
}
/** create QueryDataSet and buffer it for fetchResults */
- protected QueryDataSet createQueryDataSet(
+ public QueryDataSet createQueryDataSet(
QueryContext context, PhysicalPlan physicalPlan, int fetchSize)
throws QueryProcessException, QueryFilterOptimizationException, StorageEngineException,
IOException, MetadataException, SQLException, TException, InterruptedException {
@@ -245,7 +245,7 @@ public class BasicServiceProvider {
return queryDataSet;
}
- protected boolean executeNonQuery(PhysicalPlan plan)
+ public boolean executeNonQuery(PhysicalPlan plan)
throws QueryProcessException, StorageGroupNotSetException, StorageEngineException {
plan.checkIntegrity();
if (!(plan instanceof SetSystemModePlan)