use of org.apache.hadoop.hive.metastore.RawStore in project hive by apache.
the class ThreadWithGarbageCleanup method cacheThreadLocalRawStore.
/**
* Cache the ThreadLocal RawStore object. Called from the corresponding thread.
*/
public void cacheThreadLocalRawStore() {
Long threadId = this.getId();
RawStore threadLocalRawStore = HiveMetaStore.HMSHandler.getRawStore();
if (threadLocalRawStore != null && !threadRawStoreMap.containsKey(threadId)) {
LOG.debug("Adding RawStore: " + threadLocalRawStore + ", for the thread: " + this.getName() + " to threadRawStoreMap for future cleanup.");
threadRawStoreMap.put(threadId, threadLocalRawStore);
}
}
use of org.apache.hadoop.hive.metastore.RawStore in project hive by apache.
the class ThreadWithGarbageCleanup method cleanRawStore.
private void cleanRawStore() {
Long threadId = this.getId();
RawStore threadLocalRawStore = threadRawStoreMap.get(threadId);
if (threadLocalRawStore != null) {
LOG.debug("RawStore: " + threadLocalRawStore + ", for the thread: " + this.getName() + " will be closed now.");
threadLocalRawStore.shutdown();
threadRawStoreMap.remove(threadId);
}
}
use of org.apache.hadoop.hive.metastore.RawStore in project hive by apache.
the class TestHBaseImport method importOneFunc.
@Test
public void importOneFunc() throws Exception {
RawStore rdbms;
rdbms = new ObjectStore();
rdbms.setConf(conf);
String[] dbNames = new String[] { "onefuncdb1", "onefuncdb2" };
String[] roles = new String[] { "onefuncrole1", "onefuncrole2" };
String[] tokenIds = new String[] { "onefunctokenid1", "onefunctokenid2" };
String[] tokens = new String[] { "onefunctoken1", "onefunctoken2" };
String[] masterKeys = new String[] { "onefuncmk1", "onefuncmk2" };
int now = (int) System.currentTimeMillis() / 1000;
setupObjectStore(rdbms, roles, dbNames, tokenIds, tokens, masterKeys, now);
int baseNumRoles = store.listRoleNames() == null ? 0 : store.listRoleNames().size();
int baseNumDbs = store.getAllDatabases() == null ? 0 : store.getAllDatabases().size();
int baseNumToks = store.getAllTokenIdentifiers() == null ? 0 : store.getAllTokenIdentifiers().size();
int baseNumKeys = store.getMasterKeys() == null ? 0 : store.getMasterKeys().length;
// Create the database so I can put the function in it.
store.createDatabase(new Database(dbNames[0], "no description", "file:/tmp", emptyParameters));
HBaseImport importer = new HBaseImport("-f", dbNames[0] + "." + funcNames[0]);
importer.setConnections(rdbms, store);
importer.run();
// Make sure there aren't any extra roles
Assert.assertEquals(baseNumRoles, store.listRoleNames().size());
Database db = store.getDatabase(dbNames[0]);
Assert.assertNotNull(db);
Assert.assertEquals(0, store.getAllTables(dbNames[0]).size());
Assert.assertEquals(1, store.getFunctions(dbNames[0], "*").size());
Assert.assertNotNull(store.getFunction(dbNames[0], funcNames[0]));
Assert.assertNull(store.getFunction(dbNames[0], funcNames[1]));
Assert.assertEquals(baseNumDbs + 1, store.getAllDatabases().size());
Assert.assertEquals(baseNumToks, store.getAllTokenIdentifiers().size());
String[] hbaseKeys = store.getMasterKeys();
Assert.assertEquals(baseNumKeys, hbaseKeys.length);
}
use of org.apache.hadoop.hive.metastore.RawStore in project hive by apache.
the class TestHBaseImport method importAll.
@Test
public void importAll() throws Exception {
RawStore rdbms;
rdbms = new ObjectStore();
rdbms.setConf(conf);
String[] dbNames = new String[] { "alldb1", "alldb2" };
String[] roles = new String[] { "allrole1", "allrole2" };
String[] tokenIds = new String[] { "alltokenid1", "alltokenid2" };
String[] tokens = new String[] { "alltoken1", "alltoken2" };
String[] masterKeys = new String[] { "allmk1", "allmk2" };
int now = (int) System.currentTimeMillis() / 1000;
setupObjectStore(rdbms, roles, dbNames, tokenIds, tokens, masterKeys, now);
int baseNumRoles = store.listRoleNames() == null ? 0 : store.listRoleNames().size();
int baseNumDbs = store.getAllDatabases() == null ? 0 : store.getAllDatabases().size();
HBaseImport importer = new HBaseImport("-a");
importer.setConnections(rdbms, store);
importer.run();
for (int i = 0; i < roles.length; i++) {
Role role = store.getRole(roles[i]);
Assert.assertNotNull(role);
Assert.assertEquals(roles[i], role.getRoleName());
}
// Make sure there aren't any extra roles
Assert.assertEquals(baseNumRoles + 2, store.listRoleNames().size());
for (int i = 0; i < dbNames.length; i++) {
Database db = store.getDatabase(dbNames[i]);
Assert.assertNotNull(db);
// check one random value in the db rather than every value
Assert.assertEquals("file:/tmp", db.getLocationUri());
Table table = store.getTable(db.getName(), tableNames[0]);
Assert.assertNotNull(table);
Assert.assertEquals(now, table.getLastAccessTime());
Assert.assertEquals("input", table.getSd().getInputFormat());
table = store.getTable(db.getName(), tableNames[1]);
Assert.assertNotNull(table);
for (int j = 0; j < partVals.length; j++) {
Partition part = store.getPartition(dbNames[i], tableNames[1], Arrays.asList(partVals[j]));
Assert.assertNotNull(part);
Assert.assertEquals("file:/tmp/region=" + partVals[j], part.getSd().getLocation());
}
Assert.assertEquals(4, store.getPartitions(dbNames[i], tableNames[1], -1).size());
// Including two index table
Assert.assertEquals(4, store.getAllTables(dbNames[i]).size());
Assert.assertEquals(2, store.getIndexes(dbNames[i], tableNames[0], -1).size());
Assert.assertEquals(0, store.getIndexes(dbNames[i], tableNames[1], -1).size());
Assert.assertEquals(2, store.getFunctions(dbNames[i], "*").size());
for (int j = 0; j < funcNames.length; j++) {
Assert.assertNotNull(store.getFunction(dbNames[i], funcNames[j]));
}
}
Assert.assertEquals(baseNumDbs + 2, store.getAllDatabases().size());
// guarantee.
for (int i = 0; i < tokenIds.length; i++) {
Assert.assertEquals(tokens[i], store.getToken(tokenIds[i]));
}
String[] hbaseKeys = store.getMasterKeys();
Set<String> keys = new HashSet<>(Arrays.asList(hbaseKeys));
for (int i = 0; i < masterKeys.length; i++) {
Assert.assertTrue(keys.contains(masterKeys[i]));
}
}
use of org.apache.hadoop.hive.metastore.RawStore in project hive by apache.
the class TestHBaseImport method importOneDb.
@Test
public void importOneDb() throws Exception {
RawStore rdbms;
rdbms = new ObjectStore();
rdbms.setConf(conf);
String[] dbNames = new String[] { "onedbdb1", "onedbdb2" };
String[] roles = new String[] { "onedbrole1", "onedbrole2" };
String[] tokenIds = new String[] { "onedbtokenid1", "onedbtokenid2" };
String[] tokens = new String[] { "onedbtoken1", "onedbtoken2" };
String[] masterKeys = new String[] { "onedbmk1", "onedbmk2" };
int now = (int) System.currentTimeMillis() / 1000;
setupObjectStore(rdbms, roles, dbNames, tokenIds, tokens, masterKeys, now);
int baseNumRoles = store.listRoleNames() == null ? 0 : store.listRoleNames().size();
int baseNumDbs = store.getAllDatabases() == null ? 0 : store.getAllDatabases().size();
int baseNumToks = store.getAllTokenIdentifiers() == null ? 0 : store.getAllTokenIdentifiers().size();
int baseNumKeys = store.getMasterKeys() == null ? 0 : store.getMasterKeys().length;
HBaseImport importer = new HBaseImport("-d", dbNames[0]);
importer.setConnections(rdbms, store);
importer.run();
// Make sure there aren't any extra roles
Assert.assertEquals(baseNumRoles, store.listRoleNames().size());
Database db = store.getDatabase(dbNames[0]);
Assert.assertNotNull(db);
// check one random value in the db rather than every value
Assert.assertEquals("file:/tmp", db.getLocationUri());
Table table = store.getTable(db.getName(), tableNames[0]);
Assert.assertNotNull(table);
Assert.assertEquals(now, table.getLastAccessTime());
Assert.assertEquals("input", table.getSd().getInputFormat());
table = store.getTable(db.getName(), tableNames[1]);
Assert.assertNotNull(table);
for (int j = 0; j < partVals.length; j++) {
Partition part = store.getPartition(dbNames[0], tableNames[1], Arrays.asList(partVals[j]));
Assert.assertNotNull(part);
Assert.assertEquals("file:/tmp/region=" + partVals[j], part.getSd().getLocation());
}
Assert.assertEquals(4, store.getPartitions(dbNames[0], tableNames[1], -1).size());
// Including two index table
Assert.assertEquals(4, store.getAllTables(dbNames[0]).size());
Assert.assertEquals(2, store.getIndexes(dbNames[0], tableNames[0], -1).size());
Assert.assertEquals(0, store.getIndexes(dbNames[0], tableNames[1], -1).size());
Assert.assertEquals(2, store.getFunctions(dbNames[0], "*").size());
for (int j = 0; j < funcNames.length; j++) {
Assert.assertNotNull(store.getFunction(dbNames[0], funcNames[j]));
}
Assert.assertEquals(baseNumDbs + 1, store.getAllDatabases().size());
Assert.assertEquals(baseNumToks, store.getAllTokenIdentifiers().size());
String[] hbaseKeys = store.getMasterKeys();
Assert.assertEquals(baseNumKeys, hbaseKeys.length);
// Have to do this last as it will throw an exception
thrown.expect(NoSuchObjectException.class);
store.getDatabase(dbNames[1]);
}
Aggregations