[phoenix] branch master updated: PHOENIX-5178 SYSTEM schema is not getting cached at MetaData server(addendum)

2019-03-11 Thread ankit
This is an automated email from the ASF dual-hosted git repository.

ankit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
 new f969444  PHOENIX-5178 SYSTEM schema is not getting cached at MetaData 
server(addendum)
f969444 is described below

commit f969444c96a060a5619e70e543c6d6fb21b32bed
Author: Ankit Singhal 
AuthorDate: Mon Mar 11 21:54:40 2019 -0700

PHOENIX-5178 SYSTEM schema is not getting cached at MetaData 
server(addendum)
---
 .../java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java  | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 06d36d9..192d004 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -1088,7 +1088,12 @@ public class MetaDataEndpointImpl extends 
MetaDataProtocol implements RegionCopr
 keyRanges.add(PVarbinary.INSTANCE.getKeyRange(key, true, stopKey, 
false));
 }
 Scan scan = new Scan();
-scan.setTimeRange(MIN_TABLE_TIMESTAMP, clientTimeStamp + 1);
+if (clientTimeStamp != HConstants.LATEST_TIMESTAMP
+&& clientTimeStamp != HConstants.OLDEST_TIMESTAMP) {
+scan.setTimeRange(MIN_TABLE_TIMESTAMP, clientTimeStamp + 1);
+} else {
+scan.setTimeRange(MIN_TABLE_TIMESTAMP, clientTimeStamp);
+}
 ScanRanges scanRanges = ScanRanges.createPointLookup(keyRanges);
 scanRanges.initializeScan(scan);
 scan.setFilter(scanRanges.getSkipScanFilter());



[phoenix] branch master updated: PHOENIX-5178 SYSTEM schema is not getting cached at MetaData server

2019-03-11 Thread ankit
This is an automated email from the ASF dual-hosted git repository.

ankit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
 new 5d66774  PHOENIX-5178 SYSTEM schema is not getting cached at MetaData 
server
5d66774 is described below

commit 5d66774fe886cdc9cf060276a367559cf908c091
Author: Ankit Singhal 
AuthorDate: Mon Mar 11 17:09:36 2019 -0700

PHOENIX-5178 SYSTEM schema is not getting cached at MetaData server
---
 .../phoenix/end2end/SystemTablePermissionsIT.java  | 43 ++
 .../phoenix/coprocessor/MetaDataEndpointImpl.java  |  2 +-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablePermissionsIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablePermissionsIT.java
index 0788ed7..6da970b 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablePermissionsIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablePermissionsIT.java
@@ -17,12 +17,23 @@
 package org.apache.phoenix.end2end;
 
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.security.PrivilegedExceptionAction;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
 import java.util.Collections;
+import java.util.Properties;
 import java.util.Set;
 
 import org.apache.hadoop.hbase.security.access.Permission.Action;
+import org.apache.phoenix.coprocessor.MetaDataProtocol;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.NewerSchemaAlreadyExistsException;
+import org.apache.phoenix.schema.NewerTableAlreadyExistsException;
+import org.apache.phoenix.util.PhoenixRuntime;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -84,5 +95,37 @@ public class SystemTablePermissionsIT extends 
BasePermissionsIT {
 
 // Make sure that the unprivileged user can now read the table
 verifyAllowed(readTable(TABLE_NAME), regularUser1);
+//This verification is added to test PHOENIX-5178
+superUser1.runAs(new PrivilegedExceptionAction() {
+@Override public Void run() throws Exception {
+try {
+if (isNamespaceMapped) {
+grantPermissions(regularUser1.getShortName(),"SYSTEM", 
Action.ADMIN);
+}
+return null;
+} catch (Throwable e) {
+throw new Exception(e);
+}
+
+}
+});
+if(isNamespaceMapped) {
+verifyAllowed(new AccessTestAction() {
+@Override public Object run() throws Exception {
+Properties props = new Properties();
+
props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, 
Boolean.toString(isNamespaceMapped));
+props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, 
Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP));
+//Impersonate meta connection
+try (Connection metaConnection = 
DriverManager.getConnection(getUrl(), props);
+Statement stmt = metaConnection.createStatement()) {
+stmt.executeUpdate("CREATE SCHEMA IF NOT EXISTS 
SYSTEM");
+}catch(NewerSchemaAlreadyExistsException e){
+
+}
+return null;
+}
+}, regularUser1);
+}
 }
+
 }
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 0b95b26..06d36d9 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -1088,7 +1088,7 @@ public class MetaDataEndpointImpl extends 
MetaDataProtocol implements RegionCopr
 keyRanges.add(PVarbinary.INSTANCE.getKeyRange(key, true, stopKey, 
false));
 }
 Scan scan = new Scan();
-scan.setTimeRange(MIN_TABLE_TIMESTAMP, clientTimeStamp);
+scan.setTimeRange(MIN_TABLE_TIMESTAMP, clientTimeStamp + 1);
 ScanRanges scanRanges = ScanRanges.createPointLookup(keyRanges);
 scanRanges.initializeScan(scan);
 scan.setFilter(scanRanges.getSkipScanFilter());