Search in sources :

Example 1 with ColumnType

use of org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType in project accumulo by apache.

the class TabletMetadataTest method testLocationStates.

@Test
public void testLocationStates() {
    KeyExtent extent = new KeyExtent(TableId.of("5"), new Text("df"), new Text("da"));
    TServerInstance ser1 = new TServerInstance(HostAndPort.fromParts("server1", 8555), "s001");
    TServerInstance ser2 = new TServerInstance(HostAndPort.fromParts("server2", 8111), "s002");
    TServerInstance deadSer = new TServerInstance(HostAndPort.fromParts("server3", 8000), "s003");
    Set<TServerInstance> tservers = new LinkedHashSet<>();
    tservers.add(ser1);
    tservers.add(ser2);
    EnumSet<ColumnType> colsToFetch = EnumSet.of(LOCATION, LAST, SUSPEND);
    // test assigned
    Mutation mutation = TabletColumnFamily.createPrevRowMutation(extent);
    mutation.at().family(FutureLocationColumnFamily.NAME).qualifier(ser1.getSession()).put(ser1.getHostPort());
    SortedMap<Key, Value> rowMap = toRowMap(mutation);
    TabletMetadata tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), colsToFetch, false);
    TabletState state = tm.getTabletState(tservers);
    assertEquals(TabletState.ASSIGNED, state);
    assertEquals(ser1, tm.getLocation());
    assertEquals(ser1.getSession(), tm.getLocation().getSession());
    assertEquals(LocationType.FUTURE, tm.getLocation().getType());
    assertFalse(tm.hasCurrent());
    // test hosted
    mutation = TabletColumnFamily.createPrevRowMutation(extent);
    mutation.at().family(CurrentLocationColumnFamily.NAME).qualifier(ser2.getSession()).put(ser2.getHostPort());
    rowMap = toRowMap(mutation);
    tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), colsToFetch, false);
    assertEquals(TabletState.HOSTED, tm.getTabletState(tservers));
    assertEquals(ser2, tm.getLocation());
    assertEquals(ser2.getSession(), tm.getLocation().getSession());
    assertEquals(LocationType.CURRENT, tm.getLocation().getType());
    assertTrue(tm.hasCurrent());
    // test ASSIGNED_TO_DEAD_SERVER
    mutation = TabletColumnFamily.createPrevRowMutation(extent);
    mutation.at().family(CurrentLocationColumnFamily.NAME).qualifier(deadSer.getSession()).put(deadSer.getHostPort());
    rowMap = toRowMap(mutation);
    tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), colsToFetch, false);
    assertEquals(TabletState.ASSIGNED_TO_DEAD_SERVER, tm.getTabletState(tservers));
    assertEquals(deadSer, tm.getLocation());
    assertEquals(deadSer.getSession(), tm.getLocation().getSession());
    assertEquals(LocationType.CURRENT, tm.getLocation().getType());
    assertTrue(tm.hasCurrent());
    // test UNASSIGNED
    mutation = TabletColumnFamily.createPrevRowMutation(extent);
    rowMap = toRowMap(mutation);
    tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), colsToFetch, false);
    assertEquals(TabletState.UNASSIGNED, tm.getTabletState(tservers));
    assertNull(tm.getLocation());
    assertFalse(tm.hasCurrent());
    // test SUSPENDED
    mutation = TabletColumnFamily.createPrevRowMutation(extent);
    mutation.at().family(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily()).qualifier(SuspendLocationColumn.SUSPEND_COLUMN.getColumnQualifier()).put(SuspendingTServer.toValue(ser2, 1000L));
    rowMap = toRowMap(mutation);
    tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), colsToFetch, false);
    assertEquals(TabletState.SUSPENDED, tm.getTabletState(tservers));
    assertEquals(1000L, tm.getSuspend().suspensionTime);
    assertEquals(ser2.getHostAndPort(), tm.getSuspend().server);
    assertNull(tm.getLocation());
    assertFalse(tm.hasCurrent());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ColumnType(org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) TabletState(org.apache.accumulo.core.metadata.TabletState) Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 Key (org.apache.accumulo.core.data.Key)1 Mutation (org.apache.accumulo.core.data.Mutation)1 Value (org.apache.accumulo.core.data.Value)1 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)1 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)1 TabletState (org.apache.accumulo.core.metadata.TabletState)1 ColumnType (org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType)1 Text (org.apache.hadoop.io.Text)1 Test (org.junit.jupiter.api.Test)1