Search in sources :

Example 1 with MergeState

use of org.apache.accumulo.server.manager.state.MergeState in project accumulo by apache.

the class TabletGroupWatcher method updateMergeState.

private void updateMergeState(Map<TableId, MergeStats> mergeStatsCache) {
    for (MergeStats stats : mergeStatsCache.values()) {
        try {
            MergeState update = stats.nextMergeState(manager.getContext(), manager);
            // not finish
            if (update == MergeState.COMPLETE)
                update = MergeState.NONE;
            if (update != stats.getMergeInfo().getState()) {
                manager.setMergeState(stats.getMergeInfo(), update);
            }
            if (update == MergeState.MERGING) {
                try {
                    if (stats.getMergeInfo().isDelete()) {
                        deleteTablets(stats.getMergeInfo());
                    } else {
                        mergeMetadataRecords(stats.getMergeInfo());
                    }
                    update = MergeState.COMPLETE;
                    manager.setMergeState(stats.getMergeInfo(), update);
                } catch (Exception ex) {
                    Manager.log.error("Unable merge metadata table records", ex);
                }
            }
        } catch (Exception ex) {
            Manager.log.error("Unable to update merge state for merge " + stats.getMergeInfo().getExtent(), ex);
        }
    }
}
Also used : MergeState(org.apache.accumulo.server.manager.state.MergeState) MergeStats(org.apache.accumulo.manager.state.MergeStats) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) DistributedStoreException(org.apache.accumulo.server.manager.state.DistributedStoreException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) WalMarkerException(org.apache.accumulo.server.log.WalStateManager.WalMarkerException) BadLocationStateException(org.apache.accumulo.core.metadata.TabletLocationState.BadLocationStateException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 2 with MergeState

use of org.apache.accumulo.server.manager.state.MergeState in project accumulo by apache.

the class MergeStats method nextMergeState.

public MergeState nextMergeState(AccumuloClient accumuloClient, CurrentState manager) throws Exception {
    MergeState state = info.getState();
    if (state == MergeState.NONE)
        return state;
    if (total == 0) {
        log.trace("failed to see any tablets for this range, ignoring {}", info.getExtent());
        return state;
    }
    log.info("Computing next merge state for {} which is presently {} isDelete : {}", info.getExtent(), state, info.isDelete());
    if (state == MergeState.STARTED) {
        state = MergeState.SPLITTING;
    }
    if (state == MergeState.SPLITTING) {
        log.info("{} are hosted, total {}", hosted, total);
        if (!info.isDelete() && total == 1) {
            log.info("Merge range is already contained in a single tablet {}", info.getExtent());
            state = MergeState.COMPLETE;
        } else if (hosted == total) {
            if (info.isDelete()) {
                if (!lowerSplit)
                    log.info("Waiting for {} lower split to occur {}", info, info.getExtent());
                else if (!upperSplit)
                    log.info("Waiting for {} upper split to occur {}", info, info.getExtent());
                else
                    state = MergeState.WAITING_FOR_CHOPPED;
            } else {
                state = MergeState.WAITING_FOR_CHOPPED;
            }
        } else {
            log.info("Waiting for {} hosted tablets to be {} {}", hosted, total, info.getExtent());
        }
    }
    if (state == MergeState.WAITING_FOR_CHOPPED) {
        log.info("{} tablets are chopped {}", chopped, info.getExtent());
        if (chopped == needsToBeChopped) {
            state = MergeState.WAITING_FOR_OFFLINE;
        } else {
            log.info("Waiting for {} chopped tablets to be {} {}", chopped, needsToBeChopped, info.getExtent());
        }
    }
    if (state == MergeState.WAITING_FOR_OFFLINE) {
        if (chopped == needsToBeChopped) {
            log.info("{} tablets are chopped, {} are offline {}", chopped, unassigned, info.getExtent());
            if (unassigned == total) {
                if (verifyMergeConsistency(accumuloClient, manager))
                    state = MergeState.MERGING;
                else
                    log.info("Merge consistency check failed {}", info.getExtent());
            } else {
                log.info("Waiting for {} unassigned tablets to be {} {}", unassigned, total, info.getExtent());
            }
        } else {
            log.warn("Unexpected state: chopped tablets should be {} was {} merge {}", needsToBeChopped, chopped, info.getExtent());
            // Perhaps a split occurred after we chopped, but before we went offline: start over
            state = MergeState.WAITING_FOR_CHOPPED;
        }
    }
    if (state == MergeState.MERGING) {
        if (hosted != 0) {
            // Shouldn't happen
            log.error("Unexpected state: hosted tablets should be zero {} merge {}", hosted, info.getExtent());
            state = MergeState.WAITING_FOR_OFFLINE;
        }
        if (unassigned != total) {
            // Shouldn't happen
            log.error("Unexpected state: unassigned tablets should be {} was {} merge {}", total, unassigned, info.getExtent());
            state = MergeState.WAITING_FOR_CHOPPED;
        }
        log.info("{} tablets are unassigned {}", unassigned, info.getExtent());
    }
    return state;
}
Also used : MergeState(org.apache.accumulo.server.manager.state.MergeState)

Example 3 with MergeState

use of org.apache.accumulo.server.manager.state.MergeState in project accumulo by apache.

the class MergeStateIT method test.

@Test
public void test() throws Exception {
    ServerContext context = getServerContext();
    try (AccumuloClient accumuloClient = Accumulo.newClient().from(getClientProperties()).build()) {
        accumuloClient.securityOperations().grantTablePermission(accumuloClient.whoami(), MetadataTable.NAME, TablePermission.WRITE);
        BatchWriter bw = accumuloClient.createBatchWriter(MetadataTable.NAME);
        // Create a fake METADATA table with these splits
        String[] splits = { "a", "e", "j", "o", "t", "z" };
        // create metadata for a table "t" with the splits above
        TableId tableId = TableId.of("t");
        Text pr = null;
        for (String s : splits) {
            Text split = new Text(s);
            Mutation prevRow = TabletColumnFamily.createPrevRowMutation(new KeyExtent(tableId, split, pr));
            prevRow.put(CurrentLocationColumnFamily.NAME, new Text("123456"), new Value("127.0.0.1:1234"));
            ChoppedColumnFamily.CHOPPED_COLUMN.put(prevRow, new Value("junk"));
            bw.addMutation(prevRow);
            pr = split;
        }
        // Add the default tablet
        Mutation defaultTablet = TabletColumnFamily.createPrevRowMutation(new KeyExtent(tableId, null, pr));
        defaultTablet.put(CurrentLocationColumnFamily.NAME, new Text("123456"), new Value("127.0.0.1:1234"));
        bw.addMutation(defaultTablet);
        bw.close();
        // Read out the TabletLocationStates
        MockCurrentState state = new MockCurrentState(new MergeInfo(new KeyExtent(tableId, new Text("p"), new Text("e")), MergeInfo.Operation.MERGE));
        // Verify the tablet state: hosted, and count
        TabletStateStore metaDataStateStore = TabletStateStore.getStoreForLevel(DataLevel.USER, context, state);
        int count = 0;
        for (TabletLocationState tss : metaDataStateStore) {
            if (tss != null)
                count++;
        }
        // the normal case is to skip tablets in a good state
        assertEquals(0, count);
        // Create the hole
        // Split the tablet at one end of the range
        Mutation m = TabletColumnFamily.createPrevRowMutation(new KeyExtent(tableId, new Text("t"), new Text("p")));
        TabletColumnFamily.SPLIT_RATIO_COLUMN.put(m, new Value("0.5"));
        TabletColumnFamily.OLD_PREV_ROW_COLUMN.put(m, TabletColumnFamily.encodePrevEndRow(new Text("o")));
        update(accumuloClient, m);
        // do the state check
        MergeStats stats = scan(state, metaDataStateStore);
        MergeState newState = stats.nextMergeState(accumuloClient, state);
        assertEquals(MergeState.WAITING_FOR_OFFLINE, newState);
        // unassign the tablets
        try (BatchDeleter deleter = accumuloClient.createBatchDeleter(MetadataTable.NAME, Authorizations.EMPTY, 1000)) {
            deleter.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
            deleter.setRanges(Collections.singletonList(new Range()));
            deleter.delete();
        }
        // now we should be ready to merge but, we have inconsistent metadata
        stats = scan(state, metaDataStateStore);
        assertEquals(MergeState.WAITING_FOR_OFFLINE, stats.nextMergeState(accumuloClient, state));
        // finish the split
        KeyExtent tablet = new KeyExtent(tableId, new Text("p"), new Text("o"));
        m = TabletColumnFamily.createPrevRowMutation(tablet);
        TabletColumnFamily.SPLIT_RATIO_COLUMN.put(m, new Value("0.5"));
        update(accumuloClient, m);
        metaDataStateStore.setLocations(Collections.singletonList(new Assignment(tablet, state.someTServer)));
        // onos... there's a new tablet online
        stats = scan(state, metaDataStateStore);
        assertEquals(MergeState.WAITING_FOR_CHOPPED, stats.nextMergeState(accumuloClient, state));
        // chop it
        m = TabletColumnFamily.createPrevRowMutation(tablet);
        ChoppedColumnFamily.CHOPPED_COLUMN.put(m, new Value("junk"));
        update(accumuloClient, m);
        stats = scan(state, metaDataStateStore);
        assertEquals(MergeState.WAITING_FOR_OFFLINE, stats.nextMergeState(accumuloClient, state));
        // take it offline
        m = TabletColumnFamily.createPrevRowMutation(tablet);
        Collection<Collection<String>> walogs = Collections.emptyList();
        metaDataStateStore.unassign(Collections.singletonList(new TabletLocationState(tablet, null, state.someTServer, null, null, walogs, false)), null);
        // now we can split
        stats = scan(state, metaDataStateStore);
        assertEquals(MergeState.MERGING, stats.nextMergeState(accumuloClient, state));
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableId(org.apache.accumulo.core.data.TableId) MergeInfo(org.apache.accumulo.server.manager.state.MergeInfo) BatchDeleter(org.apache.accumulo.core.client.BatchDeleter) MergeState(org.apache.accumulo.server.manager.state.MergeState) Text(org.apache.hadoop.io.Text) TabletStateStore(org.apache.accumulo.server.manager.state.TabletStateStore) Range(org.apache.accumulo.core.data.Range) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Assignment(org.apache.accumulo.server.manager.state.Assignment) ServerContext(org.apache.accumulo.server.ServerContext) Value(org.apache.accumulo.core.data.Value) MergeStats(org.apache.accumulo.manager.state.MergeStats) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) Collection(java.util.Collection) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Aggregations

MergeState (org.apache.accumulo.server.manager.state.MergeState)3 MergeStats (org.apache.accumulo.manager.state.MergeStats)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 BatchDeleter (org.apache.accumulo.core.client.BatchDeleter)1 BatchWriter (org.apache.accumulo.core.client.BatchWriter)1 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 Mutation (org.apache.accumulo.core.data.Mutation)1 Range (org.apache.accumulo.core.data.Range)1 TableId (org.apache.accumulo.core.data.TableId)1 Value (org.apache.accumulo.core.data.Value)1 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)1 TabletLocationState (org.apache.accumulo.core.metadata.TabletLocationState)1 BadLocationStateException (org.apache.accumulo.core.metadata.TabletLocationState.BadLocationStateException)1 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)1 ServerContext (org.apache.accumulo.server.ServerContext)1 WalMarkerException (org.apache.accumulo.server.log.WalStateManager.WalMarkerException)1