Search in sources :

Example 16 with TabletMutator

use of org.apache.accumulo.core.metadata.schema.Ample.TabletMutator in project accumulo by apache.

the class ManagerMetadataUtil method replaceDatafiles.

public static void replaceDatafiles(ServerContext context, KeyExtent extent, Set<StoredTabletFile> datafilesToDelete, Set<StoredTabletFile> scanFiles, TabletFile path, Long compactionId, DataFileValue size, String address, TServerInstance lastLocation, ServiceLock zooLock, Optional<ExternalCompactionId> ecid) {
    context.getAmple().putGcCandidates(extent.tableId(), datafilesToDelete);
    TabletMutator tablet = context.getAmple().mutateTablet(extent);
    datafilesToDelete.forEach(tablet::deleteFile);
    scanFiles.forEach(tablet::putScan);
    if (size.getNumEntries() > 0)
        tablet.putFile(path, size);
    if (compactionId != null)
        tablet.putCompactionId(compactionId);
    TServerInstance self = getTServerInstance(address, zooLock);
    tablet.putLocation(self, LocationType.LAST);
    // remove the old location
    if (lastLocation != null && !lastLocation.equals(self))
        tablet.deleteLocation(lastLocation, LocationType.LAST);
    if (ecid.isPresent())
        tablet.deleteExternalCompaction(ecid.get());
    tablet.putZooLock(zooLock);
    tablet.mutate();
}
Also used : TabletMutator(org.apache.accumulo.core.metadata.schema.Ample.TabletMutator) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Example 17 with TabletMutator

use of org.apache.accumulo.core.metadata.schema.Ample.TabletMutator in project accumulo by apache.

the class SplitRecoveryIT method splitPartiallyAndRecover.

private void splitPartiallyAndRecover(ServerContext context, KeyExtent extent, KeyExtent high, KeyExtent low, double splitRatio, SortedMap<StoredTabletFile, DataFileValue> mapFiles, Text midRow, String location, int steps, ServiceLock zl) throws Exception {
    SortedMap<StoredTabletFile, DataFileValue> lowDatafileSizes = new TreeMap<>();
    SortedMap<StoredTabletFile, DataFileValue> highDatafileSizes = new TreeMap<>();
    List<StoredTabletFile> highDatafilesToRemove = new ArrayList<>();
    MetadataTableUtil.splitDatafiles(midRow, splitRatio, new HashMap<>(), mapFiles, lowDatafileSizes, highDatafileSizes, highDatafilesToRemove);
    MetadataTableUtil.splitTablet(high, extent.prevEndRow(), splitRatio, context, zl, Set.of());
    TServerInstance instance = new TServerInstance(location, zl.getSessionId());
    Assignment assignment = new Assignment(high, instance);
    TabletMutator tabletMutator = context.getAmple().mutateTablet(extent);
    tabletMutator.putLocation(assignment.server, LocationType.FUTURE);
    tabletMutator.mutate();
    if (steps >= 1) {
        Map<Long, List<TabletFile>> bulkFiles = getBulkFilesLoaded(context, high);
        ManagerMetadataUtil.addNewTablet(context, low, "lowDir", instance, lowDatafileSizes, bulkFiles, new MetadataTime(0, TimeType.LOGICAL), -1L, -1L, zl);
    }
    if (steps >= 2) {
        MetadataTableUtil.finishSplit(high, highDatafileSizes, highDatafilesToRemove, context, zl);
    }
    TabletMetadata meta = context.getAmple().readTablet(high);
    KeyExtent fixedExtent = ManagerMetadataUtil.fixSplit(context, meta, zl);
    if (steps < 2)
        assertEquals(splitRatio, meta.getSplitRatio(), 0.0);
    if (steps >= 1) {
        assertEquals(high, fixedExtent);
        ensureTabletHasNoUnexpectedMetadataEntries(context, low, lowDatafileSizes);
        ensureTabletHasNoUnexpectedMetadataEntries(context, high, highDatafileSizes);
        Map<Long, ? extends Collection<TabletFile>> lowBulkFiles = getBulkFilesLoaded(context, low);
        Map<Long, ? extends Collection<TabletFile>> highBulkFiles = getBulkFilesLoaded(context, high);
        if (!lowBulkFiles.equals(highBulkFiles)) {
            throw new Exception(" " + lowBulkFiles + " != " + highBulkFiles + " " + low + " " + high);
        }
        if (lowBulkFiles.isEmpty()) {
            throw new Exception(" no bulk files " + low);
        }
    } else {
        assertEquals(extent, fixedExtent);
        ensureTabletHasNoUnexpectedMetadataEntries(context, extent, mapFiles);
    }
}
Also used : DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) ArrayList(java.util.ArrayList) TabletMutator(org.apache.accumulo.core.metadata.schema.Ample.TabletMutator) TreeMap(java.util.TreeMap) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) Assignment(org.apache.accumulo.server.manager.state.Assignment) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) List(java.util.List) ArrayList(java.util.ArrayList) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) TabletFile(org.apache.accumulo.core.metadata.TabletFile) MetadataTime(org.apache.accumulo.core.metadata.schema.MetadataTime)

Example 18 with TabletMutator

use of org.apache.accumulo.core.metadata.schema.Ample.TabletMutator in project accumulo by apache.

the class ManagerRepairsDualAssignmentIT method test.

@Test
public void test() throws Exception {
    // make some tablets, spread 'em around
    try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
        ClientContext context = (ClientContext) c;
        ServerContext serverContext = cluster.getServerContext();
        String table = this.getUniqueNames(1)[0];
        c.securityOperations().grantTablePermission("root", MetadataTable.NAME, TablePermission.WRITE);
        c.securityOperations().grantTablePermission("root", RootTable.NAME, TablePermission.WRITE);
        SortedSet<Text> partitions = new TreeSet<>();
        for (String part : "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")) {
            partitions.add(new Text(part));
        }
        NewTableConfiguration ntc = new NewTableConfiguration().withSplits(partitions);
        c.tableOperations().create(table, ntc);
        // scan the metadata table and get the two table location states
        Set<TServerInstance> states = new HashSet<>();
        Set<TabletLocationState> oldLocations = new HashSet<>();
        TabletStateStore store = TabletStateStore.getStoreForLevel(DataLevel.USER, context);
        while (states.size() < 2) {
            UtilWaitThread.sleep(250);
            oldLocations.clear();
            for (TabletLocationState tls : store) {
                if (tls.current != null) {
                    states.add(tls.current);
                    oldLocations.add(tls);
                }
            }
        }
        assertEquals(2, states.size());
        // Kill a tablet server... we don't care which one... wait for everything to be reassigned
        cluster.killProcess(ServerType.TABLET_SERVER, cluster.getProcesses().get(ServerType.TABLET_SERVER).iterator().next());
        Set<TServerInstance> replStates = new HashSet<>();
        @SuppressWarnings("deprecation") TableId repTable = org.apache.accumulo.core.replication.ReplicationTable.ID;
        // Find out which tablet server remains
        while (true) {
            UtilWaitThread.sleep(1000);
            states.clear();
            replStates.clear();
            boolean allAssigned = true;
            for (TabletLocationState tls : store) {
                if (tls != null && tls.current != null) {
                    states.add(tls.current);
                } else if (tls != null && tls.extent.equals(new KeyExtent(repTable, null, null))) {
                    replStates.add(tls.current);
                } else {
                    allAssigned = false;
                }
            }
            System.out.println(states + " size " + states.size() + " allAssigned " + allAssigned);
            if (states.size() != 2 && allAssigned)
                break;
        }
        assertEquals(1, replStates.size());
        assertEquals(1, states.size());
        // pick an assigned tablet and assign it to the old tablet
        TabletLocationState moved = null;
        for (TabletLocationState old : oldLocations) {
            if (!states.contains(old.current)) {
                moved = old;
            }
        }
        assertNotEquals(null, moved);
        // throw a mutation in as if we were the dying tablet
        TabletMutator tabletMutator = serverContext.getAmple().mutateTablet(moved.extent);
        tabletMutator.putLocation(moved.current, LocationType.CURRENT);
        tabletMutator.mutate();
        // wait for the manager to fix the problem
        waitForCleanStore(store);
        // now jam up the metadata table
        tabletMutator = serverContext.getAmple().mutateTablet(new KeyExtent(MetadataTable.ID, null, null));
        tabletMutator.putLocation(moved.current, LocationType.CURRENT);
        tabletMutator.mutate();
        waitForCleanStore(TabletStateStore.getStoreForLevel(DataLevel.METADATA, context));
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableId(org.apache.accumulo.core.data.TableId) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) TabletMutator(org.apache.accumulo.core.metadata.schema.Ample.TabletMutator) Text(org.apache.hadoop.io.Text) TabletStateStore(org.apache.accumulo.server.manager.state.TabletStateStore) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ServerContext(org.apache.accumulo.server.ServerContext) TreeSet(java.util.TreeSet) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

TabletMutator (org.apache.accumulo.core.metadata.schema.Ample.TabletMutator)18 StoredTabletFile (org.apache.accumulo.core.metadata.StoredTabletFile)4 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)4 TabletLocationState (org.apache.accumulo.core.metadata.TabletLocationState)3 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)2 TabletFile (org.apache.accumulo.core.metadata.TabletFile)2 DataFileValue (org.apache.accumulo.core.metadata.schema.DataFileValue)2 MetadataTime (org.apache.accumulo.core.metadata.schema.MetadataTime)2 LogEntry (org.apache.accumulo.core.tabletserver.log.LogEntry)2 Path (org.apache.hadoop.fs.Path)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)1 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)1 ClientContext (org.apache.accumulo.core.clientImpl.ClientContext)1 TableId (org.apache.accumulo.core.data.TableId)1