Search in sources :

Example 1 with TableMaster

use of alluxio.master.table.TableMaster in project alluxio by Alluxio.

the class TableMasterJournalIntegrationTest method journalTransformDb.

@Test
public void journalTransformDb() throws Exception {
    LocalAlluxioCluster mCluster = sClusterResource.get();
    TableMaster tableMaster = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(TableMaster.class);
    LocalAlluxioJobCluster jobCluster = new LocalAlluxioJobCluster();
    jobCluster.start();
    JobMaster jobMaster = jobCluster.getMaster().getJobMaster();
    genTable(1, 2, true);
    tableMaster.attachDatabase(TestUdbFactory.TYPE, "connect", DB_NAME, DB_NAME, Collections.emptyMap(), false);
    List<String> tables = tableMaster.getAllTables(DB_NAME);
    assertFalse(tables.isEmpty());
    // all partitions are not transformed, so baselayout is the same as layout
    String tableName = tables.get(0);
    assertTrue(tableMaster.getTable(DB_NAME, tableName).getPartitions().stream().allMatch(partition -> partition.getBaseLayout() == partition.getLayout()));
    long jobid = tableMaster.transformTable(DB_NAME, tableName, null);
    assertNotEquals(0, jobid);
    JobTestUtils.waitForJobStatus(jobMaster, jobid, ImmutableSet.of(Status.COMPLETED, Status.CANCELED, Status.FAILED));
    final JobInfo status = jobMaster.getStatus(jobid);
    assertEquals("", status.getErrorMessage());
    assertEquals(Status.COMPLETED, status.getStatus());
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_TABLE_TRANSFORMATION_MONITOR);
    // all partitions are transformed, so baselayout should be different as layout
    assertTrue(tableMaster.getTable(DB_NAME, tableName).getPartitions().stream().allMatch(partition -> partition.getBaseLayout() != partition.getLayout()));
    restartMaster();
    genTable(1, 4, true);
    TableMaster tableMasterRestart = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(TableMaster.class);
    Table table = tableMaster.getTable(DB_NAME, tableName);
    // all partitions remain transformed
    assertTrue(tableMaster.getTable(DB_NAME, tableName).getPartitions().stream().allMatch(partition -> partition.getBaseLayout() != partition.getLayout()));
    tableMasterRestart.syncDatabase(DB_NAME);
    // The first two partitions should remain transformed, the new partitions are not transformed
    assertTrue(tableMaster.getTable(DB_NAME, tableName).getPartitions().stream().allMatch(partition -> (partition.getSpec().endsWith("0") || partition.getSpec().endsWith("1")) == (partition.getBaseLayout() != partition.getLayout())));
}
Also used : JobMaster(alluxio.master.job.JobMaster) PrincipalType(alluxio.grpc.table.PrincipalType) TestUdbFactory(alluxio.master.table.TestUdbFactory) TestRule(org.junit.rules.TestRule) Status(alluxio.job.wire.Status) PropertyKey(alluxio.conf.PropertyKey) TableMaster(alluxio.master.table.TableMaster) HeartbeatScheduler(alluxio.heartbeat.HeartbeatScheduler) DatabaseInfo(alluxio.master.table.DatabaseInfo) Constants(alluxio.Constants) Database(alluxio.grpc.table.Database) JobTestUtils(alluxio.job.util.JobTestUtils) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) HeartbeatContext(alluxio.heartbeat.HeartbeatContext) ManuallyScheduleHeartbeat(alluxio.heartbeat.ManuallyScheduleHeartbeat) ImmutableMap(com.google.common.collect.ImmutableMap) LocalAlluxioClusterResource(alluxio.testutils.LocalAlluxioClusterResource) LocalAlluxioJobCluster(alluxio.master.LocalAlluxioJobCluster) JobMaster(alluxio.master.job.JobMaster) Assert.assertTrue(org.junit.Assert.assertTrue) TestDatabase.genTable(alluxio.master.table.TestDatabase.genTable) Test(org.junit.Test) IOException(java.io.IOException) TestDatabase(alluxio.master.table.TestDatabase) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) List(java.util.List) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) JobInfo(alluxio.job.wire.JobInfo) LocalAlluxioCluster(alluxio.master.LocalAlluxioCluster) Table(alluxio.master.table.Table) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) LocalAlluxioJobCluster(alluxio.master.LocalAlluxioJobCluster) TestDatabase.genTable(alluxio.master.table.TestDatabase.genTable) Table(alluxio.master.table.Table) LocalAlluxioCluster(alluxio.master.LocalAlluxioCluster) JobInfo(alluxio.job.wire.JobInfo) TableMaster(alluxio.master.table.TableMaster) Test(org.junit.Test)

Example 2 with TableMaster

use of alluxio.master.table.TableMaster in project alluxio by Alluxio.

the class TableMasterJournalIntegrationTest method journalAttachDb.

@Test
public void journalAttachDb() throws Exception {
    LocalAlluxioCluster mCluster = sClusterResource.get();
    TableMaster tableMaster = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(TableMaster.class);
    try {
        tableMaster.getDatabase(DB_NAME);
        fail();
    } catch (IOException e) {
        assertEquals("Database " + DB_NAME + " does not exist", e.getMessage());
    }
    genTable(1, 2, true);
    tableMaster.attachDatabase(TestUdbFactory.TYPE, "connect", DB_NAME, DB_NAME, Collections.emptyMap(), false);
    assertEquals(DB_NAME, tableMaster.getDatabase(DB_NAME).getDbName());
    List<String> oldTableNames = tableMaster.getAllTables(DB_NAME);
    Table tableOld = tableMaster.getTable(DB_NAME, oldTableNames.get(0));
    restartMaster();
    // Update Udb, the table should stay the same, until we detach / reattach
    genTable(2, 2, true);
    TableMaster tableMasterRestart = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(TableMaster.class);
    List<String> newTableNames = tableMaster.getAllTables(DB_NAME);
    assertEquals(oldTableNames, newTableNames);
    Table tableNew = tableMasterRestart.getTable(DB_NAME, newTableNames.get(0));
    assertEquals(tableOld.getName(), tableNew.getName());
}
Also used : TestDatabase.genTable(alluxio.master.table.TestDatabase.genTable) Table(alluxio.master.table.Table) LocalAlluxioCluster(alluxio.master.LocalAlluxioCluster) TableMaster(alluxio.master.table.TableMaster) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with TableMaster

use of alluxio.master.table.TableMaster in project alluxio by Alluxio.

the class TableMasterJournalIntegrationTest method journalSync.

@Test
public void journalSync() throws Exception {
    LocalAlluxioCluster mCluster = sClusterResource.get();
    TableMaster tableMaster = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(TableMaster.class);
    genTable(1, 2, true);
    tableMaster.attachDatabase(TestUdbFactory.TYPE, "connect", DB_NAME, DB_NAME, Collections.emptyMap(), false);
    checkDb(tableMaster, DB_NAME, TestDatabase.sTestDbInfo);
    DatabaseInfo oldInfo = TestDatabase.sTestDbInfo;
    DatabaseInfo newInfo = new DatabaseInfo("test2://test2", "newowner", PrincipalType.ROLE, "newcomment", ImmutableMap.of("key", "value"));
    checkTable(tableMaster, DB_NAME, 1, 2);
    checkTable(tableMaster, DB_NAME, 1, 2);
    assertEquals(TestDatabase.getTableName(0), tableMaster.getAllTables(DB_NAME).get(0));
    assertEquals(1, tableMaster.getAllTables(DB_NAME).size());
    assertEquals(2, tableMaster.getTable(DB_NAME, TestDatabase.getTableName(0)).getPartitions().size());
    // Update Udb, the table should stay the same, until we sync
    genTable(2, 3, true);
    tableMaster.syncDatabase(DB_NAME);
    checkTable(tableMaster, DB_NAME, 2, 3);
    // Drop a table to create a 'remove_table' entry
    genTable(1, 10, true);
    tableMaster.syncDatabase(DB_NAME);
    checkTable(tableMaster, DB_NAME, 1, 10);
    restartMaster();
    TableMaster tableMasterRestart = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(TableMaster.class);
    TestDatabase.sTestDbInfo = newInfo;
    checkDb(tableMasterRestart, DB_NAME, oldInfo);
    tableMasterRestart.syncDatabase(DB_NAME);
    checkDb(tableMasterRestart, DB_NAME, newInfo);
    checkTable(tableMasterRestart, DB_NAME, 1, 10);
}
Also used : LocalAlluxioCluster(alluxio.master.LocalAlluxioCluster) DatabaseInfo(alluxio.master.table.DatabaseInfo) TableMaster(alluxio.master.table.TableMaster) Test(org.junit.Test)

Example 4 with TableMaster

use of alluxio.master.table.TableMaster in project alluxio by Alluxio.

the class TableMasterJournalIntegrationTest method journalDetachDb.

@Test
public void journalDetachDb() throws Exception {
    LocalAlluxioCluster mCluster = sClusterResource.get();
    TableMaster tableMaster = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(TableMaster.class);
    genTable(1, 2, true);
    tableMaster.attachDatabase(TestUdbFactory.TYPE, "connect", DB_NAME, DB_NAME, Collections.emptyMap(), false);
    tableMaster.detachDatabase(DB_NAME);
    assertTrue(tableMaster.getAllDatabases().isEmpty());
    genTable(2, 2, true);
    restartMaster();
    TableMaster tableMasterRestart = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(TableMaster.class);
    assertTrue(tableMasterRestart.getAllDatabases().isEmpty());
}
Also used : LocalAlluxioCluster(alluxio.master.LocalAlluxioCluster) TableMaster(alluxio.master.table.TableMaster) Test(org.junit.Test)

Aggregations

LocalAlluxioCluster (alluxio.master.LocalAlluxioCluster)4 TableMaster (alluxio.master.table.TableMaster)4 Test (org.junit.Test)4 DatabaseInfo (alluxio.master.table.DatabaseInfo)2 Table (alluxio.master.table.Table)2 TestDatabase.genTable (alluxio.master.table.TestDatabase.genTable)2 IOException (java.io.IOException)2 Constants (alluxio.Constants)1 PropertyKey (alluxio.conf.PropertyKey)1 Database (alluxio.grpc.table.Database)1 PrincipalType (alluxio.grpc.table.PrincipalType)1 HeartbeatContext (alluxio.heartbeat.HeartbeatContext)1 HeartbeatScheduler (alluxio.heartbeat.HeartbeatScheduler)1 ManuallyScheduleHeartbeat (alluxio.heartbeat.ManuallyScheduleHeartbeat)1 JobTestUtils (alluxio.job.util.JobTestUtils)1 JobInfo (alluxio.job.wire.JobInfo)1 Status (alluxio.job.wire.Status)1 LocalAlluxioJobCluster (alluxio.master.LocalAlluxioJobCluster)1 JobMaster (alluxio.master.job.JobMaster)1 TestDatabase (alluxio.master.table.TestDatabase)1