-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
PHOENIX-7474 Migrate IndexTool tables and make sure they are created
1 parent
a75c4dc
commit 7c2b511
Showing
11 changed files
with
691 additions
and
82 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
phoenix-core-client/src/main/java/org/apache/phoenix/mapreduce/index/IndexToolTableUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.phoenix.mapreduce.index; | ||
|
||
|
||
|
||
import java.io.IOException; | ||
import java.sql.Connection; | ||
|
||
import java.sql.SQLException; | ||
import java.util.UUID; | ||
|
||
|
||
import org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting; | ||
import org.apache.hadoop.hbase.TableExistsException; | ||
import org.apache.hadoop.hbase.client.*; | ||
import org.apache.phoenix.coprocessorclient.MetaDataProtocol; | ||
import org.apache.phoenix.query.QueryConstants; | ||
|
||
import org.apache.hadoop.conf.Configured; | ||
import org.apache.hadoop.hbase.TableName; | ||
|
||
import org.apache.phoenix.jdbc.PhoenixConnection; | ||
|
||
import org.apache.phoenix.query.ConnectionQueryServices; | ||
|
||
import org.apache.phoenix.schema.PTableType; | ||
import org.apache.phoenix.util.SchemaUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static org.apache.phoenix.query.QueryConstants.SYSTEM_SCHEMA_NAME; | ||
|
||
/** | ||
* Utility class to create index tables and/or migrate them. | ||
* | ||
*/ | ||
public class IndexToolTableUtil extends Configured { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(IndexToolTableUtil.class); | ||
|
||
public final static String OUTPUT_TABLE_NAME = "PHOENIX_INDEX_TOOL"; | ||
public static String SYSTEM_OUTPUT_TABLE_NAME = SchemaUtil.getTableName(SYSTEM_SCHEMA_NAME, | ||
OUTPUT_TABLE_NAME); | ||
|
||
public final static String RESULT_TABLE_NAME = "PHOENIX_INDEX_TOOL_RESULT"; | ||
public static String SYSTEM_RESULT_TABLE_NAME = SchemaUtil.getTableName(SYSTEM_SCHEMA_NAME, | ||
RESULT_TABLE_NAME); | ||
|
||
public static void setIndexToolTableName(Connection connection) throws Exception { | ||
ConnectionQueryServices queryServices = connection.unwrap(PhoenixConnection.class).getQueryServices(); | ||
if (SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM, queryServices.getConfiguration())) { | ||
SYSTEM_OUTPUT_TABLE_NAME = SYSTEM_OUTPUT_TABLE_NAME.replace( | ||
QueryConstants.NAME_SEPARATOR, | ||
QueryConstants.NAMESPACE_SEPARATOR); | ||
SYSTEM_RESULT_TABLE_NAME = SYSTEM_RESULT_TABLE_NAME.replace( | ||
QueryConstants.NAME_SEPARATOR, | ||
QueryConstants.NAMESPACE_SEPARATOR); | ||
} | ||
} | ||
|
||
public static Table createResultTable(Connection connection) throws IOException, SQLException { | ||
ConnectionQueryServices queryServices = connection.unwrap(PhoenixConnection.class).getQueryServices(); | ||
try (Admin admin = queryServices.getAdmin()) { | ||
TableName resultTableName = TableName.valueOf(SYSTEM_RESULT_TABLE_NAME); | ||
return createTable(admin, resultTableName); | ||
} | ||
} | ||
|
||
public static Table createOutputTable(Connection connection) throws IOException, SQLException { | ||
ConnectionQueryServices queryServices = connection.unwrap(PhoenixConnection.class).getQueryServices(); | ||
try (Admin admin = queryServices.getAdmin()) { | ||
TableName outputTableName = TableName.valueOf(SYSTEM_OUTPUT_TABLE_NAME); | ||
return createTable(admin, outputTableName); | ||
} | ||
} | ||
|
||
@VisibleForTesting | ||
private static Table createTable(Admin admin, TableName tableName) throws IOException { | ||
if (!admin.tableExists(tableName)) { | ||
ColumnFamilyDescriptor columnDescriptor = | ||
ColumnFamilyDescriptorBuilder | ||
.newBuilder(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES) | ||
.setTimeToLive(MetaDataProtocol.DEFAULT_LOG_TTL) | ||
.build(); | ||
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName) | ||
.setColumnFamily(columnDescriptor).build(); | ||
try { | ||
admin.createTable(tableDescriptor); | ||
} catch (TableExistsException e) { | ||
LOGGER.warn("Table exists, ignoring", e); | ||
} | ||
} | ||
return admin.getConnection().getTable(tableName); | ||
} | ||
|
||
|
||
public static void createNewIndexToolTables(Connection connection) throws Exception { | ||
setIndexToolTableName(connection); | ||
|
||
migrateTable(connection, OUTPUT_TABLE_NAME); | ||
migrateTable(connection, RESULT_TABLE_NAME); | ||
} | ||
|
||
private static void migrateTable(Connection connection, String tableName) throws Exception { | ||
if (!tableName.equals(OUTPUT_TABLE_NAME) && !tableName.equals(RESULT_TABLE_NAME)) { | ||
LOGGER.info("Only migrating PHOENIX_INDEX_TOOL tables!"); | ||
} else { | ||
ConnectionQueryServices queryServices = connection.unwrap(PhoenixConnection.class).getQueryServices(); | ||
try (Admin admin = queryServices.getAdmin()) { | ||
TableName oldTableName = TableName.valueOf(tableName); | ||
String newTableNameString = tableName.equals(OUTPUT_TABLE_NAME) ? | ||
SYSTEM_OUTPUT_TABLE_NAME : SYSTEM_RESULT_TABLE_NAME; | ||
|
||
TableName newTableName = TableName.valueOf(newTableNameString); | ||
|
||
if (admin.tableExists(oldTableName)) { | ||
String snapshotName = tableName + "_" + UUID.randomUUID(); | ||
admin.disableTable(oldTableName); | ||
admin.snapshot(snapshotName, oldTableName); | ||
admin.cloneSnapshot(snapshotName, newTableName); | ||
admin.deleteSnapshot(snapshotName); | ||
admin.deleteTable(oldTableName); | ||
} else { | ||
createTable(admin, newTableName); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
340 changes: 340 additions & 0 deletions
340
phoenix-core/src/it/java/org/apache/phoenix/end2end/AsyncIndexPermissionIT.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIndexToolTablesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.phoenix.end2end; | ||
|
||
|
||
import org.apache.hadoop.hbase.TableName; | ||
import org.apache.hadoop.hbase.client.Admin; | ||
|
||
import org.apache.phoenix.mapreduce.index.IndexToolTableUtil; | ||
import org.apache.phoenix.query.QueryConstants; | ||
import org.apache.phoenix.query.QueryServices; | ||
import org.apache.phoenix.query.QueryServicesOptions; | ||
import org.apache.phoenix.thirdparty.com.google.common.collect.Maps; | ||
import org.apache.phoenix.util.ReadOnlyProps; | ||
import org.apache.phoenix.util.SchemaUtil; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.apache.phoenix.mapreduce.index.IndexToolTableUtil.RESULT_TABLE_NAME; | ||
import static org.apache.phoenix.query.QueryConstants.SYSTEM_SCHEMA_NAME; | ||
import static org.junit.Assert.*; | ||
|
||
public class UpgradeIndexToolTablesIT extends LoadSystemTableSnapshotBase { | ||
protected String nameSpaceMapping = "true"; | ||
|
||
@Before | ||
public synchronized void doSetup() throws Exception { | ||
setupCluster(nameSpaceMapping); | ||
} | ||
|
||
public synchronized void setupCluster(String nameSpaceMappingEnabled) throws Exception { | ||
HashMap<String, String> snapshotsToLoad = new HashMap<>(); | ||
snapshotsToLoad.put("phoenixtoolresultsnapshot", "PHOENIX_INDEX_TOOL_RESULT"); | ||
setupCluster(false, "indexToolsnapshot.tar.gz", "indexToolResultSnapshot/", snapshotsToLoad, nameSpaceMappingEnabled); | ||
} | ||
|
||
@Test | ||
public void testPhoenixUpgradeIndexToolTables() throws Exception { | ||
try (Admin admin = utility.getAdmin()) { | ||
// we load the RESULT_TABLE_NAME from snapshot | ||
assertTrue(admin.tableExists(TableName.valueOf(IndexToolTableUtil.RESULT_TABLE_NAME))); | ||
assertFalse(admin.tableExists(TableName.valueOf(IndexToolTableUtil.SYSTEM_RESULT_TABLE_NAME))); | ||
// we don't load the OUTPUT_TABLE_NAME | ||
assertFalse(admin.tableExists(TableName.valueOf(IndexToolTableUtil.OUTPUT_TABLE_NAME))); | ||
assertFalse(admin.tableExists(TableName.valueOf(IndexToolTableUtil.SYSTEM_OUTPUT_TABLE_NAME))); | ||
} | ||
|
||
Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(2); | ||
serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS); | ||
serverProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, nameSpaceMapping); | ||
Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(2); | ||
clientProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, nameSpaceMapping); | ||
|
||
|
||
//Now we can start Phoenix | ||
setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet() | ||
.iterator())); | ||
assertTrue(true); | ||
|
||
|
||
// Check the IndexTool Tables after upgrade | ||
try (Admin admin = utility.getAdmin()) { | ||
assertFalse(admin.tableExists(TableName.valueOf(IndexToolTableUtil.OUTPUT_TABLE_NAME))); | ||
assertFalse(admin.tableExists(TableName.valueOf(IndexToolTableUtil.RESULT_TABLE_NAME))); | ||
assertTrue(admin.tableExists(TableName.valueOf(IndexToolTableUtil.SYSTEM_OUTPUT_TABLE_NAME))); | ||
assertTrue(admin.tableExists(TableName.valueOf(IndexToolTableUtil.SYSTEM_RESULT_TABLE_NAME))); | ||
} | ||
|
||
String tableName = SchemaUtil.getTableName(SYSTEM_SCHEMA_NAME, RESULT_TABLE_NAME); | ||
if (nameSpaceMapping.equals("true")) { | ||
assertEquals(IndexToolTableUtil.SYSTEM_RESULT_TABLE_NAME, tableName.replace(QueryConstants.NAME_SEPARATOR, | ||
QueryConstants.NAMESPACE_SEPARATOR)); | ||
} else { | ||
assertEquals(IndexToolTableUtil.SYSTEM_RESULT_TABLE_NAME, tableName); | ||
} | ||
|
||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
.../it/java/org/apache/phoenix/end2end/UpgradeIndexToolTablesNameSpaceMappingDisabledIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.phoenix.end2end; | ||
|
||
import org.junit.Before; | ||
|
||
|
||
public class UpgradeIndexToolTablesNameSpaceMappingDisabledIT extends UpgradeIndexToolTablesIT { | ||
|
||
@Override | ||
@Before | ||
public synchronized void doSetup() throws Exception { | ||
nameSpaceMapping = "false"; | ||
setupCluster(nameSpaceMapping); | ||
} | ||
} |
Binary file added
BIN
+20 KB
phoenix-core/src/it/resources/indexToolResultSnapshot/indexToolsnapshot.tar.gz
Binary file not shown.