Search in sources :

Example 86 with TServerInstance

use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.

the class DatafileManager method bringMajorCompactionOnline.

StoredTabletFile bringMajorCompactionOnline(Set<StoredTabletFile> oldDatafiles, TabletFile tmpDatafile, Long compactionId, Set<StoredTabletFile> selectedFiles, DataFileValue dfv, Optional<ExternalCompactionId> ecid) throws IOException {
    final KeyExtent extent = tablet.getExtent();
    VolumeManager vm = tablet.getTabletServer().getContext().getVolumeManager();
    long t1, t2;
    TabletFile newDatafile = CompactableUtils.computeCompactionFileDest(tmpDatafile);
    if (vm.exists(newDatafile.getPath())) {
        log.error("Target map file already exist " + newDatafile, new Exception());
        throw new IllegalStateException("Target map file already exist " + newDatafile);
    }
    if (dfv.getNumEntries() == 0) {
        vm.deleteRecursively(tmpDatafile.getPath());
    } else {
        // rename before putting in metadata table, so files in metadata table should
        // always exist
        rename(vm, tmpDatafile.getPath(), newDatafile.getPath());
    }
    TServerInstance lastLocation = null;
    // calling insert to get the new file before inserting into the metadata
    StoredTabletFile newFile = newDatafile.insert();
    Long compactionIdToWrite = null;
    synchronized (tablet) {
        t1 = System.currentTimeMillis();
        Preconditions.checkState(datafileSizes.keySet().containsAll(oldDatafiles), "Compacted files %s are not a subset of tablet files %s", oldDatafiles, datafileSizes.keySet());
        if (dfv.getNumEntries() > 0) {
            Preconditions.checkState(!datafileSizes.containsKey(newFile), "New compaction file %s already exist in tablet files %s", newFile, datafileSizes.keySet());
        }
        tablet.incrementDataSourceDeletions();
        datafileSizes.keySet().removeAll(oldDatafiles);
        if (dfv.getNumEntries() > 0) {
            datafileSizes.put(newFile, dfv);
        // could be used by a follow on compaction in a multipass compaction
        }
        updateCount++;
        tablet.computeNumEntries();
        lastLocation = tablet.resetLastLocation();
        if (compactionId != null && Collections.disjoint(selectedFiles, datafileSizes.keySet())) {
            compactionIdToWrite = compactionId;
        }
        t2 = System.currentTimeMillis();
    }
    // known consistency issue between minor and major compactions - see ACCUMULO-18
    Set<StoredTabletFile> filesInUseByScans = waitForScansToFinish(oldDatafiles);
    if (!filesInUseByScans.isEmpty())
        log.debug("Adding scan refs to metadata {} {}", extent, filesInUseByScans);
    ManagerMetadataUtil.replaceDatafiles(tablet.getContext(), extent, oldDatafiles, filesInUseByScans, newFile, compactionIdToWrite, dfv, tablet.getTabletServer().getClientAddressString(), lastLocation, tablet.getTabletServer().getLock(), ecid);
    tablet.setLastCompactionID(compactionIdToWrite);
    removeFilesAfterScan(filesInUseByScans);
    if (log.isTraceEnabled()) {
        log.trace(String.format("MajC finish lock %.2f secs", (t2 - t1) / 1000.0));
    }
    return newFile;
}
Also used : VolumeManager(org.apache.accumulo.server.fs.VolumeManager) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) TabletFile(org.apache.accumulo.core.metadata.TabletFile) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) IOException(java.io.IOException) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Example 87 with TServerInstance

use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.

the class CheckTabletMetadataTest method testBadTabletMetadata.

@Test
public void testBadTabletMetadata() throws Exception {
    KeyExtent ke = new KeyExtent(TableId.of("1"), null, null);
    TreeMap<Key, Value> tabletMeta = new TreeMap<>();
    put(tabletMeta, "1<", TabletColumnFamily.PREV_ROW_COLUMN, TabletColumnFamily.encodePrevEndRow(null).get());
    put(tabletMeta, "1<", ServerColumnFamily.DIRECTORY_COLUMN, "t1".getBytes());
    put(tabletMeta, "1<", ServerColumnFamily.TIME_COLUMN, "M0".getBytes());
    put(tabletMeta, "1<", FutureLocationColumnFamily.NAME, "4", "127.0.0.1:9997");
    TServerInstance tsi = new TServerInstance("127.0.0.1:9997", 4);
    TabletMetadata tm = TabletMetadata.convertRow(tabletMeta.entrySet().iterator(), EnumSet.allOf(ColumnType.class), true);
    assertTrue(checkTabletMetadata(ke, tsi, tm));
    assertFail(tabletMeta, ke, new TServerInstance("127.0.0.1:9998", 4));
    assertFail(tabletMeta, ke, new TServerInstance("127.0.0.1:9998", 5));
    assertFail(tabletMeta, ke, new TServerInstance("127.0.0.1:9997", 5));
    assertFail(tabletMeta, ke, new TServerInstance("127.0.0.2:9997", 4));
    assertFail(tabletMeta, ke, new TServerInstance("127.0.0.2:9997", 5));
    assertFail(tabletMeta, new KeyExtent(TableId.of("1"), null, new Text("m")), tsi);
    assertFail(tabletMeta, new KeyExtent(TableId.of("1"), new Text("r"), new Text("m")), tsi);
    assertFail(tabletMeta, ke, tsi, newKey("1<", TabletColumnFamily.PREV_ROW_COLUMN));
    assertFail(tabletMeta, ke, tsi, newKey("1<", ServerColumnFamily.DIRECTORY_COLUMN));
    assertFail(tabletMeta, ke, tsi, newKey("1<", ServerColumnFamily.TIME_COLUMN));
    assertFail(tabletMeta, ke, tsi, newKey("1<", FutureLocationColumnFamily.NAME, "4"));
    TreeMap<Key, Value> copy = new TreeMap<>(tabletMeta);
    put(copy, "1<", CurrentLocationColumnFamily.NAME, "4", "127.0.0.1:9997");
    assertFail(copy, ke, tsi);
    assertFail(copy, ke, tsi, newKey("1<", FutureLocationColumnFamily.NAME, "4"));
    copy = new TreeMap<>(tabletMeta);
    put(copy, "1<", CurrentLocationColumnFamily.NAME, "5", "127.0.0.1:9998");
    assertFail(copy, ke, tsi);
    put(copy, "1<", CurrentLocationColumnFamily.NAME, "6", "127.0.0.1:9999");
    assertFail(copy, ke, tsi);
    copy = new TreeMap<>(tabletMeta);
    put(copy, "1<", FutureLocationColumnFamily.NAME, "5", "127.0.0.1:9998");
    assertFail(copy, ke, tsi);
    assertFail(new TreeMap<>(), ke, tsi);
}
Also used : ColumnType(org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType) Value(org.apache.accumulo.core.data.Value) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) AssignmentHandler.checkTabletMetadata(org.apache.accumulo.tserver.AssignmentHandler.checkTabletMetadata) Text(org.apache.hadoop.io.Text) TreeMap(java.util.TreeMap) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Key(org.apache.accumulo.core.data.Key) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) Test(org.junit.Test)

Example 88 with TServerInstance

use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.

the class ListTabletsCommand method getMetadataInfo.

protected List<TabletRowInfo> getMetadataInfo(Shell shellState, TableInfo tableInfo) throws Exception {
    List<TabletRowInfo> results = new ArrayList<>();
    final ClientContext context = shellState.getContext();
    Set<TServerInstance> liveTserverSet = TabletMetadata.getLiveTServers(context);
    try (var tabletsMetadata = TabletsMetadata.builder(context).forTable(tableInfo.id).build()) {
        for (var md : tabletsMetadata) {
            TabletRowInfo.Factory factory = new TabletRowInfo.Factory(tableInfo.name, md.getExtent());
            var fileMap = md.getFilesMap();
            factory.numFiles(fileMap.size());
            long entries = 0L;
            long size = 0L;
            for (DataFileValue dfv : fileMap.values()) {
                entries += dfv.getNumEntries();
                size += dfv.getSize();
            }
            factory.numEntries(entries);
            factory.size(size);
            factory.numWalLogs(md.getLogs().size());
            factory.dir(md.getDirName());
            factory.location(md.getLocation());
            factory.status(md.getTabletState(liveTserverSet).toString());
            results.add(factory.build());
        }
    }
    return results;
}
Also used : DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) ArrayList(java.util.ArrayList) LoggerFactory(org.slf4j.LoggerFactory) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Example 89 with TServerInstance

use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.

the class Tablet method resetLastLocation.

public TServerInstance resetLastLocation() {
    TServerInstance result = lastLocation;
    lastLocation = null;
    return result;
}
Also used : TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Aggregations

TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)89 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)32 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)30 HashMap (java.util.HashMap)21 ServerContext (org.apache.accumulo.server.ServerContext)18 TabletLocationState (org.apache.accumulo.core.metadata.TabletLocationState)17 HostAndPort (org.apache.accumulo.core.util.HostAndPort)14 HashSet (java.util.HashSet)13 TabletServerStatus (org.apache.accumulo.core.master.thrift.TabletServerStatus)13 TableId (org.apache.accumulo.core.data.TableId)12 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)11 List (java.util.List)10 LiveTServerSet (org.apache.accumulo.server.manager.LiveTServerSet)10 TException (org.apache.thrift.TException)10 TreeMap (java.util.TreeMap)9 UUID (java.util.UUID)9 TreeSet (java.util.TreeSet)8 Key (org.apache.accumulo.core.data.Key)8 Value (org.apache.accumulo.core.data.Value)8