Skip to content

Commit

Permalink
fix missing cluster name when get info via http (#33)
Browse files Browse the repository at this point in the history
* modify thirdparty/build-thirdparty.sh to fix compilation bug of thrift. (#10)
update pre-compile binaries.

* fix export LD_LIBRARY_PATH in build-thirdparty.sh

* fix export LD_LIBRARY_PATH in build-thirdparty.sh

* fix missing cluster name bug when get load job info via http.
fix compilation bugs in fe unit test
  • Loading branch information
morningman authored and imay committed Aug 19, 2017
1 parent fff8e6a commit 71f06ae
Show file tree
Hide file tree
Showing 30 changed files with 546 additions and 459 deletions.
20 changes: 11 additions & 9 deletions fe/src/com/baidu/palo/clone/CloneChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.baidu.palo.catalog.Catalog;
import com.baidu.palo.catalog.DataProperty;
import com.baidu.palo.catalog.Database;
import com.baidu.palo.catalog.Database.DbState;
import com.baidu.palo.catalog.MaterializedIndex;
import com.baidu.palo.catalog.MaterializedIndex.IndexState;
import com.baidu.palo.catalog.OlapTable;
Expand All @@ -42,7 +43,6 @@
import com.baidu.palo.catalog.Table;
import com.baidu.palo.catalog.Table.TableType;
import com.baidu.palo.catalog.Tablet;
import com.baidu.palo.catalog.Database.DbState;
import com.baidu.palo.clone.CloneJob.JobPriority;
import com.baidu.palo.clone.CloneJob.JobState;
import com.baidu.palo.clone.CloneJob.JobType;
Expand Down Expand Up @@ -238,6 +238,11 @@ private void checkTablets() {
List<String> dbNames = catalog.getDbNames();
for (String name : dbNames) {
Database db = catalog.getDb(name);
if (db == null) {
LOG.warn("db does not exist. name: {}", name);
continue;
}

final String clusterName = db.getClusterName();

if (Strings.isNullOrEmpty(clusterName)) {
Expand All @@ -252,16 +257,13 @@ private void checkTablets() {
LOG.warn("init backend infos error");
continue;
}
final Map<Level, Set<Long>> cluserCapacityLevelToBackendIds = initBackendCapacityInfos(clusterBackendInfos);
if (cluserCapacityLevelToBackendIds == null || cluserCapacityLevelToBackendIds.isEmpty()) {
final Map<Level, Set<Long>> clusterCapacityLevelToBackendIds = initBackendCapacityInfos(
clusterBackendInfos);
if (clusterCapacityLevelToBackendIds == null || clusterCapacityLevelToBackendIds.isEmpty()) {
LOG.warn("init backend capacity infos error");
continue;
}

if (db == null) {
LOG.warn("db does not exist. name: {}", db.getName());
continue;
}
long dbId = db.getId();

Set<String> tableNames = db.getTableNamesWithLock();
Expand Down Expand Up @@ -395,10 +397,10 @@ private void checkTablets() {
&& !clusterDistributionLevelToBackendIds.isEmpty()) {
// supplement
checkSupplement(cloneTabletMap, clusterDistributionLevelToBackendIds,
cluserCapacityLevelToBackendIds, clusterBackendInfos);
clusterCapacityLevelToBackendIds, clusterBackendInfos);
// migration
checkMigration(backendToTablets, clusterDistributionLevelToBackendIds,
cluserCapacityLevelToBackendIds, clusterBackendInfos);
clusterCapacityLevelToBackendIds, clusterBackendInfos);
} else {
LOG.warn("init backend distribution infos error");
}
Expand Down
27 changes: 13 additions & 14 deletions fe/src/com/baidu/palo/http/BaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected void writeCookies(BaseResponse response, HttpResponse responseObj) {
}

public static class AuthorizationInfo {
public String user;
public String fullUserName;
public String password;
public String cluster;
}
Expand All @@ -246,13 +246,14 @@ public boolean parseAuth(BaseRequest request, AuthorizationInfo authInfo) {
// Note that password may contain colon, so can not simply use a
// colon to split.
int index = authString.indexOf(":");
authInfo.user = authString.substring(0, index);
final String[] elements = authInfo.user.split("@");
authInfo.fullUserName = authString.substring(0, index);
final String[] elements = authInfo.fullUserName.split("@");
if (elements != null && elements.length < 2) {
authInfo.user = ClusterNamespace.getUserFullName(SystemInfoService.DEFAULT_CLUSTER, authInfo.user);
authInfo.fullUserName = ClusterNamespace.getUserFullName(SystemInfoService.DEFAULT_CLUSTER,
authInfo.fullUserName);
authInfo.cluster = SystemInfoService.DEFAULT_CLUSTER;
} else if (elements != null && elements.length == 2) {
authInfo.user = ClusterNamespace.getUserFullName(elements[1], elements[0]);
authInfo.fullUserName = ClusterNamespace.getUserFullName(elements[1], elements[0]);
authInfo.cluster = elements[1];
}
authInfo.password = authString.substring(index + 1);
Expand All @@ -272,10 +273,10 @@ private AuthorizationInfo checkAndGetUser(BaseRequest request) throws DdlExcepti
if (!parseAuth(request, authInfo)) {
throw new UnauthorizedException("Need auth information.");
}
byte[] hashedPasswd = catalog.getUserMgr().getPassword(authInfo.user);
byte[] hashedPasswd = catalog.getUserMgr().getPassword(authInfo.fullUserName);
if (hashedPasswd == null) {
// No such user
throw new DdlException("No such user(" + authInfo.user + ")");
throw new DdlException("No such user(" + authInfo.fullUserName + ")");
}
if (!MysqlPassword.checkPlainPass(hashedPasswd, authInfo.password)) {
throw new DdlException("Password error");
Expand All @@ -285,21 +286,19 @@ private AuthorizationInfo checkAndGetUser(BaseRequest request) throws DdlExcepti

protected void checkAdmin(BaseRequest request) throws DdlException {
final AuthorizationInfo authInfo = checkAndGetUser(request);
if (!catalog.getUserMgr().isAdmin(authInfo.user)) {
if (!catalog.getUserMgr().isAdmin(authInfo.fullUserName)) {
throw new DdlException("Administrator needed");
}
}

protected void checkReadPriv(BaseRequest request, String db) throws DdlException {
final AuthorizationInfo authInfo = checkAndGetUser(request);
if (!catalog.getUserMgr().checkAccess(authInfo.user, db, AccessPrivilege.READ_ONLY)) {
protected void checkReadPriv(String fullUserName, String fullDbName) throws DdlException {
if (!catalog.getUserMgr().checkAccess(fullUserName, fullDbName, AccessPrivilege.READ_ONLY)) {
throw new DdlException("Read Privilege needed");
}
}

protected void checkWritePriv(BaseRequest request, String db) throws DdlException {
final AuthorizationInfo authInfo = checkAndGetUser(request);
if (!catalog.getUserMgr().checkAccess(authInfo.user, db, AccessPrivilege.READ_WRITE)) {
protected void checkWritePriv(String fullUserName, String fullDbName) throws DdlException {
if (!catalog.getUserMgr().checkAccess(fullUserName, fullDbName, AccessPrivilege.READ_WRITE)) {
throw new DdlException("Write Privilege needed");
}
}
Expand Down
18 changes: 12 additions & 6 deletions fe/src/com/baidu/palo/http/rest/GetLoadInfoAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

package com.baidu.palo.http.rest;

import com.baidu.palo.cluster.ClusterNamespace;
import com.baidu.palo.common.DdlException;
import com.baidu.palo.http.ActionController;
import com.baidu.palo.http.BaseRequest;
import com.baidu.palo.http.BaseResponse;
import com.baidu.palo.http.IllegalArgException;
import com.baidu.palo.load.Load;

import com.google.common.base.Strings;

import io.netty.handler.codec.http.HttpMethod;
Expand All @@ -35,24 +35,30 @@ public GetLoadInfoAction(ActionController controller) {
super(controller);
}

public static void registerAction (ActionController controller)
public static void registerAction(ActionController controller)
throws IllegalArgException {
GetLoadInfoAction action = new GetLoadInfoAction(controller);
controller.registerHandler(HttpMethod.GET, "/api/{db}/_load_info", action);
}

@Override
public void execute(BaseRequest request, BaseResponse response) throws DdlException {
Load.JobInfo info = new Load.JobInfo(
request.getSingleParameter(DB_KEY),
request.getSingleParameter(LABEL_KEY));
AuthorizationInfo authInfo = getAuthorizationInfo(request);
Load.JobInfo info = new Load.JobInfo(request.getSingleParameter(DB_KEY), request.getSingleParameter(LABEL_KEY),
authInfo.cluster);
if (Strings.isNullOrEmpty(info.dbName)) {
throw new DdlException("No database selected");
}
if (Strings.isNullOrEmpty(info.label)) {
throw new DdlException("No label selected");
}
checkReadPriv(request, info.dbName);
if (Strings.isNullOrEmpty(info.clusterName)) {
throw new DdlException("No cluster name selected");
}

String fullDbName = ClusterNamespace.getDbFullName(info.clusterName, info.dbName);
checkReadPriv(authInfo.fullUserName, fullDbName);

if (redirectToMaster(request, response)) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions fe/src/com/baidu/palo/http/rest/LoadAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ public void execute(BaseRequest request, BaseResponse response) throws DdlExcept
throw new DdlException("No table selected.");
}

dbName = ClusterNamespace.getDbFullName(authInfo.cluster, dbName);
String fullDbName = ClusterNamespace.getDbFullName(authInfo.cluster, dbName);
String label = request.getSingleParameter(LABEL_NAME_PARAM);
String subLabel = request.getSingleParameter(SUB_LABEL_NAME_PARAM);
if (Strings.isNullOrEmpty(label)) {
throw new DdlException("No label selected.");
}

checkWritePriv(request, dbName);
checkWritePriv(authInfo.fullUserName, fullDbName);
// Try to redirect to master
if (redirectToMaster(request, response)) {
return;
Expand Down
8 changes: 6 additions & 2 deletions fe/src/com/baidu/palo/http/rest/MultiAbort.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

package com.baidu.palo.http.rest;

import com.baidu.palo.cluster.ClusterNamespace;
import com.baidu.palo.common.DdlException;
import com.baidu.palo.http.ActionController;
import com.baidu.palo.http.BaseRequest;
import com.baidu.palo.http.BaseResponse;
import com.baidu.palo.http.IllegalArgException;
import com.baidu.palo.service.ExecuteEnv;

import com.google.common.base.Strings;

import io.netty.handler.codec.http.HttpMethod;

public class MultiAbort extends RestBaseAction {
Expand Down Expand Up @@ -52,7 +53,10 @@ public void execute(BaseRequest request, BaseResponse response) throws DdlExcept
if (Strings.isNullOrEmpty(label)) {
throw new DdlException("No label selected");
}
checkWritePriv(request, db);
AuthorizationInfo authInfo = getAuthorizationInfo(request);
String fullDbName = ClusterNamespace.getDbFullName(authInfo.cluster, db);

checkWritePriv(authInfo.fullUserName, fullDbName);
if (redirectToMaster(request, response)) {
return;
}
Expand Down
9 changes: 7 additions & 2 deletions fe/src/com/baidu/palo/http/rest/MultiCommit.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

package com.baidu.palo.http.rest;

import com.baidu.palo.cluster.ClusterNamespace;
import com.baidu.palo.common.DdlException;
import com.baidu.palo.http.ActionController;
import com.baidu.palo.http.BaseRequest;
import com.baidu.palo.http.BaseResponse;
import com.baidu.palo.http.IllegalArgException;
import com.baidu.palo.service.ExecuteEnv;

import com.google.common.base.Strings;

import io.netty.handler.codec.http.HttpMethod;

public class MultiCommit extends RestBaseAction {
Expand Down Expand Up @@ -52,7 +53,11 @@ public void execute(BaseRequest request, BaseResponse response) throws DdlExcept
if (Strings.isNullOrEmpty(label)) {
throw new DdlException("No label selected");
}
checkWritePriv(request, db);
AuthorizationInfo authInfo = getAuthorizationInfo(request);
String fullDbName = ClusterNamespace.getDbFullName(authInfo.cluster, db);

checkWritePriv(authInfo.fullUserName, fullDbName);

if (redirectToMaster(request, response)) {
return;
}
Expand Down
13 changes: 9 additions & 4 deletions fe/src/com/baidu/palo/http/rest/MultiDesc.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@

package com.baidu.palo.http.rest;

import java.util.List;

import com.baidu.palo.cluster.ClusterNamespace;
import com.baidu.palo.common.DdlException;
import com.baidu.palo.http.ActionController;
import com.baidu.palo.http.BaseRequest;
import com.baidu.palo.http.BaseResponse;
import com.baidu.palo.http.IllegalArgException;
import com.baidu.palo.service.ExecuteEnv;

import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import io.netty.handler.codec.http.HttpMethod;

import java.util.List;
import io.netty.handler.codec.http.HttpMethod;

// List all labels of one multi-load
public class MultiDesc extends RestBaseAction {
Expand Down Expand Up @@ -56,7 +57,11 @@ public void execute(BaseRequest request, BaseResponse response) throws DdlExcept
if (Strings.isNullOrEmpty(label)) {
throw new DdlException("No label selected");
}
checkReadPriv(request, db);
AuthorizationInfo authInfo = getAuthorizationInfo(request);
String fullDbName = ClusterNamespace.getDbFullName(authInfo.cluster, db);

checkReadPriv(authInfo.fullUserName, fullDbName);

if (redirectToMaster(request, response)) {
return;
}
Expand Down
13 changes: 9 additions & 4 deletions fe/src/com/baidu/palo/http/rest/MultiList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@

package com.baidu.palo.http.rest;

import java.util.List;

import com.baidu.palo.cluster.ClusterNamespace;
import com.baidu.palo.common.DdlException;
import com.baidu.palo.http.ActionController;
import com.baidu.palo.http.BaseRequest;
import com.baidu.palo.http.BaseResponse;
import com.baidu.palo.http.IllegalArgException;
import com.baidu.palo.service.ExecuteEnv;

import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import io.netty.handler.codec.http.HttpMethod;

import java.util.List;
import io.netty.handler.codec.http.HttpMethod;

// list all multi load before commit
public class MultiList extends RestBaseAction {
Expand All @@ -51,7 +52,11 @@ public void execute(BaseRequest request, BaseResponse response) throws DdlExcept
if (Strings.isNullOrEmpty(db)) {
throw new DdlException("No database selected");
}
checkReadPriv(request, db);
AuthorizationInfo authInfo = getAuthorizationInfo(request);
String fullDbName = ClusterNamespace.getDbFullName(authInfo.cluster, db);

checkReadPriv(authInfo.fullUserName, fullDbName);

if (redirectToMaster(request, response)) {
return;
}
Expand Down
12 changes: 8 additions & 4 deletions fe/src/com/baidu/palo/http/rest/MultiStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@

package com.baidu.palo.http.rest;

import java.util.Map;

import com.baidu.palo.analysis.LoadStmt;
import com.baidu.palo.cluster.ClusterNamespace;
import com.baidu.palo.common.DdlException;
import com.baidu.palo.http.ActionController;
import com.baidu.palo.http.BaseRequest;
import com.baidu.palo.http.BaseResponse;
import com.baidu.palo.http.IllegalArgException;
import com.baidu.palo.service.ExecuteEnv;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.netty.handler.codec.http.HttpMethod;

import java.util.Map;
import io.netty.handler.codec.http.HttpMethod;

// Start multi action
public class MultiStart extends RestBaseAction {
Expand Down Expand Up @@ -57,7 +58,10 @@ public void execute(BaseRequest request, BaseResponse response) throws DdlExcept
if (Strings.isNullOrEmpty(label)) {
throw new DdlException("No label selected");
}
checkWritePriv(request, db);
AuthorizationInfo authInfo = getAuthorizationInfo(request);
String fullDbName = ClusterNamespace.getDbFullName(authInfo.cluster, db);

checkWritePriv(authInfo.fullUserName, fullDbName);

if (redirectToMaster(request, response)) {
return;
Expand Down
9 changes: 7 additions & 2 deletions fe/src/com/baidu/palo/http/rest/MultiUnload.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

package com.baidu.palo.http.rest;

import com.baidu.palo.cluster.ClusterNamespace;
import com.baidu.palo.common.DdlException;
import com.baidu.palo.http.ActionController;
import com.baidu.palo.http.BaseRequest;
import com.baidu.palo.http.BaseResponse;
import com.baidu.palo.http.IllegalArgException;
import com.baidu.palo.service.ExecuteEnv;

import com.google.common.base.Strings;

import io.netty.handler.codec.http.HttpMethod;

public class MultiUnload extends RestBaseAction {
Expand Down Expand Up @@ -57,7 +58,11 @@ public void execute(BaseRequest request, BaseResponse response) throws DdlExcept
if (Strings.isNullOrEmpty(subLabel)) {
throw new DdlException("No sub_label selected");
}
checkWritePriv(request, db);

AuthorizationInfo authInfo = getAuthorizationInfo(request);
String fullDbName = ClusterNamespace.getDbFullName(authInfo.cluster, db);
checkWritePriv(authInfo.fullUserName, fullDbName);

if (redirectToMaster(request, response)) {
return;
}
Expand Down
Loading

0 comments on commit 71f06ae

Please sign in to comment.