Search in sources :

Example 1 with MapFileInfo

use of org.apache.accumulo.core.dataImpl.thrift.MapFileInfo in project accumulo by apache.

the class ThriftClientHandler method bulkImport.

@Override
public List<TKeyExtent> bulkImport(TInfo tinfo, TCredentials credentials, final long tid, final Map<TKeyExtent, Map<String, MapFileInfo>> files, final boolean setTime) throws ThriftSecurityException {
    if (!security.canPerformSystemActions(credentials)) {
        throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    }
    try {
        return transactionWatcher.run(Constants.BULK_ARBITRATOR_TYPE, tid, () -> {
            List<TKeyExtent> failures = new ArrayList<>();
            for (Entry<TKeyExtent, Map<String, MapFileInfo>> entry : files.entrySet()) {
                TKeyExtent tke = entry.getKey();
                Map<String, MapFileInfo> fileMap = entry.getValue();
                Map<TabletFile, MapFileInfo> fileRefMap = new HashMap<>();
                for (Entry<String, MapFileInfo> mapping : fileMap.entrySet()) {
                    Path path = new Path(mapping.getKey());
                    FileSystem ns = context.getVolumeManager().getFileSystemByPath(path);
                    path = ns.makeQualified(path);
                    fileRefMap.put(new TabletFile(path), mapping.getValue());
                }
                Tablet importTablet = server.getOnlineTablet(KeyExtent.fromThrift(tke));
                if (importTablet == null) {
                    failures.add(tke);
                } else {
                    try {
                        importTablet.importMapFiles(tid, fileRefMap, setTime);
                    } catch (IOException ioe) {
                        log.info("files {} not imported to {}: {}", fileMap.keySet(), KeyExtent.fromThrift(tke), ioe.getMessage());
                        failures.add(tke);
                    }
                }
            }
            return failures;
        });
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MapFileInfo(org.apache.accumulo.core.dataImpl.thrift.MapFileInfo) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) IOException(java.io.IOException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) CancellationException(java.util.concurrent.CancellationException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) TimeoutException(java.util.concurrent.TimeoutException) TabletClosedException(org.apache.accumulo.tserver.tablet.TabletClosedException) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) FileSystem(org.apache.hadoop.fs.FileSystem) TabletFile(org.apache.accumulo.core.metadata.TabletFile) Tablet(org.apache.accumulo.tserver.tablet.Tablet) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with MapFileInfo

use of org.apache.accumulo.core.dataImpl.thrift.MapFileInfo in project accumulo by apache.

the class ThriftClientHandler method loadFiles.

@Override
public void loadFiles(TInfo tinfo, TCredentials credentials, long tid, String dir, Map<TKeyExtent, Map<String, MapFileInfo>> tabletImports, boolean setTime) throws ThriftSecurityException {
    if (!security.canPerformSystemActions(credentials)) {
        throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    }
    transactionWatcher.runQuietly(Constants.BULK_ARBITRATOR_TYPE, tid, () -> {
        tabletImports.forEach((tke, fileMap) -> {
            Map<TabletFile, MapFileInfo> newFileMap = new HashMap<>();
            for (Entry<String, MapFileInfo> mapping : fileMap.entrySet()) {
                Path path = new Path(dir, mapping.getKey());
                FileSystem ns = context.getVolumeManager().getFileSystemByPath(path);
                path = ns.makeQualified(path);
                newFileMap.put(new TabletFile(path), mapping.getValue());
            }
            var files = newFileMap.keySet().stream().map(TabletFile::getPathStr).collect(toList());
            server.updateBulkImportState(files, BulkImportState.INITIAL);
            Tablet importTablet = server.getOnlineTablet(KeyExtent.fromThrift(tke));
            if (importTablet != null) {
                try {
                    server.updateBulkImportState(files, BulkImportState.PROCESSING);
                    importTablet.importMapFiles(tid, newFileMap, setTime);
                } catch (IOException ioe) {
                    log.debug("files {} not imported to {}: {}", fileMap.keySet(), KeyExtent.fromThrift(tke), ioe.getMessage());
                } finally {
                    server.removeBulkImportState(files);
                }
            }
        });
    });
}
Also used : Path(org.apache.hadoop.fs.Path) HashMap(java.util.HashMap) FileSystem(org.apache.hadoop.fs.FileSystem) TabletFile(org.apache.accumulo.core.metadata.TabletFile) MapFileInfo(org.apache.accumulo.core.dataImpl.thrift.MapFileInfo) Tablet(org.apache.accumulo.tserver.tablet.Tablet) IOException(java.io.IOException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)

Example 3 with MapFileInfo

use of org.apache.accumulo.core.dataImpl.thrift.MapFileInfo 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)

Example 4 with MapFileInfo

use of org.apache.accumulo.core.dataImpl.thrift.MapFileInfo in project accumulo by apache.

the class BulkFailureIT method oldLoad.

private static void oldLoad(long txid, ClientContext context, KeyExtent extent, Path path, long size, boolean expectFailure) throws Exception {
    TabletClientService.Iface client = getClient(context, extent);
    try {
        Map<String, MapFileInfo> val = Map.of(path.toString(), new MapFileInfo(size));
        Map<KeyExtent, Map<String, MapFileInfo>> files = Map.of(extent, val);
        client.bulkImport(TraceUtil.traceInfo(), context.rpcCreds(), txid, files.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().toThrift(), Entry::getValue)), false);
        if (expectFailure) {
            fail("Expected RPC to fail");
        }
    } catch (TApplicationException tae) {
        if (!expectFailure) {
            throw tae;
        }
    } finally {
        ThriftUtil.returnClient((TServiceClient) client, context);
    }
}
Also used : Entry(java.util.Map.Entry) MapFileInfo(org.apache.accumulo.core.dataImpl.thrift.MapFileInfo) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) TApplicationException(org.apache.thrift.TApplicationException)

Example 5 with MapFileInfo

use of org.apache.accumulo.core.dataImpl.thrift.MapFileInfo in project accumulo by apache.

the class BulkFailureIT method newLoad.

private static void newLoad(long txid, ClientContext context, KeyExtent extent, Path path, long size, boolean expectFailure) throws Exception {
    TabletClientService.Iface client = getClient(context, extent);
    try {
        Map<String, MapFileInfo> val = Map.of(path.getName(), new MapFileInfo(size));
        Map<KeyExtent, Map<String, MapFileInfo>> files = Map.of(extent, val);
        client.loadFiles(TraceUtil.traceInfo(), context.rpcCreds(), txid, path.getParent().toString(), files.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().toThrift(), Entry::getValue)), false);
        if (!expectFailure) {
            while (!getLoaded(context, extent).contains(path)) {
                Thread.sleep(100);
            }
        }
    } finally {
        ThriftUtil.returnClient((TServiceClient) client, context);
    }
}
Also used : Entry(java.util.Map.Entry) MapFileInfo(org.apache.accumulo.core.dataImpl.thrift.MapFileInfo) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap)

Aggregations

MapFileInfo (org.apache.accumulo.core.dataImpl.thrift.MapFileInfo)5 Map (java.util.Map)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)3 TabletFile (org.apache.accumulo.core.metadata.TabletFile)3 Path (org.apache.hadoop.fs.Path)3 ArrayList (java.util.ArrayList)2 TabletClientService (org.apache.accumulo.core.tabletserver.thrift.TabletClientService)2 Preconditions (com.google.common.base.Preconditions)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Span (io.opentelemetry.api.trace.Span)1 Scope (io.opentelemetry.context.Scope)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1