Search in sources :

Example 31 with TabletFile

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

the class CollectTabletStats method reportHdfsBlockLocations.

private static void reportHdfsBlockLocations(ServerContext context, List<TabletFile> files) throws Exception {
    VolumeManager fs = context.getVolumeManager();
    System.out.println("\t\tFile block report : ");
    for (TabletFile file : files) {
        FileStatus status = fs.getFileStatus(file.getPath());
        if (status.isDirectory()) {
            // assume it is a map file
            status = fs.getFileStatus(new Path(file + "/data"));
        }
        FileSystem ns = fs.getFileSystemByPath(file.getPath());
        BlockLocation[] locs = ns.getFileBlockLocations(status, 0, status.getLen());
        System.out.println("\t\t\tBlocks for : " + file);
        for (BlockLocation blockLocation : locs) {
            System.out.printf("\t\t\t\t offset : %,13d  hosts :", blockLocation.getOffset());
            for (String host : blockLocation.getHosts()) {
                System.out.print(" " + host);
            }
            System.out.println();
        }
    }
    System.out.println();
}
Also used : Path(org.apache.hadoop.fs.Path) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) TabletFile(org.apache.accumulo.core.metadata.TabletFile) BlockLocation(org.apache.hadoop.fs.BlockLocation)

Example 32 with TabletFile

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

the class CollectTabletStats method readFilesUsingIterStack.

private static int readFilesUsingIterStack(VolumeManager fs, ServerContext context, List<TabletFile> files, Authorizations auths, KeyExtent ke, String[] columns, boolean useTableIterators) throws Exception {
    SortedKeyValueIterator<Key, Value> reader;
    List<SortedKeyValueIterator<Key, Value>> readers = new ArrayList<>(files.size());
    for (TabletFile file : files) {
        FileSystem ns = fs.getFileSystemByPath(file.getPath());
        readers.add(FileOperations.getInstance().newReaderBuilder().forFile(file.getPathStr(), ns, ns.getConf(), CryptoServiceFactory.newDefaultInstance()).withTableConfiguration(context.getConfiguration()).build());
    }
    List<IterInfo> emptyIterinfo = Collections.emptyList();
    Map<String, Map<String, String>> emptySsio = Collections.emptyMap();
    TableConfiguration tconf = context.getTableConfiguration(ke.tableId());
    reader = createScanIterator(ke, readers, auths, new byte[] {}, new HashSet<>(), emptyIterinfo, emptySsio, useTableIterators, tconf);
    HashSet<ByteSequence> columnSet = createColumnBSS(columns);
    reader.seek(new Range(ke.prevEndRow(), false, ke.endRow(), true), columnSet, !columnSet.isEmpty());
    int count = 0;
    while (reader.hasTop()) {
        count++;
        reader.next();
    }
    return count;
}
Also used : ArrayList(java.util.ArrayList) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) Range(org.apache.accumulo.core.data.Range) IterInfo(org.apache.accumulo.core.dataImpl.thrift.IterInfo) FileSystem(org.apache.hadoop.fs.FileSystem) Value(org.apache.accumulo.core.data.Value) TabletFile(org.apache.accumulo.core.metadata.TabletFile) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Key(org.apache.accumulo.core.data.Key) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) HashSet(java.util.HashSet)

Example 33 with TabletFile

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

the class CollectTabletStats method main.

public static void main(String[] args) throws Exception {
    final CollectOptions opts = new CollectOptions();
    opts.parseArgs(CollectTabletStats.class.getName(), args);
    String[] columnsTmp = {};
    if (opts.columns != null)
        columnsTmp = opts.columns.split(",");
    final String[] columns = columnsTmp;
    ServerContext context = opts.getServerContext();
    final VolumeManager fs = context.getVolumeManager();
    TableId tableId = context.getTableId(opts.tableName);
    if (tableId == null) {
        log.error("Unable to find table named {}", opts.tableName);
        System.exit(-1);
    }
    TreeMap<KeyExtent, String> tabletLocations = new TreeMap<>();
    List<KeyExtent> candidates = findTablets(context, !opts.selectFarTablets, opts.tableName, tabletLocations);
    if (candidates.size() < opts.numThreads) {
        System.err.println("ERROR : Unable to find " + opts.numThreads + " " + (opts.selectFarTablets ? "far" : "local") + " tablets");
        System.exit(-1);
    }
    List<KeyExtent> tabletsToTest = selectRandomTablets(opts.numThreads, candidates);
    Map<KeyExtent, List<TabletFile>> tabletFiles = new HashMap<>();
    for (KeyExtent ke : tabletsToTest) {
        List<TabletFile> files = getTabletFiles(context, ke);
        tabletFiles.put(ke, files);
    }
    System.out.println();
    System.out.println("run location      : " + InetAddress.getLocalHost().getHostName() + "/" + InetAddress.getLocalHost().getHostAddress());
    System.out.println("num threads       : " + opts.numThreads);
    System.out.println("table             : " + opts.tableName);
    System.out.println("table id          : " + tableId);
    for (KeyExtent ke : tabletsToTest) {
        System.out.println("\t *** Information about tablet " + ke.getUUID() + " *** ");
        System.out.println("\t\t# files in tablet : " + tabletFiles.get(ke).size());
        System.out.println("\t\ttablet location   : " + tabletLocations.get(ke));
        reportHdfsBlockLocations(context, tabletFiles.get(ke));
    }
    System.out.println("%n*** RUNNING TEST ***%n");
    ExecutorService threadPool = Executors.newFixedThreadPool(opts.numThreads);
    for (int i = 0; i < opts.iterations; i++) {
        ArrayList<Test> tests = new ArrayList<>();
        for (final KeyExtent ke : tabletsToTest) {
            final List<TabletFile> files = tabletFiles.get(ke);
            Test test = new Test(ke) {

                @Override
                public int runTest() throws Exception {
                    return readFiles(fs, context.getConfiguration(), files, ke, columns);
                }
            };
            tests.add(test);
        }
        runTest("read files", tests, opts.numThreads, threadPool);
    }
    for (int i = 0; i < opts.iterations; i++) {
        ArrayList<Test> tests = new ArrayList<>();
        for (final KeyExtent ke : tabletsToTest) {
            final List<TabletFile> files = tabletFiles.get(ke);
            Test test = new Test(ke) {

                @Override
                public int runTest() throws Exception {
                    return readFilesUsingIterStack(fs, context, files, opts.auths, ke, columns, false);
                }
            };
            tests.add(test);
        }
        runTest("read tablet files w/ system iter stack", tests, opts.numThreads, threadPool);
    }
    for (int i = 0; i < opts.iterations; i++) {
        ArrayList<Test> tests = new ArrayList<>();
        for (final KeyExtent ke : tabletsToTest) {
            final List<TabletFile> files = tabletFiles.get(ke);
            Test test = new Test(ke) {

                @Override
                public int runTest() throws Exception {
                    return readFilesUsingIterStack(fs, context, files, opts.auths, ke, columns, true);
                }
            };
            tests.add(test);
        }
        runTest("read tablet files w/ table iter stack", tests, opts.numThreads, threadPool);
    }
    try (AccumuloClient client = Accumulo.newClient().from(opts.getClientProps()).build()) {
        for (int i = 0; i < opts.iterations; i++) {
            ArrayList<Test> tests = new ArrayList<>();
            for (final KeyExtent ke : tabletsToTest) {
                Test test = new Test(ke) {

                    @Override
                    public int runTest() throws Exception {
                        return scanTablet(client, opts.tableName, opts.auths, ke.prevEndRow(), ke.endRow(), columns);
                    }
                };
                tests.add(test);
            }
            runTest("read tablet data through accumulo", tests, opts.numThreads, threadPool);
        }
        for (final KeyExtent ke : tabletsToTest) {
            threadPool.submit(() -> {
                try {
                    calcTabletStats(client, opts.tableName, opts.auths, ke, columns);
                } catch (Exception e) {
                    log.error("Failed to calculate tablet stats.", e);
                }
            });
        }
    }
    threadPool.shutdown();
}
Also used : TableId(org.apache.accumulo.core.data.TableId) AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) IOException(java.io.IOException) ServerContext(org.apache.accumulo.server.ServerContext) ExecutorService(java.util.concurrent.ExecutorService) List(java.util.List) ArrayList(java.util.ArrayList) TabletFile(org.apache.accumulo.core.metadata.TabletFile)

Example 34 with TabletFile

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

the class CollectTabletStats method readFiles.

private static int readFiles(VolumeManager fs, AccumuloConfiguration aconf, List<TabletFile> files, KeyExtent ke, String[] columns) throws Exception {
    int count = 0;
    HashSet<ByteSequence> columnSet = createColumnBSS(columns);
    for (TabletFile file : files) {
        FileSystem ns = fs.getFileSystemByPath(file.getPath());
        FileSKVIterator reader = FileOperations.getInstance().newReaderBuilder().forFile(file.getPathStr(), ns, ns.getConf(), CryptoServiceFactory.newDefaultInstance()).withTableConfiguration(aconf).build();
        Range range = new Range(ke.prevEndRow(), false, ke.endRow(), true);
        reader.seek(range, columnSet, !columnSet.isEmpty());
        while (reader.hasTop() && !range.afterEndKey(reader.getTopKey())) {
            count++;
            reader.next();
        }
        reader.close();
    }
    return count;
}
Also used : FileSKVIterator(org.apache.accumulo.core.file.FileSKVIterator) FileSystem(org.apache.hadoop.fs.FileSystem) TabletFile(org.apache.accumulo.core.metadata.TabletFile) Range(org.apache.accumulo.core.data.Range) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence)

Example 35 with TabletFile

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

the class Tablet method importMapFiles.

public void importMapFiles(long tid, Map<TabletFile, MapFileInfo> fileMap, boolean setTime) throws IOException {
    Map<TabletFile, DataFileValue> entries = new HashMap<>(fileMap.size());
    List<String> files = new ArrayList<>();
    for (Entry<TabletFile, MapFileInfo> entry : fileMap.entrySet()) {
        entries.put(entry.getKey(), new DataFileValue(entry.getValue().estimatedSize, 0L));
        files.add(entry.getKey().getPathStr());
    }
    // Clients timeout and will think that this operation failed.
    // Don't do it if we spent too long waiting for the lock
    long now = System.currentTimeMillis();
    synchronized (this) {
        if (isClosed()) {
            throw new IOException("tablet " + extent + " is closed");
        }
        // TODO check seems unneeded now - ACCUMULO-1291
        long lockWait = System.currentTimeMillis() - now;
        if (lockWait > getTabletServer().getConfiguration().getTimeInMillis(Property.GENERAL_RPC_TIMEOUT)) {
            throw new IOException("Timeout waiting " + (lockWait / 1000.) + " seconds to get tablet lock for " + extent);
        }
        List<TabletFile> alreadyImported = bulkImported.get(tid);
        if (alreadyImported != null) {
            for (TabletFile entry : alreadyImported) {
                if (fileMap.remove(entry) != null) {
                    log.trace("Ignoring import of bulk file already imported: {}", entry);
                }
            }
        }
        fileMap.keySet().removeIf(file -> {
            if (bulkImporting.contains(file)) {
                log.info("Ignoring import of bulk file currently importing: " + file);
                return true;
            }
            return false;
        });
        if (fileMap.isEmpty()) {
            return;
        }
        incrementWritesInProgress();
        // prevent other threads from processing this file while its added to the metadata table.
        bulkImporting.addAll(fileMap.keySet());
    }
    try {
        tabletServer.updateBulkImportState(files, BulkImportState.LOADING);
        var storedTabletFile = getDatafileManager().importMapFiles(tid, entries, setTime);
        lastMapFileImportTime = System.currentTimeMillis();
        if (needsSplit()) {
            getTabletServer().executeSplit(this);
        } else {
            compactable.filesAdded(false, storedTabletFile);
        }
    } finally {
        synchronized (this) {
            decrementWritesInProgress();
            if (!bulkImporting.removeAll(fileMap.keySet())) {
                throw new AssertionError("Likely bug in code, always expect to remove something.  Please open an Accumulo issue.");
            }
            try {
                bulkImported.computeIfAbsent(tid, k -> new ArrayList<>()).addAll(fileMap.keySet());
            } catch (Exception ex) {
                log.info(ex.toString(), ex);
            }
            tabletServer.removeBulkImportState(files);
        }
    }
}
Also used : ByteSequence(org.apache.accumulo.core.data.ByteSequence) VolumeChooserEnvironmentImpl(org.apache.accumulo.server.fs.VolumeChooserEnvironmentImpl) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) Text(org.apache.hadoop.io.Text) MetadataTableUtil(org.apache.accumulo.server.util.MetadataTableUtil) FileStatus(org.apache.hadoop.fs.FileStatus) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) Map(java.util.Map) MapFileInfo(org.apache.accumulo.core.dataImpl.thrift.MapFileInfo) MetadataTime(org.apache.accumulo.core.metadata.schema.MetadataTime) DfsLogger(org.apache.accumulo.tserver.log.DfsLogger) BulkImportState(org.apache.accumulo.core.master.thrift.BulkImportState) Property(org.apache.accumulo.core.conf.Property) TabletServer(org.apache.accumulo.tserver.TabletServer) TableState(org.apache.accumulo.core.manager.state.tables.TableState) Compactable(org.apache.accumulo.tserver.compactions.Compactable) DecoderException(org.apache.commons.codec.DecoderException) TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) Deriver(org.apache.accumulo.core.conf.AccumuloConfiguration.Deriver) Set(java.util.Set) Stream(java.util.stream.Stream) Violations(org.apache.accumulo.core.constraints.Violations) UtilWaitThread.sleepUninterruptibly(org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly) TabletFiles(org.apache.accumulo.server.fs.VolumeUtil.TabletFiles) ProblemType(org.apache.accumulo.server.problems.ProblemType) ProblemReports(org.apache.accumulo.server.problems.ProblemReports) ReplicationTableUtil(org.apache.accumulo.server.util.ReplicationTableUtil) DurabilityImpl(org.apache.accumulo.core.clientImpl.DurabilityImpl) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) ArrayList(java.util.ArrayList) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) ColumnUpdate(org.apache.accumulo.core.data.ColumnUpdate) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) Key(org.apache.accumulo.core.data.Key) TabletFile(org.apache.accumulo.core.metadata.TabletFile) ServerContext(org.apache.accumulo.server.ServerContext) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) IOException(java.io.IOException) TabletTime(org.apache.accumulo.server.tablets.TabletTime) Range(org.apache.accumulo.core.data.Range) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ExternalCompactionMetadata(org.apache.accumulo.core.metadata.schema.ExternalCompactionMetadata) Preconditions(com.google.common.base.Preconditions) YieldCallback(org.apache.accumulo.core.iterators.YieldCallback) UserCompactionUtils(org.apache.accumulo.core.clientImpl.UserCompactionUtils) FileUtil(org.apache.accumulo.server.util.FileUtil) LoggerFactory(org.slf4j.LoggerFactory) Status(org.apache.accumulo.server.replication.proto.Replication.Status) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TabletLogger(org.apache.accumulo.core.logging.TabletLogger) Mutation(org.apache.accumulo.core.data.Mutation) VolumeUtil(org.apache.accumulo.server.fs.VolumeUtil) ScanParameters(org.apache.accumulo.tserver.scan.ScanParameters) LocalityGroupUtil(org.apache.accumulo.core.util.LocalityGroupUtil) FileOperations(org.apache.accumulo.core.file.FileOperations) ByteArrayInputStream(java.io.ByteArrayInputStream) Path(org.apache.hadoop.fs.Path) Value(org.apache.accumulo.core.data.Value) ConstraintChecker(org.apache.accumulo.tserver.constraints.ConstraintChecker) ProblemReport(org.apache.accumulo.server.problems.ProblemReport) ConditionChecker(org.apache.accumulo.tserver.ConditionCheckerContext.ConditionChecker) InMemoryMap(org.apache.accumulo.tserver.InMemoryMap) Span(io.opentelemetry.api.trace.Span) Operation(org.apache.accumulo.tserver.TabletStatsKeeper.Operation) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Durability(org.apache.accumulo.core.client.Durability) Collectors(java.util.stream.Collectors) SourceSwitchingIterator(org.apache.accumulo.core.iteratorsImpl.system.SourceSwitchingIterator) FileNotFoundException(java.io.FileNotFoundException) TabletStatsKeeper(org.apache.accumulo.tserver.TabletStatsKeeper) List(java.util.List) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) Pair(org.apache.accumulo.core.util.Pair) ManagerMetadataUtil(org.apache.accumulo.server.util.ManagerMetadataUtil) Entry(java.util.Map.Entry) Optional(java.util.Optional) TraceUtil(org.apache.accumulo.core.trace.TraceUtil) SortedMap(java.util.SortedMap) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) DataInputStream(java.io.DataInputStream) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) ProtobufUtil(org.apache.accumulo.core.protobuf.ProtobufUtil) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) Hex(org.apache.commons.codec.binary.Hex) MinorCompactionReason(org.apache.accumulo.tserver.MinorCompactionReason) HashSet(java.util.HashSet) Volume(org.apache.accumulo.core.volume.Volume) TabletResourceManager(org.apache.accumulo.tserver.TabletServerResourceManager.TabletResourceManager) TabletServerMinCMetrics(org.apache.accumulo.tserver.metrics.TabletServerMinCMetrics) Objects.requireNonNull(java.util.Objects.requireNonNull) UniqueNameAllocator(org.apache.accumulo.server.tablets.UniqueNameAllocator) CompactionStats(org.apache.accumulo.server.compaction.CompactionStats) ServerColumnFamily(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry) Logger(org.slf4j.Logger) ReentrantLock(java.util.concurrent.locks.ReentrantLock) KeeperException(org.apache.zookeeper.KeeperException) Scope(io.opentelemetry.context.Scope) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ScanDispatch(org.apache.accumulo.core.spi.scan.ScanDispatch) VolumeChooserEnvironment(org.apache.accumulo.core.spi.fs.VolumeChooserEnvironment) Constants(org.apache.accumulo.core.Constants) Authorizations(org.apache.accumulo.core.security.Authorizations) TimeUnit(java.util.concurrent.TimeUnit) TservConstraintEnv(org.apache.accumulo.tserver.TservConstraintEnv) Collectors.toList(java.util.stream.Collectors.toList) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ShutdownUtil(org.apache.accumulo.core.util.ShutdownUtil) Collections(java.util.Collections) ColumnType(org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MapFileInfo(org.apache.accumulo.core.dataImpl.thrift.MapFileInfo) IOException(java.io.IOException) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) DecoderException(org.apache.commons.codec.DecoderException) IOException(java.io.IOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) FileNotFoundException(java.io.FileNotFoundException) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) KeeperException(org.apache.zookeeper.KeeperException) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) TabletFile(org.apache.accumulo.core.metadata.TabletFile)

Aggregations

TabletFile (org.apache.accumulo.core.metadata.TabletFile)36 StoredTabletFile (org.apache.accumulo.core.metadata.StoredTabletFile)20 IOException (java.io.IOException)17 Path (org.apache.hadoop.fs.Path)15 ArrayList (java.util.ArrayList)14 DataFileValue (org.apache.accumulo.core.metadata.schema.DataFileValue)14 Key (org.apache.accumulo.core.data.Key)13 FileSystem (org.apache.hadoop.fs.FileSystem)13 HashMap (java.util.HashMap)12 TreeMap (java.util.TreeMap)10 Value (org.apache.accumulo.core.data.Value)8 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)8 HashSet (java.util.HashSet)6 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)6 FileSKVIterator (org.apache.accumulo.core.file.FileSKVIterator)6 SortedKeyValueIterator (org.apache.accumulo.core.iterators.SortedKeyValueIterator)6 Text (org.apache.hadoop.io.Text)6 Map (java.util.Map)5 PartialKey (org.apache.accumulo.core.data.PartialKey)5 List (java.util.List)4